From b041e3237da2e49df35cfc50c46b5a836f8d9ad5 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 21 Jun 2018 23:23:59 +0200 Subject: [PATCH 001/211] 2.x: Use different wording on blockingForEach() JavaDocs (#6057) --- src/main/java/io/reactivex/Flowable.java | 20 +++++++++----------- src/main/java/io/reactivex/Observable.java | 20 +++++++++----------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 13853d4603..406198507c 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -5472,20 +5472,18 @@ public final T blockingFirst(T defaultItem) { } /** - * Invokes a method on each item emitted by this {@code Flowable} and blocks until the Flowable - * completes. - *

- * Note: This will block even if the underlying Flowable is asynchronous. + * Consumes the upstream {@code Flowable} in a blocking fashion and invokes the given + * {@code Consumer} with each upstream item on the current thread until the + * upstream terminates. *

* *

- * This is similar to {@link Flowable#subscribe(Subscriber)}, but it blocks. Because it blocks it does not - * need the {@link Subscriber#onComplete()} or {@link Subscriber#onError(Throwable)} methods. If the - * underlying Flowable terminates with an error, rather than calling {@code onError}, this method will - * throw an exception. - * - *

The difference between this method and {@link #subscribe(Consumer)} is that the {@code onNext} action - * is executed on the emission thread instead of the current thread. + * Note: the method will only return if the upstream terminates or the current + * thread is interrupted. + *

+ *

This method executes the {@code Consumer} on the current thread while + * {@link #subscribe(Consumer)} executes the consumer on the original caller thread of the + * sequence. *

*
Backpressure:
*
The operator consumes the source {@code Flowable} in an unbounded manner diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index feddca1fed..045fe3d987 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -5018,20 +5018,18 @@ public final T blockingFirst(T defaultItem) { } /** - * Invokes a method on each item emitted by this {@code Observable} and blocks until the Observable - * completes. - *

- * Note: This will block even if the underlying Observable is asynchronous. + * Consumes the upstream {@code Observable} in a blocking fashion and invokes the given + * {@code Consumer} with each upstream item on the current thread until the + * upstream terminates. *

* *

- * This is similar to {@link Observable#subscribe(Observer)}, but it blocks. Because it blocks it does not - * need the {@link Observer#onComplete()} or {@link Observer#onError(Throwable)} methods. If the - * underlying Observable terminates with an error, rather than calling {@code onError}, this method will - * throw an exception. - * - *

The difference between this method and {@link #subscribe(Consumer)} is that the {@code onNext} action - * is executed on the emission thread instead of the current thread. + * Note: the method will only return if the upstream terminates or the current + * thread is interrupted. + *

+ *

This method executes the {@code Consumer} on the current thread while + * {@link #subscribe(Consumer)} executes the consumer on the original caller thread of the + * sequence. *

*
Scheduler:
*
{@code blockingForEach} does not operate by default on a particular {@link Scheduler}.
From 2e39d9923e034cd8648bba8cfd7fd15f3d3031b9 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 22 Jun 2018 00:38:18 +0200 Subject: [PATCH 002/211] 2.x: Expand {X}Processor JavaDocs by syncing with {X}Subject docs (#6054) * 2.x: Expand {X}Processor JavaDocs by syncing with {X}Subject docs * A-an * Fix javadoc warnings --- src/main/java/io/reactivex/Maybe.java | 2 +- src/main/java/io/reactivex/Observable.java | 1 - .../reactivex/processors/AsyncProcessor.java | 109 +++++++++++++-- .../processors/BehaviorProcessor.java | 20 +-- .../processors/PublishProcessor.java | 85 +++++++++--- .../reactivex/processors/ReplayProcessor.java | 130 +++++++++++++----- .../processors/UnicastProcessor.java | 122 ++++++++++++++-- .../io/reactivex/subjects/UnicastSubject.java | 17 ++- 8 files changed, 388 insertions(+), 98 deletions(-) diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index de4cbec178..918dbeccd5 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -272,9 +272,9 @@ public static Flowable concat(Publisher *

* + *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
*
Scheduler:
diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 045fe3d987..70fff76e3a 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -13173,7 +13173,6 @@ public final Observable throttleLatest(long timeout, TimeUnit unit, Scheduler * will be emitted by the resulting ObservableSource. *

* - *

*

*
Scheduler:
*
{@code throttleWithTimeout} operates by default on the {@code computation} {@link Scheduler}.
diff --git a/src/main/java/io/reactivex/processors/AsyncProcessor.java b/src/main/java/io/reactivex/processors/AsyncProcessor.java index 37d6937e49..6ef3044d6d 100644 --- a/src/main/java/io/reactivex/processors/AsyncProcessor.java +++ b/src/main/java/io/reactivex/processors/AsyncProcessor.java @@ -28,9 +28,90 @@ *

* *

- * 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. + * This processor does not have a public constructor by design; a new empty instance of this + * {@code AsyncProcessor} can be created via the {@link #create()} method. + *

+ * Since an {@code AsyncProcessor} is a Reactive Streams {@code Processor} type, + * {@code null}s are not allowed (Rule 2.13) + * as parameters to {@link #onNext(Object)} and {@link #onError(Throwable)}. Such calls will result in a + * {@link NullPointerException} being thrown and the processor's state is not changed. + *

+ * {@code AsyncProcessor} is a {@link io.reactivex.Flowable} as well as a {@link FlowableProcessor} and supports backpressure from the downstream but + * its {@link Subscriber}-side consumes items in an unbounded manner. + *

+ * When this {@code AsyncProcessor} is terminated via {@link #onError(Throwable)}, the + * last observed item (if any) is cleared and late {@link Subscriber}s only receive + * the {@code onError} event. + *

+ * The {@code AsyncProcessor} caches the latest item internally and it emits this item only when {@code onComplete} is called. + * Therefore, it is not recommended to use this {@code Processor} with infinite or never-completing sources. + *

+ * Even though {@code AsyncProcessor} implements the {@link Subscriber} interface, calling + * {@code onSubscribe} is not required (Rule 2.12) + * if the processor is used as a standalone source. However, calling {@code onSubscribe} + * after the {@code AsyncProcessor} reached its terminal state will result in the + * given {@link Subscription} being canceled immediately. + *

+ * Calling {@link #onNext(Object)}, {@link #onError(Throwable)} and {@link #onComplete()} + * is required to be serialized (called from the same thread or called non-overlappingly from different threads + * through external means of serialization). The {@link #toSerialized()} method available to all {@code FlowableProcessor}s + * provides such serialization and also protects against reentrance (i.e., when a downstream {@code Subscriber} + * consuming this processor also wants to call {@link #onNext(Object)} on this processor recursively). + * The implementation of {@code onXXX} methods are technically thread-safe but non-serialized calls + * to them may lead to undefined state in the currently subscribed {@code Subscriber}s. + *

+ * This {@code AsyncProcessor} supports the standard state-peeking methods {@link #hasComplete()}, {@link #hasThrowable()}, + * {@link #getThrowable()} and {@link #hasSubscribers()} as well as means to read the very last observed value - + * after this {@code AsyncProcessor} has been completed - in a non-blocking and thread-safe + * manner via {@link #hasValue()}, {@link #getValue()}, {@link #getValues()} or {@link #getValues(Object[])}. + *

+ *
Backpressure:
+ *
The {@code AsyncProcessor} honors the backpressure of the downstream {@code Subscriber}s and won't emit + * its single value to a particular {@code Subscriber} until that {@code Subscriber} has requested an item. + * When the {@code AsyncProcessor} is subscribed to a {@link io.reactivex.Flowable}, the processor consumes this + * {@code Flowable} in an unbounded manner (requesting `Long.MAX_VALUE`) as only the very last upstream item is + * retained by it. + *
+ *
Scheduler:
+ *
{@code AsyncProcessor} does not operate by default on a particular {@link io.reactivex.Scheduler} and + * the {@code Subscriber}s get notified on the thread where the terminating {@code onError} or {@code onComplete} + * methods were invoked.
+ *
Error handling:
+ *
When the {@link #onError(Throwable)} is called, the {@code AsyncProcessor} enters into a terminal state + * and emits the same {@code Throwable} instance to the last set of {@code Subscriber}s. During this emission, + * if one or more {@code Subscriber}s dispose their respective {@code Subscription}s, the + * {@code Throwable} is delivered to the global error handler via + * {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)} (multiple times if multiple {@code Subscriber}s + * cancel at once). + * If there were no {@code Subscriber}s subscribed to this {@code AsyncProcessor} when the {@code onError()} + * was called, the global error handler is not invoked. + *
+ *
+ *

+ * Example usage: + *


+ * AsyncProcessor<Object> processor = AsyncProcessor.create();
+ * 
+ * TestSubscriber<Object> ts1 = processor.test();
+ *
+ * ts1.assertEmpty();
+ *
+ * processor.onNext(1);
+ *
+ * // AsyncProcessor only emits when onComplete was called.
+ * ts1.assertEmpty();
+ *
+ * processor.onNext(2);
+ * processor.onComplete();
+ *
+ * // onComplete triggers the emission of the last cached item and the onComplete event.
+ * ts1.assertResult(2);
+ *
+ * TestSubscriber<Object> ts2 = processor.test();
  *
+ * // late Subscribers receive the last cached item too
+ * ts2.assertResult(2);
+ * 
* @param the value type */ public final class AsyncProcessor extends FlowableProcessor { @@ -75,7 +156,7 @@ public void onSubscribe(Subscription s) { s.cancel(); return; } - // PublishSubject doesn't bother with request coordination. + // AsyncProcessor doesn't bother with request coordination. s.request(Long.MAX_VALUE); } @@ -168,9 +249,9 @@ protected void subscribeActual(Subscriber s) { /** * Tries to add the given subscriber to the subscribers array atomically - * or returns false if the subject has terminated. + * or returns false if the processor has terminated. * @param ps the subscriber to add - * @return true if successful, false if the subject has terminated + * @return true if successful, false if the processor has terminated */ boolean add(AsyncSubscription ps) { for (;;) { @@ -192,8 +273,8 @@ boolean add(AsyncSubscription ps) { } /** - * Atomically removes the given subscriber if it is subscribed to the subject. - * @param ps the subject to remove + * Atomically removes the given subscriber if it is subscribed to this processor. + * @param ps the subscriber's subscription wrapper to remove */ @SuppressWarnings("unchecked") void remove(AsyncSubscription ps) { @@ -232,18 +313,18 @@ void remove(AsyncSubscription ps) { } /** - * Returns true if the subject has any value. + * Returns true if this processor has any value. *

The method is thread-safe. - * @return true if the subject has any value + * @return true if this processor has any value */ public boolean hasValue() { return subscribers.get() == TERMINATED && value != null; } /** - * Returns a single value the Subject currently has or null if no such value exists. + * Returns a single value this processor currently has or null if no such value exists. *

The method is thread-safe. - * @return a single value the Subject currently has or null if no such value exists + * @return a single value this processor currently has or null if no such value exists */ @Nullable public T getValue() { @@ -251,9 +332,9 @@ public T getValue() { } /** - * Returns an Object array containing snapshot all values of the Subject. + * Returns an Object array containing snapshot all values of this processor. *

The method is thread-safe. - * @return the array containing the snapshot of all values of the Subject + * @return the array containing the snapshot of all values of this processor * @deprecated in 2.1.14; put the result of {@link #getValue()} into an array manually, will be removed in 3.x */ @Deprecated @@ -263,7 +344,7 @@ public Object[] getValues() { } /** - * Returns a typed array containing a snapshot of all values of the Subject. + * Returns a typed array containing a snapshot of all values of this processor. *

The method follows the conventions of Collection.toArray by setting the array element * after the last value to null (if the capacity permits). *

The method is thread-safe. diff --git a/src/main/java/io/reactivex/processors/BehaviorProcessor.java b/src/main/java/io/reactivex/processors/BehaviorProcessor.java index 4c407a7e7f..5ee462824f 100644 --- a/src/main/java/io/reactivex/processors/BehaviorProcessor.java +++ b/src/main/java/io/reactivex/processors/BehaviorProcessor.java @@ -85,11 +85,13 @@ * after the {@code BehaviorProcessor} reached its terminal state will result in the * given {@code Subscription} being cancelled immediately. *

- * Calling {@link #onNext(Object)}, {@link #onError(Throwable)} and {@link #onComplete()} + * Calling {@link #onNext(Object)}, {@link #offer(Object)}, {@link #onError(Throwable)} and {@link #onComplete()} * is required to be serialized (called from the same thread or called non-overlappingly from different threads * through external means of serialization). The {@link #toSerialized()} method available to all {@code FlowableProcessor}s * provides such serialization and also protects against reentrance (i.e., when a downstream {@code Subscriber} * consuming this processor also wants to call {@link #onNext(Object)} on this processor recursively). + * Note that serializing over {@link #offer(Object)} is not supported through {@code toSerialized()} because it is a method + * available on the {@code PublishProcessor} and {@code BehaviorProcessor} classes only. *

* This {@code BehaviorProcessor} supports the standard state-peeking methods {@link #hasComplete()}, {@link #hasThrowable()}, * {@link #getThrowable()} and {@link #hasSubscribers()} as well as means to read the latest observed value @@ -127,34 +129,34 @@ * Example usage: *

 {@code
 
-  // observer will receive all events.
+  // subscriber will receive all events.
   BehaviorProcessor processor = BehaviorProcessor.create("default");
-  processor.subscribe(observer);
+  processor.subscribe(subscriber);
   processor.onNext("one");
   processor.onNext("two");
   processor.onNext("three");
 
-  // observer will receive the "one", "two" and "three" events, but not "zero"
+  // subscriber will receive the "one", "two" and "three" events, but not "zero"
   BehaviorProcessor processor = BehaviorProcessor.create("default");
   processor.onNext("zero");
   processor.onNext("one");
-  processor.subscribe(observer);
+  processor.subscribe(subscriber);
   processor.onNext("two");
   processor.onNext("three");
 
-  // observer will receive only onComplete
+  // subscriber will receive only onComplete
   BehaviorProcessor processor = BehaviorProcessor.create("default");
   processor.onNext("zero");
   processor.onNext("one");
   processor.onComplete();
-  processor.subscribe(observer);
+  processor.subscribe(subscriber);
 
-  // observer will receive only onError
+  // subscriber will receive only onError
   BehaviorProcessor processor = BehaviorProcessor.create("default");
   processor.onNext("zero");
   processor.onNext("one");
   processor.onError(new RuntimeException("error"));
-  processor.subscribe(observer);
+  processor.subscribe(subscriber);
   } 
  *
  * @param 
diff --git a/src/main/java/io/reactivex/processors/PublishProcessor.java b/src/main/java/io/reactivex/processors/PublishProcessor.java
index 725b5fed91..3f409555df 100644
--- a/src/main/java/io/reactivex/processors/PublishProcessor.java
+++ b/src/main/java/io/reactivex/processors/PublishProcessor.java
@@ -28,17 +28,67 @@
  *
  * 

* - * - *

The processor 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 PublishProcessor - * to multiple sources (note on serialization though) unlike the standard Subscriber contract. 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 Flowables are constructed, the PublishProcessor can't be instantiated through - * {@code new} but must be created via the {@link #create()} method. + *

+ * This processor does not have a public constructor by design; a new empty instance of this + * {@code PublishProcessor} can be created via the {@link #create()} method. + *

+ * Since a {@code PublishProcessor} is a Reactive Streams {@code Processor} type, + * {@code null}s are not allowed (Rule 2.13) as + * parameters to {@link #onNext(Object)} and {@link #onError(Throwable)}. Such calls will result in a + * {@link NullPointerException} being thrown and the processor's state is not changed. + *

+ * {@code PublishProcessor} is a {@link io.reactivex.Flowable} as well as a {@link FlowableProcessor}, + * however, it does not coordinate backpressure between different subscribers and between an + * upstream source and a subscriber. If an upstream item is received via {@link #onNext(Object)}, if + * a subscriber is not ready to receive an item, that subscriber is terminated via a {@link MissingBackpressureException}. + * To avoid this case, use {@link #offer(Object)} and retry sometime later if it returned false. + * The {@code PublishProcessor}'s {@link Subscriber}-side consumes items in an unbounded manner. + *

+ * For a multicasting processor type that also coordinates between the downstream {@code Subscriber}s and the upstream + * source as well, consider using {@link MulticastProcessor}. + *

+ * When this {@code PublishProcessor} is terminated via {@link #onError(Throwable)} or {@link #onComplete()}, + * late {@link Subscriber}s only receive the respective terminal event. + *

+ * Unlike a {@link BehaviorProcessor}, a {@code PublishProcessor} doesn't retain/cache items, therefore, a new + * {@code Subscriber} won't receive any past items. + *

+ * Even though {@code PublishProcessor} implements the {@link Subscriber} interface, calling + * {@code onSubscribe} is not required (Rule 2.12) + * if the processor is used as a standalone source. However, calling {@code onSubscribe} + * after the {@code PublishProcessor} reached its terminal state will result in the + * given {@link Subscription} being canceled immediately. + *

+ * Calling {@link #onNext(Object)}, {@link #offer(Object)}, {@link #onError(Throwable)} and {@link #onComplete()} + * is required to be serialized (called from the same thread or called non-overlappingly from different threads + * through external means of serialization). The {@link #toSerialized()} method available to all {@link FlowableProcessor}s + * provides such serialization and also protects against reentrance (i.e., when a downstream {@code Subscriber} + * consuming this processor also wants to call {@link #onNext(Object)} on this processor recursively). + * Note that serializing over {@link #offer(Object)} is not supported through {@code toSerialized()} because it is a method + * available on the {@code PublishProcessor} and {@code BehaviorProcessor} classes only. + *

+ * This {@code PublishProcessor} supports the standard state-peeking methods {@link #hasComplete()}, {@link #hasThrowable()}, + * {@link #getThrowable()} and {@link #hasSubscribers()}. + *

+ *
Backpressure:
+ *
The processor does not coordinate backpressure for its subscribers and implements a weaker {@code onSubscribe} which + * calls requests Long.MAX_VALUE from the incoming Subscriptions. This makes it possible to subscribe the {@code PublishProcessor} + * to multiple sources (note on serialization though) unlike the standard {@code Subscriber} contract. Child subscribers, however, are not overflown but receive an + * {@link IllegalStateException} in case their requested amount is zero.
+ *
Scheduler:
+ *
{@code PublishProcessor} does not operate by default on a particular {@link io.reactivex.Scheduler} and + * the {@code Subscriber}s get notified on the thread the respective {@code onXXX} methods were invoked.
+ *
Error handling:
+ *
When the {@link #onError(Throwable)} is called, the {@code PublishProcessor} enters into a terminal state + * and emits the same {@code Throwable} instance to the last set of {@code Subscriber}s. During this emission, + * if one or more {@code Subscriber}s cancel their respective {@code Subscription}s, the + * {@code Throwable} is delivered to the global error handler via + * {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)} (multiple times if multiple {@code Subscriber}s + * cancel at once). + * If there were no {@code Subscriber}s subscribed to this {@code PublishProcessor} when the {@code onError()} + * was called, the global error handler is not invoked. + *
+ *
* * Example usage: *
 {@code
@@ -55,6 +105,7 @@
 
   } 
* @param the value type multicasted to Subscribers. + * @see MulticastProcessor */ public final class PublishProcessor extends FlowableProcessor { /** The terminated indicator for the subscribers array. */ @@ -113,9 +164,9 @@ protected void subscribeActual(Subscriber t) { /** * Tries to add the given subscriber to the subscribers array atomically - * or returns false if the subject has terminated. + * or returns false if this processor has terminated. * @param ps the subscriber to add - * @return true if successful, false if the subject has terminated + * @return true if successful, false if this processor has terminated */ boolean add(PublishSubscription ps) { for (;;) { @@ -137,8 +188,8 @@ boolean add(PublishSubscription ps) { } /** - * Atomically removes the given subscriber if it is subscribed to the subject. - * @param ps the subject to remove + * Atomically removes the given subscriber if it is subscribed to this processor. + * @param ps the subscription wrapping a subscriber to remove */ @SuppressWarnings("unchecked") void remove(PublishSubscription ps) { @@ -182,7 +233,7 @@ public void onSubscribe(Subscription s) { s.cancel(); return; } - // PublishSubject doesn't bother with request coordination. + // PublishProcessor doesn't bother with request coordination. s.request(Long.MAX_VALUE); } @@ -288,7 +339,7 @@ static final class PublishSubscription extends AtomicLong implements Subscrip private static final long serialVersionUID = 3562861878281475070L; /** The actual subscriber. */ final Subscriber actual; - /** The subject state. */ + /** The parent processor servicing this subscriber. */ final PublishProcessor parent; /** diff --git a/src/main/java/io/reactivex/processors/ReplayProcessor.java b/src/main/java/io/reactivex/processors/ReplayProcessor.java index 3d2fc83f5d..b16ef80f68 100644 --- a/src/main/java/io/reactivex/processors/ReplayProcessor.java +++ b/src/main/java/io/reactivex/processors/ReplayProcessor.java @@ -56,19 +56,73 @@ * * *

- * The ReplayProcessor can be created in bounded and unbounded mode. It can be bounded by + * The {@code ReplayProcessor} can be created in bounded and unbounded mode. It can be bounded by * size (maximum number of elements retained at most) and/or time (maximum age of elements replayed). - * - *

This Processor respects the backpressure behavior of its Subscribers (individually) but - * does not coordinate their request amounts towards the upstream (because there might not be any). - * - *

Note that Subscribers receive a continuous sequence of values after they subscribed even - * if an individual item gets delayed due to backpressure. - * *

+ * Since a {@code ReplayProcessor} is a Reactive Streams {@code Processor}, + * {@code null}s are not allowed (Rule 2.13) as + * parameters to {@link #onNext(Object)} and {@link #onError(Throwable)}. Such calls will result in a + * {@link NullPointerException} being thrown and the processor's state is not changed. + *

+ * This {@code ReplayProcessor} respects the individual backpressure behavior of its {@code Subscriber}s but + * does not coordinate their request amounts towards the upstream (because there might not be any) and + * consumes the upstream in an unbounded manner (requesting {@code Long.MAX_VALUE}). + * Note that {@code Subscriber}s receive a continuous sequence of values after they subscribed even + * if an individual item gets delayed due to backpressure. * Due to concurrency requirements, a size-bounded {@code ReplayProcessor} may hold strong references to more source * emissions than specified. - * + *

+ * When this {@code ReplayProcessor} is terminated via {@link #onError(Throwable)} or {@link #onComplete()}, + * late {@link Subscriber}s will receive the retained/cached items first (if any) followed by the respective + * terminal event. If the {@code ReplayProcessor} has a time-bound, the age of the retained/cached items are still considered + * when replaying and thus it may result in no items being emitted before the terminal event. + *

+ * Once an {@code Subscriber} has subscribed, it will receive items continuously from that point on. Bounds only affect how + * many past items a new {@code Subscriber} will receive before it catches up with the live event feed. + *

+ * Even though {@code ReplayProcessor} implements the {@code Subscriber} interface, calling + * {@code onSubscribe} is not required (Rule 2.12) + * if the processor is used as a standalone source. However, calling {@code onSubscribe} + * after the {@code ReplayProcessor} reached its terminal state will result in the + * given {@code Subscription} being canceled immediately. + *

+ * Calling {@link #onNext(Object)}, {@link #onError(Throwable)} and {@link #onComplete()} + * is required to be serialized (called from the same thread or called non-overlappingly from different threads + * through external means of serialization). The {@link #toSerialized()} method available to all {@code FlowableProcessor}s + * provides such serialization and also protects against reentrance (i.e., when a downstream {@code Subscriber} + * consuming this processor also wants to call {@link #onNext(Object)} on this processor recursively). + *

+ * This {@code ReplayProcessor} supports the standard state-peeking methods {@link #hasComplete()}, {@link #hasThrowable()}, + * {@link #getThrowable()} and {@link #hasSubscribers()} as well as means to read the retained/cached items + * in a non-blocking and thread-safe manner via {@link #hasValue()}, {@link #getValue()}, + * {@link #getValues()} or {@link #getValues(Object[])}. + *

+ * Note that due to concurrency requirements, a size- and time-bounded {@code ReplayProcessor} may hold strong references to more + * source emissions than specified while it isn't terminated yet. Use the {@link #cleanupBuffer()} to allow + * such inaccessible items to be cleaned up by GC once no consumer references them anymore. + *

+ *
Backpressure:
+ *
This {@code ReplayProcessor} respects the individual backpressure behavior of its {@code Subscriber}s but + * does not coordinate their request amounts towards the upstream (because there might not be any) and + * consumes the upstream in an unbounded manner (requesting {@code Long.MAX_VALUE}). + * Note that {@code Subscriber}s receive a continuous sequence of values after they subscribed even + * if an individual item gets delayed due to backpressure.
+ *
Scheduler:
+ *
{@code ReplayProcessor} does not operate by default on a particular {@link io.reactivex.Scheduler} and + * the {@code Subscriber}s get notified on the thread the respective {@code onXXX} methods were invoked. + * Time-bound {@code ReplayProcessor}s use the given {@code Scheduler} in their {@code create} methods + * as time source to timestamp of items received for the age checks.
+ *
Error handling:
+ *
When the {@link #onError(Throwable)} is called, the {@code ReplayProcessor} enters into a terminal state + * and emits the same {@code Throwable} instance to the last set of {@code Subscriber}s. During this emission, + * if one or more {@code Subscriber}s cancel their respective {@code Subscription}s, the + * {@code Throwable} is delivered to the global error handler via + * {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)} (multiple times if multiple {@code Subscriber}s + * cancel at once). + * If there were no {@code Subscriber}s subscribed to this {@code ReplayProcessor} when the {@code onError()} + * was called, the global error handler is not invoked. + *
+ *
*

* Example usage: *

 {@code
@@ -132,10 +186,10 @@ public static  ReplayProcessor create() {
      * due to frequent array-copying.
      *
      * @param 
-     *          the type of items observed and emitted by the Subject
+     *          the type of items observed and emitted by this type of processor
      * @param capacityHint
      *          the initial buffer capacity
-     * @return the created subject
+     * @return the created processor
      */
     @CheckReturnValue
     @NonNull
@@ -149,19 +203,19 @@ public static  ReplayProcessor create(int capacityHint) {
      * In this setting, the {@code ReplayProcessor} holds at most {@code size} items in its internal buffer and
      * discards the oldest item.
      * 

- * When observers subscribe to a terminated {@code ReplayProcessor}, they are guaranteed to see at most + * When {@code Subscriber}s subscribe to a terminated {@code ReplayProcessor}, they are guaranteed to see at most * {@code size} {@code onNext} events followed by a termination event. *

- * If an observer subscribes while the {@code ReplayProcessor} is active, it will observe all items in the + * If a {@code Subscriber} subscribes while the {@code ReplayProcessor} is active, it will observe all items in the * buffer at that point in time and each item observed afterwards, even if the buffer evicts items due to - * the size constraint in the mean time. In other words, once an Observer subscribes, it will receive items + * the size constraint in the mean time. In other words, once a {@code Subscriber} subscribes, it will receive items * without gaps in the sequence. * * @param - * the type of items observed and emitted by the Subject + * the type of items observed and emitted by this type of processor * @param maxSize * the maximum number of buffered items - * @return the created subject + * @return the created processor */ @CheckReturnValue @NonNull @@ -179,8 +233,8 @@ public static ReplayProcessor createWithSize(int maxSize) { * of the bounded implementations without the interference of the eviction policies. * * @param - * the type of items observed and emitted by the Subject - * @return the created subject + * the type of items observed and emitted by this type of processor + * @return the created processor */ /* test */ static ReplayProcessor createUnbounded() { return new ReplayProcessor(new SizeBoundReplayBuffer(Integer.MAX_VALUE)); @@ -194,29 +248,29 @@ public static ReplayProcessor createWithSize(int maxSize) { * converted to milliseconds. For example, an item arrives at T=0 and the max age is set to 5; at T>=5 * this first item is then evicted by any subsequent item or termination event, leaving the buffer empty. *

- * Once the subject is terminated, observers subscribing to it will receive items that remained in the + * Once the processor is terminated, {@code Subscriber}s subscribing to it will receive items that remained in the * buffer after the terminal event, regardless of their age. *

- * If an observer subscribes while the {@code ReplayProcessor} is active, it will observe only those items + * If a {@code Subscriber} subscribes while the {@code ReplayProcessor} is active, it will observe only those items * from within the buffer that have an age less than the specified time, and each item observed thereafter, - * even if the buffer evicts items due to the time constraint in the mean time. In other words, once an - * observer subscribes, it observes items without gaps in the sequence except for any outdated items at the + * even if the buffer evicts items due to the time constraint in the mean time. In other words, once a + * {@code Subscriber} subscribes, it observes items without gaps in the sequence except for any outdated items at the * beginning of the sequence. *

* Note that terminal notifications ({@code onError} and {@code onComplete}) trigger eviction as well. For * example, with a max age of 5, the first item is observed at T=0, then an {@code onComplete} notification - * arrives at T=10. If an observer subscribes at T=11, it will find an empty {@code ReplayProcessor} with just + * arrives at T=10. If a {@code Subscriber} subscribes at T=11, it will find an empty {@code ReplayProcessor} with just * an {@code onComplete} notification. * * @param - * the type of items observed and emitted by the Subject + * the type of items observed and emitted by this type of processor * @param maxAge * the maximum age of the contained items * @param unit * the time unit of {@code time} * @param scheduler * the {@link Scheduler} that provides the current time - * @return the created subject + * @return the created processor */ @CheckReturnValue @NonNull @@ -232,22 +286,22 @@ public static ReplayProcessor createWithTime(long maxAge, TimeUnit unit, * items from the start of the buffer if their age becomes less-than or equal to the supplied age in * milliseconds or the buffer reaches its {@code size} limit. *

- * When observers subscribe to a terminated {@code ReplayProcessor}, they observe the items that remained in + * When {@code Subscriber}s subscribe to a terminated {@code ReplayProcessor}, they observe the items that remained in * the buffer after the terminal notification, regardless of their age, but at most {@code size} items. *

- * If an observer subscribes while the {@code ReplayProcessor} is active, it will observe only those items + * If a {@code Subscriber} subscribes while the {@code ReplayProcessor} is active, it will observe only those items * from within the buffer that have age less than the specified time and each subsequent item, even if the - * buffer evicts items due to the time constraint in the mean time. In other words, once an observer + * buffer evicts items due to the time constraint in the mean time. In other words, once a {@code Subscriber} * subscribes, it observes items without gaps in the sequence except for the outdated items at the beginning * of the sequence. *

* Note that terminal notifications ({@code onError} and {@code onComplete}) trigger eviction as well. For * example, with a max age of 5, the first item is observed at T=0, then an {@code onComplete} notification - * arrives at T=10. If an observer subscribes at T=11, it will find an empty {@code ReplayProcessor} with just + * arrives at T=10. If a {@code Subscriber} subscribes at T=11, it will find an empty {@code ReplayProcessor} with just * an {@code onComplete} notification. * * @param - * the type of items observed and emitted by the Subject + * the type of items observed and emitted by this type of processor * @param maxAge * the maximum age of the contained items * @param unit @@ -256,7 +310,7 @@ public static ReplayProcessor createWithTime(long maxAge, TimeUnit unit, * the maximum number of buffered items * @param scheduler * the {@link Scheduler} that provides the current time - * @return the created subject + * @return the created processor */ @CheckReturnValue @NonNull @@ -387,18 +441,18 @@ public void cleanupBuffer() { } /** - * Returns a single value the Subject currently has or null if no such value exists. + * Returns the latest value this processor has or null if no such value exists. *

The method is thread-safe. - * @return a single value the Subject currently has or null if no such value exists + * @return the latest value this processor currently has or null if no such value exists */ public T getValue() { return buffer.getValue(); } /** - * Returns an Object array containing snapshot all values of the Subject. + * Returns an Object array containing snapshot all values of this processor. *

The method is thread-safe. - * @return the array containing the snapshot of all values of the Subject + * @return the array containing the snapshot of all values of this processor */ public Object[] getValues() { @SuppressWarnings("unchecked") @@ -412,7 +466,7 @@ public Object[] getValues() { } /** - * Returns a typed array containing a snapshot of all values of the Subject. + * Returns a typed array containing a snapshot of all values of this processor. *

The method follows the conventions of Collection.toArray by setting the array element * after the last value to null (if the capacity permits). *

The method is thread-safe. @@ -436,9 +490,9 @@ public boolean hasThrowable() { } /** - * Returns true if the subject has any value. + * Returns true if this processor has any value. *

The method is thread-safe. - * @return true if the subject has any value + * @return true if the processor has any value */ public boolean hasValue() { return buffer.size() != 0; // NOPMD diff --git a/src/main/java/io/reactivex/processors/UnicastProcessor.java b/src/main/java/io/reactivex/processors/UnicastProcessor.java index e712f1f5c8..62abd68cd4 100644 --- a/src/main/java/io/reactivex/processors/UnicastProcessor.java +++ b/src/main/java/io/reactivex/processors/UnicastProcessor.java @@ -29,18 +29,122 @@ import io.reactivex.plugins.RxJavaPlugins; /** - * Processor that allows only a single Subscriber to subscribe to it during its lifetime. - * - *

This processor buffers notifications and replays them to the Subscriber as requested. - * - *

This processor holds an unbounded internal buffer. - * - *

If more than one Subscriber attempts to subscribe to this Processor, they - * will receive an IllegalStateException if this Processor hasn't terminated yet, + * A {@link FlowableProcessor} variant that queues up events until a single {@link Subscriber} subscribes to it, replays + * those events to it until the {@code Subscriber} catches up and then switches to relaying events live to + * this single {@code Subscriber} until this {@code UnicastProcessor} terminates or the {@code Subscriber} cancels + * its subscription. + *

+ * + *

+ * This processor does not have a public constructor by design; a new empty instance of this + * {@code UnicastProcessor} can be created via the following {@code create} methods that + * allow specifying the retention policy for items: + *

    + *
  • {@link #create()} - creates an empty, unbounded {@code UnicastProcessor} that + * caches all items and the terminal event it receives.
  • + *
  • {@link #create(int)} - creates an empty, unbounded {@code UnicastProcessor} + * with a hint about how many total items one expects to retain.
  • + *
  • {@link #create(boolean)} - creates an empty, unbounded {@code UnicastProcessor} that + * optionally delays an error it receives and replays it after the regular items have been emitted.
  • + *
  • {@link #create(int, Runnable)} - creates an empty, unbounded {@code UnicastProcessor} + * with a hint about how many total items one expects to retain and a callback that will be + * called exactly once when the {@code UnicastProcessor} gets terminated or the single {@code Subscriber} cancels.
  • + *
  • {@link #create(int, Runnable, boolean)} - creates an empty, unbounded {@code UnicastProcessor} + * with a hint about how many total items one expects to retain and a callback that will be + * called exactly once when the {@code UnicastProcessor} gets terminated or the single {@code Subscriber} cancels + * and optionally delays an error it receives and replays it after the regular items have been emitted.
  • + *
+ *

+ * If more than one {@code Subscriber} attempts to subscribe to this Processor, they + * will receive an {@link IllegalStateException} if this {@link UnicastProcessor} hasn't terminated yet, * or the Subscribers receive the terminal event (error or completion) if this * Processor has terminated. *

- * + * The {@code UnicastProcessor} buffers notifications and replays them to the single {@code Subscriber} as requested, + * for which it holds upstream items an unbounded internal buffer until they can be emitted. + *

+ * Since a {@code UnicastProcessor} is a Reactive Streams {@code Processor}, + * {@code null}s are not allowed (Rule 2.13) as + * parameters to {@link #onNext(Object)} and {@link #onError(Throwable)}. Such calls will result in a + * {@link NullPointerException} being thrown and the processor's state is not changed. + *

+ * Since a {@code UnicastProcessor} is a {@link io.reactivex.Flowable} as well as a {@link FlowableProcessor}, it + * honors the downstream backpressure but consumes an upstream source in an unbounded manner (requesting {@code Long.MAX_VALUE}). + *

+ * When this {@code UnicastProcessor} is terminated via {@link #onError(Throwable)} the current or late single {@code Subscriber} + * may receive the {@code Throwable} before any available items could be emitted. To make sure an {@code onError} event is delivered + * to the {@code Subscriber} after the normal items, create a {@code UnicastProcessor} with the {@link #create(boolean)} or + * {@link #create(int, Runnable, boolean)} factory methods. + *

+ * Even though {@code UnicastProcessor} implements the {@code Subscriber} interface, calling + * {@code onSubscribe} is not required (Rule 2.12) + * if the processor is used as a standalone source. However, calling {@code onSubscribe} + * after the {@code UnicastProcessor} reached its terminal state will result in the + * given {@code Subscription} being canceled immediately. + *

+ * Calling {@link #onNext(Object)}, {@link #onError(Throwable)} and {@link #onComplete()} + * is required to be serialized (called from the same thread or called non-overlappingly from different threads + * through external means of serialization). The {@link #toSerialized()} method available to all {@link FlowableProcessor}s + * provides such serialization and also protects against reentrance (i.e., when a downstream {@code Subscriber} + * consuming this processor also wants to call {@link #onNext(Object)} on this processor recursively). + *

+ * This {@code UnicastProcessor} supports the standard state-peeking methods {@link #hasComplete()}, {@link #hasThrowable()}, + * {@link #getThrowable()} and {@link #hasSubscribers()}. + *

+ *
Backpressure:
+ *
{@code UnicastProcessor} honors the downstream backpressure but consumes an upstream source + * (if any) in an unbounded manner (requesting {@code Long.MAX_VALUE}).
+ *
Scheduler:
+ *
{@code UnicastProcessor} does not operate by default on a particular {@link io.reactivex.Scheduler} and + * the single {@code Subscriber} gets notified on the thread the respective {@code onXXX} methods were invoked.
+ *
Error handling:
+ *
When the {@link #onError(Throwable)} is called, the {@code UnicastProcessor} enters into a terminal state + * and emits the same {@code Throwable} instance to the current single {@code Subscriber}. During this emission, + * if the single {@code Subscriber}s cancels its respective {@code Subscription}s, the + * {@code Throwable} is delivered to the global error handler via + * {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}. + * If there were no {@code Subscriber}s subscribed to this {@code UnicastProcessor} when the {@code onError()} + * was called, the global error handler is not invoked. + *
+ *
+ *

+ * Example usage: + *


+ * UnicastProcessor<Integer> processor = UnicastProcessor.create();
+ *
+ * TestSubscriber<Integer> ts1 = processor.test();
+ *
+ * // fresh UnicastProcessors are empty
+ * ts1.assertEmpty();
+ *
+ * TestSubscriber<Integer> ts2 = processor.test();
+ *
+ * // A UnicastProcessor only allows one Subscriber during its lifetime
+ * ts2.assertFailure(IllegalStateException.class);
+ *
+ * processor.onNext(1);
+ * ts1.assertValue(1);
+ *
+ * processor.onNext(2);
+ * ts1.assertValues(1, 2);
+ *
+ * processor.onComplete();
+ * ts1.assertResult(1, 2);
+ *
+ * // ----------------------------------------------------
+ *
+ * UnicastProcessor<Integer> processor2 = UnicastProcessor.create();
+ *
+ * // a UnicastProcessor caches events until its single Subscriber subscribes
+ * processor2.onNext(1);
+ * processor2.onNext(2);
+ * processor2.onComplete();
+ *
+ * TestSubscriber<Integer> ts3 = processor2.test();
+ *
+ * // the cached events are emitted in order
+ * ts3.assertResult(1, 2);
+ * 
* * @param the value type received and emitted by this Processor subclass * @since 2.0 diff --git a/src/main/java/io/reactivex/subjects/UnicastSubject.java b/src/main/java/io/reactivex/subjects/UnicastSubject.java index 61700dec55..f19a8b0a38 100644 --- a/src/main/java/io/reactivex/subjects/UnicastSubject.java +++ b/src/main/java/io/reactivex/subjects/UnicastSubject.java @@ -90,14 +90,13 @@ *
*
Scheduler:
*
{@code UnicastSubject} does not operate by default on a particular {@link io.reactivex.Scheduler} and - * the {@code Observer}s get notified on the thread the respective {@code onXXX} methods were invoked.
+ * the single {@code Observer} gets notified on the thread the respective {@code onXXX} methods were invoked. *
Error handling:
*
When the {@link #onError(Throwable)} is called, the {@code UnicastSubject} enters into a terminal state - * and emits the same {@code Throwable} instance to the last set of {@code Observer}s. During this emission, - * if one or more {@code Observer}s dispose their respective {@code Disposable}s, the + * and emits the same {@code Throwable} instance to the current single {@code Observer}. During this emission, + * if the single {@code Observer}s disposes its respective {@code Disposable}, the * {@code Throwable} is delivered to the global error handler via - * {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)} (multiple times if multiple {@code Observer}s - * cancel at once). + * {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}. * If there were no {@code Observer}s subscribed to this {@code UnicastSubject} when the {@code onError()} * was called, the global error handler is not invoked. *
@@ -130,10 +129,10 @@ * * UnicastSubject<Integer> subject2 = UnicastSubject.create(); * - * // a UnicastSubject caches events util its single Observer subscribes - * subject.onNext(1); - * subject.onNext(2); - * subject.onComplete(); + * // a UnicastSubject caches events until its single Observer subscribes + * subject2.onNext(1); + * subject2.onNext(2); + * subject2.onComplete(); * * TestObserver<Integer> to3 = subject2.test(); * From 869c2aaefa2f6bd88265816992d5d1bf9fa10588 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 22 Jun 2018 09:39:12 +0200 Subject: [PATCH 003/211] Release 2.1.15 --- CHANGES.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 0cfef94c45..2e23a0c7e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,41 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.1.15 - June 22, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.1.15%7C)) + +#### API changes + +- [Pull 6026](https://github.com/ReactiveX/RxJava/pull/6026): Add `blockingSubscribe` overload with prefetch amount allowing bounded backpressure. +- [Pull 6052](https://github.com/ReactiveX/RxJava/pull/6052): Change `{PublishSubject|PublishProcessor}.subscribeActual` to `protected`. They were accidentally made public and there is no reason to call them outside of RxJava internals. + +#### Documentation changes + +- [Pull 6031](https://github.com/ReactiveX/RxJava/pull/6031): Inline `CompositeDisposable` JavaDoc. +- [Pull 6042](https://github.com/ReactiveX/RxJava/pull/6042): Fix `MulticastProcessor` JavaDoc comment. +- [Pull 6049](https://github.com/ReactiveX/RxJava/pull/6049): Make it explicit that `throttleWithTimout` is an alias of `debounce`. +- [Pull 6053](https://github.com/ReactiveX/RxJava/pull/6053): Add `Maybe` marble diagrams 06/21/a +- [Pull 6057](https://github.com/ReactiveX/RxJava/pull/6057): Use different wording on `blockingForEach()` JavaDocs. +- [Pull 6054](https://github.com/ReactiveX/RxJava/pull/6054): Expand `{X}Processor` JavaDocs by syncing with `{X}Subject` docs. + +#### Performance enhancements + +- [Pull 6021](https://github.com/ReactiveX/RxJava/pull/6021): Add full implementation for `Single.flatMapPublisher` so it doesn't batch requests. +- [Pull 6024](https://github.com/ReactiveX/RxJava/pull/6024): Dedicated `{Single|Maybe}.flatMap{Publisher|Observable}` & `andThen(Observable|Publisher)` implementations. +- [Pull 6028](https://github.com/ReactiveX/RxJava/pull/6028): Improve `Observable.takeUntil`. + +#### Bugfixes + +- [Pull 6019](https://github.com/ReactiveX/RxJava/pull/6019): Fix `Single.takeUntil`, `Maybe.takeUntil` dispose behavior. +- [Pull 5947](https://github.com/ReactiveX/RxJava/pull/5947): Fix `groupBy` eviction so that source is cancelled and reduce volatile reads. +- [Pull 6036](https://github.com/ReactiveX/RxJava/pull/6036): Fix disposed `LambdaObserver.onError` to route to global error handler. +- [Pull 6045](https://github.com/ReactiveX/RxJava/pull/6045): Fix check in `BlockingSubscriber` that would always be false due to wrong variable. + +#### Other changes + +- [Pull 6022](https://github.com/ReactiveX/RxJava/pull/6022): Add TCK for `MulticastProcessor` & `{0..1}.flatMapPublisher` +- [Pull 6029](https://github.com/ReactiveX/RxJava/pull/6029): Upgrade to Gradle 4.3.1, add `TakeUntilPerf`. +- [Pull 6033](https://github.com/ReactiveX/RxJava/pull/6033): Update & fix grammar of `DESIGN.md` + ### Version 2.1.14 - May 23, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.1.14%7C)) #### API changes From 8bbe51d10519fc8a5c4f0fbf15f4af3e265e80b7 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 22 Jun 2018 15:58:44 +0200 Subject: [PATCH 004/211] 2.x: Fix concatMap{Single|Maybe} null emission on dispose race (#6060) --- .../mixed/FlowableConcatMapMaybe.java | 1 + .../mixed/FlowableConcatMapSingle.java | 1 + .../mixed/ObservableConcatMapMaybe.java | 1 + .../mixed/ObservableConcatMapSingle.java | 1 + .../mixed/FlowableConcatMapMaybeTest.java | 31 +++++++++++++++++++ .../mixed/FlowableConcatMapSingleTest.java | 30 ++++++++++++++++++ .../mixed/ObservableConcatMapMaybeTest.java | 30 ++++++++++++++++++ .../mixed/ObservableConcatMapSingleTest.java | 31 +++++++++++++++++++ 8 files changed, 126 insertions(+) diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybe.java index 0b7eb3bd7d..bafc9d4aab 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybe.java @@ -218,6 +218,7 @@ void drain() { if (cancelled) { queue.clear(); item = null; + break; } int s = state; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingle.java index 3164d16a4b..654e7cabe5 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingle.java @@ -213,6 +213,7 @@ void drain() { if (cancelled) { queue.clear(); item = null; + break; } int s = state; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java index 8331c38f23..f62669b705 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java @@ -199,6 +199,7 @@ void drain() { if (cancelled) { queue.clear(); item = null; + break; } int s = state; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java index 45799e8916..82afca6341 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java @@ -194,6 +194,7 @@ void drain() { if (cancelled) { queue.clear(); item = null; + break; } int s = state; diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybeTest.java index 334b2e4d69..5e6ef2c82b 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybeTest.java @@ -394,4 +394,35 @@ public void cancelNoConcurrentClean() { assertTrue(operator.queue.isEmpty()); } + + @Test + public void innerSuccessDisposeRace() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + + final MaybeSubject ms = MaybeSubject.create(); + + final TestSubscriber ts = Flowable.just(1) + .hide() + .concatMapMaybe(Functions.justFunction(ms)) + .test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + ms.onSuccess(1); + } + }; + Runnable r2 = new Runnable() { + @Override + public void run() { + ts.dispose(); + } + }; + + TestHelper.race(r1, r2); + + ts.assertNoErrors(); + } + } + } diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingleTest.java index c572e9ba30..6f07102918 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingleTest.java @@ -309,4 +309,34 @@ public void cancelNoConcurrentClean() { assertTrue(operator.queue.isEmpty()); } + + @Test + public void innerSuccessDisposeRace() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + + final SingleSubject ss = SingleSubject.create(); + + final TestSubscriber ts = Flowable.just(1) + .hide() + .concatMapSingle(Functions.justFunction(ss)) + .test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + ss.onSuccess(1); + } + }; + Runnable r2 = new Runnable() { + @Override + public void run() { + ts.dispose(); + } + }; + + TestHelper.race(r1, r2); + + ts.assertNoErrors(); + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java index 8fbd2937f1..fb732ff878 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java @@ -416,4 +416,34 @@ public void checkUnboundedInnerQueue() { to.assertResult(1, 2, 3, 4); } + + @Test + public void innerSuccessDisposeRace() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + + final MaybeSubject ms = MaybeSubject.create(); + + final TestObserver to = Observable.just(1) + .hide() + .concatMapMaybe(Functions.justFunction(ms)) + .test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + ms.onSuccess(1); + } + }; + Runnable r2 = new Runnable() { + @Override + public void run() { + to.dispose(); + } + }; + + TestHelper.race(r1, r2); + + to.assertNoErrors(); + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java index bdd4f9e4cc..b5743dd5d7 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java @@ -353,4 +353,35 @@ public void checkUnboundedInnerQueue() { to.assertResult(1, 2, 3, 4); } + + @Test + public void innerSuccessDisposeRace() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + + final SingleSubject ss = SingleSubject.create(); + + final TestObserver to = Observable.just(1) + .hide() + .concatMapSingle(Functions.justFunction(ss)) + .test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + ss.onSuccess(1); + } + }; + Runnable r2 = new Runnable() { + @Override + public void run() { + to.dispose(); + } + }; + + TestHelper.race(r1, r2); + + to.assertNoErrors(); + } + } + } From 83f2bd771ee172a2154e0fb30c5ffcaf8f71433c Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 26 Jun 2018 09:45:57 +0200 Subject: [PATCH 005/211] Release 2.1.16 --- CHANGES.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2e23a0c7e4..91bd6b465c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,14 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.1.16 - June 26, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.1.16%7C)) + +This is a hotfix release for a late-identified issue with `concatMapMaybe` and `concatMapSingle`. + +#### Bugfixes + +- [Pull 6060](https://github.com/ReactiveX/RxJava/pull/6060): Fix `concatMap{Single|Maybe}` null emission on success-dispose race. + ### Version 2.1.15 - June 22, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.1.15%7C)) #### API changes From 27ce955dfc9b2457ae09cdbbe3c9a0542c5eb2a6 Mon Sep 17 00:00:00 2001 From: akarnokd Date: Wed, 27 Jun 2018 12:10:16 +0200 Subject: [PATCH 006/211] 2.x: Fix Javadoc warnings on empty

--- src/main/java/io/reactivex/Flowable.java | 2 +- src/main/java/io/reactivex/Observable.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 406198507c..04a31f471d 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -5481,7 +5481,7 @@ public final T blockingFirst(T defaultItem) { * Note: the method will only return if the upstream terminates or the current * thread is interrupted. *

- *

This method executes the {@code Consumer} on the current thread while + * This method executes the {@code Consumer} on the current thread while * {@link #subscribe(Consumer)} executes the consumer on the original caller thread of the * sequence. *

diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 70fff76e3a..c74ab3f7d4 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -5027,7 +5027,7 @@ public final T blockingFirst(T defaultItem) { * Note: the method will only return if the upstream terminates or the current * thread is interrupted. *

- *

This method executes the {@code Consumer} on the current thread while + * This method executes the {@code Consumer} on the current thread while * {@link #subscribe(Consumer)} executes the consumer on the original caller thread of the * sequence. *

From 6b07923f2c51d76c45e3879f9c7b9d9ed9ccfb93 Mon Sep 17 00:00:00 2001 From: Aleksandr Podkutin Date: Sat, 30 Jun 2018 13:20:06 +0200 Subject: [PATCH 007/211] Fix links for Single class (#6066) * Change observable.html to single.html * Delete completable.html link which doesn't exist --- src/main/java/io/reactivex/Single.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 89fe25c6f9..84e96defbb 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -51,7 +51,7 @@ *

* *

- * For more information see the ReactiveX + * For more information see the ReactiveX * documentation. * * @param @@ -3591,7 +3591,6 @@ public final R to(Function, R> convert) { * * @return a {@link Completable} that calls {@code onComplete} on it's subscriber when the source {@link Single} * calls {@code onSuccess}. - * @see ReactiveX documentation: Completable * @since 2.0 * @deprecated see {@link #ignoreElement()} instead, will be removed in 3.0 */ @@ -3614,7 +3613,6 @@ public final Completable toCompletable() { * * @return a {@link Completable} that calls {@code onComplete} on it's observer when the source {@link Single} * calls {@code onSuccess}. - * @see ReactiveX documentation: Completable * @since 2.1.13 */ @CheckReturnValue From 909920a5f13f5acc6507d6de2b62370df7e86573 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 4 Jul 2018 11:13:17 +0200 Subject: [PATCH 008/211] 2.x: Adjust JavaDocs dl/dd entry stylesheet (#6070) --- build.gradle | 1 + gradle/stylesheet.css | 346 +++++++++++++++++++++++++++--------------- 2 files changed, 224 insertions(+), 123 deletions(-) diff --git a/build.gradle b/build.gradle index 8b9203ee06..2f33e66093 100644 --- a/build.gradle +++ b/build.gradle @@ -91,6 +91,7 @@ javadoc { options.addStringOption("top").value = "" options.addStringOption("doctitle").value = "" options.addStringOption("header").value = "" + options.stylesheetFile = new File(projectDir, "gradle/stylesheet.css"); options.links( "https://docs.oracle.com/javase/7/docs/api/", diff --git a/gradle/stylesheet.css b/gradle/stylesheet.css index 7f1f6e733b..52b6b690b0 100644 --- a/gradle/stylesheet.css +++ b/gradle/stylesheet.css @@ -2,16 +2,19 @@ /* Overall document style */ + +@import url('http://github.com/resources/fonts/dejavu.css'); + body { background-color:#ffffff; color:#353833; - font-family:Arial, Helvetica, sans-serif; - font-size:76%; + font-family:'DejaVu Sans', Arial, Helvetica, sans-serif; + font-size:14px; margin:0; } a:link, a:visited { text-decoration:none; - color:#4c6b87; + color:#4A6782; } a:hover, a:focus { text-decoration:none; @@ -19,7 +22,7 @@ a:hover, a:focus { } a:active { text-decoration:none; - color:#4c6b87; + color:#4A6782; } a[name] { color:#353833; @@ -29,41 +32,51 @@ a[name]:hover { color:#353833; } pre { - font-size:1.3em; + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; } h1 { - font-size:1.8em; + font-size:20px; } h2 { - font-size:1.5em; + font-size:18px; } h3 { - font-size:1.4em; + font-size:16px; + font-style:italic; } h4 { - font-size:1.3em; + font-size:13px; } h5 { - font-size:1.2em; + font-size:12px; } h6 { - font-size:1.1em; + font-size:11px; } ul { list-style-type:disc; } code, tt { - font-size:1.2em; + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; + margin-top:8px; + line-height:1.4em; } dt code { - font-size:1.2em; + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; } table tr td dt code { - font-size:1.2em; + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; vertical-align:top; + padding-top:4px; } sup { - font-size:.6em; + font-size:8px; } /* Document title and Copyright styles @@ -76,9 +89,9 @@ Document title and Copyright styles .aboutLanguage { float:right; padding:0px 21px; - font-size:.8em; + font-size:11px; z-index:200; - margin-top:-7px; + margin-top:-9px; } .legalCopy { margin-left:.5em; @@ -92,9 +105,6 @@ Document title and Copyright styles } .tab { background-color:#0066FF; - background-image:url(http://github.com/resources/titlebar.gif); - background-position:left top; - background-repeat:no-repeat; color:#ffffff; padding:8px; width:5em; @@ -104,17 +114,15 @@ Document title and Copyright styles Navigation bar styles */ .bar { - background-image:url(http://github.com/resources/background.gif); - background-repeat:repeat-x; + background-color:#4D7A97; color:#FFFFFF; padding:.8em .5em .4em .8em; height:auto;/*height:1.8em;*/ - font-size:1em; + font-size:11px; margin:0; } .topNav { - background-image:url(http://github.com/resources/background.gif); - background-repeat:repeat-x; + background-color:#4D7A97; color:#FFFFFF; float:left; padding:0; @@ -123,11 +131,11 @@ Navigation bar styles height:2.8em; padding-top:10px; overflow:hidden; + font-size:12px; } .bottomNav { margin-top:10px; - background-image:url(http://github.com/resources/background.gif); - background-repeat:repeat-x; + background-color:#4D7A97; color:#FFFFFF; float:left; padding:0; @@ -136,18 +144,20 @@ Navigation bar styles height:2.8em; padding-top:10px; overflow:hidden; + font-size:12px; } .subNav { background-color:#dee3e9; - border-bottom:1px solid #9eadc0; float:left; width:100%; overflow:hidden; + font-size:12px; } .subNav div { clear:left; float:left; padding:0 0 5px 6px; + text-transform:uppercase; } ul.navList, ul.subNavList { float:left; @@ -157,27 +167,33 @@ ul.navList, ul.subNavList { ul.navList li{ list-style:none; float:left; - padding:3px 6px; + padding: 5px 6px; + text-transform:uppercase; } ul.subNavList li{ list-style:none; float:left; - font-size:90%; } .topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { color:#FFFFFF; text-decoration:none; + text-transform:uppercase; } .topNav a:hover, .bottomNav a:hover { text-decoration:none; color:#bb7a2a; + text-transform:uppercase; } .navBarCell1Rev { - background-image:url(http://github.com/resources/tab.gif); - background-color:#a88834; - color:#FFFFFF; + background-color:#F8981D; + color:#253441; margin: auto 5px; - border:1px solid #c9aa44; +} +.skipNav { + position:absolute; + top:auto; + left:-9999px; + overflow:hidden; } /* Page header and footer styles @@ -191,8 +207,11 @@ Page header and footer styles margin:10px; position:relative; } +.indexHeader span{ + margin-right:15px; +} .indexHeader h1 { - font-size:1.3em; + font-size:13px; } .title { color:#2c4557; @@ -202,7 +221,7 @@ Page header and footer styles margin:5px 0 0 0; } .header ul { - margin:0 0 25px 0; + margin:0 0 15px 0; padding:0; } .footer ul { @@ -210,24 +229,22 @@ Page header and footer styles } .header ul li, .footer ul li { list-style:none; - font-size:1.2em; + font-size:13px; } /* Heading styles */ div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { background-color:#dee3e9; - border-top:1px solid #9eadc0; - border-bottom:1px solid #9eadc0; + border:1px solid #d0d9e0; margin:0 0 6px -8px; - padding:2px 5px; + padding:7px 5px; } ul.blockList ul.blockList ul.blockList li.blockList h3 { background-color:#dee3e9; - border-top:1px solid #9eadc0; - border-bottom:1px solid #9eadc0; + border:1px solid #d0d9e0; margin:0 0 6px -8px; - padding:2px 5px; + padding:7px 5px; } ul.blockList ul.blockList li.blockList h3 { padding:0; @@ -247,10 +264,10 @@ Page layout container styles .indexContainer { margin:10px; position:relative; - font-size:1.0em; + font-size:12px; } .indexContainer h2 { - font-size:1.1em; + font-size:13px; padding:0 0 3px 0; } .indexContainer ul { @@ -259,15 +276,18 @@ Page layout container styles } .indexContainer ul li { list-style:none; + padding-top:2px; } .contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { - font-size:1.1em; + font-size:12px; font-weight:bold; margin:10px 0 0 0; color:#4E4E4E; } -.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { - margin:10px 0 10px 20px; +/*.contentContainer .description dl dd, */.contentContainer .details dl dd, .serializedFormContainer dl dd { + margin:5px 0 10px 0px; + font-size:14px; + font-family:'DejaVu Sans Mono',monospace; } .serializedFormContainer dl.nameValue dt { margin-left:1px; @@ -306,25 +326,24 @@ ul.blockList, ul.blockListLast { } ul.blockList li.blockList, ul.blockListLast li.blockList { list-style:none; - margin-bottom:25px; + margin-bottom:15px; + line-height:1.4; } ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { padding:0px 20px 5px 10px; - border:1px solid #9eadc0; - background-color:#f9f9f9; + border:1px solid #ededed; + background-color:#f8f8f8; } ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { padding:0 0 5px 8px; background-color:#ffffff; - border:1px solid #9eadc0; - border-top:none; + border:none; } ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { margin-left:0; padding-left:0; padding-bottom:15px; border:none; - border-bottom:1px solid #9eadc0; } ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { list-style:none; @@ -338,107 +357,155 @@ table tr td dl, table tr td dl dt, table tr td dl dd { /* Table styles */ -.contentContainer table, .classUseContainer table, .constantValuesContainer table { - border-bottom:1px solid #9eadc0; - width:100%; -} -.contentContainer ul li table, .classUseContainer ul li table, .constantValuesContainer ul li table { +.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary { width:100%; + border-left:1px solid #EEE; + border-right:1px solid #EEE; + border-bottom:1px solid #EEE; } -.contentContainer .description table, .contentContainer .details table { - border-bottom:none; -} -.contentContainer ul li table th.colOne, .contentContainer ul li table th.colFirst, .contentContainer ul li table th.colLast, .classUseContainer ul li table th, .constantValuesContainer ul li table th, .contentContainer ul li table td.colOne, .contentContainer ul li table td.colFirst, .contentContainer ul li table td.colLast, .classUseContainer ul li table td, .constantValuesContainer ul li table td{ - vertical-align:top; - padding-right:20px; -} -.contentContainer ul li table th.colLast, .classUseContainer ul li table th.colLast,.constantValuesContainer ul li table th.colLast, -.contentContainer ul li table td.colLast, .classUseContainer ul li table td.colLast,.constantValuesContainer ul li table td.colLast, -.contentContainer ul li table th.colOne, .classUseContainer ul li table th.colOne, -.contentContainer ul li table td.colOne, .classUseContainer ul li table td.colOne { - padding-right:3px; +.overviewSummary, .memberSummary { + padding:0px; } -.overviewSummary caption, .packageSummary caption, .contentContainer ul.blockList li.blockList caption, .summary caption, .classUseContainer caption, .constantValuesContainer caption { +.overviewSummary caption, .memberSummary caption, .typeSummary caption, +.useSummary caption, .constantsSummary caption, .deprecatedSummary caption { position:relative; text-align:left; background-repeat:no-repeat; - color:#FFFFFF; + color:#253441; font-weight:bold; clear:none; overflow:hidden; padding:0px; + padding-top:10px; + padding-left:1px; margin:0px; -} -caption a:link, caption a:hover, caption a:active, caption a:visited { + white-space:pre; +} +.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link, +.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link, +.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover, +.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover, +.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active, +.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active, +.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited, +.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited { color:#FFFFFF; } -.overviewSummary caption span, .packageSummary caption span, .contentContainer ul.blockList li.blockList caption span, .summary caption span, .classUseContainer caption span, .constantValuesContainer caption span { +.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span, +.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span { white-space:nowrap; - padding-top:8px; - padding-left:8px; - display:block; + padding-top:5px; + padding-left:12px; + padding-right:12px; + padding-bottom:7px; + display:inline-block; float:left; - background-image:url(http://github.com/resources/titlebar.gif); - height:18px; + background-color:#F8981D; + border: none; + height:16px; } -.overviewSummary .tabEnd, .packageSummary .tabEnd, .contentContainer ul.blockList li.blockList .tabEnd, .summary .tabEnd, .classUseContainer .tabEnd, .constantValuesContainer .tabEnd { - width:10px; - background-image:url(http://github.com/resources/titlebar_end.gif); - background-repeat:no-repeat; - background-position:top right; - position:relative; +.memberSummary caption span.activeTableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; float:left; + background-color:#F8981D; + height:16px; } -ul.blockList ul.blockList li.blockList table { - margin:0 0 12px 0px; - width:100%; +.memberSummary caption span.tableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#4D7A97; + height:16px; +} +.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab { + padding-top:0px; + padding-left:0px; + padding-right:0px; + background-image:none; + float:none; + display:inline; } -.tableSubHeadingColor { - background-color: #EEEEFF; +.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd, +.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd { + display:none; + width:5px; + position:relative; + float:left; + background-color:#F8981D; } -.altColor { - background-color:#eeeeef; +.memberSummary .activeTableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + float:left; + background-color:#F8981D; } -.rowColor { - background-color:#ffffff; +.memberSummary .tableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + background-color:#4D7A97; + float:left; + } -.overviewSummary td, .packageSummary td, .contentContainer ul.blockList li.blockList td, .summary td, .classUseContainer td, .constantValuesContainer td { +.overviewSummary td, .memberSummary td, .typeSummary td, +.useSummary td, .constantsSummary td, .deprecatedSummary td { text-align:left; - padding:3px 3px 3px 7px; + padding:0px 0px 12px 10px; +} +th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, +td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ + vertical-align:top; + padding-right:0px; + padding-top:8px; + padding-bottom:3px; } -th.colFirst, th.colLast, th.colOne, .constantValuesContainer th { +th.colFirst, th.colLast, th.colOne, .constantsSummary th { background:#dee3e9; - border-top:1px solid #9eadc0; - border-bottom:1px solid #9eadc0; text-align:left; - padding:3px 3px 3px 7px; -} -td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { - font-weight:bold; + padding:8px 3px 3px 7px; } td.colFirst, th.colFirst { - border-left:1px solid #9eadc0; white-space:nowrap; + font-size:13px; } td.colLast, th.colLast { - border-right:1px solid #9eadc0; + font-size:13px; } td.colOne, th.colOne { - border-right:1px solid #9eadc0; - border-left:1px solid #9eadc0; + font-size:13px; +} +.overviewSummary td.colFirst, .overviewSummary th.colFirst, +.useSummary td.colFirst, .useSummary th.colFirst, +.overviewSummary td.colOne, .overviewSummary th.colOne, +.memberSummary td.colFirst, .memberSummary th.colFirst, +.memberSummary td.colOne, .memberSummary th.colOne, +.typeSummary td.colFirst{ + width:25%; + vertical-align:top; } -table.overviewSummary { - padding:0px; - margin-left:0px; +td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { + font-weight:bold; } -table.overviewSummary td.colFirst, table.overviewSummary th.colFirst, -table.overviewSummary td.colOne, table.overviewSummary th.colOne { - width:25%; - vertical-align:middle; +.tableSubHeadingColor { + background-color:#EEEEFF; } -table.packageSummary td.colFirst, table.overviewSummary th.colFirst { - width:25%; - vertical-align:middle; +.altColor { + background-color:#FFFFFF; +} +.rowColor { + background-color:#EEEEEF; } /* Content styles @@ -453,6 +520,24 @@ Content styles .docSummary { padding:0; } + +ul.blockList ul.blockList ul.blockList li.blockList h3 { + font-style:normal; +} + +div.block { + font-size:14px; + font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; +} + +td.colLast div { + padding-top:0px; +} + + +td.colLast a { + padding-bottom:3px; +} /* Formatting effect styles */ @@ -463,12 +548,27 @@ Formatting effect styles h1.hidden { visibility:hidden; overflow:hidden; - font-size:.9em; + font-size:10px; } .block { display:block; - margin:3px 0 0 0; + margin:3px 10px 2px 0px; + color:#474747; } -.strong { +.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink, +.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel, +.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink { font-weight:bold; -} \ No newline at end of file +} +.deprecationComment, .emphasizedPhrase, .interfaceName { + font-style:italic; +} + +div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase, +div.block div.block span.interfaceName { + font-style:normal; +} + +div.contentContainer ul.blockList li.blockList h2{ + padding-bottom:0px; +} From e29b57b666954d37129da17430e592631ff17a79 Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Sun, 8 Jul 2018 12:58:17 +0200 Subject: [PATCH 009/211] Add marble diagram to the Single.never method (#6074) * Add marble diagram to the Single.never method * Use correct marble diagram URL for Single.never method --- src/main/java/io/reactivex/Single.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 84e96defbb..7385455421 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -1162,6 +1162,8 @@ public static Flowable mergeDelayError( /** * Returns a singleton instance of a never-signalling Single (only calls onSubscribe). + *

+ * *

*
Scheduler:
*
{@code never} does not operate by default on a particular {@link Scheduler}.
@@ -2603,7 +2605,7 @@ public final T blockingGet() { * Example: *

      * // Step 1: Create the consumer type that will be returned by the SingleOperator.apply():
-     * 
+     *
      * public final class CustomSingleObserver<T> implements SingleObserver<T>, Disposable {
      *
      *     // The downstream's SingleObserver that will receive the onXXX events

From c8a98520ee38152d8acce56bdb0a9e9127ccf7cc Mon Sep 17 00:00:00 2001
From: Aleksandar Simic 
Date: Sun, 8 Jul 2018 20:27:18 +0200
Subject: [PATCH 010/211] Add marble diagram to the Single.filter method
 (#6075)

* Add marble diagram to the Single.filter method

* Use correct marble diagram URL for Single.filter method
---
 src/main/java/io/reactivex/Single.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java
index 7385455421..a97e3f1efa 100644
--- a/src/main/java/io/reactivex/Single.java
+++ b/src/main/java/io/reactivex/Single.java
@@ -2373,7 +2373,7 @@ public final Single doOnDispose(final Action onDispose) {
      * Filters the success item of the Single via a predicate function and emitting it if the predicate
      * returns true, completing otherwise.
      * 

- * + * *

*
Scheduler:
*
{@code filter} does not operate by default on a particular {@link Scheduler}.
From e51cf16db0d9d100da09476aa0dab5b1c3c35de8 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 9 Jul 2018 10:35:45 +0200 Subject: [PATCH 011/211] 2.x: Add Maybe.hide() marble diagram (#6078) --- src/main/java/io/reactivex/Maybe.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 918dbeccd5..3a4ec3a76d 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -3090,6 +3090,8 @@ public final Completable flatMapCompletable(final Function + * *

Allows preventing certain identity-based * optimizations (fusion). *

From fd76594dc7e19d4da889613f2d9afdf6043879b9 Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Tue, 10 Jul 2018 09:44:54 +0200 Subject: [PATCH 012/211] Add marble diagrams to the Single.delay method (#6076) * Add marble diagrams to the Single.delay method * Update marbles for Single.delay with error events * Use correct marble diagram URLs for Single.delay methods --- src/main/java/io/reactivex/Single.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index a97e3f1efa..0d8677ea73 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -1980,6 +1980,8 @@ public final Flowable concatWith(SingleSource other) { /** * Delays the emission of the success signal from the current Single by the specified amount. * An error signal will not be delayed. + *

+ * *

*
Scheduler:
*
{@code delay} operates by default on the {@code computation} {@link Scheduler}.
@@ -1998,6 +2000,8 @@ public final Single delay(long time, TimeUnit unit) { /** * Delays the emission of the success or error signal from the current Single by the specified amount. + *

+ * *

*
Scheduler:
*
{@code delay} operates by default on the {@code computation} {@link Scheduler}.
@@ -2019,6 +2023,8 @@ public final Single delay(long time, TimeUnit unit, boolean delayError) { /** * Delays the emission of the success signal from the current Single by the specified amount. * An error signal will not be delayed. + *

+ * *

*
Scheduler:
*
you specify the {@link Scheduler} where the non-blocking wait and emission happens
@@ -2041,6 +2047,8 @@ public final Single delay(final long time, final TimeUnit unit, final Schedul /** * Delays the emission of the success or error signal from the current Single by the specified amount. + *

+ * *

*
Scheduler:
*
you specify the {@link Scheduler} where the non-blocking wait and emission happens
From 7e301d44d6dee9dce12f5417b41134f3a9eda12f Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 11 Jul 2018 09:19:02 +0200 Subject: [PATCH 013/211] 2.x: Add Completable.takeUntil(Completable) operator (#6079) --- src/main/java/io/reactivex/Completable.java | 26 ++ .../CompletableTakeUntilCompletable.java | 145 +++++++++++ .../completable/CompletableTakeUntilTest.java | 235 ++++++++++++++++++ 3 files changed, 406 insertions(+) create mode 100644 src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java create mode 100644 src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index c07ba8ae6a..bc9cd271dc 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -2031,6 +2031,32 @@ public final Completable subscribeOn(final Scheduler scheduler) { return RxJavaPlugins.onAssembly(new CompletableSubscribeOn(this, scheduler)); } + /** + * Terminates the downstream if this or the other {@code Completable} + * terminates (wins the termination race) while disposing the connection to the losing source. + *

+ * + *

+ *
Scheduler:
+ *
{@code takeUntil} does not operate by default on a particular {@link Scheduler}.
+ *
Error handling:
+ *
If both this and the other sources signal an error, only one of the errors + * is signaled to the downstream and the other error is signaled to the global + * error handler via {@link RxJavaPlugins#onError(Throwable)}.
+ *
+ * @param other the other completable source to observe for the terminal signals + * @return the new Completable instance + * @since 2.1.17 - experimental + */ + @CheckReturnValue + @Experimental + @SchedulerSupport(SchedulerSupport.NONE) + public final Completable takeUntil(CompletableSource other) { + ObjectHelper.requireNonNull(other, "other is null"); + + return RxJavaPlugins.onAssembly(new CompletableTakeUntilCompletable(this, other)); + } + /** * Returns a Completable that runs this Completable and emits a TimeoutException in case * this Completable doesn't complete within the given time. diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java new file mode 100644 index 0000000000..1343d35b98 --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java @@ -0,0 +1,145 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.completable; + +import java.util.concurrent.atomic.*; + +import io.reactivex.*; +import io.reactivex.annotations.Experimental; +import io.reactivex.disposables.Disposable; +import io.reactivex.internal.disposables.DisposableHelper; +import io.reactivex.plugins.RxJavaPlugins; + +/** + * Terminates the sequence if either the main or the other Completable terminate. + * @since 2.1.17 - experimental + */ +@Experimental +public final class CompletableTakeUntilCompletable extends Completable { + + final Completable source; + + final CompletableSource other; + + public CompletableTakeUntilCompletable(Completable source, + CompletableSource other) { + this.source = source; + this.other = other; + } + + @Override + protected void subscribeActual(CompletableObserver s) { + TakeUntilMainObserver parent = new TakeUntilMainObserver(s); + s.onSubscribe(parent); + + other.subscribe(parent.other); + source.subscribe(parent); + } + + static final class TakeUntilMainObserver extends AtomicReference + implements CompletableObserver, Disposable { + + private static final long serialVersionUID = 3533011714830024923L; + + final CompletableObserver downstream; + + final OtherObserver other; + + final AtomicBoolean once; + + TakeUntilMainObserver(CompletableObserver downstream) { + this.downstream = downstream; + this.other = new OtherObserver(this); + this.once = new AtomicBoolean(); + } + + @Override + public void dispose() { + if (once.compareAndSet(false, true)) { + DisposableHelper.dispose(this); + DisposableHelper.dispose(other); + } + } + + @Override + public boolean isDisposed() { + return once.get(); + } + + @Override + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); + } + + @Override + public void onComplete() { + if (once.compareAndSet(false, true)) { + DisposableHelper.dispose(other); + downstream.onComplete(); + } + } + + @Override + public void onError(Throwable e) { + if (once.compareAndSet(false, true)) { + DisposableHelper.dispose(other); + downstream.onError(e); + } else { + RxJavaPlugins.onError(e); + } + } + + void innerComplete() { + if (once.compareAndSet(false, true)) { + DisposableHelper.dispose(this); + downstream.onComplete(); + } + } + + void innerError(Throwable e) { + if (once.compareAndSet(false, true)) { + DisposableHelper.dispose(this); + downstream.onError(e); + } else { + RxJavaPlugins.onError(e); + } + } + + static final class OtherObserver extends AtomicReference + implements CompletableObserver { + + private static final long serialVersionUID = 5176264485428790318L; + final TakeUntilMainObserver parent; + + OtherObserver(TakeUntilMainObserver parent) { + this.parent = parent; + } + + @Override + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); + } + + @Override + public void onComplete() { + parent.innerComplete(); + } + + @Override + public void onError(Throwable e) { + parent.innerError(e); + } + } + } +} diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java new file mode 100644 index 0000000000..586e0c3207 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java @@ -0,0 +1,235 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.completable; + +import static org.junit.Assert.*; + +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +import org.junit.Test; + +import io.reactivex.*; +import io.reactivex.disposables.Disposables; +import io.reactivex.exceptions.TestException; +import io.reactivex.observers.TestObserver; +import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.subjects.CompletableSubject; + +public class CompletableTakeUntilTest { + + @Test + public void consumerDisposes() { + CompletableSubject cs1 = CompletableSubject.create(); + CompletableSubject cs2 = CompletableSubject.create(); + + TestObserver to = cs1.takeUntil(cs2).test(); + + to.assertEmpty(); + + assertTrue(cs1.hasObservers()); + assertTrue(cs2.hasObservers()); + + to.dispose(); + + assertFalse(cs1.hasObservers()); + assertFalse(cs2.hasObservers()); + } + + @Test + public void mainCompletes() { + CompletableSubject cs1 = CompletableSubject.create(); + CompletableSubject cs2 = CompletableSubject.create(); + + TestObserver to = cs1.takeUntil(cs2).test(); + + to.assertEmpty(); + + assertTrue(cs1.hasObservers()); + assertTrue(cs2.hasObservers()); + + cs1.onComplete(); + + assertFalse(cs1.hasObservers()); + assertFalse(cs2.hasObservers()); + + to.assertResult(); + } + + @Test + public void otherCompletes() { + CompletableSubject cs1 = CompletableSubject.create(); + CompletableSubject cs2 = CompletableSubject.create(); + + TestObserver to = cs1.takeUntil(cs2).test(); + + to.assertEmpty(); + + assertTrue(cs1.hasObservers()); + assertTrue(cs2.hasObservers()); + + cs2.onComplete(); + + assertFalse(cs1.hasObservers()); + assertFalse(cs2.hasObservers()); + + to.assertResult(); + } + + @Test + public void mainErrors() { + CompletableSubject cs1 = CompletableSubject.create(); + CompletableSubject cs2 = CompletableSubject.create(); + + TestObserver to = cs1.takeUntil(cs2).test(); + + to.assertEmpty(); + + assertTrue(cs1.hasObservers()); + assertTrue(cs2.hasObservers()); + + cs1.onError(new TestException()); + + assertFalse(cs1.hasObservers()); + assertFalse(cs2.hasObservers()); + + to.assertFailure(TestException.class); + } + + @Test + public void otherErrors() { + CompletableSubject cs1 = CompletableSubject.create(); + CompletableSubject cs2 = CompletableSubject.create(); + + TestObserver to = cs1.takeUntil(cs2).test(); + + to.assertEmpty(); + + assertTrue(cs1.hasObservers()); + assertTrue(cs2.hasObservers()); + + cs2.onError(new TestException()); + + assertFalse(cs1.hasObservers()); + assertFalse(cs2.hasObservers()); + + to.assertFailure(TestException.class); + } + + @Test + public void isDisposed() { + CompletableSubject cs1 = CompletableSubject.create(); + CompletableSubject cs2 = CompletableSubject.create(); + + TestHelper.checkDisposed(cs1.takeUntil(cs2)); + } + + @Test + public void mainErrorLate() { + + List errors = TestHelper.trackPluginErrors(); + try { + + new Completable() { + @Override + protected void subscribeActual(CompletableObserver s) { + s.onSubscribe(Disposables.empty()); + s.onError(new TestException()); + } + }.takeUntil(Completable.complete()) + .test() + .assertResult(); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void mainCompleteLate() { + + List errors = TestHelper.trackPluginErrors(); + try { + + new Completable() { + @Override + protected void subscribeActual(CompletableObserver s) { + s.onSubscribe(Disposables.empty()); + s.onComplete(); + } + }.takeUntil(Completable.complete()) + .test() + .assertResult(); + + assertTrue(errors.isEmpty()); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void otherErrorLate() { + + List errors = TestHelper.trackPluginErrors(); + try { + + final AtomicReference ref = new AtomicReference(); + + Completable.complete() + .takeUntil(new Completable() { + @Override + protected void subscribeActual(CompletableObserver s) { + s.onSubscribe(Disposables.empty()); + ref.set(s); + } + }) + .test() + .assertResult(); + + ref.get().onError(new TestException()); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void otherCompleteLate() { + + List errors = TestHelper.trackPluginErrors(); + try { + + final AtomicReference ref = new AtomicReference(); + + Completable.complete() + .takeUntil(new Completable() { + @Override + protected void subscribeActual(CompletableObserver s) { + s.onSubscribe(Disposables.empty()); + ref.set(s); + } + }) + .test() + .assertResult(); + + ref.get().onComplete(); + + assertTrue(errors.isEmpty()); + } finally { + RxJavaPlugins.reset(); + } + } +} From d4c1da01b157262b326b21cd97a844fcdedc7c6e Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Thu, 12 Jul 2018 09:28:57 +0200 Subject: [PATCH 014/211] Add marble diagram for Single.hide operator (#6077) * Add marble diagram for Single.hide operator * Use correct marble diagram URL for Single.hide method --- src/main/java/io/reactivex/Single.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 0d8677ea73..4a3573a8d8 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -1877,6 +1877,8 @@ public final R as(@NonNull SingleConverter converter) { /** * Hides the identity of the current Single, including the Disposable that is sent * to the downstream via {@code onSubscribe()}. + *

+ * *

*
Scheduler:
*
{@code hide} does not operate by default on a particular {@link Scheduler}.
From 535ab3534851609e25750f50b9a1366f22a80ac9 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sat, 14 Jul 2018 21:42:01 +0200 Subject: [PATCH 015/211] 2.x: Improve class Javadoc of Single, Maybe and Completable (#6080) --- src/main/java/io/reactivex/Completable.java | 69 +++++++++++++++++++- src/main/java/io/reactivex/Maybe.java | 70 +++++++++++++++++++-- src/main/java/io/reactivex/Single.java | 67 +++++++++++++++++--- 3 files changed, 192 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index bc9cd271dc..1c49af16a0 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -33,9 +33,74 @@ import io.reactivex.schedulers.Schedulers; /** - * Represents a deferred computation without any value but only indication for completion or exception. + * The {@code Completable} class represents a deferred computation without any value but + * only indication for completion or exception. + *

+ * {@code Completable} behaves similarly to {@link Observable} except that it can only emit either + * a completion or error signal (there is no {@code onNext} or {@code onSuccess} as with the other + * reactive types). + *

+ * The {@code Completable} class implements the {@link CompletableSource} base interface and the default consumer + * type it interacts with is the {@link CompletableObserver} via the {@link #subscribe(CompletableObserver)} method. + * The {@code Completable} operates with the following sequential protocol: + *


+ *     onSubscribe (onError | onComplete)?
+ * 
+ *

+ * Note that as with the {@code Observable} protocol, {@code onError} and {@code onComplete} are mutually exclusive events. + *

+ * Like {@link Observable}, a running {@code Completable} can be stopped through the {@link Disposable} instance + * provided to consumers through {@link SingleObserver#onSubscribe}. + *

+ * Like an {@code Observable}, a {@code Completable} is lazy, can be either "hot" or "cold", synchronous or + * asynchronous. {@code Completable} instances returned by the methods of this class are cold + * and there is a standard hot implementation in the form of a subject: + * {@link io.reactivex.subjects.CompletableSubject CompletableSubject}. + *

+ * The documentation for this class makes use of marble diagrams. The following legend explains these diagrams: + *

+ * + *

+ * See {@link Flowable} or {@link Observable} for the + * implementation of the Reactive Pattern for a stream or vector of values. + *

+ * Example: + *


+ * Disposable d = Completable.complete()
+ *    .delay(10, TimeUnit.SECONDS, Schedulers.io())
+ *    .subscribeWith(new DisposableCompletableObserver() {
+ *        @Override
+ *        public void onStart() {
+ *            System.out.println("Started");
+ *        }
  *
- * The class follows a similar event pattern as Reactive-Streams: onSubscribe (onError|onComplete)?
+ *        @Override
+ *        public void onError(Throwable error) {
+ *            error.printStackTrace();
+ *        }
+ *
+ *        @Override
+ *        public void onComplete() {
+ *            System.out.println("Done!");
+ *        }
+ *    });
+ * 
+ * Thread.sleep(5000);
+ * 
+ * d.dispose();
+ * 
+ *

+ * Note that by design, subscriptions via {@link #subscribe(CompletableObserver)} can't be cancelled/disposed + * from the outside (hence the + * {@code void} return of the {@link #subscribe(CompletableObserver)} method) and it is the + * responsibility of the implementor of the {@code CompletableObserver} to allow this to happen. + * RxJava supports such usage with the standard + * {@link io.reactivex.observers.DisposableCompletableObserver DisposableCompletableObserver} instance. + * For convenience, the {@link #subscribeWith(CompletableObserver)} method is provided as well to + * allow working with a {@code CompletableObserver} (or subclass) instance to be applied with in + * a fluent manner (such as in the example above). + * + * @see io.reactivex.observers.DisposableCompletableObserver */ public abstract class Completable implements CompletableSource { /** diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 3a4ec3a76d..7b040b58f9 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -34,18 +34,78 @@ import io.reactivex.schedulers.Schedulers; /** - * Represents a deferred computation and emission of a maybe value or exception. + * The {@code Maybe} class represents a deferred computation and emission of a single value, no value at all or an exception. *

- * + * The {@code Maybe} class implements the {@link MaybeSource} base interface and the default consumer + * type it interacts with is the {@link MaybeObserver} via the {@link #subscribe(MaybeObserver)} method. *

- * The main consumer type of Maybe is {@link MaybeObserver} whose methods are called - * in a sequential fashion following this protocol:
- * {@code onSubscribe (onSuccess | onError | onComplete)?}. + * The {@code Maybe} operates with the following sequential protocol: + *


+ *     onSubscribe (onSuccess | onError | onComplete)?
+ * 
*

* Note that {@code onSuccess}, {@code onError} and {@code onComplete} are mutually exclusive events; unlike {@code Observable}, * {@code onSuccess} is never followed by {@code onError} or {@code onComplete}. + *

+ * Like {@link Observable}, a running {@code Maybe} can be stopped through the {@link Disposable} instance + * provided to consumers through {@link MaybeObserver#onSubscribe}. + *

+ * Like an {@code Observable}, a {@code Maybe} is lazy, can be either "hot" or "cold", synchronous or + * asynchronous. {@code Maybe} instances returned by the methods of this class are cold + * and there is a standard hot implementation in the form of a subject: + * {@link io.reactivex.subjects.MaybeSubject MaybeSubject}. + *

+ * The documentation for this class makes use of marble diagrams. The following legend explains these diagrams: + *

+ * + *

+ * See {@link Flowable} or {@link Observable} for the + * implementation of the Reactive Pattern for a stream or vector of values. + *

+ * Example: + *


+ * Disposable d = Maybe.just("Hello World")
+ *    .delay(10, TimeUnit.SECONDS, Schedulers.io())
+ *    .subscribeWith(new DisposableMaybeObserver<String>() {
+ *        @Override
+ *        public void onStart() {
+ *            System.out.println("Started");
+ *        }
+ *
+ *        @Override
+ *        public void onSuccess(String value) {
+ *            System.out.println("Success: " + value);
+ *        }
+ *
+ *        @Override
+ *        public void onError(Throwable error) {
+ *            error.printStackTrace();
+ *        }
+ *
+ *        @Override
+ *        public void onComplete() {
+ *            System.out.println("Done!");
+ *        }
+ *    });
+ * 
+ * Thread.sleep(5000);
+ * 
+ * d.dispose();
+ * 
+ *

+ * Note that by design, subscriptions via {@link #subscribe(MaybeObserver)} can't be cancelled/disposed + * from the outside (hence the + * {@code void} return of the {@link #subscribe(MaybeObserver)} method) and it is the + * responsibility of the implementor of the {@code MaybeObserver} to allow this to happen. + * RxJava supports such usage with the standard + * {@link io.reactivex.observers.DisposableMaybeObserver DisposableMaybeObserver} instance. + * For convenience, the {@link #subscribeWith(MaybeObserver)} method is provided as well to + * allow working with a {@code MaybeObserver} (or subclass) instance to be applied with in + * a fluent manner (such as in the example above). + * * @param the value type * @since 2.0 + * @see io.reactivex.observers.DisposableMaybeObserver */ public abstract class Maybe implements MaybeSource { diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 4a3573a8d8..62ff373d0e 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -37,26 +37,79 @@ import io.reactivex.schedulers.Schedulers; /** - * The Single class implements the Reactive Pattern for a single value response. - * See {@link Flowable} or {@link Observable} for the - * implementation of the Reactive Pattern for a stream or vector of values. + * The {@code Single} class implements the Reactive Pattern for a single value response. + *

+ * {@code Single} behaves similarly to {@link Observable} except that it can only emit either a single successful + * value or an error (there is no "onComplete" notification as there is for an {@link Observable}). + *

+ * The {@code Single} class implements the {@link SingleSource} base interface and the default consumer + * type it interacts with is the {@link SingleObserver} via the {@link #subscribe(SingleObserver)} method. + *

+ * The {@code Single} operates with the following sequential protocol: + *

+ *     onSubscribe (onSuccess | onError)?
+ * 
+ *

+ * Note that {@code onSuccess} and {@code onError} are mutually exclusive events; unlike {@code Observable}, + * {@code onSuccess} is never followed by {@code onError}. *

- * {@code Single} behaves the same as {@link Observable} except that it can only emit either a single successful - * value, or an error (there is no "onComplete" notification as there is for {@link Observable}) + * Like {@code Observable}, a running {@code Single} can be stopped through the {@link Disposable} instance + * provided to consumers through {@link SingleObserver#onSubscribe}. *

- * Like an {@link Observable}, a {@code Single} is lazy, can be either "hot" or "cold", synchronous or - * asynchronous. + * Like an {@code Observable}, a {@code Single} is lazy, can be either "hot" or "cold", synchronous or + * asynchronous. {@code Single} instances returned by the methods of this class are cold + * and there is a standard hot implementation in the form of a subject: + * {@link io.reactivex.subjects.SingleSubject SingleSubject}. *

* The documentation for this class makes use of marble diagrams. The following legend explains these diagrams: *

* *

+ * See {@link Flowable} or {@link Observable} for the + * implementation of the Reactive Pattern for a stream or vector of values. + *

* For more information see the ReactiveX * documentation. + *

+ * Example: + *


+ * Disposable d = Single.just("Hello World")
+ *    .delay(10, TimeUnit.SECONDS, Schedulers.io())
+ *    .subscribeWith(new DisposableSingleObserver<String>() {
+ *        @Override
+ *        public void onStart() {
+ *            System.out.println("Started");
+ *        }
+ *
+ *        @Override
+ *        public void onSuccess(String value) {
+ *            System.out.println("Success: " + value);
+ *        }
  *
+ *        @Override
+ *        public void onError(Throwable error) {
+ *            error.printStackTrace();
+ *        }
+ *    });
+ * 
+ * Thread.sleep(5000);
+ * 
+ * d.dispose();
+ * 
+ *

+ * Note that by design, subscriptions via {@link #subscribe(SingleObserver)} can't be cancelled/disposed + * from the outside (hence the + * {@code void} return of the {@link #subscribe(SingleObserver)} method) and it is the + * responsibility of the implementor of the {@code SingleObserver} to allow this to happen. + * RxJava supports such usage with the standard + * {@link io.reactivex.observers.DisposableSingleObserver DisposableSingleObserver} instance. + * For convenience, the {@link #subscribeWith(SingleObserver)} method is provided as well to + * allow working with a {@code SingleObserver} (or subclass) instance to be applied with in + * a fluent manner (such as in the example above). * @param * the type of the item emitted by the Single * @since 2.0 + * @see io.reactivex.observers.DisposableSingleObserver */ public abstract class Single implements SingleSource { From 53dd15fcb5c3e154b58ecb1768732d55aa49f5c9 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 17 Jul 2018 11:19:13 +0200 Subject: [PATCH 016/211] 2.x: Add Completable marble diagrams (07/17a) (#6083) --- src/main/java/io/reactivex/Completable.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 1c49af16a0..319e31272d 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -106,6 +106,8 @@ public abstract class Completable implements CompletableSource { /** * Returns a Completable which terminates as soon as one of the source Completables * terminates (normally or with an error) and cancels all other Completables. + *

+ * *

*
Scheduler:
*
{@code ambArray} does not operate by default on a particular {@link Scheduler}.
@@ -132,6 +134,8 @@ public static Completable ambArray(final CompletableSource... sources) { /** * Returns a Completable which terminates as soon as one of the source Completables * terminates (normally or with an error) and cancels all other Completables. + *

+ * *

*
Scheduler:
*
{@code amb} does not operate by default on a particular {@link Scheduler}.
@@ -151,6 +155,8 @@ public static Completable amb(final Iterable source /** * Returns a Completable instance that completes immediately when subscribed to. + *

+ * *

*
Scheduler:
*
{@code complete} does not operate by default on a particular {@link Scheduler}.
@@ -165,6 +171,8 @@ public static Completable complete() { /** * Returns a Completable which completes only when all sources complete, one after another. + *

+ * *

*
Scheduler:
*
{@code concatArray} does not operate by default on a particular {@link Scheduler}.
@@ -188,6 +196,8 @@ public static Completable concatArray(CompletableSource... sources) { /** * Returns a Completable which completes only when all sources complete, one after another. + *

+ * *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
@@ -206,6 +216,8 @@ public static Completable concat(Iterable sources) /** * Returns a Completable which completes only when all sources complete, one after another. + *

+ * *

*
Backpressure:
*
The returned {@code Completable} honors the backpressure of the downstream consumer @@ -226,6 +238,8 @@ public static Completable concat(Publisher sources) /** * Returns a Completable which completes only when all sources complete, one after another. + *

+ * *

*
Backpressure:
*
The returned {@code Completable} honors the backpressure of the downstream consumer @@ -312,6 +326,8 @@ public static Completable unsafeCreate(CompletableSource source) { /** * Defers the subscription to a Completable instance returned by a supplier. + *

+ * *

*
Scheduler:
*
{@code defer} does not operate by default on a particular {@link Scheduler}.
@@ -330,6 +346,8 @@ public static Completable defer(final Callable comp * Creates a Completable which calls the given error supplier for each subscriber * and emits its returned Throwable. *

+ * + *

* If the errorSupplier returns null, the child CompletableObservers will receive a * NullPointerException. *

@@ -349,6 +367,8 @@ public static Completable error(final Callable errorSupplie /** * Creates a Completable instance that emits the given Throwable exception to subscribers. + *

+ * *

*
Scheduler:
*
{@code error} does not operate by default on a particular {@link Scheduler}.
From c8bcb3c92bebde39616597bd46ddb93d6f0f6e18 Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Tue, 17 Jul 2018 15:06:10 +0200 Subject: [PATCH 017/211] Add marble diagrams for Single.repeat operators (#6081) * Add marble diagrams for Single.repeat operators * Use correct marble diagram URLs --- src/main/java/io/reactivex/Single.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 62ff373d0e..441d0b6a43 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -3051,6 +3051,8 @@ public final Single onTerminateDetach() { /** * Repeatedly re-subscribes to the current Single and emits each success value. + *

+ * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
@@ -3069,6 +3071,8 @@ public final Flowable repeat() { /** * Re-subscribes to the current Single at most the given number of times and emits each success value. + *

+ * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
@@ -3090,6 +3094,8 @@ public final Flowable repeat(long times) { * Re-subscribes to the current Single if * the Publisher returned by the handler function signals a value in response to a * value signalled through the Flowable the handle receives. + *

+ * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer. From ccfa4bf521fae76e1b7157c1880625333304e304 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 17 Jul 2018 15:15:25 +0200 Subject: [PATCH 018/211] 2.x: More Completable marbles, add C.fromMaybe (#6085) --- src/main/java/io/reactivex/Completable.java | 58 +++++++++++++++++++ .../completable/CompletableFromMaybeTest.java | 46 +++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/test/java/io/reactivex/internal/operators/completable/CompletableFromMaybeTest.java diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 319e31272d..e82664e0a6 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -388,6 +388,8 @@ public static Completable error(final Throwable error) { /** * Returns a Completable instance that runs the given Action for each subscriber and * emits either an unchecked exception or simply completes. + *

+ * *

*
Scheduler:
*
{@code fromAction} does not operate by default on a particular {@link Scheduler}.
@@ -406,6 +408,8 @@ public static Completable fromAction(final Action run) { /** * Returns a Completable which when subscribed, executes the callable function, ignores its * normal result and emits onError or onComplete only. + *

+ * *

*
Scheduler:
*
{@code fromCallable} does not operate by default on a particular {@link Scheduler}.
@@ -423,6 +427,8 @@ public static Completable fromCallable(final Callable callable) { /** * Returns a Completable instance that reacts to the termination of the given Future in a blocking fashion. *

+ * + *

* Note that cancellation from any of the subscribers to this Completable will cancel the future. *

*
Scheduler:
@@ -438,9 +444,33 @@ public static Completable fromFuture(final Future future) { return fromAction(Functions.futureAction(future)); } + /** + * Returns a Completable instance that when subscribed to, subscribes to the {@code Maybe} instance and + * emits a completion event if the maybe emits {@code onSuccess}/{@code onComplete} or forwards any + * {@code onError} events. + *

+ * + *

+ *
Scheduler:
+ *
{@code fromMaybe} does not operate by default on a particular {@link Scheduler}.
+ *
+ * @param the value type of the {@link MaybeSource} element + * @param maybe the Maybe instance to subscribe to, not null + * @return the new Completable instance + * @throws NullPointerException if single is null + */ + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + public static Completable fromMaybe(final MaybeSource maybe) { + ObjectHelper.requireNonNull(maybe, "maybe is null"); + return RxJavaPlugins.onAssembly(new MaybeIgnoreElementCompletable(maybe)); + } + /** * Returns a Completable instance that runs the given Runnable for each subscriber and * emits either its exception or simply completes. + *

+ * *

*
Scheduler:
*
{@code fromRunnable} does not operate by default on a particular {@link Scheduler}.
@@ -459,6 +489,8 @@ public static Completable fromRunnable(final Runnable run) { /** * Returns a Completable instance that subscribes to the given Observable, ignores all values and * emits only the terminal event. + *

+ * *

*
Scheduler:
*
{@code fromObservable} does not operate by default on a particular {@link Scheduler}.
@@ -479,6 +511,8 @@ public static Completable fromObservable(final ObservableSource observabl * Returns a Completable instance that subscribes to the given publisher, ignores all values and * emits only the terminal event. *

+ * + *

* The {@link Publisher} must follow the * Reactive-Streams specification. * Violating the specification may result in undefined behavior. @@ -513,6 +547,8 @@ public static Completable fromPublisher(final Publisher publisher) { /** * Returns a Completable instance that when subscribed to, subscribes to the Single instance and * emits a completion event if the single emits onSuccess or forwards any onError events. + *

+ * *

*
Scheduler:
*
{@code fromSingle} does not operate by default on a particular {@link Scheduler}.
@@ -532,6 +568,8 @@ public static Completable fromSingle(final SingleSource single) { /** * Returns a Completable instance that subscribes to all sources at once and * completes only when all source Completables complete or one of them emits an error. + *

+ * *

*
Scheduler:
*
{@code mergeArray} does not operate by default on a particular {@link Scheduler}.
@@ -569,6 +607,8 @@ public static Completable mergeArray(CompletableSource... sources) { /** * Returns a Completable instance that subscribes to all sources at once and * completes only when all source Completables complete or one of them emits an error. + *

+ * *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
@@ -601,6 +641,8 @@ public static Completable merge(Iterable sources) { /** * Returns a Completable instance that subscribes to all sources at once and * completes only when all source Completables complete or one of them emits an error. + *

+ * *

*
Backpressure:
*
The returned {@code Completable} honors the backpressure of the downstream consumer @@ -635,6 +677,8 @@ public static Completable merge(Publisher sources) /** * Returns a Completable instance that keeps subscriptions to a limited number of sources at once and * completes only when all source Completables complete or one of them emits an error. + *

+ * *

*
Backpressure:
*
The returned {@code Completable} honors the backpressure of the downstream consumer @@ -699,6 +743,8 @@ private static Completable merge0(Publisher sources * Returns a CompletableConsumable that subscribes to all Completables in the source array and delays * any error emitted by either the sources observable or any of the inner Completables until all of * them terminate in a way or another. + *

+ * *

*
Scheduler:
*
{@code mergeArrayDelayError} does not operate by default on a particular {@link Scheduler}.
@@ -718,6 +764,8 @@ public static Completable mergeArrayDelayError(CompletableSource... sources) { * Returns a Completable that subscribes to all Completables in the source sequence and delays * any error emitted by either the sources observable or any of the inner Completables until all of * them terminate in a way or another. + *

+ * *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
@@ -738,6 +786,8 @@ public static Completable mergeDelayError(Iterable * Returns a Completable that subscribes to all Completables in the source sequence and delays * any error emitted by either the sources observable or any of the inner Completables until all of * them terminate in a way or another. + *

+ * *

*
Backpressure:
*
The returned {@code Completable} honors the backpressure of the downstream consumer @@ -761,6 +811,8 @@ public static Completable mergeDelayError(Publisher * the source sequence and delays any error emitted by either the sources * observable or any of the inner Completables until all of * them terminate in a way or another. + *

+ * *

*
Backpressure:
*
The returned {@code Completable} honors the backpressure of the downstream consumer @@ -782,6 +834,8 @@ public static Completable mergeDelayError(Publisher /** * Returns a Completable that never calls onError or onComplete. + *

+ * *

*
Scheduler:
*
{@code never} does not operate by default on a particular {@link Scheduler}.
@@ -796,6 +850,8 @@ public static Completable never() { /** * Returns a Completable instance that fires its onComplete event after the given delay elapsed. + *

+ * *

*
Scheduler:
*
{@code timer} does operate by default on the {@code computation} {@link Scheduler}.
@@ -813,6 +869,8 @@ public static Completable timer(long delay, TimeUnit unit) { /** * Returns a Completable instance that fires its onComplete event after the given delay elapsed * by using the supplied scheduler. + *

+ * *

*
Scheduler:
*
{@code timer} operates on the {@link Scheduler} you specify.
diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableFromMaybeTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableFromMaybeTest.java new file mode 100644 index 0000000000..46f62d0b7a --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableFromMaybeTest.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.completable; + +import io.reactivex.Completable; +import io.reactivex.Maybe; +import org.junit.Test; + +public class CompletableFromMaybeTest { + @Test(expected = NullPointerException.class) + public void fromMaybeNull() { + Completable.fromMaybe(null); + } + + @Test + public void fromMaybe() { + Completable.fromMaybe(Maybe.just(1)) + .test() + .assertResult(); + } + + @Test + public void fromMaybeEmpty() { + Completable.fromMaybe(Maybe.empty()) + .test() + .assertResult(); + } + + @Test + public void fromMaybeError() { + Completable.fromMaybe(Maybe.error(new UnsupportedOperationException())) + .test() + .assertFailure(UnsupportedOperationException.class); + } +} From 97ebd2c0ba3d1505631b844d2ff5000944be2ae6 Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Tue, 17 Jul 2018 15:45:35 +0200 Subject: [PATCH 019/211] Add marble diagram for Single.repeatUntil operator (#6084) * Add marble diagram for Single.repeatUntil operator * Use proper URL for marble --- src/main/java/io/reactivex/Single.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 441d0b6a43..25adddd0eb 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -3119,6 +3119,8 @@ public final Flowable repeatWhen(Function, ? extends /** * Re-subscribes to the current Single until the given BooleanSupplier returns true. + *

+ * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
From 396f2f6d15a52e5c79d0ee7b4dcfb62f6a8029b7 Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Wed, 18 Jul 2018 09:22:44 +0200 Subject: [PATCH 020/211] Add marbles for Single.from operators (#6087) --- src/main/java/io/reactivex/Single.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 25adddd0eb..a87b7e5ad4 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -554,6 +554,8 @@ public static Single error(final Throwable exception) { * Allows you to defer execution of passed function until SingleObserver subscribes to the {@link Single}. * It makes passed function "lazy". * Result of the function invocation will be emitted by the {@link Single}. + *

+ * *

*
Scheduler:
*
{@code fromCallable} does not operate by default on a particular {@link Scheduler}.
@@ -714,6 +716,8 @@ public static Single fromFuture(Future future, Scheduler sch * Note that even though {@link Publisher} appears to be a functional interface, it * is not recommended to implement it through a lambda as the specification requires * state management that is not achievable with a stateless lambda. + *

+ * *

*
Backpressure:
*
The {@code publisher} is consumed in an unbounded fashion but will be cancelled @@ -738,6 +742,8 @@ public static Single fromPublisher(final Publisher publisher * Wraps a specific ObservableSource into a Single and signals its single element or error. *

If the ObservableSource is empty, a NoSuchElementException is signalled. * If the source has more than one element, an IndexOutOfBoundsException is signalled. + *

+ * *

*
Scheduler:
*
{@code fromObservable} does not operate by default on a particular {@link Scheduler}.
From fd4b614d4a4f1b136f51c4bb0d29e8bfbf91fa0c Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Wed, 18 Jul 2018 09:36:25 +0200 Subject: [PATCH 021/211] Single error operators marbles (#6086) * Add marbles for Single.error operators * Add marbles for Single.onError operators * Use proper URLs for marble diagrams --- src/main/java/io/reactivex/Single.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index a87b7e5ad4..874f8adcd6 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -507,6 +507,8 @@ public static Single defer(final Callable + * *
*
Scheduler:
*
{@code error} does not operate by default on a particular {@link Scheduler}.
@@ -527,7 +529,7 @@ public static Single error(final Callable errorSuppl * Returns a Single that invokes a subscriber's {@link SingleObserver#onError onError} method when the * subscriber subscribes to it. *

- * + * *

*
Scheduler:
*
{@code error} does not operate by default on a particular {@link Scheduler}.
@@ -2921,7 +2923,7 @@ public final Single observeOn(final Scheduler scheduler) { * Instructs a Single to emit an item (returned by a specified function) rather than invoking * {@link SingleObserver#onError onError} if it encounters an error. *

- * + * *

* By default, when a Single encounters an error that prevents it from emitting the expected item to its * subscriber, the Single invokes its subscriber's {@link SingleObserver#onError} method, and then quits @@ -2952,6 +2954,8 @@ public final Single onErrorReturn(final Function resu /** * Signals the specified value as success in case the current Single signals an error. + *

+ * *

*
Scheduler:
*
{@code onErrorReturnItem} does not operate by default on a particular {@link Scheduler}.
@@ -2971,7 +2975,7 @@ public final Single onErrorReturnItem(final T value) { * Instructs a Single to pass control to another Single rather than invoking * {@link SingleObserver#onError(Throwable)} if it encounters an error. *

- * + * *

* By default, when a Single encounters an error that prevents it from emitting the expected item to * its {@link SingleObserver}, the Single invokes its SingleObserver's {@code onError} method, and then quits @@ -3005,7 +3009,7 @@ public final Single onErrorResumeNext(final Single resumeSingleI * Instructs a Single to pass control to another Single rather than invoking * {@link SingleObserver#onError(Throwable)} if it encounters an error. *

- * + * *

* By default, when a Single encounters an error that prevents it from emitting the expected item to * its {@link SingleObserver}, the Single invokes its SingleObserver's {@code onError} method, and then quits From 4a744153e9cea4e32f4c88bc49893e0b13b85359 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 18 Jul 2018 12:21:02 +0200 Subject: [PATCH 022/211] 2.x: Add missing Completable marbles (07/18a) (#6090) --- src/main/java/io/reactivex/Completable.java | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index e82664e0a6..c1d6b2fb07 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -903,6 +903,8 @@ private static NullPointerException toNpe(Throwable ex) { * Returns a Completable instance which manages a resource along * with a custom Completable instance while the subscription is active. *

+ * + *

* This overload disposes eagerly before the terminal event is emitted. *

*
Scheduler:
@@ -927,6 +929,8 @@ public static Completable using(Callable resourceSupplier, * with a custom Completable instance while the subscription is active and performs eager or lazy * resource disposition. *

+ * + *

* If this overload performs a lazy cancellation after the terminal event is emitted. * Exceptions thrown at this time will be delivered to RxJavaPlugins only. *

@@ -959,6 +963,8 @@ public static Completable using( /** * Wraps the given CompletableSource into a Completable * if not already Completable. + *

+ * *

*
Scheduler:
*
{@code wrap} does not operate by default on a particular {@link Scheduler}.
@@ -980,6 +986,8 @@ public static Completable wrap(CompletableSource source) { /** * Returns a Completable that emits the a terminated event of either this Completable * or the other Completable whichever fires first. + *

+ * *

*
Scheduler:
*
{@code ambWith} does not operate by default on a particular {@link Scheduler}.
@@ -1001,6 +1009,8 @@ public final Completable ambWith(CompletableSource other) { * will subscribe to the {@code next} ObservableSource. An error event from this Completable will be * propagated to the downstream subscriber and will result in skipping the subscription of the * Observable. + *

+ * *

*
Scheduler:
*
{@code andThen} does not operate by default on a particular {@link Scheduler}.
@@ -1022,6 +1032,8 @@ public final Observable andThen(ObservableSource next) { * will subscribe to the {@code next} Flowable. An error event from this Completable will be * propagated to the downstream subscriber and will result in skipping the subscription of the * Publisher. + *

+ * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer @@ -1047,6 +1059,8 @@ public final Flowable andThen(Publisher next) { * will subscribe to the {@code next} SingleSource. An error event from this Completable will be * propagated to the downstream subscriber and will result in skipping the subscription of the * Single. + *

+ * *

*
Scheduler:
*
{@code andThen} does not operate by default on a particular {@link Scheduler}.
@@ -1068,6 +1082,8 @@ public final Single andThen(SingleSource next) { * will subscribe to the {@code next} MaybeSource. An error event from this Completable will be * propagated to the downstream subscriber and will result in skipping the subscription of the * Maybe. + *

+ * *

*
Scheduler:
*
{@code andThen} does not operate by default on a particular {@link Scheduler}.
@@ -1088,6 +1104,8 @@ public final Maybe andThen(MaybeSource next) { * Returns a Completable that first runs this Completable * and then the other completable. *

+ * + *

* This is an alias for {@link #concatWith(CompletableSource)}. *

*
Scheduler:
@@ -1106,6 +1124,8 @@ public final Completable andThen(CompletableSource next) { /** * Calls the specified converter function during assembly time and returns its resulting value. *

+ * + *

* This allows fluent conversion to any other type. *

*
Scheduler:
@@ -1128,6 +1148,8 @@ public final R as(@NonNull CompletableConverter converter) { /** * Subscribes to and awaits the termination of this Completable instance in a blocking manner and * rethrows any exception emitted. + *

+ * *

*
Scheduler:
*
{@code blockingAwait} does not operate by default on a particular {@link Scheduler}.
@@ -1148,6 +1170,8 @@ public final void blockingAwait() { /** * Subscribes to and awaits the termination of this Completable instance in a blocking manner * with a specific timeout and rethrows any exception emitted within the timeout window. + *

+ * *

*
Scheduler:
*
{@code blockingAwait} does not operate by default on a particular {@link Scheduler}.
@@ -1174,6 +1198,8 @@ public final boolean blockingAwait(long timeout, TimeUnit unit) { /** * Subscribes to this Completable instance and blocks until it terminates, then returns null or * the emitted exception if any. + *

+ * *

*
Scheduler:
*
{@code blockingGet} does not operate by default on a particular {@link Scheduler}.
@@ -1192,6 +1218,8 @@ public final Throwable blockingGet() { /** * Subscribes to this Completable instance and blocks until it terminates or the specified timeout * elapses, then returns null for normal termination or the emitted exception if any. + *

+ * *

*
Scheduler:
*
{@code blockingGet} does not operate by default on a particular {@link Scheduler}.
@@ -1216,6 +1244,8 @@ public final Throwable blockingGet(long timeout, TimeUnit unit) { * subscribes to the result Completable, caches its terminal event * and relays/replays it to observers. *

+ * + *

* Note that this operator doesn't allow disposing the connection * of the upstream source. *

@@ -1235,6 +1265,8 @@ public final Completable cache() { /** * Calls the given transformer function with this instance and returns the function's resulting * Completable. + *

+ * *

*
Scheduler:
*
{@code compose} does not operate by default on a particular {@link Scheduler}.
@@ -2308,6 +2340,8 @@ private Completable timeout0(long timeout, TimeUnit unit, Scheduler scheduler, C /** * Allows fluent conversion to another type via a function callback. + *

+ * *

*
Scheduler:
*
{@code to} does not operate by default on a particular {@link Scheduler}.
From 1aeac067ae3c9844f77d264e47de6a31f3eb1a53 Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Wed, 18 Jul 2018 13:12:27 +0200 Subject: [PATCH 023/211] Add marbles for Single.amb operators (#6091) --- src/main/java/io/reactivex/Single.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 874f8adcd6..5cef88c846 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -116,6 +116,8 @@ public abstract class Single implements SingleSource { /** * Runs multiple SingleSources and signals the events of the first one that signals (cancelling * the rest). + *

+ * *

*
Scheduler:
*
{@code amb} does not operate by default on a particular {@link Scheduler}.
@@ -136,6 +138,8 @@ public static Single amb(final Iterable + * *
*
Scheduler:
*
{@code ambArray} does not operate by default on a particular {@link Scheduler}.
From 27c63b6a4c2074657aed4e7ee6e39a52173bbed5 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 19 Jul 2018 10:45:25 +0200 Subject: [PATCH 024/211] 2.x: Improve Completable.delay operator internals (#6096) --- .../completable/CompletableDelay.java | 78 ++++++++++++------- .../completable/CompletableDelayTest.java | 76 ++++++++++++++++-- 2 files changed, 117 insertions(+), 37 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDelay.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDelay.java index fa600c64b1..79b0a49383 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDelay.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDelay.java @@ -14,9 +14,11 @@ package io.reactivex.internal.operators.completable; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import io.reactivex.*; -import io.reactivex.disposables.*; +import io.reactivex.disposables.Disposable; +import io.reactivex.internal.disposables.DisposableHelper; public final class CompletableDelay extends Completable { @@ -40,54 +42,70 @@ public CompletableDelay(CompletableSource source, long delay, TimeUnit unit, Sch @Override protected void subscribeActual(final CompletableObserver s) { - final CompositeDisposable set = new CompositeDisposable(); - - source.subscribe(new Delay(set, s)); + source.subscribe(new Delay(s, delay, unit, scheduler, delayError)); } - final class Delay implements CompletableObserver { + static final class Delay extends AtomicReference + implements CompletableObserver, Runnable, Disposable { + + private static final long serialVersionUID = 465972761105851022L; + + final CompletableObserver downstream; + + final long delay; + + final TimeUnit unit; - private final CompositeDisposable set; - final CompletableObserver s; + final Scheduler scheduler; - Delay(CompositeDisposable set, CompletableObserver s) { - this.set = set; - this.s = s; + final boolean delayError; + + Throwable error; + + Delay(CompletableObserver downstream, long delay, TimeUnit unit, Scheduler scheduler, boolean delayError) { + this.downstream = downstream; + this.delay = delay; + this.unit = unit; + this.scheduler = scheduler; + this.delayError = delayError; + } + + @Override + public void onSubscribe(Disposable d) { + if (DisposableHelper.setOnce(this, d)) { + downstream.onSubscribe(this); + } } @Override public void onComplete() { - set.add(scheduler.scheduleDirect(new OnComplete(), delay, unit)); + DisposableHelper.replace(this, scheduler.scheduleDirect(this, delay, unit)); } @Override public void onError(final Throwable e) { - set.add(scheduler.scheduleDirect(new OnError(e), delayError ? delay : 0, unit)); + error = e; + DisposableHelper.replace(this, scheduler.scheduleDirect(this, delayError ? delay : 0, unit)); } @Override - public void onSubscribe(Disposable d) { - set.add(d); - s.onSubscribe(set); + public void dispose() { + DisposableHelper.dispose(this); } - final class OnComplete implements Runnable { - @Override - public void run() { - s.onComplete(); - } + @Override + public boolean isDisposed() { + return DisposableHelper.isDisposed(get()); } - final class OnError implements Runnable { - private final Throwable e; - - OnError(Throwable e) { - this.e = e; - } - - @Override - public void run() { - s.onError(e); + @Override + public void run() { + Throwable e = error; + error = null; + if (e != null) { + downstream.onError(e); + } else { + downstream.onComplete(); } } } diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java index 78393b39ae..174a520e0f 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java @@ -13,17 +13,18 @@ package io.reactivex.internal.operators.completable; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertNotEquals; + +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.functions.Consumer; import org.junit.Test; -import io.reactivex.Completable; -import io.reactivex.schedulers.Schedulers; - -import static org.junit.Assert.assertNotEquals; +import io.reactivex.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.*; +import io.reactivex.observers.TestObserver; +import io.reactivex.schedulers.*; public class CompletableDelayTest { @@ -58,4 +59,65 @@ public void accept(Throwable throwable) throws Exception { assertNotEquals(Thread.currentThread(), thread.get()); } + @Test + public void disposed() { + TestHelper.checkDisposed(Completable.never().delay(1, TimeUnit.MINUTES)); + } + + @Test + public void doubleOnSubscribe() { + TestHelper.checkDoubleOnSubscribeCompletable(new Function() { + @Override + public CompletableSource apply(Completable c) throws Exception { + return c.delay(1, TimeUnit.MINUTES); + } + }); + } + + @Test + public void normal() { + Completable.complete() + .delay(1, TimeUnit.MILLISECONDS) + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(); + } + + @Test + public void errorNotDelayed() { + TestScheduler scheduler = new TestScheduler(); + + TestObserver to = Completable.error(new TestException()) + .delay(100, TimeUnit.MILLISECONDS, scheduler, false) + .test(); + + to.assertEmpty(); + + scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); + + to.assertFailure(TestException.class); + + scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); + + to.assertFailure(TestException.class); + } + + @Test + public void errorDelayed() { + TestScheduler scheduler = new TestScheduler(); + + TestObserver to = Completable.error(new TestException()) + .delay(100, TimeUnit.MILLISECONDS, scheduler, true) + .test(); + + to.assertEmpty(); + + scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); + + to.assertEmpty(); + + scheduler.advanceTimeBy(99, TimeUnit.MILLISECONDS); + + to.assertFailure(TestException.class); + } } From 382ba69afe6fdaab90682f9d37c32b4f538bb5c0 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 19 Jul 2018 13:27:57 +0200 Subject: [PATCH 025/211] 2.x: Add missing Completable marbles (+19, 07/19a) (#6097) --- src/main/java/io/reactivex/Completable.java | 48 +++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index c1d6b2fb07..06a9cd79da 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -1283,6 +1283,8 @@ public final Completable compose(CompletableTransformer transformer) { /** * Concatenates this Completable with another Completable. + *

+ * *

*
Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
@@ -1304,6 +1306,8 @@ public final Completable concatWith(CompletableSource other) { /** * Returns a Completable which delays the emission of the completion event by the given time. + *

+ * *

*
Scheduler:
*
{@code delay} does operate by default on the {@code computation} {@link Scheduler}.
@@ -1322,6 +1326,8 @@ public final Completable delay(long delay, TimeUnit unit) { /** * Returns a Completable which delays the emission of the completion event by the given time while * running on the specified scheduler. + *

+ * *

*
Scheduler:
*
{@code delay} operates on the {@link Scheduler} you specify.
@@ -1341,6 +1347,8 @@ public final Completable delay(long delay, TimeUnit unit, Scheduler scheduler) { /** * Returns a Completable which delays the emission of the completion event, and optionally the error as well, by the given time while * running on the specified scheduler. + *

+ * *

*
Scheduler:
*
{@code delay} operates on the {@link Scheduler} you specify.
@@ -1362,6 +1370,8 @@ public final Completable delay(final long delay, final TimeUnit unit, final Sche /** * Returns a Completable which calls the given onComplete callback if this Completable completes. + *

+ * *

*
Scheduler:
*
{@code doOnComplete} does not operate by default on a particular {@link Scheduler}.
@@ -1382,6 +1392,8 @@ public final Completable doOnComplete(Action onComplete) { /** * Calls the shared {@code Action} if a CompletableObserver subscribed to the current * Completable disposes the common Disposable it received via onSubscribe. + *

+ * *

*
Scheduler:
*
{@code doOnDispose} does not operate by default on a particular {@link Scheduler}.
@@ -1400,6 +1412,8 @@ public final Completable doOnDispose(Action onDispose) { /** * Returns a Completable which calls the given onError callback if this Completable emits an error. + *

+ * *

*
Scheduler:
*
{@code doOnError} does not operate by default on a particular {@link Scheduler}.
@@ -1420,6 +1434,8 @@ public final Completable doOnError(Consumer onError) { /** * Returns a Completable which calls the given onEvent callback with the (throwable) for an onError * or (null) for an onComplete signal from this Completable before delivering said signal to the downstream. + *

+ * *

*
Scheduler:
*
{@code doOnEvent} does not operate by default on a particular {@link Scheduler}.
@@ -1470,6 +1486,8 @@ private Completable doOnLifecycle( /** * Returns a Completable instance that calls the given onSubscribe callback with the disposable * that child subscribers receive on subscription. + *

+ * *

*
Scheduler:
*
{@code doOnSubscribe} does not operate by default on a particular {@link Scheduler}.
@@ -1489,6 +1507,8 @@ public final Completable doOnSubscribe(Consumer onSubscribe) /** * Returns a Completable instance that calls the given onTerminate callback just before this Completable * completes normally or with an exception. + *

+ * *

*
Scheduler:
*
{@code doOnTerminate} does not operate by default on a particular {@link Scheduler}.
@@ -1508,6 +1528,8 @@ public final Completable doOnTerminate(final Action onTerminate) { /** * Returns a Completable instance that calls the given onTerminate callback after this Completable * completes normally or with an exception. + *

+ * *

*
Scheduler:
*
{@code doAfterTerminate} does not operate by default on a particular {@link Scheduler}.
@@ -1530,9 +1552,13 @@ public final Completable doAfterTerminate(final Action onAfterTerminate) { /** * Calls the specified action after this Completable signals onError or onComplete or gets disposed by * the downstream. - *

In case of a race between a terminal event and a dispose call, the provided {@code onFinally} action + *

+ * + *

+ * In case of a race between a terminal event and a dispose call, the provided {@code onFinally} action * is executed once per subscription. - *

Note that the {@code onFinally} action is shared between subscriptions and as such + *

+ * Note that the {@code onFinally} action is shared between subscriptions and as such * should be thread-safe. *

*
Scheduler:
@@ -1688,6 +1714,8 @@ public final Completable lift(final CompletableOperator onLift) { /** * Returns a Completable which subscribes to this and the other Completable and completes * when both of them complete or one emits an error. + *

+ * *

*
Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
@@ -1705,6 +1733,8 @@ public final Completable mergeWith(CompletableSource other) { /** * Returns a Completable which emits the terminal events from the thread of the specified scheduler. + *

+ * *

*
Scheduler:
*
{@code observeOn} operates on a {@link Scheduler} you specify.
@@ -1723,6 +1753,8 @@ public final Completable observeOn(final Scheduler scheduler) { /** * Returns a Completable instance that if this Completable emits an error, it will emit an onComplete * and swallow the throwable. + *

+ * *

*
Scheduler:
*
{@code onErrorComplete} does not operate by default on a particular {@link Scheduler}.
@@ -1738,6 +1770,8 @@ public final Completable onErrorComplete() { /** * Returns a Completable instance that if this Completable emits an error and the predicate returns * true, it will emit an onComplete and swallow the throwable. + *

+ * *

*
Scheduler:
*
{@code onErrorComplete} does not operate by default on a particular {@link Scheduler}.
@@ -1758,6 +1792,8 @@ public final Completable onErrorComplete(final Predicate pred * Returns a Completable instance that when encounters an error from this Completable, calls the * specified mapper function that returns another Completable instance for it and resumes the * execution with it. + *

+ * *

*
Scheduler:
*
{@code onErrorResumeNext} does not operate by default on a particular {@link Scheduler}.
@@ -1776,6 +1812,8 @@ public final Completable onErrorResumeNext(final Function + * *
*
Scheduler:
*
{@code onTerminateDetach} does not operate by default on a particular {@link Scheduler}.
@@ -2050,8 +2088,10 @@ public final Flowable startWith(Publisher other) { /** * Hides the identity of this Completable and its Disposable. - *

Allows preventing certain identity-based - * optimizations (fusion). + *

+ * + *

+ * Allows preventing certain identity-based optimizations (fusion). *

*
Scheduler:
*
{@code hide} does not operate by default on a particular {@link Scheduler}.
From 8b9740840f21d131595dac2115241b1f739b03f2 Mon Sep 17 00:00:00 2001 From: akarnokd Date: Thu, 19 Jul 2018 15:20:26 +0200 Subject: [PATCH 026/211] 2.x: Fix aspect of some Completable marbles. --- src/main/java/io/reactivex/Completable.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 06a9cd79da..de9f021277 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -511,7 +511,7 @@ public static Completable fromObservable(final ObservableSource observabl * Returns a Completable instance that subscribes to the given publisher, ignores all values and * emits only the terminal event. *

- * + * *

* The {@link Publisher} must follow the * Reactive-Streams specification. @@ -2427,8 +2427,6 @@ public final Flowable toFlowable() { /** * Converts this Completable into a {@link Maybe}. - *

- * *

*
Scheduler:
*
{@code toMaybe} does not operate by default on a particular {@link Scheduler}.
@@ -2451,6 +2449,8 @@ public final Maybe toMaybe() { /** * Returns an Observable which when subscribed to subscribes to this Completable and * relays the terminal events to the subscriber. + *

+ * *

*
Scheduler:
*
{@code toObservable} does not operate by default on a particular {@link Scheduler}.
From a80b657e2dfa213061ea43ffa1e6096ef319d3a8 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 19 Jul 2018 16:11:01 +0200 Subject: [PATCH 027/211] 2.x: Several more Completable marbles (7/19b) (#6098) --- src/main/java/io/reactivex/Completable.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index de9f021277..42ae598e35 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -2230,6 +2230,8 @@ public final Disposable subscribe(final Action onComplete) { /** * Returns a Completable which subscribes the child subscriber on the specified scheduler, making * sure the subscription side-effects happen on that specific thread of the scheduler. + *

+ * *

*
Scheduler:
*
{@code subscribeOn} operates on a {@link Scheduler} you specify.
@@ -2405,6 +2407,8 @@ public final U to(Function converter) { /** * Returns a Flowable which when subscribed to subscribes to this Completable and * relays the terminal events to the subscriber. + *

+ * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
@@ -2427,6 +2431,8 @@ public final Flowable toFlowable() { /** * Converts this Completable into a {@link Maybe}. + *

+ * *

*
Scheduler:
*
{@code toMaybe} does not operate by default on a particular {@link Scheduler}.
@@ -2471,6 +2477,8 @@ public final Observable toObservable() { /** * Converts this Completable into a Single which when this Completable completes normally, * calls the given supplier and emits its returned value through onSuccess. + *

+ * *

*
Scheduler:
*
{@code toSingle} does not operate by default on a particular {@link Scheduler}.
@@ -2490,6 +2498,8 @@ public final Single toSingle(final Callable completionValueS /** * Converts this Completable into a Single which when this Completable completes normally, * emits the given value through onSuccess. + *

+ * *

*
Scheduler:
*
{@code toSingleDefault} does not operate by default on a particular {@link Scheduler}.
@@ -2509,6 +2519,8 @@ public final Single toSingleDefault(final T completionValue) { /** * Returns a Completable which makes sure when a subscriber cancels the subscription, the * dispose is called on the specified scheduler. + *

+ * *

*
Scheduler:
*
{@code unsubscribeOn} calls dispose() of the upstream on the {@link Scheduler} you specify.
From ca5119cde5b5761d12d0c8071f17f1b2406971c4 Mon Sep 17 00:00:00 2001 From: Jason Neufeld Date: Thu, 19 Jul 2018 12:54:37 -0700 Subject: [PATCH 028/211] Update TestHelper.java: trivial typo fix (#6099) --- src/test/java/io/reactivex/TestHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/reactivex/TestHelper.java b/src/test/java/io/reactivex/TestHelper.java index 60a7fdfd81..6ac1e5cc75 100644 --- a/src/test/java/io/reactivex/TestHelper.java +++ b/src/test/java/io/reactivex/TestHelper.java @@ -482,7 +482,7 @@ public static > void checkEnum(Class enumClass) { } /** - * Returns an Consumer that asserts the TestSubscriber has exaclty one value + completed + * Returns an Consumer that asserts the TestSubscriber has exactly one value + completed * normally and that single value is not the value specified. * @param the value type * @param value the value not expected @@ -505,7 +505,7 @@ public void accept(TestSubscriber ts) throws Exception { } /** - * Returns an Consumer that asserts the TestObserver has exaclty one value + completed + * Returns an Consumer that asserts the TestObserver has exactly one value + completed * normally and that single value is not the value specified. * @param the value type * @param value the value not expected From f4a18fdb9b7ccb9cd868aaf1e31605df55046230 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 20 Jul 2018 13:15:09 +0200 Subject: [PATCH 029/211] 2.x: Final set of missing Completable marbles (#6101) --- src/main/java/io/reactivex/Completable.java | 52 +++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 42ae598e35..d00cd9b451 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -264,6 +264,8 @@ public static Completable concat(Publisher sources, /** * Provides an API (via a cold Completable) that bridges the reactive world with the callback-style world. *

+ * + *

* Example: *


      * Completable.create(emitter -> {
@@ -305,6 +307,8 @@ public static Completable create(CompletableOnSubscribe source) {
      * Constructs a Completable instance by wrapping the given source callback
      * without any safeguards; you should manage the lifecycle and response
      * to downstream cancellation/dispose.
+     * 

+ * *

*
Scheduler:
*
{@code unsafeCreate} does not operate by default on a particular {@link Scheduler}.
@@ -1585,6 +1589,8 @@ public final Completable doFinally(Action onFinally) { * and providing a new {@code CompletableObserver}, containing the custom operator's intended business logic, that will be * used in the subscription process going further upstream. *

+ * + *

* Generally, such a new {@code CompletableObserver} will wrap the downstream's {@code CompletableObserver} and forwards the * {@code onError} and {@code onComplete} events from the upstream directly or according to the * emission pattern the custom operator's business logic requires. In addition, such operator can intercept the @@ -1831,6 +1837,8 @@ public final Completable onTerminateDetach() { /** * Returns a Completable that repeatedly subscribes to this Completable until cancelled. + *

+ * *

*
Scheduler:
*
{@code repeat} does not operate by default on a particular {@link Scheduler}.
@@ -1845,6 +1853,8 @@ public final Completable repeat() { /** * Returns a Completable that subscribes repeatedly at most the given times to this Completable. + *

+ * *

*
Scheduler:
*
{@code repeat} does not operate by default on a particular {@link Scheduler}.
@@ -1862,6 +1872,8 @@ public final Completable repeat(long times) { /** * Returns a Completable that repeatedly subscribes to this Completable so long as the given * stop supplier returns false. + *

+ * *

*
Scheduler:
*
{@code repeatUntil} does not operate by default on a particular {@link Scheduler}.
@@ -1879,6 +1891,8 @@ public final Completable repeatUntil(BooleanSupplier stop) { /** * Returns a Completable instance that repeats when the Publisher returned by the handler * emits an item or completes when this Publisher emits a completed event. + *

+ * *

*
Scheduler:
*
{@code repeatWhen} does not operate by default on a particular {@link Scheduler}.
@@ -1897,6 +1911,8 @@ public final Completable repeatWhen(Function, ? extends /** * Returns a Completable that retries this Completable as long as it emits an onError event. + *

+ * *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
@@ -1912,6 +1928,8 @@ public final Completable retry() { /** * Returns a Completable that retries this Completable in case of an error as long as the predicate * returns true. + *

+ * *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
@@ -1929,6 +1947,8 @@ public final Completable retry(BiPredicate p /** * Returns a Completable that when this Completable emits an error, retries at most the given * number of times before giving up and emitting the last error. + *

+ * *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
@@ -1946,6 +1966,8 @@ public final Completable retry(long times) { /** * Returns a Completable that when this Completable emits an error, retries at most times * or until the predicate returns false, whichever happens first and emitting the last error. + *

+ * *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
@@ -1968,6 +1990,8 @@ public final Completable retry(long times, Predicate predicat /** * Returns a Completable that when this Completable emits an error, calls the given predicate with * the latest exception to decide whether to resubscribe to this or not. + *

+ * *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
@@ -1988,6 +2012,8 @@ public final Completable retry(Predicate predicate) { * that error through a Flowable and the Publisher should signal a value indicating a retry in response * or a terminal event indicating a termination. *

+ * + *

* Note that the inner {@code Publisher} returned by the handler function should signal * either {@code onNext}, {@code onError} or {@code onComplete} in response to the received * {@code Throwable} to indicate the operator should retry or terminate. If the upstream to @@ -2030,6 +2056,8 @@ public final Completable retryWhen(Function, ? exten /** * Returns a Completable which first runs the other Completable * then this completable if the other completed normally. + *

+ * *

*
Scheduler:
*
{@code startWith} does not operate by default on a particular {@link Scheduler}.
@@ -2048,6 +2076,8 @@ public final Completable startWith(CompletableSource other) { /** * Returns an Observable which first delivers the events * of the other Observable then runs this CompletableConsumable. + *

+ * *

*
Scheduler:
*
{@code startWith} does not operate by default on a particular {@link Scheduler}.
@@ -2066,6 +2096,8 @@ public final Observable startWith(Observable other) { /** * Returns a Flowable which first delivers the events * of the other Publisher then runs this Completable. + *

+ * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer @@ -2109,6 +2141,8 @@ public final Completable hide() { /** * Subscribes to this CompletableConsumable and returns a Disposable which can be used to cancel * the subscription. + *

+ * *

*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
@@ -2153,6 +2187,8 @@ public final void subscribe(CompletableObserver s) { /** * Subscribes a given CompletableObserver (subclass) to this Completable and returns the given * CompletableObserver as is. + *

+ * *

Usage example: *


      * Completable source = Completable.complete().delay(1, TimeUnit.SECONDS);
@@ -2183,6 +2219,8 @@ public final  E subscribeWith(E observer) {
 
     /**
      * Subscribes to this Completable and calls back either the onError or onComplete functions.
+     * 

+ * *

*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
@@ -2207,6 +2245,8 @@ public final Disposable subscribe(final Action onComplete, final Consumer + * + *

* If the Completable emits an error, it is wrapped into an * {@link io.reactivex.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException} * and routed to the RxJavaPlugins.onError handler. @@ -2277,6 +2317,8 @@ public final Completable takeUntil(CompletableSource other) { /** * Returns a Completable that runs this Completable and emits a TimeoutException in case * this Completable doesn't complete within the given time. + *

+ * *

*
Scheduler:
*
{@code timeout} signals the TimeoutException on the {@code computation} {@link Scheduler}.
@@ -2295,6 +2337,8 @@ public final Completable timeout(long timeout, TimeUnit unit) { /** * Returns a Completable that runs this Completable and switches to the other Completable * in case this Completable doesn't complete within the given time. + *

+ * *

*
Scheduler:
*
{@code timeout} subscribes to the other CompletableSource on @@ -2317,6 +2361,8 @@ public final Completable timeout(long timeout, TimeUnit unit, CompletableSource * Returns a Completable that runs this Completable and emits a TimeoutException in case * this Completable doesn't complete within the given time while "waiting" on the specified * Scheduler. + *

+ * *

*
Scheduler:
*
{@code timeout} signals the TimeoutException on the {@link Scheduler} you specify.
@@ -2337,6 +2383,8 @@ public final Completable timeout(long timeout, TimeUnit unit, Scheduler schedule * Returns a Completable that runs this Completable and switches to the other Completable * in case this Completable doesn't complete within the given time while "waiting" on * the specified scheduler. + *

+ * *

*
Scheduler:
*
{@code timeout} subscribes to the other CompletableSource on @@ -2542,6 +2590,8 @@ public final Completable unsubscribeOn(final Scheduler scheduler) { /** * Creates a TestObserver and subscribes * it to this Completable. + *

+ * *

*
Scheduler:
*
{@code test} does not operate by default on a particular {@link Scheduler}.
@@ -2561,6 +2611,8 @@ public final TestObserver test() { * Creates a TestObserver optionally in cancelled state, then subscribes it to this Completable. * @param cancelled if true, the TestObserver will be cancelled before subscribing to this * Completable. + *

+ * *

*
Scheduler:
*
{@code test} does not operate by default on a particular {@link Scheduler}.
From 4c89100dbb237c4d549ec503d5ef6bbee802ae9d Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 20 Jul 2018 14:26:44 +0200 Subject: [PATCH 030/211] 2.x: Adjust JavaDoc stylesheet of dt/dd within the method details (#6102) --- gradle/stylesheet.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/stylesheet.css b/gradle/stylesheet.css index 52b6b690b0..5e381dce8b 100644 --- a/gradle/stylesheet.css +++ b/gradle/stylesheet.css @@ -284,10 +284,10 @@ Page layout container styles margin:10px 0 0 0; color:#4E4E4E; } -/*.contentContainer .description dl dd, */.contentContainer .details dl dd, .serializedFormContainer dl dd { - margin:5px 0 10px 0px; +.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { + /* margin:5px 0 10px 0px; */ font-size:14px; - font-family:'DejaVu Sans Mono',monospace; + font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; } .serializedFormContainer dl.nameValue dt { margin-left:1px; From c5a42a273836c4d1f87d07843bef2789354ac710 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 20 Jul 2018 14:44:11 +0200 Subject: [PATCH 031/211] 2.x: Fix Completable mergeX JavaDoc missing dt before dd (#6103) --- src/main/java/io/reactivex/Completable.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index d00cd9b451..08485ee3f5 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -577,6 +577,7 @@ public static Completable fromSingle(final SingleSource single) { *
*
Scheduler:
*
{@code mergeArray} does not operate by default on a particular {@link Scheduler}.
+ *
Error handling:
*
If any of the source {@code CompletableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are cancelled. * If more than one {@code CompletableSource} signals an error, the resulting {@code Completable} may terminate with the @@ -653,6 +654,7 @@ public static Completable merge(Iterable sources) { * and expects the other {@code Publisher} to honor it as well.
*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
+ *
Error handling:
*
If any of the source {@code CompletableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are cancelled. * If more than one {@code CompletableSource} signals an error, the resulting {@code Completable} may terminate with the @@ -689,6 +691,7 @@ public static Completable merge(Publisher sources) * and expects the other {@code Publisher} to honor it as well.
*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
+ *
Error handling:
*
If any of the source {@code CompletableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are cancelled. * If more than one {@code CompletableSource} signals an error, the resulting {@code Completable} may terminate with the From 0155b69866f07f02902674c1d57311d273f4325c Mon Sep 17 00:00:00 2001 From: lcybo Date: Sun, 22 Jul 2018 19:26:52 +0800 Subject: [PATCH 032/211] Fixing javadoc's code example of Observable#lift. (#6104) --- src/main/java/io/reactivex/Observable.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index c74ab3f7d4..a3f204206b 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -9414,7 +9414,7 @@ public final Single lastOrError() { * @Override * public void onSubscribe(Disposable s) { * if (upstream != null) { - * s.cancel(); + * s.dispose(); * } else { * upstream = s; * downstream.onSubscribe(this); @@ -9473,10 +9473,10 @@ public final Single lastOrError() { * // Such class may define additional parameters to be submitted to * // the custom consumer type. * - * final class CustomOperator<T> implements ObservableOperator<String> { + * final class CustomOperator<T> implements ObservableOperator<String, T> { * @Override - * public Observer<? super String> apply(Observer<? super T> upstream) { - * return new CustomObserver<T>(upstream); + * public Observer<T> apply(Observer<? super String> downstream) { + * return new CustomObserver<T>(downstream); * } * } * From ce5ce4bbb2e2da38d0098d228cc81812f430f44c Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 23 Jul 2018 09:21:10 +0200 Subject: [PATCH 033/211] Release 2.1.17 --- CHANGES.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 91bd6b465c..2312403710 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,40 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.1.17 - July 23, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.1.17%7C)) + +#### API changes + + - [Pull 6079](https://github.com/ReactiveX/RxJava/pull/6079): Add `Completable.takeUntil(Completable)` operator. + - [Pull 6085](https://github.com/ReactiveX/RxJava/pull/6085): Add `Completable.fromMaybe` operator. + +#### Performance improvements + + - [Pull 6096](https://github.com/ReactiveX/RxJava/pull/6096): Improve `Completable.delay` operator internals. + +#### Documentation changes +- [Pull 6066](https://github.com/ReactiveX/RxJava/pull/6066): Fix links for `Single` class. +- [Pull 6070](https://github.com/ReactiveX/RxJava/pull/6070): Adjust JavaDocs `dl`/`dd` entry stylesheet. +- [Pull 6080](https://github.com/ReactiveX/RxJava/pull/6080): Improve class JavaDoc of `Single`, `Maybe` and `Completable`. +- [Pull 6102](https://github.com/ReactiveX/RxJava/pull/6102): Adjust JavaDoc stylesheet of `dt`/`dd` within the method details. +- [Pull 6103](https://github.com/ReactiveX/RxJava/pull/6103): Fix `Completable` `mergeX` JavaDoc missing `dt` before `dd`. +- [Pull 6104](https://github.com/ReactiveX/RxJava/pull/6104): Fixing javadoc's code example of `Observable#lift`. +- Marble diagrams ([Tracking issue 5789](https://github.com/ReactiveX/RxJava/issues/5789)) + - [Pull 6074](https://github.com/ReactiveX/RxJava/pull/6074): `Single.never` method. + - [Pull 6075](https://github.com/ReactiveX/RxJava/pull/6075): `Single.filter` method. + - [Pull 6078](https://github.com/ReactiveX/RxJava/pull/6078): `Maybe.hide` marble diagram. + - [Pull 6076](https://github.com/ReactiveX/RxJava/pull/6076): `Single.delay` method. + - [Pull 6077](https://github.com/ReactiveX/RxJava/pull/6077): `Single.hide` operator. + - [Pull 6083](https://github.com/ReactiveX/RxJava/pull/6083): Add `Completable` marble diagrams (07/17a). + - [Pull 6081](https://github.com/ReactiveX/RxJava/pull/6081): `Single.repeat` operators. + - [Pull 6085](https://github.com/ReactiveX/RxJava/pull/6085): More `Completable` marbles. + - [Pull 6084](https://github.com/ReactiveX/RxJava/pull/6084): `Single.repeatUntil` operator. + - [Pull 6090](https://github.com/ReactiveX/RxJava/pull/6090): Add missing `Completable` marbles (+17, 07/18a). + - [Pull 6091](https://github.com/ReactiveX/RxJava/pull/6091): `Single.amb` operators. + - [Pull 6097](https://github.com/ReactiveX/RxJava/pull/6097): Add missing `Completable` marbles (+19, 07/19a). + - [Pull 6098](https://github.com/ReactiveX/RxJava/pull/6098): Several more `Completable` marbles (7/19b). + - [Pull 6101](https://github.com/ReactiveX/RxJava/pull/6101): Final set of missing `Completable` marbles (+26). + ### Version 2.1.16 - June 26, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.1.16%7C)) This is a hotfix release for a late-identified issue with `concatMapMaybe` and `concatMapSingle`. From e8930c2830869f1089ac7627dda044e8d861fb6b Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 30 Jul 2018 15:56:37 +0200 Subject: [PATCH 034/211] 2.x: Promote all Experimental/Beta API to standard (#6105) --- src/main/java/io/reactivex/Completable.java | 19 +- .../io/reactivex/CompletableConverter.java | 5 +- .../java/io/reactivex/CompletableEmitter.java | 4 +- src/main/java/io/reactivex/Flowable.java | 179 ++++++++---------- .../java/io/reactivex/FlowableConverter.java | 5 +- .../java/io/reactivex/FlowableEmitter.java | 4 +- .../java/io/reactivex/FlowableSubscriber.java | 5 +- src/main/java/io/reactivex/Maybe.java | 15 +- .../java/io/reactivex/MaybeConverter.java | 5 +- src/main/java/io/reactivex/MaybeEmitter.java | 4 +- src/main/java/io/reactivex/Observable.java | 136 +++++++------ .../io/reactivex/ObservableConverter.java | 5 +- .../java/io/reactivex/ObservableEmitter.java | 4 +- src/main/java/io/reactivex/Single.java | 50 +++-- .../java/io/reactivex/SingleConverter.java | 5 +- src/main/java/io/reactivex/SingleEmitter.java | 4 +- .../annotations/SchedulerSupport.java | 4 +- .../OnErrorNotImplementedException.java | 5 +- .../ProtocolViolationException.java | 7 +- .../exceptions/UndeliverableException.java | 7 +- .../flowables/ConnectableFlowable.java | 20 +- .../completable/CompletableCache.java | 6 +- .../completable/CompletableDetach.java | 6 +- .../completable/CompletableDoFinally.java | 6 +- .../CompletableTakeUntilCompletable.java | 5 +- .../FlowableConcatMapEagerPublisher.java | 3 +- .../FlowableConcatWithCompletable.java | 3 +- .../flowable/FlowableConcatWithMaybe.java | 3 +- .../flowable/FlowableConcatWithSingle.java | 3 +- .../flowable/FlowableDoAfterNext.java | 4 +- .../operators/flowable/FlowableDoFinally.java | 5 +- .../operators/flowable/FlowableLimit.java | 6 +- .../flowable/FlowableMapPublisher.java | 4 +- .../FlowableMergeWithCompletable.java | 4 +- .../flowable/FlowableMergeWithMaybe.java | 4 +- .../flowable/FlowableMergeWithSingle.java | 4 +- .../flowable/FlowableTakePublisher.java | 4 +- .../flowable/FlowableThrottleLatest.java | 6 +- .../operators/maybe/MaybeDoAfterSuccess.java | 5 +- .../operators/maybe/MaybeDoFinally.java | 6 +- .../maybe/MaybeFlatMapSingleElement.java | 6 +- .../operators/maybe/MaybeToObservable.java | 5 +- .../mixed/FlowableConcatMapCompletable.java | 5 +- .../mixed/FlowableConcatMapMaybe.java | 7 +- .../mixed/FlowableConcatMapSingle.java | 7 +- .../mixed/FlowableSwitchMapCompletable.java | 6 +- .../mixed/FlowableSwitchMapMaybe.java | 6 +- .../mixed/FlowableSwitchMapSingle.java | 6 +- .../mixed/ObservableConcatMapCompletable.java | 5 +- .../mixed/ObservableConcatMapMaybe.java | 7 +- .../mixed/ObservableConcatMapSingle.java | 7 +- .../mixed/ObservableSwitchMapCompletable.java | 6 +- .../mixed/ObservableSwitchMapMaybe.java | 6 +- .../mixed/ObservableSwitchMapSingle.java | 6 +- .../operators/mixed/ScalarXMapZHelper.java | 5 +- .../ObservableConcatWithCompletable.java | 3 +- .../observable/ObservableConcatWithMaybe.java | 3 +- .../ObservableConcatWithSingle.java | 3 +- .../observable/ObservableDoAfterNext.java | 5 +- .../observable/ObservableDoFinally.java | 6 +- .../ObservableMergeWithCompletable.java | 4 +- .../observable/ObservableMergeWithMaybe.java | 4 +- .../observable/ObservableMergeWithSingle.java | 4 +- .../observable/ObservableThrottleLatest.java | 6 +- .../parallel/ParallelDoOnNextTry.java | 4 +- .../operators/parallel/ParallelMapTry.java | 4 +- .../operators/single/SingleDetach.java | 6 +- .../single/SingleDoAfterSuccess.java | 5 +- .../single/SingleDoAfterTerminate.java | 3 +- .../operators/single/SingleDoFinally.java | 6 +- .../operators/single/SingleToObservable.java | 5 +- .../SchedulerMultiWorkerSupport.java | 5 +- .../internal/schedulers/SchedulerWhen.java | 4 +- .../observables/ConnectableObservable.java | 20 +- .../reactivex/observers/BaseTestConsumer.java | 56 +++--- .../LambdaConsumerIntrospection.java | 9 +- .../parallel/ParallelFailureHandling.java | 5 +- .../reactivex/parallel/ParallelFlowable.java | 43 ++--- .../parallel/ParallelFlowableConverter.java | 5 +- .../parallel/ParallelTransformer.java | 6 +- .../io/reactivex/plugins/RxJavaPlugins.java | 15 +- .../processors/BehaviorProcessor.java | 4 +- .../processors/MulticastProcessor.java | 4 +- .../processors/PublishProcessor.java | 4 +- .../reactivex/processors/ReplayProcessor.java | 4 +- .../processors/UnicastProcessor.java | 13 +- .../SchedulerRunnableIntrospection.java | 5 +- .../io/reactivex/subjects/ReplaySubject.java | 4 +- .../io/reactivex/subjects/UnicastSubject.java | 17 +- 89 files changed, 428 insertions(+), 535 deletions(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 08485ee3f5..8993524b46 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -458,10 +458,12 @@ public static Completable fromFuture(final Future future) { *
Scheduler:
*
{@code fromMaybe} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.17 - beta * @param the value type of the {@link MaybeSource} element * @param maybe the Maybe instance to subscribe to, not null * @return the new Completable instance * @throws NullPointerException if single is null + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @@ -1138,14 +1140,13 @@ public final Completable andThen(CompletableSource next) { *

Scheduler:
*
{@code as} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.7 - experimental * @param the resulting object type * @param converter the function that receives the current Completable instance and returns a value * @return the converted value * @throws NullPointerException if converter is null - * @since 2.1.7 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final R as(@NonNull CompletableConverter converter) { @@ -1827,11 +1828,11 @@ public final Completable onErrorResumeNext(final FunctionScheduler: *

{@code onTerminateDetach} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.5 - experimental * @return a Completable which nulls out references to the upstream producer and downstream CompletableObserver if * the sequence is terminated or downstream calls dispose() - * @since 2.1.5 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable onTerminateDetach() { @@ -1975,15 +1976,15 @@ public final Completable retry(long times) { *

Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.8 - experimental * @param times the number of times the returned Completable should retry this Completable * @param predicate the predicate that is called with the latest throwable and should return * true to indicate the returned Completable should resubscribe to this Completable. * @return the new Completable instance * @throws NullPointerException if predicate is null * @throws IllegalArgumentException if times is negative - * @since 2.1.8 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable retry(long times, Predicate predicate) { @@ -2304,12 +2305,12 @@ public final Completable subscribeOn(final Scheduler scheduler) { * is signaled to the downstream and the other error is signaled to the global * error handler via {@link RxJavaPlugins#onError(Throwable)}.

*
+ *

History: 2.1.17 - experimental * @param other the other completable source to observe for the terminal signals * @return the new Completable instance - * @since 2.1.17 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.NONE) public final Completable takeUntil(CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); diff --git a/src/main/java/io/reactivex/CompletableConverter.java b/src/main/java/io/reactivex/CompletableConverter.java index 39ec9b452b..1bea8631c8 100644 --- a/src/main/java/io/reactivex/CompletableConverter.java +++ b/src/main/java/io/reactivex/CompletableConverter.java @@ -18,11 +18,10 @@ /** * Convenience interface and callback used by the {@link Completable#as} operator to turn a Completable into another * value fluently. - * + *

History: 2.1.7 - experimental * @param the output type - * @since 2.1.7 - experimental + * @since 2.2 */ -@Experimental public interface CompletableConverter { /** * Applies a function to the upstream Completable and returns a converted value of type {@code R}. diff --git a/src/main/java/io/reactivex/CompletableEmitter.java b/src/main/java/io/reactivex/CompletableEmitter.java index 7a8d2e1e75..b32e329c3b 100644 --- a/src/main/java/io/reactivex/CompletableEmitter.java +++ b/src/main/java/io/reactivex/CompletableEmitter.java @@ -88,11 +88,11 @@ public interface CompletableEmitter { *

* Unlike {@link #onError(Throwable)}, the {@code RxJavaPlugins.onError} is not called * if the error could not be delivered. + *

History: 2.1.1 - experimental * @param t the throwable error to signal if possible * @return true if successful, false if the downstream is not able to accept further * events - * @since 2.1.1 - experimental + * @since 2.2 */ - @Experimental boolean tryOnError(@NonNull Throwable t); } diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 04a31f471d..84d4e6bba5 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -5392,14 +5392,13 @@ public final Single any(Predicate predicate) { *

Scheduler:
*
{@code as} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.7 - experimental * @param the resulting object type * @param converter the function that receives the current Flowable instance and returns a value * @return the converted value * @throws NullPointerException if converter is null - * @since 2.1.7 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) @@ -5870,15 +5869,15 @@ public final void blockingSubscribe(Consumer onNext) { *

Scheduler:
*
{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.15 - experimental * @param onNext the callback action for each source value * @param bufferSize the size of the buffer - * @since 2.1.15 - experimental * @see #blockingSubscribe(Consumer, Consumer) * @see #blockingSubscribe(Consumer, Consumer, Action) + * @since 2.2 */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final void blockingSubscribe(Consumer onNext, int bufferSize) { FlowableBlockingSubscribe.subscribe(this, onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION, bufferSize); } @@ -5920,15 +5919,15 @@ public final void blockingSubscribe(Consumer onNext, ConsumerScheduler: *

{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.15 - experimental * @param onNext the callback action for each source value * @param onError the callback action for an error event * @param bufferSize the size of the buffer - * @since 2.1.15 - experimental + * @since 2.2 * @see #blockingSubscribe(Consumer, Consumer, Action) */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final void blockingSubscribe(Consumer onNext, Consumer onError, int bufferSize) { FlowableBlockingSubscribe.subscribe(this, onNext, onError, Functions.EMPTY_ACTION, bufferSize); @@ -5971,15 +5970,15 @@ public final void blockingSubscribe(Consumer onNext, ConsumerScheduler: *

{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.15 - experimental * @param onNext the callback action for each source value * @param onError the callback action for an error event * @param onComplete the callback action for the completion event. * @param bufferSize the size of the buffer - * @since 2.1.15 - experimental + * @since 2.2 */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final void blockingSubscribe(Consumer onNext, Consumer onError, Action onComplete, int bufferSize) { FlowableBlockingSubscribe.subscribe(this, onNext, onError, onComplete, bufferSize); @@ -7067,17 +7066,17 @@ public final Flowable concatMap(FunctionScheduler: *

{@code concatMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to * @return a new Completable instance - * @since 2.1.11 - experimental * @see #concatMapCompletableDelayError(Function) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.FULL) - @Experimental public final Completable concatMapCompletable(Function mapper) { return concatMapCompletable(mapper, 2); } @@ -7094,6 +7093,7 @@ public final Completable concatMapCompletable(FunctionScheduler: *

{@code concatMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to @@ -7102,13 +7102,12 @@ public final Completable concatMapCompletable(Function mapper, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -7128,17 +7127,17 @@ public final Completable concatMapCompletable(FunctionScheduler: *

{@code concatMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to * @return a new Completable instance - * @since 2.1.11 - experimental * @see #concatMapCompletable(Function, int) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.FULL) - @Experimental public final Completable concatMapCompletableDelayError(Function mapper) { return concatMapCompletableDelayError(mapper, true, 2); } @@ -7156,6 +7155,7 @@ public final Completable concatMapCompletableDelayError(FunctionScheduler: *

{@code concatMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to @@ -7166,13 +7166,12 @@ public final Completable concatMapCompletableDelayError(Function mapper, boolean tillTheEnd) { return concatMapCompletableDelayError(mapper, tillTheEnd, 2); } @@ -7190,6 +7189,7 @@ public final Completable concatMapCompletableDelayError(FunctionScheduler: *

{@code concatMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to @@ -7204,13 +7204,12 @@ public final Completable concatMapCompletableDelayError(Function mapper, boolean tillTheEnd, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -7495,19 +7494,19 @@ public final Flowable concatMapIterable(final FunctionScheduler: *

{@code concatMapMaybe} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to * be subscribed to * @return a new Flowable instance - * @since 2.1.11 - experimental * @see #concatMapMaybeDelayError(Function) * @see #concatMapMaybe(Function, int) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable concatMapMaybe(Function> mapper) { return concatMapMaybe(mapper, 2); } @@ -7526,6 +7525,7 @@ public final Flowable concatMapMaybe(FunctionScheduler: *

{@code concatMapMaybe} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to @@ -7535,14 +7535,13 @@ public final Flowable concatMapMaybe(Function Flowable concatMapMaybe(Function> mapper, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -7563,19 +7562,19 @@ public final Flowable concatMapMaybe(FunctionScheduler: *

{@code concatMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to * be subscribed to * @return a new Flowable instance - * @since 2.1.11 - experimental * @see #concatMapMaybe(Function) * @see #concatMapMaybeDelayError(Function, boolean) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable concatMapMaybeDelayError(Function> mapper) { return concatMapMaybeDelayError(mapper, true, 2); } @@ -7594,6 +7593,7 @@ public final Flowable concatMapMaybeDelayError(FunctionScheduler: *

{@code concatMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to @@ -7605,14 +7605,13 @@ public final Flowable concatMapMaybeDelayError(Function Flowable concatMapMaybeDelayError(Function> mapper, boolean tillTheEnd) { return concatMapMaybeDelayError(mapper, tillTheEnd, 2); } @@ -7631,6 +7630,7 @@ public final Flowable concatMapMaybeDelayError(FunctionScheduler: *

{@code concatMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to @@ -7646,13 +7646,12 @@ public final Flowable concatMapMaybeDelayError(Function Flowable concatMapMaybeDelayError(Function> mapper, boolean tillTheEnd, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -7673,19 +7672,19 @@ public final Flowable concatMapMaybeDelayError(FunctionScheduler: *

{@code concatMapSingle} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to * be subscribed to * @return a new Flowable instance - * @since 2.1.11 - experimental * @see #concatMapSingleDelayError(Function) * @see #concatMapSingle(Function, int) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable concatMapSingle(Function> mapper) { return concatMapSingle(mapper, 2); } @@ -7704,6 +7703,7 @@ public final Flowable concatMapSingle(FunctionScheduler: *

{@code concatMapSingle} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to @@ -7713,14 +7713,13 @@ public final Flowable concatMapSingle(Function Flowable concatMapSingle(Function> mapper, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -7741,19 +7740,19 @@ public final Flowable concatMapSingle(FunctionScheduler: *

{@code concatMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to * be subscribed to * @return a new Flowable instance - * @since 2.1.11 - experimental * @see #concatMapSingle(Function) * @see #concatMapSingleDelayError(Function, boolean) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable concatMapSingleDelayError(Function> mapper) { return concatMapSingleDelayError(mapper, true, 2); } @@ -7772,6 +7771,7 @@ public final Flowable concatMapSingleDelayError(FunctionScheduler: *

{@code concatMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to @@ -7783,14 +7783,13 @@ public final Flowable concatMapSingleDelayError(Function Flowable concatMapSingleDelayError(Function> mapper, boolean tillTheEnd) { return concatMapSingleDelayError(mapper, tillTheEnd, 2); } @@ -7809,6 +7808,7 @@ public final Flowable concatMapSingleDelayError(FunctionScheduler: *

{@code concatMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to @@ -7824,13 +7824,12 @@ public final Flowable concatMapSingleDelayError(Function Flowable concatMapSingleDelayError(Function> mapper, boolean tillTheEnd, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -7877,14 +7876,14 @@ public final Flowable concatWith(Publisher other) { *

Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.10 - experimental * @param other the SingleSource whose signal should be emitted after this {@code Flowable} completes normally. * @return the new Flowable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable concatWith(@NonNull SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new FlowableConcatWithSingle(this, other)); @@ -7902,14 +7901,14 @@ public final Flowable concatWith(@NonNull SingleSource other) { *

Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.10 - experimental * @param other the MaybeSource whose signal should be emitted after this Flowable completes normally. * @return the new Flowable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable concatWith(@NonNull MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new FlowableConcatWithMaybe(this, other)); @@ -7929,14 +7928,14 @@ public final Flowable concatWith(@NonNull MaybeSource other) { *

Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.10 - experimental * @param other the {@code CompletableSource} to subscribe to once the current {@code Flowable} completes normally * @return the new Flowable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable concatWith(@NonNull CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new FlowableConcatWithCompletable(this, other)); @@ -10468,7 +10467,7 @@ public final Flowable> groupBy(FunctionScheduler: *

{@code groupBy} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.10 - beta * @param keySelector * a function that extracts the key for each item * @param valueSelector @@ -10493,12 +10492,11 @@ public final Flowable> groupBy(FunctionReactiveX operators documentation: GroupBy * - * @since 2.1.10 + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Beta public final Flowable> groupBy(Function keySelector, Function valueSelector, boolean delayError, int bufferSize, @@ -10936,16 +10934,15 @@ public final Flowable lift(FlowableOperator lifte *

Scheduler:
*
{@code limit} does not operate by default on a particular {@link Scheduler}.
*
- + *

History: 2.1.6 - experimental * @param count the maximum number of items and the total request amount, non-negative. * Zero will immediately cancel the upstream on subscription and complete * the downstream. * @return the new Flowable instance * @see #take(long) * @see #rebatchRequests(int) - * @since 2.1.6 - experimental + * @since 2.2 */ - @Experimental @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) @CheckReturnValue @@ -11050,15 +11047,14 @@ public final Flowable mergeWith(Publisher other) { *

Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.10 - experimental * @param other the {@code SingleSource} whose success value to merge with * @return the new Flowable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable mergeWith(@NonNull SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new FlowableMergeWithSingle(this, other)); @@ -11079,15 +11075,14 @@ public final Flowable mergeWith(@NonNull SingleSource other) { *

Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.10 - experimental * @param other the {@code MaybeSource} which provides a success value to merge with or completes * @return the new Flowable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable mergeWith(@NonNull MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new FlowableMergeWithMaybe(this, other)); @@ -11105,15 +11100,14 @@ public final Flowable mergeWith(@NonNull MaybeSource other) { *

Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.10 - experimental * @param other the {@code CompletableSource} to await for completion * @return the new Flowable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable mergeWith(@NonNull CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new FlowableMergeWithCompletable(this, other)); @@ -11842,14 +11836,13 @@ public final Flowable onTerminateDetach() { *

Scheduler:
*
{@code parallel} does not operate by default on a particular {@link Scheduler}.
*
- *

History: 2.0.5 - experimental + *

History: 2.0.5 - experimental; 2.1 - beta * @return the new ParallelFlowable instance - * @since 2.1 - beta + * @since 2.2 */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @CheckReturnValue - @Beta public final ParallelFlowable parallel() { return ParallelFlowable.from(this); } @@ -11872,15 +11865,14 @@ public final ParallelFlowable parallel() { *

Scheduler:
*
{@code parallel} does not operate by default on a particular {@link Scheduler}.
*
- *

History: 2.0.5 - experimental + *

History: 2.0.5 - experimental; 2.1 - beta * @param parallelism the number of 'rails' to use * @return the new ParallelFlowable instance - * @since 2.1 - beta + * @since 2.2 */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @CheckReturnValue - @Beta public final ParallelFlowable parallel(int parallelism) { ObjectHelper.verifyPositive(parallelism, "parallelism"); return ParallelFlowable.from(this, parallelism); @@ -11905,16 +11897,15 @@ public final ParallelFlowable parallel(int parallelism) { *

Scheduler:
*
{@code parallel} does not operate by default on a particular {@link Scheduler}.
*
- *

History: 2.0.5 - experimental + *

History: 2.0.5 - experimental; 2.1 - beta * @param parallelism the number of 'rails' to use * @param prefetch the number of items each 'rail' should prefetch * @return the new ParallelFlowable instance - * @since 2.1 - beta + * @since 2.2 */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @CheckReturnValue - @Beta public final ParallelFlowable parallel(int parallelism, int prefetch) { ObjectHelper.verifyPositive(parallelism, "parallelism"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -14402,13 +14393,12 @@ public final void subscribe(Subscriber s) { *

Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
- *

History: 2.0.7 - experimental + *

History: 2.0.7 - experimental; 2.1 - beta * @param s the FlowableSubscriber that will consume signals from this Flowable - * @since 2.1 - beta + * @since 2.2 */ @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) - @Beta public final void subscribe(FlowableSubscriber s) { ObjectHelper.requireNonNull(s, "s is null"); try { @@ -14525,7 +14515,7 @@ public final Flowable subscribeOn(@NonNull Scheduler scheduler) { *

Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
- * + *

History: 2.1.1 - experimental * @param scheduler * the {@link Scheduler} to perform subscription actions on * @param requestOn if true, requests are rerouted to the given Scheduler as well (strong pipelining) @@ -14536,12 +14526,11 @@ public final Flowable subscribeOn(@NonNull Scheduler scheduler) { * @see ReactiveX operators documentation: SubscribeOn * @see RxJava Threading Examples * @see #observeOn - * @since 2.1.1 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.CUSTOM) - @Experimental public final Flowable subscribeOn(@NonNull Scheduler scheduler, boolean requestOn) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new FlowableSubscribeOn(this, scheduler, requestOn)); @@ -14675,17 +14664,17 @@ public final Flowable switchMap(Function *

+ *

History: 2.1.11 - experimental * @param mapper the function called with each upstream item and should return a * {@link CompletableSource} to be subscribed to and awaited for * (non blockingly) for its terminal event * @return the new Completable instance - * @since 2.1.11 - experimental * @see #switchMapCompletableDelayError(Function) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Completable switchMapCompletable(@NonNull Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new FlowableSwitchMapCompletable(this, mapper, false)); @@ -14721,17 +14710,17 @@ public final Completable switchMapCompletable(@NonNull Function *

+ *

History: 2.1.11 - experimental * @param mapper the function called with each upstream item and should return a * {@link CompletableSource} to be subscribed to and awaited for * (non blockingly) for its terminal event * @return the new Completable instance - * @since 2.1.11 - experimental * @see #switchMapCompletableDelayError(Function) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Completable switchMapCompletableDelayError(@NonNull Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new FlowableSwitchMapCompletable(this, mapper, true)); @@ -14846,18 +14835,18 @@ Flowable switchMap0(Function> * {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)} as * {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}

*
+ *

History: 2.1.11 - experimental * @param the output value type * @param mapper the function called with the current upstream event and should * return a {@code MaybeSource} to replace the current active inner source * and get subscribed to. * @return the new Flowable instance - * @since 2.1.11 - experimental * @see #switchMapMaybe(Function) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable switchMapMaybe(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new FlowableSwitchMapMaybe(this, mapper, false)); @@ -14876,18 +14865,18 @@ public final Flowable switchMapMaybe(@NonNull FunctionScheduler: *

{@code switchMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the output value type * @param mapper the function called with the current upstream event and should * return a {@code MaybeSource} to replace the current active inner source * and get subscribed to. * @return the new Flowable instance - * @since 2.1.11 - experimental * @see #switchMapMaybe(Function) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable switchMapMaybeDelayError(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new FlowableSwitchMapMaybe(this, mapper, true)); @@ -14916,18 +14905,18 @@ public final Flowable switchMapMaybeDelayError(@NonNull Function *

+ *

History: 2.1.11 - experimental * @param the output value type * @param mapper the function called with the current upstream event and should * return a {@code SingleSource} to replace the current active inner source * and get subscribed to. * @return the new Flowable instance - * @since 2.1.11 - experimental * @see #switchMapSingle(Function) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable switchMapSingle(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new FlowableSwitchMapSingle(this, mapper, false)); @@ -14946,18 +14935,18 @@ public final Flowable switchMapSingle(@NonNull FunctionScheduler: *

{@code switchMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the output value type * @param mapper the function called with the current upstream event and should * return a {@code SingleSource} to replace the current active inner source * and get subscribed to. * @return the new Flowable instance - * @since 2.1.11 - experimental * @see #switchMapSingle(Function) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Flowable switchMapSingleDelayError(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new FlowableSwitchMapSingle(this, mapper, true)); @@ -15627,15 +15616,15 @@ public final Flowable throttleLast(long intervalDuration, TimeUnit unit, Sche *

Scheduler:
*
{@code throttleLatest} operates by default on the {@code computation} {@link Scheduler}.
*
+ *

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit * @return the new Flowable instance - * @since 2.1.14 - experimental + * @since 2.2 * @see #throttleLatest(long, TimeUnit, boolean) * @see #throttleLatest(long, TimeUnit, Scheduler) */ - @Experimental @CheckReturnValue @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.COMPUTATION) @@ -15661,6 +15650,7 @@ public final Flowable throttleLatest(long timeout, TimeUnit unit) { *

Scheduler:
*
{@code throttleLatest} operates by default on the {@code computation} {@link Scheduler}.
*
+ *

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit @@ -15669,10 +15659,9 @@ public final Flowable throttleLatest(long timeout, TimeUnit unit) { * a timeout window active or not. If {@code false}, the very last * upstream item is ignored and the flow terminates. * @return the new Flowable instance - * @since 2.1.14 - experimental * @see #throttleLatest(long, TimeUnit, Scheduler, boolean) + * @since 2.2 */ - @Experimental @CheckReturnValue @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.COMPUTATION) @@ -15701,16 +15690,16 @@ public final Flowable throttleLatest(long timeout, TimeUnit unit, boolean emi *

Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
+ *

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit * @param scheduler the {@link Scheduler} where the timed wait and latest item * emission will be performed * @return the new Flowable instance - * @since 2.1.14 - experimental * @see #throttleLatest(long, TimeUnit, Scheduler, boolean) + * @since 2.2 */ - @Experimental @CheckReturnValue @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) @@ -15736,6 +15725,7 @@ public final Flowable throttleLatest(long timeout, TimeUnit unit, Scheduler s *

Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
+ *

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit @@ -15746,9 +15736,8 @@ public final Flowable throttleLatest(long timeout, TimeUnit unit, Scheduler s * a timeout window active or not. If {@code false}, the very last * upstream item is ignored and the flow terminates. * @return the new Flowable instance - * @since 2.1.14 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) diff --git a/src/main/java/io/reactivex/FlowableConverter.java b/src/main/java/io/reactivex/FlowableConverter.java index 541e335bcd..cf9176bf6d 100644 --- a/src/main/java/io/reactivex/FlowableConverter.java +++ b/src/main/java/io/reactivex/FlowableConverter.java @@ -18,12 +18,11 @@ /** * Convenience interface and callback used by the {@link Flowable#as} operator to turn a Flowable into another * value fluently. - * + *

History: 2.1.7 - experimental * @param the upstream type * @param the output type - * @since 2.1.7 - experimental + * @since 2.2 */ -@Experimental public interface FlowableConverter { /** * Applies a function to the upstream Flowable and returns a converted value of type {@code R}. diff --git a/src/main/java/io/reactivex/FlowableEmitter.java b/src/main/java/io/reactivex/FlowableEmitter.java index f3c1d8e0cb..06636449c4 100644 --- a/src/main/java/io/reactivex/FlowableEmitter.java +++ b/src/main/java/io/reactivex/FlowableEmitter.java @@ -94,11 +94,11 @@ public interface FlowableEmitter extends Emitter { *

* Unlike {@link #onError(Throwable)}, the {@code RxJavaPlugins.onError} is not called * if the error could not be delivered. + *

History: 2.1.1 - experimental * @param t the throwable error to signal if possible * @return true if successful, false if the downstream is not able to accept further * events - * @since 2.1.1 - experimental + * @since 2.2 */ - @Experimental boolean tryOnError(@NonNull Throwable t); } diff --git a/src/main/java/io/reactivex/FlowableSubscriber.java b/src/main/java/io/reactivex/FlowableSubscriber.java index e483064610..2ef1019acf 100644 --- a/src/main/java/io/reactivex/FlowableSubscriber.java +++ b/src/main/java/io/reactivex/FlowableSubscriber.java @@ -20,11 +20,10 @@ * Represents a Reactive-Streams inspired Subscriber that is RxJava 2 only * and weakens rules §1.3 and §3.9 of the specification for gaining performance. * - *

History: 2.0.7 - experimental + *

History: 2.0.7 - experimental; 2.1 - beta * @param the value type - * @since 2.1 - beta + * @since 2.2 */ -@Beta public interface FlowableSubscriber extends Subscriber { /** diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 7b040b58f9..9c50ef8518 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -1331,7 +1331,7 @@ public static Flowable mergeDelayError(PublisherScheduler: *

{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.9 - experimental * @param the common element base type * @param sources * a Publisher that emits MaybeSources @@ -1339,13 +1339,12 @@ public static Flowable mergeDelayError(PublisherReactiveX operators documentation: Merge - * @since 2.1.9 - experimental + * @since 2.2 */ @SuppressWarnings({ "unchecked", "rawtypes" }) @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public static Flowable mergeDelayError(Publisher> sources, int maxConcurrency) { ObjectHelper.requireNonNull(sources, "source is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); @@ -2241,14 +2240,13 @@ public final Maybe ambWith(MaybeSource other) { *

Scheduler:
*
{@code as} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.7 - experimental * @param the resulting object type * @param converter the function that receives the current Maybe instance and returns a value * @return the converted value * @throws NullPointerException if converter is null - * @since 2.1.7 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final R as(@NonNull MaybeConverter converter) { @@ -4259,14 +4257,13 @@ public final Maybe switchIfEmpty(MaybeSource other) { *

Scheduler:
*
{@code switchIfEmpty} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.4 - experimental * @param other * the alternate SingleSource to subscribe to if the main does not emit any items * @return a Single that emits the items emitted by the source Maybe or the item of an * alternate SingleSource if the source Maybe is empty. - * @since 2.1.4 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single switchIfEmpty(SingleSource other) { diff --git a/src/main/java/io/reactivex/MaybeConverter.java b/src/main/java/io/reactivex/MaybeConverter.java index e156ed5944..c997399d99 100644 --- a/src/main/java/io/reactivex/MaybeConverter.java +++ b/src/main/java/io/reactivex/MaybeConverter.java @@ -18,12 +18,11 @@ /** * Convenience interface and callback used by the {@link Maybe#as} operator to turn a Maybe into another * value fluently. - * + *

History: 2.1.7 - experimental * @param the upstream type * @param the output type - * @since 2.1.7 - experimental + * @since 2.2 */ -@Experimental public interface MaybeConverter { /** * Applies a function to the upstream Maybe and returns a converted value of type {@code R}. diff --git a/src/main/java/io/reactivex/MaybeEmitter.java b/src/main/java/io/reactivex/MaybeEmitter.java index c772430730..f0e6ed6266 100644 --- a/src/main/java/io/reactivex/MaybeEmitter.java +++ b/src/main/java/io/reactivex/MaybeEmitter.java @@ -97,11 +97,11 @@ public interface MaybeEmitter { *

* Unlike {@link #onError(Throwable)}, the {@code RxJavaPlugins.onError} is not called * if the error could not be delivered. + *

History: 2.1.1 - experimental * @param t the throwable error to signal if possible * @return true if successful, false if the downstream is not able to accept further * events - * @since 2.1.1 - experimental + * @since 2.2 */ - @Experimental boolean tryOnError(@NonNull Throwable t); } diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index a3f204206b..918bfea14c 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -4951,14 +4951,13 @@ public final Single any(Predicate predicate) { *

Scheduler:
*
{@code as} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.7 - experimental * @param the resulting object type * @param converter the function that receives the current Observable instance and returns a value * @return the converted value * @throws NullPointerException if converter is null - * @since 2.1.7 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final R as(@NonNull ObservableConverter converter) { @@ -6536,13 +6535,12 @@ public final Observable concatMapEagerDelayError(FunctionScheduler: *

{@code concatMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.6 - experimental * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns a CompletableSource * @return a Completable that signals {@code onComplete} when the upstream and all CompletableSources complete - * @since 2.1.6 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable concatMapCompletable(Function mapper) { @@ -6558,7 +6556,7 @@ public final Completable concatMapCompletable(FunctionScheduler: *

{@code concatMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.6 - experimental * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns a CompletableSource * @@ -6566,9 +6564,8 @@ public final Completable concatMapCompletable(Function mapper, int capacityHint) { @@ -6587,16 +6584,16 @@ public final Completable concatMapCompletable(FunctionScheduler: *

{@code concatMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to * @return a new Completable instance - * @since 2.1.11 - experimental * @see #concatMapCompletable(Function, int) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Completable concatMapCompletableDelayError(Function mapper) { return concatMapCompletableDelayError(mapper, true, 2); } @@ -6611,6 +6608,7 @@ public final Completable concatMapCompletableDelayError(FunctionScheduler: *

{@code concatMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to @@ -6621,12 +6619,11 @@ public final Completable concatMapCompletableDelayError(Function mapper, boolean tillTheEnd) { return concatMapCompletableDelayError(mapper, tillTheEnd, 2); } @@ -6641,6 +6638,7 @@ public final Completable concatMapCompletableDelayError(FunctionScheduler: *

{@code concatMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to @@ -6655,12 +6653,11 @@ public final Completable concatMapCompletableDelayError(Function mapper, boolean tillTheEnd, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -6734,18 +6731,18 @@ public final Observable concatMapIterable(final FunctionScheduler: *

{@code concatMapMaybe} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to * be subscribed to * @return a new Observable instance - * @since 2.1.11 - experimental * @see #concatMapMaybeDelayError(Function) * @see #concatMapMaybe(Function, int) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable concatMapMaybe(Function> mapper) { return concatMapMaybe(mapper, 2); } @@ -6760,6 +6757,7 @@ public final Observable concatMapMaybe(FunctionScheduler: *

{@code concatMapMaybe} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to @@ -6769,13 +6767,12 @@ public final Observable concatMapMaybe(Function Observable concatMapMaybe(Function> mapper, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -6792,18 +6789,18 @@ public final Observable concatMapMaybe(FunctionScheduler: *

{@code concatMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to * be subscribed to * @return a new Observable instance - * @since 2.1.11 - experimental * @see #concatMapMaybe(Function) * @see #concatMapMaybeDelayError(Function, boolean) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable concatMapMaybeDelayError(Function> mapper) { return concatMapMaybeDelayError(mapper, true, 2); } @@ -6818,6 +6815,7 @@ public final Observable concatMapMaybeDelayError(FunctionScheduler: *

{@code concatMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to @@ -6829,13 +6827,12 @@ public final Observable concatMapMaybeDelayError(Function Observable concatMapMaybeDelayError(Function> mapper, boolean tillTheEnd) { return concatMapMaybeDelayError(mapper, tillTheEnd, 2); } @@ -6850,6 +6847,7 @@ public final Observable concatMapMaybeDelayError(FunctionScheduler: *

{@code concatMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to @@ -6865,12 +6863,11 @@ public final Observable concatMapMaybeDelayError(Function Observable concatMapMaybeDelayError(Function> mapper, boolean tillTheEnd, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -6887,18 +6884,18 @@ public final Observable concatMapMaybeDelayError(FunctionScheduler: *

{@code concatMapSingle} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to * be subscribed to * @return a new Observable instance - * @since 2.1.11 - experimental * @see #concatMapSingleDelayError(Function) * @see #concatMapSingle(Function, int) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable concatMapSingle(Function> mapper) { return concatMapSingle(mapper, 2); } @@ -6913,6 +6910,7 @@ public final Observable concatMapSingle(FunctionScheduler: *

{@code concatMapSingle} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to @@ -6922,13 +6920,12 @@ public final Observable concatMapSingle(Function Observable concatMapSingle(Function> mapper, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -6945,18 +6942,18 @@ public final Observable concatMapSingle(FunctionScheduler: *

{@code concatMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to * be subscribed to * @return a new Observable instance - * @since 2.1.11 - experimental * @see #concatMapSingle(Function) * @see #concatMapSingleDelayError(Function, boolean) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable concatMapSingleDelayError(Function> mapper) { return concatMapSingleDelayError(mapper, true, 2); } @@ -6971,6 +6968,7 @@ public final Observable concatMapSingleDelayError(FunctionScheduler: *

{@code concatMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to @@ -6982,13 +6980,12 @@ public final Observable concatMapSingleDelayError(Function Observable concatMapSingleDelayError(Function> mapper, boolean tillTheEnd) { return concatMapSingleDelayError(mapper, tillTheEnd, 2); } @@ -7003,6 +7000,7 @@ public final Observable concatMapSingleDelayError(FunctionScheduler: *

{@code concatMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to @@ -7018,12 +7016,11 @@ public final Observable concatMapSingleDelayError(Function Observable concatMapSingleDelayError(Function> mapper, boolean tillTheEnd, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); @@ -7062,13 +7059,13 @@ public final Observable concatWith(ObservableSource other) { *

Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.10 - experimental * @param other the SingleSource whose signal should be emitted after this {@code Observable} completes normally. * @return the new Observable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable concatWith(@NonNull SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableConcatWithSingle(this, other)); @@ -7083,13 +7080,13 @@ public final Observable concatWith(@NonNull SingleSource other) *

Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.10 - experimental * @param other the MaybeSource whose signal should be emitted after this Observable completes normally. * @return the new Observable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable concatWith(@NonNull MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableConcatWithMaybe(this, other)); @@ -7104,13 +7101,13 @@ public final Observable concatWith(@NonNull MaybeSource other) { *

Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.10 - experimental * @param other the {@code CompletableSource} to subscribe to once the current {@code Observable} completes normally * @return the new Observable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable concatWith(@NonNull CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableConcatWithCompletable(this, other)); @@ -9604,14 +9601,13 @@ public final Observable mergeWith(ObservableSource other) { *

Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.10 - experimental * @param other the {@code SingleSource} whose success value to merge with * @return the new Observable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable mergeWith(@NonNull SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableMergeWithSingle(this, other)); @@ -9629,14 +9625,13 @@ public final Observable mergeWith(@NonNull SingleSource other) { *

Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.10 - experimental * @param other the {@code MaybeSource} which provides a success value to merge with or completes * @return the new Observable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable mergeWith(@NonNull MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableMergeWithMaybe(this, other)); @@ -9651,14 +9646,13 @@ public final Observable mergeWith(@NonNull MaybeSource other) { *

Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.10 - experimental * @param other the {@code CompletableSource} to await for completion * @return the new Observable instance - * @since 2.1.10 - experimental + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable mergeWith(@NonNull CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableMergeWithCompletable(this, other)); @@ -12228,16 +12222,16 @@ public final Observable switchMap(Function *

+ *

History: 2.1.11 - experimental * @param mapper the function called with each upstream item and should return a * {@link CompletableSource} to be subscribed to and awaited for * (non blockingly) for its terminal event * @return the new Completable instance - * @since 2.1.11 - experimental * @see #switchMapCompletableDelayError(Function) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Completable switchMapCompletable(@NonNull Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapCompletable(this, mapper, false)); @@ -12270,16 +12264,16 @@ public final Completable switchMapCompletable(@NonNull Function *

+ *

History: 2.1.11 - experimental * @param mapper the function called with each upstream item and should return a * {@link CompletableSource} to be subscribed to and awaited for * (non blockingly) for its terminal event * @return the new Completable instance - * @since 2.1.11 - experimental * @see #switchMapCompletableDelayError(Function) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Completable switchMapCompletableDelayError(@NonNull Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapCompletable(this, mapper, true)); @@ -12305,17 +12299,17 @@ public final Completable switchMapCompletableDelayError(@NonNull Function *

+ *

History: 2.1.11 - experimental * @param the output value type * @param mapper the function called with the current upstream event and should * return a {@code MaybeSource} to replace the current active inner source * and get subscribed to. * @return the new Observable instance - * @since 2.1.11 - experimental * @see #switchMapMaybe(Function) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable switchMapMaybe(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapMaybe(this, mapper, false)); @@ -12331,17 +12325,17 @@ public final Observable switchMapMaybe(@NonNull FunctionScheduler: *

{@code switchMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.11 - experimental * @param the output value type * @param mapper the function called with the current upstream event and should * return a {@code MaybeSource} to replace the current active inner source * and get subscribed to. * @return the new Observable instance - * @since 2.1.11 - experimental * @see #switchMapMaybe(Function) + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public final Observable switchMapMaybeDelayError(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapMaybe(this, mapper, true)); @@ -12360,16 +12354,15 @@ public final Observable switchMapMaybeDelayError(@NonNull FunctionScheduler: *

{@code switchMapSingle} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.0.8 - experimental * @param the element type of the inner SingleSources and the output * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns a * SingleSource * @return an Observable that emits the item emitted by the SingleSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource * @see ReactiveX operators documentation: FlatMap - * @since 2.0.8 + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @NonNull @@ -12392,16 +12385,15 @@ public final Observable switchMapSingle(@NonNull FunctionScheduler: *

{@code switchMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.0.8 - experimental * @param the element type of the inner SingleSources and the output * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns a * SingleSource * @return an Observable that emits the item emitted by the SingleSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource * @see ReactiveX operators documentation: FlatMap - * @since 2.0.8 + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @NonNull @@ -13052,15 +13044,15 @@ public final Observable throttleLast(long intervalDuration, TimeUnit unit, Sc *

Scheduler:
*
{@code throttleLatest} operates by default on the {@code computation} {@link Scheduler}.
*
+ *

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit * @return the new Observable instance - * @since 2.1.14 - experimental * @see #throttleLatest(long, TimeUnit, boolean) * @see #throttleLatest(long, TimeUnit, Scheduler) + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable throttleLatest(long timeout, TimeUnit unit) { @@ -13080,6 +13072,7 @@ public final Observable throttleLatest(long timeout, TimeUnit unit) { *

Scheduler:
*
{@code throttleLatest} operates by default on the {@code computation} {@link Scheduler}.
*
+ *

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit @@ -13088,10 +13081,9 @@ public final Observable throttleLatest(long timeout, TimeUnit unit) { * a timeout window active or not. If {@code false}, the very last * upstream item is ignored and the flow terminates. * @return the new Observable instance - * @since 2.1.14 - experimental * @see #throttleLatest(long, TimeUnit, Scheduler, boolean) + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable throttleLatest(long timeout, TimeUnit unit, boolean emitLast) { @@ -13114,16 +13106,16 @@ public final Observable throttleLatest(long timeout, TimeUnit unit, boolean e *

Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
+ *

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit * @param scheduler the {@link Scheduler} where the timed wait and latest item * emission will be performed * @return the new Observable instance - * @since 2.1.14 - experimental * @see #throttleLatest(long, TimeUnit, Scheduler, boolean) + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable throttleLatest(long timeout, TimeUnit unit, Scheduler scheduler) { @@ -13143,6 +13135,7 @@ public final Observable throttleLatest(long timeout, TimeUnit unit, Scheduler *

Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
+ *

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit @@ -13153,9 +13146,8 @@ public final Observable throttleLatest(long timeout, TimeUnit unit, Scheduler * a timeout window active or not. If {@code false}, the very last * upstream item is ignored and the flow terminates. * @return the new Observable instance - * @since 2.1.14 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable throttleLatest(long timeout, TimeUnit unit, Scheduler scheduler, boolean emitLast) { diff --git a/src/main/java/io/reactivex/ObservableConverter.java b/src/main/java/io/reactivex/ObservableConverter.java index b413de69de..12c461523d 100644 --- a/src/main/java/io/reactivex/ObservableConverter.java +++ b/src/main/java/io/reactivex/ObservableConverter.java @@ -18,12 +18,11 @@ /** * Convenience interface and callback used by the {@link Observable#as} operator to turn an Observable into another * value fluently. - * + *

History: 2.1.7 - experimental * @param the upstream type * @param the output type - * @since 2.1.7 - experimental + * @since 2.2 */ -@Experimental public interface ObservableConverter { /** * Applies a function to the upstream Observable and returns a converted value of type {@code R}. diff --git a/src/main/java/io/reactivex/ObservableEmitter.java b/src/main/java/io/reactivex/ObservableEmitter.java index 68c81207b6..0adbdb3a8d 100644 --- a/src/main/java/io/reactivex/ObservableEmitter.java +++ b/src/main/java/io/reactivex/ObservableEmitter.java @@ -86,11 +86,11 @@ public interface ObservableEmitter extends Emitter { *

* Unlike {@link #onError(Throwable)}, the {@code RxJavaPlugins.onError} is not called * if the error could not be delivered. + *

History: 2.1.1 - experimental * @param t the throwable error to signal if possible * @return true if successful, false if the downstream is not able to accept further * events - * @since 2.1.1 - experimental + * @since 2.2 */ - @Experimental boolean tryOnError(@NonNull Throwable t); } diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 5cef88c846..a42e9eaa5b 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -1060,16 +1060,16 @@ public static Flowable merge( *

Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.9 - experimental * @param the common and resulting value type * @param sources the Iterable sequence of SingleSource sources * @return the new Flowable instance - * @since 2.1.9 - experimental * @see #merge(Iterable) + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - @Experimental public static Flowable mergeDelayError(Iterable> sources) { return mergeDelayError(Flowable.fromIterable(sources)); } @@ -1083,17 +1083,17 @@ public static Flowable mergeDelayError(IterableScheduler: *

{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.9 - experimental * @param the common and resulting value type * @param sources the Flowable sequence of SingleSource sources * @return the new Flowable instance * @see #merge(Publisher) - * @since 2.1.9 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) - @Experimental public static Flowable mergeDelayError(Publisher> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); return RxJavaPlugins.onAssembly(new FlowableFlatMapPublisher(sources, SingleInternalHelper.toFlowable(), true, Integer.MAX_VALUE, Flowable.bufferSize())); @@ -1114,7 +1114,7 @@ public static Flowable mergeDelayError(PublisherScheduler: *

{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.9 - experimental * @param the common value type * @param source1 * a SingleSource to be merged @@ -1123,13 +1123,12 @@ public static Flowable mergeDelayError(PublisherReactiveX operators documentation: Merge * @see #merge(SingleSource, SingleSource) - * @since 2.1.9 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") - @Experimental public static Flowable mergeDelayError( SingleSource source1, SingleSource source2 ) { @@ -1152,7 +1151,7 @@ public static Flowable mergeDelayError( *

Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.9 - experimental * @param the common value type * @param source1 * a SingleSource to be merged @@ -1163,13 +1162,12 @@ public static Flowable mergeDelayError( * @return a Flowable that emits all of the items emitted by the source Singles * @see ReactiveX operators documentation: Merge * @see #merge(SingleSource, SingleSource, SingleSource) - * @since 2.1.9 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") - @Experimental public static Flowable mergeDelayError( SingleSource source1, SingleSource source2, SingleSource source3 @@ -1194,7 +1192,7 @@ public static Flowable mergeDelayError( *

Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.9 - experimental * @param the common value type * @param source1 * a SingleSource to be merged @@ -1207,13 +1205,12 @@ public static Flowable mergeDelayError( * @return a Flowable that emits all of the items emitted by the source Singles * @see ReactiveX operators documentation: Merge * @see #merge(SingleSource, SingleSource, SingleSource, SingleSource) - * @since 2.1.9 - experimental + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") - @Experimental public static Flowable mergeDelayError( SingleSource source1, SingleSource source2, SingleSource source3, SingleSource source4 @@ -1925,14 +1922,13 @@ public final Single ambWith(SingleSource other) { *

Scheduler:
*
{@code as} does not operate by default on a particular {@link Scheduler}.
*
- * + *

History: 2.1.7 - experimental * @param the resulting object type * @param converter the function that receives the current Single instance and returns a value * @return the converted value * @throws NullPointerException if converter is null - * @since 2.1.7 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final R as(@NonNull SingleConverter converter) { @@ -2073,14 +2069,13 @@ public final Single delay(long time, TimeUnit unit) { *

Scheduler:
*
{@code delay} operates by default on the {@code computation} {@link Scheduler}.
*
- * + *

History: 2.1.5 - experimental * @param time the amount of time the success or error signal should be delayed for * @param unit the time unit * @param delayError if true, both success and error signals are delayed. if false, only success signals are delayed. * @return the new Single instance - * @since 2.1.5 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Single delay(long time, TimeUnit unit, boolean delayError) { @@ -2120,7 +2115,7 @@ public final Single delay(final long time, final TimeUnit unit, final Schedul *

Scheduler:
*
you specify the {@link Scheduler} where the non-blocking wait and emission happens
*
- * + *

History: 2.1.5 - experimental * @param time the amount of time the success or error signal should be delayed for * @param unit the time unit * @param scheduler the target scheduler to use for the non-blocking wait and emission @@ -2129,9 +2124,8 @@ public final Single delay(final long time, final TimeUnit unit, final Schedul * @throws NullPointerException * if unit is null, or * if scheduler is null - * @since 2.1.5 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Single delay(final long time, final TimeUnit unit, final Scheduler scheduler, boolean delayError) { @@ -3052,11 +3046,11 @@ public final Single onErrorResumeNext( *

Scheduler:
*
{@code onTerminateDetach} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.5 - experimental * @return a Single which nulls out references to the upstream producer and downstream SingleObserver if * the sequence is terminated or downstream calls dispose() - * @since 2.1.5 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single onTerminateDetach() { @@ -3210,13 +3204,13 @@ public final Single retry(BiPredicate pre *

Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
+ *

History: 2.1.8 - experimental * @param times the number of times to resubscribe if the current Single fails * @param predicate the predicate called with the failure Throwable * and should return true if a resubscription should happen * @return the new Single instance - * @since 2.1.8 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single retry(long times, Predicate predicate) { @@ -3798,14 +3792,14 @@ public final Observable toObservable() { *

Scheduler:
*
{@code unsubscribeOn} calls dispose() of the upstream on the {@link Scheduler} you specify.
*
+ *

History: 2.0.9 - experimental * @param scheduler the target scheduler where to execute the cancellation * @return the new Single instance * @throws NullPointerException if scheduler is null - * @since 2.0.9 - experimental + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) - @Experimental public final Single unsubscribeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new SingleUnsubscribeOn(this, scheduler)); diff --git a/src/main/java/io/reactivex/SingleConverter.java b/src/main/java/io/reactivex/SingleConverter.java index 9938b22cc7..1e3944f73b 100644 --- a/src/main/java/io/reactivex/SingleConverter.java +++ b/src/main/java/io/reactivex/SingleConverter.java @@ -18,12 +18,11 @@ /** * Convenience interface and callback used by the {@link Single#as} operator to turn a Single into another * value fluently. - * + *

History: 2.1.7 - experimental * @param the upstream type * @param the output type - * @since 2.1.7 - experimental + * @since 2.2 */ -@Experimental public interface SingleConverter { /** * Applies a function to the upstream Single and returns a converted value of type {@code R}. diff --git a/src/main/java/io/reactivex/SingleEmitter.java b/src/main/java/io/reactivex/SingleEmitter.java index c623638ef7..9e98f130e0 100644 --- a/src/main/java/io/reactivex/SingleEmitter.java +++ b/src/main/java/io/reactivex/SingleEmitter.java @@ -91,11 +91,11 @@ public interface SingleEmitter { *

* Unlike {@link #onError(Throwable)}, the {@code RxJavaPlugins.onError} is not called * if the error could not be delivered. + *

History: 2.1.1 - experimental * @param t the throwable error to signal if possible * @return true if successful, false if the downstream is not able to accept further * events - * @since 2.1.1 - experimental + * @since 2.2 */ - @Experimental boolean tryOnError(@NonNull Throwable t); } diff --git a/src/main/java/io/reactivex/annotations/SchedulerSupport.java b/src/main/java/io/reactivex/annotations/SchedulerSupport.java index 737c4dbf1e..09acaa6dea 100644 --- a/src/main/java/io/reactivex/annotations/SchedulerSupport.java +++ b/src/main/java/io/reactivex/annotations/SchedulerSupport.java @@ -63,9 +63,9 @@ /** * The operator/class runs on RxJava's {@linkplain Schedulers#single() single scheduler} * or takes timing information from it. - * @since 2.0.8 - experimental + *

History: 2.0.8 - experimental + * @since 2.2 */ - @Experimental String SINGLE = "io.reactivex:single"; /** diff --git a/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java b/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java index e0e4d8e336..994a5c25a5 100644 --- a/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java +++ b/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java @@ -19,10 +19,9 @@ * Represents an exception used to signal to the {@code RxJavaPlugins.onError()} that a * callback-based subscribe() method on a base reactive type didn't specify * an onError handler. - *

History: 2.0.6 - experimental - * @since 2.1 - beta + *

History: 2.0.6 - experimental; 2.1 - beta + * @since 2.2 */ -@Beta public final class OnErrorNotImplementedException extends RuntimeException { private static final long serialVersionUID = -6298857009889503852L; diff --git a/src/main/java/io/reactivex/exceptions/ProtocolViolationException.java b/src/main/java/io/reactivex/exceptions/ProtocolViolationException.java index 00a3ee3bbc..09c0361108 100644 --- a/src/main/java/io/reactivex/exceptions/ProtocolViolationException.java +++ b/src/main/java/io/reactivex/exceptions/ProtocolViolationException.java @@ -13,15 +13,12 @@ package io.reactivex.exceptions; -import io.reactivex.annotations.Beta; - /** * Explicitly named exception to indicate a Reactive-Streams * protocol violation. - *

History: 2.0.6 - experimental - * @since 2.1 - beta + *

History: 2.0.6 - experimental; 2.1 - beta + * @since 2.2 */ -@Beta public final class ProtocolViolationException extends IllegalStateException { private static final long serialVersionUID = 1644750035281290266L; diff --git a/src/main/java/io/reactivex/exceptions/UndeliverableException.java b/src/main/java/io/reactivex/exceptions/UndeliverableException.java index 030ba755ba..6f6aec0938 100644 --- a/src/main/java/io/reactivex/exceptions/UndeliverableException.java +++ b/src/main/java/io/reactivex/exceptions/UndeliverableException.java @@ -13,14 +13,11 @@ package io.reactivex.exceptions; -import io.reactivex.annotations.Beta; - /** * Wrapper for Throwable errors that are sent to `RxJavaPlugins.onError`. - *

History: 2.0.6 - experimental - * @since 2.1 - beta + *

History: 2.0.6 - experimental; 2.1 - beta + * @since 2.2 */ -@Beta public final class UndeliverableException extends IllegalStateException { private static final long serialVersionUID = 1644750035281290266L; diff --git a/src/main/java/io/reactivex/flowables/ConnectableFlowable.java b/src/main/java/io/reactivex/flowables/ConnectableFlowable.java index e62ea61494..21636e67da 100644 --- a/src/main/java/io/reactivex/flowables/ConnectableFlowable.java +++ b/src/main/java/io/reactivex/flowables/ConnectableFlowable.java @@ -102,12 +102,12 @@ public Flowable refCount() { *

Scheduler:
*
This {@code refCount} overload does not operate on any particular {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param subscriberCount the number of subscribers required to connect to the upstream * @return the new Flowable instance - * @since 2.1.14 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.PASS_THROUGH) public final Flowable refCount(int subscriberCount) { @@ -125,14 +125,14 @@ public final Flowable refCount(int subscriberCount) { *

Scheduler:
*
This {@code refCount} overload operates on the {@code computation} {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param timeout the time to wait before disconnecting after all subscribers unsubscribed * @param unit the time unit of the timeout * @return the new Flowable instance - * @since 2.1.14 - experimental * @see #refCount(long, TimeUnit, Scheduler) + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.COMPUTATION) @BackpressureSupport(BackpressureKind.PASS_THROUGH) public final Flowable refCount(long timeout, TimeUnit unit) { @@ -150,14 +150,14 @@ public final Flowable refCount(long timeout, TimeUnit unit) { *

Scheduler:
*
This {@code refCount} overload operates on the specified {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param timeout the time to wait before disconnecting after all subscribers unsubscribed * @param unit the time unit of the timeout * @param scheduler the target scheduler to wait on before disconnecting * @return the new Flowable instance - * @since 2.1.14 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.CUSTOM) @BackpressureSupport(BackpressureKind.PASS_THROUGH) public final Flowable refCount(long timeout, TimeUnit unit, Scheduler scheduler) { @@ -175,15 +175,15 @@ public final Flowable refCount(long timeout, TimeUnit unit, Scheduler schedul *

Scheduler:
*
This {@code refCount} overload operates on the {@code computation} {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param subscriberCount the number of subscribers required to connect to the upstream * @param timeout the time to wait before disconnecting after all subscribers unsubscribed * @param unit the time unit of the timeout * @return the new Flowable instance - * @since 2.1.14 - experimental * @see #refCount(int, long, TimeUnit, Scheduler) + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.COMPUTATION) @BackpressureSupport(BackpressureKind.PASS_THROUGH) public final Flowable refCount(int subscriberCount, long timeout, TimeUnit unit) { @@ -201,15 +201,15 @@ public final Flowable refCount(int subscriberCount, long timeout, TimeUnit un *

Scheduler:
*
This {@code refCount} overload operates on the specified {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param subscriberCount the number of subscribers required to connect to the upstream * @param timeout the time to wait before disconnecting after all subscribers unsubscribed * @param unit the time unit of the timeout * @param scheduler the target scheduler to wait on before disconnecting * @return the new Flowable instance - * @since 2.1.14 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.CUSTOM) @BackpressureSupport(BackpressureKind.PASS_THROUGH) public final Flowable refCount(int subscriberCount, long timeout, TimeUnit unit, Scheduler scheduler) { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableCache.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableCache.java index b3e0aee7fa..9b1652087e 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableCache.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableCache.java @@ -16,15 +16,13 @@ import java.util.concurrent.atomic.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; /** * Consume the upstream source exactly once and cache its terminal event. - * - * @since 2.0.4 - experimental + *

History: 2.0.4 - experimental + * @since 2.1 */ -@Experimental public final class CompletableCache extends Completable implements CompletableObserver { static final InnerCompletableCache[] EMPTY = new InnerCompletableCache[0]; diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDetach.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDetach.java index 48de66f017..14e74c0485 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDetach.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDetach.java @@ -14,16 +14,14 @@ package io.reactivex.internal.operators.completable; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.DisposableHelper; /** * Breaks the references between the upstream and downstream when the Completable terminates. - * - * @since 2.1.5 - experimental + *

History: 2.1.5 - experimental + * @since 2.2 */ -@Experimental public final class CompletableDetach extends Completable { final CompletableSource source; diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java index 4077270dfb..c1b695220a 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.AtomicInteger; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Action; @@ -25,10 +24,9 @@ /** * Execute an action after an onError, onComplete or a dispose event. - * - * @since 2.0.1 - experimental + *

History: 2.0.1 - experimental + * @since 2.1 */ -@Experimental public final class CompletableDoFinally extends Completable { final CompletableSource source; diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java index 1343d35b98..391795846e 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java @@ -16,16 +16,15 @@ import java.util.concurrent.atomic.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.DisposableHelper; import io.reactivex.plugins.RxJavaPlugins; /** * Terminates the sequence if either the main or the other Completable terminate. - * @since 2.1.17 - experimental + *

History: 2.1.17 - experimental + * @since 2.2 */ -@Experimental public final class CompletableTakeUntilCompletable extends Completable { final Completable source; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerPublisher.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerPublisher.java index a88e05953d..43785a6fc5 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerPublisher.java @@ -22,9 +22,10 @@ /** * ConcatMapEager which works with an arbitrary Publisher source. + *

History: 2.0.7 - experimental * @param the input value type * @param the output type - * @since 2.0.7 - experimental + * @since 2.1 */ public final class FlowableConcatMapEagerPublisher extends Flowable { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletable.java index d683d3e788..5523614a9a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletable.java @@ -25,8 +25,9 @@ /** * Subscribe to a main Flowable first, then when it completes normally, subscribe to a Completable * and terminate when it terminates. + *

History: 2.1.10 - experimental * @param the element type of the main source and output type - * @since 2.1.10 - experimental + * @since 2.2 */ public final class FlowableConcatWithCompletable extends AbstractFlowableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybe.java index a3128b6e37..3250e0c82c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybe.java @@ -26,8 +26,9 @@ /** * Subscribe to a main Flowable first, then when it completes normally, subscribe to a Maybe, * signal its success value followed by a completion or signal its error or completion signal as is. + *

History: 2.1.10 - experimental * @param the element type of the main source and output type - * @since 2.1.10 - experimental + * @since 2.2 */ public final class FlowableConcatWithMaybe extends AbstractFlowableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithSingle.java index bf86de2003..a85090166b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithSingle.java @@ -26,8 +26,9 @@ /** * Subscribe to a main Flowable first, then when it completes normally, subscribe to a Single, * signal its success value followed by a completion or signal its error as is. + *

History: 2.1.10 - experimental * @param the element type of the main source and output type - * @since 2.1.10 - experimental + * @since 2.2 */ public final class FlowableConcatWithSingle extends AbstractFlowableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNext.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNext.java index 039dd86311..f7a079d4b7 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNext.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNext.java @@ -23,10 +23,10 @@ /** * Calls a consumer after pushing the current item to the downstream. + *

History: 2.0.1 - experimental * @param the value type - * @since 2.0.1 - experimental + * @since 2.1 */ -@Experimental public final class FlowableDoAfterNext extends AbstractFlowableWithUpstream { final Consumer onAfterNext; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoFinally.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoFinally.java index e15faff21a..116f81b712 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoFinally.java @@ -25,11 +25,10 @@ /** * Execute an action after an onError, onComplete or a cancel event. - * + *

History: 2.0.1 - experimental * @param the value type - * @since 2.0.1 - experimental + * @since 2.1 */ -@Experimental public final class FlowableDoFinally extends AbstractFlowableWithUpstream { final Action onFinally; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableLimit.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableLimit.java index 01b1f24f76..a49758dd53 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableLimit.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableLimit.java @@ -18,17 +18,15 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.internal.subscriptions.*; import io.reactivex.plugins.RxJavaPlugins; /** * Limits both the total request amount and items received from the upstream. - * + *

History: 2.1.6 - experimental * @param the source and output value type - * @since 2.1.6 - experimental + * @since 2.2 */ -@Experimental public final class FlowableLimit extends AbstractFlowableWithUpstream { final long n; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapPublisher.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapPublisher.java index 03b9fe9634..ac9fee861e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapPublisher.java @@ -22,10 +22,10 @@ /** * Map working with an arbitrary Publisher source. - * + *

History: 2.0.7 - experimental * @param the input value type * @param the output value type - * @since 2.0.7 - experimental + * @since 2.1 */ public final class FlowableMapPublisher extends Flowable { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java index cfdd0974f3..a62b10b1e2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java @@ -26,9 +26,9 @@ /** * Merges a Flowable and a Completable by emitting the items of the Flowable and waiting until * both the Flowable and Completable complete normally. - * + *

History: 2.1.10 - experimental * @param the element type of the Flowable - * @since 2.1.10 - experimental + * @since 2.2 */ public final class FlowableMergeWithCompletable extends AbstractFlowableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java index 7a48d38875..97c81551eb 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java @@ -29,9 +29,9 @@ /** * Merges an Observable and a Maybe by emitting the items of the Observable and the success * value of the Maybe and waiting until both the Observable and Maybe terminate normally. - * + *

History: 2.1.10 - experimental * @param the element type of the Observable - * @since 2.1.10 - experimental + * @since 2.2 */ public final class FlowableMergeWithMaybe extends AbstractFlowableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java index fca1812b78..05bf79f5f2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java @@ -29,9 +29,9 @@ /** * Merges an Observable and a Maybe by emitting the items of the Observable and the success * value of the Maybe and waiting until both the Observable and Maybe terminate normally. - * + *

History: 2.1.10 - experimental * @param the element type of the Observable - * @since 2.1.10 - experimental + * @since 2.2 */ public final class FlowableMergeWithSingle extends AbstractFlowableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakePublisher.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakePublisher.java index c1f52d22a8..a79501dccf 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakePublisher.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakePublisher.java @@ -20,9 +20,9 @@ /** * Take with a generic Publisher source. - * + *

History: 2.0.7 - experimental * @param the value type - * @since 2.0.7 - experimental + * @since 2.1 */ public final class FlowableTakePublisher extends Flowable { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatest.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatest.java index 1ce2dddc25..b3fe22e129 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatest.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatest.java @@ -19,7 +19,6 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.exceptions.MissingBackpressureException; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; @@ -31,11 +30,10 @@ * it tries to emit the latest item from upstream. If there was no upstream item, * in the meantime, the next upstream item is emitted immediately and the * timed process repeats. - * + *

History: 2.1.14 - experimental * @param the upstream and downstream value type - * @since 2.1.14 - experimental + * @since 2.2 */ -@Experimental public final class FlowableThrottleLatest extends AbstractFlowableWithUpstream { final long timeout; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java index d6045032ba..99c77a7b2b 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.maybe; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Consumer; @@ -23,10 +22,10 @@ /** * Calls a consumer after pushing the current item to the downstream. + *

History: 2.0.1 - experimental * @param the value type - * @since 2.0.1 - experimental + * @since 2.1 */ -@Experimental public final class MaybeDoAfterSuccess extends AbstractMaybeWithUpstream { final Consumer onAfterSuccess; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java index 354f98270f..9bba726878 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.AtomicInteger; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Action; @@ -25,11 +24,10 @@ /** * Execute an action after an onSuccess, onError, onComplete or a dispose event. - * + *

History: 2.0.1 - experimental * @param the value type - * @since 2.0.1 - experimental + * @since 2.1 */ -@Experimental public final class MaybeDoFinally extends AbstractMaybeWithUpstream { final Action onFinally; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElement.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElement.java index 3b0ca21850..91e41562d1 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElement.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElement.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.AtomicReference; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -25,12 +24,11 @@ /** * Maps the success value of the source MaybeSource into a Single. + *

History: 2.0.2 - experimental * @param the input value type * @param the result value type - * - * @since 2.0.2 - experimental + * @since 2.1 */ -@Experimental public final class MaybeFlatMapSingleElement extends Maybe { final MaybeSource source; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java index 53f87e743c..b0777bf5ac 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.maybe; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.DisposableHelper; import io.reactivex.internal.fuseable.HasUpstreamMaybeSource; @@ -46,12 +45,12 @@ protected void subscribeActual(Observer s) { /** * Creates a {@link MaybeObserver} wrapper around a {@link Observer}. + *

History: 2.1.11 - experimental * @param the value type * @param downstream the downstream {@code Observer} to talk to * @return the new MaybeObserver instance - * @since 2.1.11 - experimental + * @since 2.2 */ - @Experimental public static MaybeObserver create(Observer downstream) { return new MaybeToObservableObserver(downstream); } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletable.java index 17e32779eb..5e7da33f2e 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletable.java @@ -18,7 +18,6 @@ import org.reactivestreams.Subscription; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.functions.Function; @@ -33,10 +32,10 @@ /** * Maps the upstream items into {@link CompletableSource}s and subscribes to them one after the * other completes or terminates (in error-delaying mode). + *

History: 2.1.11 - experimental * @param the upstream value type - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class FlowableConcatMapCompletable extends Completable { final Flowable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybe.java index bafc9d4aab..82a3009a6c 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybe.java @@ -18,7 +18,6 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.functions.Function; @@ -34,13 +33,11 @@ * Maps each upstream item into a {@link MaybeSource}, subscribes to them one after the other terminates * and relays their success values, optionally delaying any errors till the main and inner sources * terminate. - * + *

History: 2.1.11 - experimental * @param the upstream element type * @param the output element type - * - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class FlowableConcatMapMaybe extends Flowable { final Flowable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingle.java index 654e7cabe5..9be42fcb7b 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingle.java @@ -18,7 +18,6 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.functions.Function; @@ -34,13 +33,11 @@ * Maps each upstream item into a {@link SingleSource}, subscribes to them one after the other terminates * and relays their success values, optionally delaying any errors till the main and inner sources * terminate. - * + *

History: 2.1.11 - experimental * @param the upstream element type * @param the output element type - * - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class FlowableConcatMapSingle extends Flowable { final Flowable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletable.java index 2d0f753fc8..0bcc6041e0 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletable.java @@ -18,7 +18,6 @@ import org.reactivestreams.Subscription; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -32,11 +31,10 @@ * Maps the upstream values into {@link CompletableSource}s, subscribes to the newer one while * disposing the subscription to the previous {@code CompletableSource}, thus keeping at most one * active {@code CompletableSource} running. - * + *

History: 2.1.11 - experimental * @param the upstream value type - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class FlowableSwitchMapCompletable extends Completable { final Flowable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybe.java index 95b0436321..7bb3941d93 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybe.java @@ -18,7 +18,6 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -32,12 +31,11 @@ * Maps the upstream items into {@link MaybeSource}s and switches (subscribes) to the newer ones * while disposing the older ones and emits the latest success value if available, optionally delaying * errors from the main source or the inner sources. - * + *

History: 2.1.11 - experimental * @param the upstream value type * @param the downstream value type - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class FlowableSwitchMapMaybe extends Flowable { final Flowable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingle.java index 3e15dfc7ed..752ee852b9 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingle.java @@ -18,7 +18,6 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -32,12 +31,11 @@ * Maps the upstream items into {@link SingleSource}s and switches (subscribes) to the newer ones * while disposing the older ones and emits the latest success value, optionally delaying * errors from the main source or the inner sources. - * + *

History: 2.1.11 - experimental * @param the upstream value type * @param the downstream value type - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class FlowableSwitchMapSingle extends Flowable { final Flowable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java index 30b463c666..60151de5c0 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -30,10 +29,10 @@ /** * Maps the upstream items into {@link CompletableSource}s and subscribes to them one after the * other completes or terminates (in error-delaying mode). + *

History: 2.1.11 - experimental * @param the upstream value type - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class ObservableConcatMapCompletable extends Completable { final Observable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java index f62669b705..f83388b5b7 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -31,13 +30,11 @@ * Maps each upstream item into a {@link MaybeSource}, subscribes to them one after the other terminates * and relays their success values, optionally delaying any errors till the main and inner sources * terminate. - * + *

History: 2.1.11 - experimental * @param the upstream element type * @param the output element type - * - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class ObservableConcatMapMaybe extends Observable { final Observable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java index 82afca6341..faca30b70f 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -31,13 +30,11 @@ * Maps each upstream item into a {@link SingleSource}, subscribes to them one after the other terminates * and relays their success values, optionally delaying any errors till the main and inner sources * terminate. - * + *

History: 2.1.11 - experimental * @param the upstream element type * @param the output element type - * - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class ObservableConcatMapSingle extends Observable { final Observable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java index 4b98e63bf2..4482a797c1 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.AtomicReference; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -29,11 +28,10 @@ * Maps the upstream values into {@link CompletableSource}s, subscribes to the newer one while * disposing the subscription to the previous {@code CompletableSource}, thus keeping at most one * active {@code CompletableSource} running. - * + *

History: 2.1.11 - experimental * @param the upstream value type - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class ObservableSwitchMapCompletable extends Completable { final Observable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java index 57baef78ea..a4e2586f95 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -29,12 +28,11 @@ * Maps the upstream items into {@link MaybeSource}s and switches (subscribes) to the newer ones * while disposing the older ones and emits the latest success value if available, optionally delaying * errors from the main source or the inner sources. - * + *

History: 2.1.11 - experimental * @param the upstream value type * @param the downstream value type - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class ObservableSwitchMapMaybe extends Observable { final Observable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java index 1000e1bd81..166dce2b74 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; @@ -29,12 +28,11 @@ * Maps the upstream items into {@link SingleSource}s and switches (subscribes) to the newer ones * while disposing the older ones and emits the latest success value if available, optionally delaying * errors from the main source or the inner sources. - * + *

History: 2.1.11 - experimental * @param the upstream value type * @param the downstream value type - * @since 2.1.11 - experimental + * @since 2.2 */ -@Experimental public final class ObservableSwitchMapSingle extends Observable { final Observable source; diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ScalarXMapZHelper.java b/src/main/java/io/reactivex/internal/operators/mixed/ScalarXMapZHelper.java index 901cbd5cbf..2755a42c9d 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ScalarXMapZHelper.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ScalarXMapZHelper.java @@ -16,7 +16,6 @@ import java.util.concurrent.Callable; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; @@ -28,9 +27,9 @@ * Utility class to extract a value from a scalar source reactive type, * map it to a 0-1 type then subscribe the output type's consumer to it, * saving on the overhead of the regular subscription channel. - * @since 2.1.11 - experimental + *

History: 2.1.11 - experimental + * @since 2.2 */ -@Experimental final class ScalarXMapZHelper { private ScalarXMapZHelper() { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletable.java index 518e2f7b28..a80795b370 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletable.java @@ -22,8 +22,9 @@ /** * Subscribe to a main Observable first, then when it completes normally, subscribe to a Single, * signal its success value followed by a completion or signal its error as is. + *

History: 2.1.10 - experimental * @param the element type of the main source and output type - * @since 2.1.10 - experimental + * @since 2.2 */ public final class ObservableConcatWithCompletable extends AbstractObservableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybe.java index e8bcbfa766..26af9856eb 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybe.java @@ -22,8 +22,9 @@ /** * Subscribe to a main Observable first, then when it completes normally, subscribe to a Maybe, * signal its success value followed by a completion or signal its error or completion signal as is. + *

History: 2.1.10 - experimental * @param the element type of the main source and output type - * @since 2.1.10 - experimental + * @since 2.2 */ public final class ObservableConcatWithMaybe extends AbstractObservableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingle.java index 516580f507..09b4da0fdb 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingle.java @@ -22,8 +22,9 @@ /** * Subscribe to a main Observable first, then when it completes normally, subscribe to a Single, * signal its success value followed by a completion or signal its error as is. + *

History: 2.1.10 - experimental * @param the element type of the main source and output type - * @since 2.1.10 - experimental + * @since 2.2 */ public final class ObservableConcatWithSingle extends AbstractObservableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java index dc01638d96..e1346d2dbe 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java @@ -14,17 +14,16 @@ package io.reactivex.internal.operators.observable; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.annotations.Nullable; import io.reactivex.functions.Consumer; import io.reactivex.internal.observers.BasicFuseableObserver; /** * Calls a consumer after pushing the current item to the downstream. + *

History: 2.0.1 - experimental * @param the value type - * @since 2.0.1 - experimental + * @since 2.1 */ -@Experimental public final class ObservableDoAfterNext extends AbstractObservableWithUpstream { final Consumer onAfterNext; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java index cf474c164d..99720ce5cc 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.annotations.Nullable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; @@ -26,11 +25,10 @@ /** * Execute an action after an onError, onComplete or a dispose event. - * + *

History: 2.0.1 - experimental * @param the value type - * @since 2.0.1 - experimental + * @since 2.1 */ -@Experimental public final class ObservableDoFinally extends AbstractObservableWithUpstream { final Action onFinally; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java index 7d0945def8..8fa2f7e2cd 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java @@ -23,9 +23,9 @@ /** * Merges an Observable and a Completable by emitting the items of the Observable and waiting until * both the Observable and Completable complete normally. - * + *

History: 2.1.10 - experimental * @param the element type of the Observable - * @since 2.1.10 - experimental + * @since 2.2 */ public final class ObservableMergeWithCompletable extends AbstractObservableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java index c1714df168..cefa778ebd 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java @@ -26,9 +26,9 @@ /** * Merges an Observable and a Maybe by emitting the items of the Observable and the success * value of the Maybe and waiting until both the Observable and Maybe terminate normally. - * + *

History: 2.1.10 - experimental * @param the element type of the Observable - * @since 2.1.10 - experimental + * @since 2.2 */ public final class ObservableMergeWithMaybe extends AbstractObservableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java index 458786dff5..28f6596915 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java @@ -26,9 +26,9 @@ /** * Merges an Observable and a Single by emitting the items of the Observable and the success * value of the Single and waiting until both the Observable and Single terminate normally. - * + *

History: 2.1.10 - experimental * @param the element type of the Observable - * @since 2.1.10 - experimental + * @since 2.2 */ public final class ObservableMergeWithSingle extends AbstractObservableWithUpstream { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java index 51df6abd1f..41130d56e2 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java @@ -17,7 +17,6 @@ import java.util.concurrent.atomic.*; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.DisposableHelper; @@ -28,11 +27,10 @@ * it tries to emit the latest item from upstream. If there was no upstream item, * in the meantime, the next upstream item is emitted immediately and the * timed process repeats. - * + *

History: 2.1.14 - experimental * @param the upstream and downstream value type - * @since 2.1.14 - experimental + * @since 2.2 */ -@Experimental public final class ObservableThrottleLatest extends AbstractObservableWithUpstream { final long timeout; diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelDoOnNextTry.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelDoOnNextTry.java index 4a599b2435..ae74461419 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelDoOnNextTry.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelDoOnNextTry.java @@ -26,9 +26,9 @@ /** * Calls a Consumer for each upstream value passing by * and handles any failure with a handler function. - * + *

History: 2.0.8 - experimental * @param the input value type - * @since 2.0.8 - experimental + * @since 2.2 */ public final class ParallelDoOnNextTry extends ParallelFlowable { diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelMapTry.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelMapTry.java index 59c8b85fde..493b5f5dc3 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelMapTry.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelMapTry.java @@ -26,10 +26,10 @@ /** * Maps each 'rail' of the source ParallelFlowable with a mapper function * and handle any failure based on a handler function. - * + *

History: 2.0.8 - experimental * @param the input value type * @param the output value type - * @since 2.0.8 - experimental + * @since 2.2 */ public final class ParallelMapTry extends ParallelFlowable { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDetach.java b/src/main/java/io/reactivex/internal/operators/single/SingleDetach.java index d51eb2d4a6..dd077d259e 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDetach.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDetach.java @@ -14,17 +14,15 @@ package io.reactivex.internal.operators.single; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.DisposableHelper; /** * Breaks the references between the upstream and downstream when the Maybe terminates. - * + *

History: 2.1.5 - experimental * @param the value type - * @since 2.1.5 - experimental + * @since 2.2 */ -@Experimental public final class SingleDetach extends Single { final SingleSource source; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java index 348a0edf9d..570def7896 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.single; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Consumer; @@ -23,10 +22,10 @@ /** * Calls a consumer after pushing the current item to the downstream. + *

History: 2.0.1 - experimental * @param the value type - * @since 2.0.1 - experimental + * @since 2.1 */ -@Experimental public final class SingleDoAfterSuccess extends Single { final SingleSource source; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java index b4b7d58f89..f9d17de184 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java @@ -24,8 +24,9 @@ /** * Calls an action after pushing the current item or an error to the downstream. + *

History: 2.0.6 - experimental * @param the value type - * @since 2.0.6 - experimental + * @since 2.1 */ public final class SingleDoAfterTerminate extends Single { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java index fddf36d050..f575e25b7e 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java @@ -16,7 +16,6 @@ import java.util.concurrent.atomic.AtomicInteger; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Action; @@ -25,11 +24,10 @@ /** * Execute an action after an onSuccess, onError or a dispose event. - * + *

History: 2.0.1 - experimental * @param the value type - * @since 2.0.1 - experimental + * @since 2.1 */ -@Experimental public final class SingleDoFinally extends Single { final SingleSource source; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java b/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java index 4515cf606a..332f910476 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.single; import io.reactivex.*; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.DisposableHelper; import io.reactivex.internal.observers.DeferredScalarDisposable; @@ -38,12 +37,12 @@ public void subscribeActual(final Observer s) { /** * Creates a {@link SingleObserver} wrapper around a {@link Observer}. + *

History: 2.0.1 - experimental * @param the value type * @param downstream the downstream {@code Observer} to talk to * @return the new SingleObserver instance - * @since 2.1.11 - experimental + * @since 2.2 */ - @Experimental public static SingleObserver create(Observer downstream) { return new SingleToObservableObserver(downstream); } diff --git a/src/main/java/io/reactivex/internal/schedulers/SchedulerMultiWorkerSupport.java b/src/main/java/io/reactivex/internal/schedulers/SchedulerMultiWorkerSupport.java index 31f7ed2a33..9eec7eef0c 100644 --- a/src/main/java/io/reactivex/internal/schedulers/SchedulerMultiWorkerSupport.java +++ b/src/main/java/io/reactivex/internal/schedulers/SchedulerMultiWorkerSupport.java @@ -22,10 +22,9 @@ * at most the parallelism level of the Scheduler, those * {@link io.reactivex.Scheduler.Worker} instances will be running * with different backing threads. - * - * @since 2.1.8 - experimental + *

History: 2.1.8 - experimental + * @since 2.2 */ -@Experimental public interface SchedulerMultiWorkerSupport { /** diff --git a/src/main/java/io/reactivex/internal/schedulers/SchedulerWhen.java b/src/main/java/io/reactivex/internal/schedulers/SchedulerWhen.java index 9b97ee6a36..4d56335527 100644 --- a/src/main/java/io/reactivex/internal/schedulers/SchedulerWhen.java +++ b/src/main/java/io/reactivex/internal/schedulers/SchedulerWhen.java @@ -24,7 +24,6 @@ import io.reactivex.Flowable; import io.reactivex.Observable; import io.reactivex.Scheduler; -import io.reactivex.annotations.Experimental; import io.reactivex.annotations.NonNull; import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; @@ -100,8 +99,9 @@ * })); * }); *

+ *

History 2.0.1 - experimental + * @since 2.1 */ -@Experimental public class SchedulerWhen extends Scheduler implements Disposable { private final Scheduler actualScheduler; private final FlowableProcessor> workerProcessor; diff --git a/src/main/java/io/reactivex/observables/ConnectableObservable.java b/src/main/java/io/reactivex/observables/ConnectableObservable.java index 04d1648077..1858397e65 100644 --- a/src/main/java/io/reactivex/observables/ConnectableObservable.java +++ b/src/main/java/io/reactivex/observables/ConnectableObservable.java @@ -93,12 +93,12 @@ public Observable refCount() { *

Scheduler:
*
This {@code refCount} overload does not operate on any particular {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param subscriberCount the number of subscribers required to connect to the upstream * @return the new Observable instance - * @since 2.1.14 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.NONE) public final Observable refCount(int subscriberCount) { return refCount(subscriberCount, 0, TimeUnit.NANOSECONDS, Schedulers.trampoline()); @@ -112,14 +112,14 @@ public final Observable refCount(int subscriberCount) { *

Scheduler:
*
This {@code refCount} overload operates on the {@code computation} {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param timeout the time to wait before disconnecting after all subscribers unsubscribed * @param unit the time unit of the timeout * @return the new Observable instance - * @since 2.1.14 - experimental * @see #refCount(long, TimeUnit, Scheduler) + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable refCount(long timeout, TimeUnit unit) { return refCount(1, timeout, unit, Schedulers.computation()); @@ -133,14 +133,14 @@ public final Observable refCount(long timeout, TimeUnit unit) { *

Scheduler:
*
This {@code refCount} overload operates on the specified {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param timeout the time to wait before disconnecting after all subscribers unsubscribed * @param unit the time unit of the timeout * @param scheduler the target scheduler to wait on before disconnecting * @return the new Observable instance - * @since 2.1.14 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable refCount(long timeout, TimeUnit unit, Scheduler scheduler) { return refCount(1, timeout, unit, scheduler); @@ -154,15 +154,15 @@ public final Observable refCount(long timeout, TimeUnit unit, Scheduler sched *

Scheduler:
*
This {@code refCount} overload operates on the {@code computation} {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param subscriberCount the number of subscribers required to connect to the upstream * @param timeout the time to wait before disconnecting after all subscribers unsubscribed * @param unit the time unit of the timeout * @return the new Observable instance - * @since 2.1.14 - experimental * @see #refCount(int, long, TimeUnit, Scheduler) + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable refCount(int subscriberCount, long timeout, TimeUnit unit) { return refCount(subscriberCount, timeout, unit, Schedulers.computation()); @@ -176,15 +176,15 @@ public final Observable refCount(int subscriberCount, long timeout, TimeUnit *

Scheduler:
*
This {@code refCount} overload operates on the specified {@link Scheduler}.
* + *

History: 2.1.14 - experimental * @param subscriberCount the number of subscribers required to connect to the upstream * @param timeout the time to wait before disconnecting after all subscribers unsubscribed * @param unit the time unit of the timeout * @param scheduler the target scheduler to wait on before disconnecting * @return the new Observable instance - * @since 2.1.14 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable refCount(int subscriberCount, long timeout, TimeUnit unit, Scheduler scheduler) { ObjectHelper.verifyPositive(subscriberCount, "subscriberCount"); diff --git a/src/main/java/io/reactivex/observers/BaseTestConsumer.java b/src/main/java/io/reactivex/observers/BaseTestConsumer.java index 84a6fe889d..373339f020 100644 --- a/src/main/java/io/reactivex/observers/BaseTestConsumer.java +++ b/src/main/java/io/reactivex/observers/BaseTestConsumer.java @@ -17,7 +17,6 @@ import java.util.concurrent.*; import io.reactivex.Notification; -import io.reactivex.annotations.Experimental; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Predicate; @@ -235,7 +234,7 @@ public final boolean await(long time, TimeUnit unit) throws InterruptedException /** * Assert that this TestObserver/TestSubscriber received exactly one onComplete event. - * @return this; + * @return this */ @SuppressWarnings("unchecked") public final U assertComplete() { @@ -251,7 +250,7 @@ public final U assertComplete() { /** * Assert that this TestObserver/TestSubscriber has not received any onComplete event. - * @return this; + * @return this */ @SuppressWarnings("unchecked") public final U assertNotComplete() { @@ -267,7 +266,7 @@ public final U assertNotComplete() { /** * Assert that this TestObserver/TestSubscriber has not received any onError event. - * @return this; + * @return this */ @SuppressWarnings("unchecked") public final U assertNoErrors() { @@ -286,7 +285,7 @@ public final U assertNoErrors() { * overload to test against the class of an error instead of an instance of an error * or {@link #assertError(Predicate)} to test with different condition. * @param error the error to check - * @return this; + * @return this * @see #assertError(Class) * @see #assertError(Predicate) */ @@ -298,7 +297,7 @@ public final U assertError(Throwable error) { * Asserts that this TestObserver/TestSubscriber received exactly one onError event which is an * instance of the specified errorClass class. * @param errorClass the error class to expect - * @return this; + * @return this */ @SuppressWarnings({ "unchecked", "rawtypes", "cast" }) public final U assertError(Class errorClass) { @@ -347,7 +346,7 @@ public final U assertError(Predicate errorPredicate) { * Assert that this TestObserver/TestSubscriber received exactly one onNext value which is equal to * the given value with respect to Objects.equals. * @param value the value to expect - * @return this; + * @return this */ @SuppressWarnings("unchecked") public final U assertValue(T value) { @@ -433,13 +432,13 @@ public final U assertNever(Predicate valuePredicate) { /** * Asserts that this TestObserver/TestSubscriber received an onNext value at the given index * which is equal to the given value with respect to null-safe Object.equals. + *

History: 2.1.3 - experimental * @param index the position to assert on * @param value the value to expect * @return this - * @since 2.1.3 - experimental + * @since 2.2 */ @SuppressWarnings("unchecked") - @Experimental public final U assertValueAt(int index, T value) { int s = values.size(); if (s == 0) { @@ -508,7 +507,7 @@ public static String valueAndClass(Object o) { /** * Assert that this TestObserver/TestSubscriber received the specified number onNext events. * @param count the expected number of onNext events - * @return this; + * @return this */ @SuppressWarnings("unchecked") public final U assertValueCount(int count) { @@ -521,7 +520,7 @@ public final U assertValueCount(int count) { /** * Assert that this TestObserver/TestSubscriber has not received any onNext events. - * @return this; + * @return this */ public final U assertNoValues() { return assertValueCount(0); @@ -530,7 +529,7 @@ public final U assertNoValues() { /** * Assert that the TestObserver/TestSubscriber received only the specified values in the specified order. * @param values the values expected - * @return this; + * @return this * @see #assertValueSet(Collection) */ @SuppressWarnings("unchecked") @@ -552,12 +551,12 @@ public final U assertValues(T... values) { /** * Assert that the TestObserver/TestSubscriber received only the specified values in the specified order without terminating. + *

History: 2.1.4 - experimental * @param values the values expected - * @return this; - * @since 2.1.4 + * @return this + * @since 2.2 */ @SuppressWarnings("unchecked") - @Experimental public final U assertValuesOnly(T... values) { return assertSubscribed() .assertValues(values) @@ -571,7 +570,7 @@ public final U assertValuesOnly(T... values) { * asynchronous streams. * * @param expected the collection of values expected in any order - * @return this; + * @return this */ @SuppressWarnings("unchecked") public final U assertValueSet(Collection expected) { @@ -589,12 +588,11 @@ public final U assertValueSet(Collection expected) { /** * Assert that the TestObserver/TestSubscriber received only the specified values in any order without terminating. + *

History: 2.1.14 - experimental * @param expected the collection of values expected in any order - * @return this; - * @since 2.1.14 - experimental + * @return this + * @since 2.2 */ - @SuppressWarnings("unchecked") - @Experimental public final U assertValueSetOnly(Collection expected) { return assertSubscribed() .assertValueSet(expected) @@ -605,7 +603,7 @@ public final U assertValueSetOnly(Collection expected) { /** * Assert that the TestObserver/TestSubscriber received only the specified sequence of values in the same order. * @param sequence the sequence of expected values in order - * @return this; + * @return this */ @SuppressWarnings("unchecked") public final U assertValueSequence(Iterable sequence) { @@ -642,12 +640,11 @@ public final U assertValueSequence(Iterable sequence) { /** * Assert that the TestObserver/TestSubscriber received only the specified values in the specified order without terminating. + *

History: 2.1.14 - experimental * @param sequence the sequence of expected values in order - * @return this; - * @since 2.1.14 - experimental + * @return this + * @since 2.2 */ - @SuppressWarnings("unchecked") - @Experimental public final U assertValueSequenceOnly(Iterable sequence) { return assertSubscribed() .assertValueSequence(sequence) @@ -657,7 +654,7 @@ public final U assertValueSequenceOnly(Iterable sequence) { /** * Assert that the TestObserver/TestSubscriber terminated (i.e., the terminal latch reached zero). - * @return this; + * @return this */ @SuppressWarnings("unchecked") public final U assertTerminated() { @@ -681,7 +678,7 @@ public final U assertTerminated() { /** * Assert that the TestObserver/TestSubscriber has not terminated (i.e., the terminal latch is still non-zero). - * @return this; + * @return this */ @SuppressWarnings("unchecked") public final U assertNotTerminated() { @@ -771,13 +768,13 @@ public final List> getEvents() { /** * Assert that the onSubscribe method was called exactly once. - * @return this; + * @return this */ public abstract U assertSubscribed(); /** * Assert that the onSubscribe method hasn't been called at all. - * @return this; + * @return this */ public abstract U assertNotSubscribed(); @@ -1024,6 +1021,7 @@ public final U awaitCount(int atLeast, Runnable waitStrategy, long timeoutMillis } /** + * Returns true if an await timed out. * @return true if one of the timeout-based await methods has timed out. *

History: 2.0.7 - experimental * @see #clearTimeout() diff --git a/src/main/java/io/reactivex/observers/LambdaConsumerIntrospection.java b/src/main/java/io/reactivex/observers/LambdaConsumerIntrospection.java index 8bcf1f694c..31588ab0c9 100644 --- a/src/main/java/io/reactivex/observers/LambdaConsumerIntrospection.java +++ b/src/main/java/io/reactivex/observers/LambdaConsumerIntrospection.java @@ -13,24 +13,21 @@ package io.reactivex.observers; -import io.reactivex.annotations.Experimental; - /** * An interface that indicates that the implementing type is composed of individual components and exposes information * about their behavior. * *

NOTE: This is considered a read-only public API and is not intended to be implemented externally. - * - * @since 2.1.4 - experimental + *

History: 2.1.4 - experimental + * @since 2.2 */ -@Experimental public interface LambdaConsumerIntrospection { /** + * Returns true or false if a custom onError consumer has been provided. * @return {@code true} if a custom onError consumer implementation was supplied. Returns {@code false} if the * implementation is missing an error consumer and thus using a throwing default implementation. */ - @Experimental boolean hasCustomOnError(); } diff --git a/src/main/java/io/reactivex/parallel/ParallelFailureHandling.java b/src/main/java/io/reactivex/parallel/ParallelFailureHandling.java index dd53aa622a..867c7496b5 100644 --- a/src/main/java/io/reactivex/parallel/ParallelFailureHandling.java +++ b/src/main/java/io/reactivex/parallel/ParallelFailureHandling.java @@ -13,14 +13,13 @@ package io.reactivex.parallel; -import io.reactivex.annotations.Experimental; import io.reactivex.functions.BiFunction; /** * Enumerations for handling failure within a parallel operator. - * @since 2.0.8 - experimental + *

History: 2.0.8 - experimental + * @since 2.2 */ -@Experimental public enum ParallelFailureHandling implements BiFunction { /** * The current rail is stopped and the error is dropped. diff --git a/src/main/java/io/reactivex/parallel/ParallelFlowable.java b/src/main/java/io/reactivex/parallel/ParallelFlowable.java index 4dd6dfd93d..519e731776 100644 --- a/src/main/java/io/reactivex/parallel/ParallelFlowable.java +++ b/src/main/java/io/reactivex/parallel/ParallelFlowable.java @@ -34,11 +34,10 @@ * Use {@code runOn()} to introduce where each 'rail' should run on thread-vise. * Use {@code sequential()} to merge the sources back into a single Flowable. * - *

History: 2.0.5 - experimental + *

History: 2.0.5 - experimental; 2.1 - beta * @param the value type - * @since 2.1 - beta + * @since 2.2 */ -@Beta public abstract class ParallelFlowable { /** @@ -126,14 +125,13 @@ public static ParallelFlowable from(@NonNull Publisher sourc * Calls the specified converter function during assembly time and returns its resulting value. *

* This allows fluent conversion to any other type. - * + *

History: 2.1.7 - experimental * @param the resulting object type * @param converter the function that receives the current ParallelFlowable instance and returns a value * @return the converted value * @throws NullPointerException if converter is null - * @since 2.1.7 - experimental + * @since 2.2 */ - @Experimental @CheckReturnValue @NonNull public final R as(@NonNull ParallelFlowableConverter converter) { @@ -160,15 +158,15 @@ public final ParallelFlowable map(@NonNull Function * Note that the same mapper function may be called from multiple threads concurrently. + *

History: 2.0.8 - experimental * @param the output value type * @param mapper the mapper function turning Ts into Us. * @param errorHandler the enumeration that defines how to handle errors thrown * from the mapper function * @return the new ParallelFlowable instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @NonNull public final ParallelFlowable map(@NonNull Function mapper, @NonNull ParallelFailureHandling errorHandler) { ObjectHelper.requireNonNull(mapper, "mapper"); @@ -181,16 +179,16 @@ public final ParallelFlowable map(@NonNull Function * Note that the same mapper function may be called from multiple threads concurrently. + *

History: 2.0.8 - experimental * @param the output value type * @param mapper the mapper function turning Ts into Us. * @param errorHandler the function called with the current repeat count and * failure Throwable and should return one of the {@link ParallelFailureHandling} * enumeration values to indicate how to proceed. * @return the new ParallelFlowable instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @NonNull public final ParallelFlowable map(@NonNull Function mapper, @NonNull BiFunction errorHandler) { ObjectHelper.requireNonNull(mapper, "mapper"); @@ -216,14 +214,14 @@ public final ParallelFlowable filter(@NonNull Predicate predicate) * handles errors based on the given {@link ParallelFailureHandling} enumeration value. *

* Note that the same predicate may be called from multiple threads concurrently. + *

History: 2.0.8 - experimental * @param predicate the function returning true to keep a value or false to drop a value * @param errorHandler the enumeration that defines how to handle errors thrown * from the predicate * @return the new ParallelFlowable instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental public final ParallelFlowable filter(@NonNull Predicate predicate, @NonNull ParallelFailureHandling errorHandler) { ObjectHelper.requireNonNull(predicate, "predicate"); ObjectHelper.requireNonNull(errorHandler, "errorHandler is null"); @@ -236,15 +234,15 @@ public final ParallelFlowable filter(@NonNull Predicate predicate, * handles errors based on the returned value by the handler function. *

* Note that the same predicate may be called from multiple threads concurrently. + *

History: 2.0.8 - experimental * @param predicate the function returning true to keep a value or false to drop a value * @param errorHandler the function called with the current repeat count and * failure Throwable and should return one of the {@link ParallelFailureHandling} * enumeration values to indicate how to proceed. * @return the new ParallelFlowable instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental public final ParallelFlowable filter(@NonNull Predicate predicate, @NonNull BiFunction errorHandler) { ObjectHelper.requireNonNull(predicate, "predicate"); ObjectHelper.requireNonNull(errorHandler, "errorHandler is null"); @@ -401,15 +399,15 @@ public final Flowable sequential(int prefetch) { *

Scheduler:
*
{@code sequentialDelayError} does not operate by default on a particular {@link Scheduler}.
* + *

History: 2.0.7 - experimental * @return the new Flowable instance * @see ParallelFlowable#sequentialDelayError(int) * @see ParallelFlowable#sequential() - * @since 2.0.7 - experimental + * @since 2.2 */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @CheckReturnValue - @Experimental @NonNull public final Flowable sequentialDelayError() { return sequentialDelayError(Flowable.bufferSize()); @@ -426,11 +424,12 @@ public final Flowable sequentialDelayError() { *

Scheduler:
*
{@code sequentialDelayError} does not operate by default on a particular {@link Scheduler}.
* + *

History: 2.0.7 - experimental * @param prefetch the prefetch amount to use for each rail * @return the new Flowable instance * @see ParallelFlowable#sequential() * @see ParallelFlowable#sequentialDelayError() - * @since 2.0.7 - experimental + * @since 2.2 */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @@ -541,15 +540,14 @@ public final ParallelFlowable doOnNext(@NonNull Consumer onNext) { /** * Call the specified consumer with the current element passing through any 'rail' and * handles errors based on the given {@link ParallelFailureHandling} enumeration value. - * + *

History: 2.0.8 - experimental * @param onNext the callback * @param errorHandler the enumeration that defines how to handle errors thrown * from the onNext consumer * @return the new ParallelFlowable instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @NonNull public final ParallelFlowable doOnNext(@NonNull Consumer onNext, @NonNull ParallelFailureHandling errorHandler) { ObjectHelper.requireNonNull(onNext, "onNext is null"); @@ -560,16 +558,15 @@ public final ParallelFlowable doOnNext(@NonNull Consumer onNext, @ /** * Call the specified consumer with the current element passing through any 'rail' and * handles errors based on the returned value by the handler function. - * + *

History: 2.0.8 - experimental * @param onNext the callback * @param errorHandler the function called with the current repeat count and * failure Throwable and should return one of the {@link ParallelFailureHandling} * enumeration values to indicate how to proceed. * @return the new ParallelFlowable instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @NonNull public final ParallelFlowable doOnNext(@NonNull Consumer onNext, @NonNull BiFunction errorHandler) { ObjectHelper.requireNonNull(onNext, "onNext is null"); diff --git a/src/main/java/io/reactivex/parallel/ParallelFlowableConverter.java b/src/main/java/io/reactivex/parallel/ParallelFlowableConverter.java index f782eb7bb0..9d1b287849 100644 --- a/src/main/java/io/reactivex/parallel/ParallelFlowableConverter.java +++ b/src/main/java/io/reactivex/parallel/ParallelFlowableConverter.java @@ -18,12 +18,11 @@ /** * Convenience interface and callback used by the {@link ParallelFlowable#as} operator to turn a ParallelFlowable into * another value fluently. - * + *

History: 2.1.7 - experimental * @param the upstream type * @param the output type - * @since 2.1.7 - experimental + * @since 2.2 */ -@Experimental public interface ParallelFlowableConverter { /** * Applies a function to the upstream ParallelFlowable and returns a converted value of type {@code R}. diff --git a/src/main/java/io/reactivex/parallel/ParallelTransformer.java b/src/main/java/io/reactivex/parallel/ParallelTransformer.java index f6837bf948..9981934867 100644 --- a/src/main/java/io/reactivex/parallel/ParallelTransformer.java +++ b/src/main/java/io/reactivex/parallel/ParallelTransformer.java @@ -17,13 +17,11 @@ /** * Interface to compose ParallelFlowable. - * + *

History: 2.0.8 - experimental * @param the upstream value type * @param the downstream value type - * - * @since 2.0.8 - experimental + * @since 2.2 */ -@Experimental public interface ParallelTransformer { /** * Applies a function to the upstream ParallelFlowable and returns a ParallelFlowable with diff --git a/src/main/java/io/reactivex/plugins/RxJavaPlugins.java b/src/main/java/io/reactivex/plugins/RxJavaPlugins.java index 339036c134..4da3a30122 100644 --- a/src/main/java/io/reactivex/plugins/RxJavaPlugins.java +++ b/src/main/java/io/reactivex/plugins/RxJavaPlugins.java @@ -1104,11 +1104,10 @@ public static Completable onAssembly(@NonNull Completable source) { /** * Sets the specific hook function. - *

History: 2.0.6 - experimental + *

History: 2.0.6 - experimental; 2.1 - beta * @param handler the hook function to set, null allowed - * @since 2.1 - beta + * @since 2.2 */ - @Beta @SuppressWarnings("rawtypes") public static void setOnParallelAssembly(@Nullable Function handler) { if (lockdown) { @@ -1119,11 +1118,10 @@ public static void setOnParallelAssembly(@Nullable FunctionHistory: 2.0.6 - experimental + *

History: 2.0.6 - experimental; 2.1 - beta * @return the hook function, may be null - * @since 2.1 - beta + * @since 2.2 */ - @Beta @SuppressWarnings("rawtypes") @Nullable public static Function getOnParallelAssembly() { @@ -1132,13 +1130,12 @@ public static void setOnParallelAssembly(@Nullable FunctionHistory: 2.0.6 - experimental + *

History: 2.0.6 - experimental; 2.1 - beta * @param the value type of the source * @param source the hook's input value * @return the value returned by the hook - * @since 2.1 - beta + * @since 2.2 */ - @Beta @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull public static ParallelFlowable onAssembly(@NonNull ParallelFlowable source) { diff --git a/src/main/java/io/reactivex/processors/BehaviorProcessor.java b/src/main/java/io/reactivex/processors/BehaviorProcessor.java index 5ee462824f..0c4af463e0 100644 --- a/src/main/java/io/reactivex/processors/BehaviorProcessor.java +++ b/src/main/java/io/reactivex/processors/BehaviorProcessor.java @@ -315,11 +315,11 @@ public void onComplete() { *

* Calling with null will terminate the PublishProcessor and a NullPointerException * is signalled to the Subscribers. + *

History: 2.0.8 - experimental * @param t the item to emit, not null * @return true if the item was emitted to all Subscribers - * @since 2.0.8 - experimental + * @since 2.2 */ - @Experimental public boolean offer(T t) { if (t == null) { onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); diff --git a/src/main/java/io/reactivex/processors/MulticastProcessor.java b/src/main/java/io/reactivex/processors/MulticastProcessor.java index 71d8a2dd8e..3d0923a8ab 100644 --- a/src/main/java/io/reactivex/processors/MulticastProcessor.java +++ b/src/main/java/io/reactivex/processors/MulticastProcessor.java @@ -123,10 +123,10 @@ mp2.test().assertResult(1, 2, 3, 4); * + *

History: 2.1.14 - experimental * @param the input and output value type - * @since 2.1.14 - experimental + * @since 2.2 */ -@Experimental @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final class MulticastProcessor extends FlowableProcessor { diff --git a/src/main/java/io/reactivex/processors/PublishProcessor.java b/src/main/java/io/reactivex/processors/PublishProcessor.java index 3f409555df..38f0aa874c 100644 --- a/src/main/java/io/reactivex/processors/PublishProcessor.java +++ b/src/main/java/io/reactivex/processors/PublishProcessor.java @@ -280,11 +280,11 @@ public void onComplete() { *

* Calling with null will terminate the PublishProcessor and a NullPointerException * is signalled to the Subscribers. + *

History: 2.0.8 - experimental * @param t the item to emit, not null * @return true if the item was emitted to all Subscribers - * @since 2.0.8 - experimental + * @since 2.2 */ - @Experimental public boolean offer(T t) { if (t == null) { onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); diff --git a/src/main/java/io/reactivex/processors/ReplayProcessor.java b/src/main/java/io/reactivex/processors/ReplayProcessor.java index b16ef80f68..95bcf5d263 100644 --- a/src/main/java/io/reactivex/processors/ReplayProcessor.java +++ b/src/main/java/io/reactivex/processors/ReplayProcessor.java @@ -433,9 +433,9 @@ public Throwable getThrowable() { *

* The method must be called sequentially, similar to the standard * {@code onXXX} methods. - * @since 2.1.11 - experimental + *

History: 2.1.11 - experimental + * @since 2.2 */ - @Experimental public void cleanupBuffer() { buffer.trimHead(); } diff --git a/src/main/java/io/reactivex/processors/UnicastProcessor.java b/src/main/java/io/reactivex/processors/UnicastProcessor.java index 62abd68cd4..c9fb44f7eb 100644 --- a/src/main/java/io/reactivex/processors/UnicastProcessor.java +++ b/src/main/java/io/reactivex/processors/UnicastProcessor.java @@ -16,7 +16,6 @@ import io.reactivex.annotations.CheckReturnValue; import java.util.concurrent.atomic.*; -import io.reactivex.annotations.Experimental; import io.reactivex.annotations.Nullable; import io.reactivex.annotations.NonNull; import org.reactivestreams.*; @@ -198,13 +197,13 @@ public static UnicastProcessor create(int capacityHint) { /** * Creates an UnicastProcessor with default internal buffer capacity hint and delay error flag. + *

History: 2.0.8 - experimental * @param the value type * @param delayError deliver pending onNext events before onError * @return an UnicastProcessor instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @NonNull public static UnicastProcessor create(boolean delayError) { return new UnicastProcessor(bufferSize(), null, delayError); @@ -235,16 +234,15 @@ public static UnicastProcessor create(int capacityHint, Runnable onCancel * *

The callback, if not null, is called exactly once and * non-overlapped with any active replay. - * + *

History: 2.0.8 - experimental * @param the value type * @param capacityHint the hint to size the internal unbounded buffer * @param onCancelled the non null callback * @param delayError deliver pending onNext events before onError * @return an UnicastProcessor instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @NonNull public static UnicastProcessor create(int capacityHint, Runnable onCancelled, boolean delayError) { ObjectHelper.requireNonNull(onCancelled, "onTerminate"); @@ -274,10 +272,11 @@ public static UnicastProcessor create(int capacityHint, Runnable onCancel /** * Creates an UnicastProcessor with the given capacity hint and callback * for when the Processor is terminated normally or its single Subscriber cancels. + *

History: 2.0.8 - experimental * @param capacityHint the capacity hint for the internal, unbounded queue * @param onTerminate the callback to run when the Processor is terminated or cancelled, null not allowed * @param delayError deliver pending onNext events before onError - * @since 2.0.8 - experimental + * @since 2.2 */ UnicastProcessor(int capacityHint, Runnable onTerminate, boolean delayError) { this.queue = new SpscLinkedArrayQueue(ObjectHelper.verifyPositive(capacityHint, "capacityHint")); diff --git a/src/main/java/io/reactivex/schedulers/SchedulerRunnableIntrospection.java b/src/main/java/io/reactivex/schedulers/SchedulerRunnableIntrospection.java index 810fd6f408..aa930e4f97 100644 --- a/src/main/java/io/reactivex/schedulers/SchedulerRunnableIntrospection.java +++ b/src/main/java/io/reactivex/schedulers/SchedulerRunnableIntrospection.java @@ -24,10 +24,9 @@ * task in a custom {@link RxJavaPlugins#onSchedule(Runnable)} hook set via * the {@link RxJavaPlugins#setScheduleHandler(Function)} method multiple times due to internal delegation * of the default {@code Scheduler.scheduleDirect} or {@code Scheduler.Worker.schedule} methods. - * - * @since 2.1.7 - experimental + *

History: 2.1.7 - experimental + * @since 2.2 */ -@Experimental public interface SchedulerRunnableIntrospection { /** diff --git a/src/main/java/io/reactivex/subjects/ReplaySubject.java b/src/main/java/io/reactivex/subjects/ReplaySubject.java index 2a553f51d5..9454de50d0 100644 --- a/src/main/java/io/reactivex/subjects/ReplaySubject.java +++ b/src/main/java/io/reactivex/subjects/ReplaySubject.java @@ -431,9 +431,9 @@ public T getValue() { *

* The method must be called sequentially, similar to the standard * {@code onXXX} methods. - * @since 2.1.11 - experimental + *

History: 2.1.11 - experimental + * @since 2.2 */ - @Experimental public void cleanupBuffer() { buffer.trimHead(); } diff --git a/src/main/java/io/reactivex/subjects/UnicastSubject.java b/src/main/java/io/reactivex/subjects/UnicastSubject.java index f19a8b0a38..e6cc271073 100644 --- a/src/main/java/io/reactivex/subjects/UnicastSubject.java +++ b/src/main/java/io/reactivex/subjects/UnicastSubject.java @@ -13,7 +13,6 @@ package io.reactivex.subjects; -import io.reactivex.annotations.Experimental; import io.reactivex.annotations.Nullable; import io.reactivex.annotations.NonNull; import io.reactivex.plugins.RxJavaPlugins; @@ -221,16 +220,15 @@ public static UnicastSubject create(int capacityHint, Runnable onTerminat * *

The callback, if not null, is called exactly once and * non-overlapped with any active replay. - * + *

History: 2.0.8 - experimental * @param the value type * @param capacityHint the hint to size the internal unbounded buffer * @param onTerminate the callback to run when the Subject is terminated or cancelled, null not allowed * @param delayError deliver pending onNext events before onError * @return an UnicastSubject instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @NonNull public static UnicastSubject create(int capacityHint, Runnable onTerminate, boolean delayError) { return new UnicastSubject(capacityHint, onTerminate, delayError); @@ -241,14 +239,13 @@ public static UnicastSubject create(int capacityHint, Runnable onTerminat * *

The callback, if not null, is called exactly once and * non-overlapped with any active replay. - * + *

History: 2.0.8 - experimental * @param the value type * @param delayError deliver pending onNext events before onError * @return an UnicastSubject instance - * @since 2.0.8 - experimental + * @since 2.2 */ @CheckReturnValue - @Experimental @NonNull public static UnicastSubject create(boolean delayError) { return new UnicastSubject(bufferSize(), delayError); @@ -257,9 +254,10 @@ public static UnicastSubject create(boolean delayError) { /** * Creates an UnicastSubject with the given capacity hint and delay error flag. + *

History: 2.0.8 - experimental * @param capacityHint the capacity hint for the internal, unbounded queue * @param delayError deliver pending onNext events before onError - * @since 2.0.8 - experimental + * @since 2.2 */ UnicastSubject(int capacityHint, boolean delayError) { this.queue = new SpscLinkedArrayQueue(ObjectHelper.verifyPositive(capacityHint, "capacityHint")); @@ -285,10 +283,11 @@ public static UnicastSubject create(boolean delayError) { /** * Creates an UnicastSubject with the given capacity hint, delay error flag and callback * for when the Subject is terminated normally or its single Subscriber cancels. + *

History: 2.0.8 - experimental * @param capacityHint the capacity hint for the internal, unbounded queue * @param onTerminate the callback to run when the Subject is terminated or cancelled, null not allowed * @param delayError deliver pending onNext events before onError - * @since 2.0.8 - experimental + * @since 2.2 */ UnicastSubject(int capacityHint, Runnable onTerminate, boolean delayError) { this.queue = new SpscLinkedArrayQueue(ObjectHelper.verifyPositive(capacityHint, "capacityHint")); From 839c70fe58b812ca5914ef5ec65a7120081d4252 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 31 Jul 2018 09:28:56 +0200 Subject: [PATCH 035/211] Release 2.2 --- CHANGES.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2312403710..86d4eda074 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,86 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.0 - July 31, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.0%7C)) + +#### Summary + +Version 2.2.0 is the next minor release of the 2.x era and contains the standardization of many experimental API additions from the past year since version 2.1.0. Therefore, the following components are now considered stable and will be supported throughout the rest of the life of RxJava 2.x. + +**Classes, Enums, Annotations** + +- **Annotation**: N/A +- **Subject**: `MulticastProcessor` +- **Classes**: `ParallelFlowable`, `UndeliverableException`, `OnErrorNotImplementedException` +- **Enum**: `ParallelFailureHandling` +- **Interfaces**: `{Completable|Single|Maybe|Observable|Flowable|Parallel}Emitter`, `{Completable|Single|Maybe|Observable|Flowable|Parallel}Converter`, `LambdaConsumerIntrospection`, `ScheduledRunnableIntrospection` + +**Operators** + +- **`Flowable`**: `as`, `concatMap{Single|Maybe|Completable}`, `limit`, `parallel`, `switchMap{Single|Maybe|Completable}`, `throttleLatest` +- **`Observable`**: `as`, `concatMap{Single|Maybe|Completable}`, `switchMap{Single|Maybe|Completable}`, `throttleLatest` +- **`Single`**: `as`, `mergeDelayError`, `onTerminateDetach`, `unsubscribeOn` +- **`Maybe`**: `as`, `mergeDelayError`, `switchIfEmpty` +- **`Completable`**: `as`, `fromMaybe`, `onTerminateDetach`, `takeUntil` +- **`ParallelFlowable`**: `as`, `map|filter|doOnNext(errorHandling)`˙, `sequentialDelayError` +- **`Connectable{Flowable, Observable}`**: `refCount(count + timeout)` +- **`Subject`/`FlowableProcessor`**: `offer`, `cleanupBuffer`, `create(..., delayError)` +- **`Test{Observer, Subscriber}`**: `assertValueAt`, `assertValuesOnly`, `assertValueSetOnly` + +*(For the complete list and details on the promotions, see [PR 6105](https://github.com/ReactiveX/RxJava/pull/6105).)* + +Release 2.2.0 is functionally identical to 2.1.17. Also to clarify, just like with previous minor version increments with RxJava, there won't be any further development or updates on the version 2.1.x (patch) level. + +##### Other promotions + +All Experimental/Beta APIs introduced up to version 2.1.17 are now standard with 2.2. + +#### Project statistics + +- Unique contributors: **75** +- Issues closed: [**283**](https://github.com/ReactiveX/RxJava/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aclosed+created%3A2017-04-29..2018-07-31+label%3A2.x+) +- Bugs reported: [**20**](https://github.com/ReactiveX/RxJava/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aclosed+created%3A2017-04-29..2018-07-31+label%3A2.x+label%3Abug) + - by community: [**19**](https://github.com/ReactiveX/RxJava/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aclosed+created%3A2017-04-29..2018-07-31+label%3A2.x+label%3Abug+-author%3Aakarnokd) (95%) +- Commits: [**320**](https://github.com/ReactiveX/RxJava/compare/v2.1.0...2.x) +- PRs: [**296**](https://github.com/ReactiveX/RxJava/pulls?q=is%3Apr+is%3Aclosed+created%3A2017-04-29..2018-07-31+label%3A2.x) + - PRs accepted: [**268**](https://github.com/ReactiveX/RxJava/pulls?q=is%3Apr+is%3Aclosed+created%3A2017-04-29..2018-07-31+label%3A2.x) (90.54%) + - Community PRs: [**96**](https://github.com/ReactiveX/RxJava/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+created%3A2017-04-29..2018-07-31+label%3A2.x+-author%3Aakarnokd+) (35.82% of all accepted) +- Bugs fixed: [**39**](https://github.com/ReactiveX/RxJava/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+merged%3A2017-04-29..2018-07-31+label%3A2.x+label%3Abug) + - by community: [**8**](https://github.com/ReactiveX/RxJava/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+merged%3A2017-04-29..2018-07-31+label%3A2.x+label%3Abug+-author%3Aakarnokd) (20.51%) +- Documentation enhancements: [**117**](https://github.com/ReactiveX/RxJava/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+merged%3A2017-04-29..2018-07-31+label%3A2.x+label%3Adocumentation) + - by community: [**40**](https://github.com/ReactiveX/RxJava/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+merged%3A2017-04-29..2018-07-31+label%3A2.x+label%3Adocumentation+-author%3Aakarnokd) (34.19%) +- Cleanup: [**50**](https://github.com/ReactiveX/RxJava/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+merged%3A2017-04-29..2018-07-31+label%3A2.x+label%3Acleanup) + - by community: [**21**](https://github.com/ReactiveX/RxJava/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+merged%3A2017-04-29..2018-07-31+label%3A2.x+label%3Acleanup+-author%3Aakarnokd) (42%) +- Performance enhancements: [**12**](https://github.com/ReactiveX/RxJava/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+merged%3A2017-04-29..2018-07-31+label%3A2.x+label%3A%22performance%22+) + - by community: [**1**](https://github.com/ReactiveX/RxJava/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+merged%3A2017-04-29..2018-07-31+label%3A2.x+label%3A%22performance%22+-author%3Aakarnokd) (8.33%) +- Lines + - added: **70,465** + - removed: **12,373** + +#### Acknowledgements + +The project would like to thank the following contributors for their work on various code and documentation improvements (in the order they appear on the [commit](https://github.com/ReactiveX/RxJava/commits/2.x) page): + +@lcybo, @jnlopar, @UMFsimke, @apodkutin, @sircelsius, +@romanzes, @Kiskae, @RomanWuattier, @satoshun, @hans123456, +@fjoshuajr, @davidmoten, @vanniktech, @antego, @strekha, +@artfullyContrived, @VeskoI, @Desislav-Petrov, @Apsaliya, @sidjain270592, +@Milack27, @mekarthedev, @kjkrum, @zhyuri, @artem-zinnatullin, +@vpriscan, @aaronhe42, @adamsp, @bangarharshit, @zhukic, +@afeozzz, @btilbrook-nextfaze, @eventualbuddha, @shaishavgandhi05, @lukaszguz, +@runningcode, @kimkevin, @JakeWharton, @hzsweers, @ggikko, +@philleonard, @sadegh, @dsrees, @benwicks, @dweebo, +@dimsuz, @levaja, @takuaraki, @PhilGlass, @bmaslakov, +@tylerbwong, @AllanWang, @NickFirmani, @plackemacher, @matgabriel, +@jemaystermind, @ansman, @Ganapathi004, @leonardortlima, @pwittchen, +@youngam, @Sroka, @serj-lotutovici, @nathankooij, @mithunsasidharan, +@devisnik, @mg6maciej, @Rémon S, @hvesalai, @kojilin, +@ragunathjawahar, @brucezz, @paulblessing, @cypressf, @langara + +**(75 contributors)** + +The project would also thank its tireless reviewer @vanniktech for all his efforts on verifying and providing feedback on the many PRs from the project lead himself. :+1: + ### Version 2.1.17 - July 23, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.1.17%7C)) #### API changes From 749d60546a52c72b158af2ecd2ddcc88afccc942 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 31 Jul 2018 10:04:41 +0200 Subject: [PATCH 036/211] 2.x: Update Readme.md about the parallel() operator (#6117) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d3b6533eb..1fadd32ba6 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ Note, however, that `flatMap` doesn't guarantee any order and the end result fro - `concatMap` that maps and runs one inner flow at a time and - `concatMapEager` which runs all inner flows "at once" but the output flow will be in the order those inner flows were created. -Alternatively, there is a [*beta*](#beta) operator `Flowable.parallel()` and type `ParallelFlowable` that helps achieve the same parallel processing pattern: +Alternatively, the `Flowable.parallel()` operator and the `ParallelFlowable` type help achieve the same parallel processing pattern: ```java Flowable.range(1, 10) From a20f993dfc9f30ee1635f7ced155eee188926f9a Mon Sep 17 00:00:00 2001 From: Marc Bramaud Date: Tue, 31 Jul 2018 10:14:26 +0200 Subject: [PATCH 037/211] 6108 changed README to use Gradle's implementation instead of compile (#6116) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fadd32ba6..957d1a05e6 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The [1.x version](https://github.com/ReactiveX/RxJava/tree/1.x) is end-of-life a The first step is to include RxJava 2 into your project, for example, as a Gradle compile dependency: ```groovy -compile "io.reactivex.rxjava2:rxjava:2.x.y" +implementation "io.reactivex.rxjava2:rxjava:2.x.y" ``` (Please replace `x` and `y` with the latest version numbers: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava2/rxjava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava2/rxjava) From 45cc53db6d9211a8fc2f62b8167ed54d4f7fda83 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 1 Aug 2018 10:23:11 +0200 Subject: [PATCH 038/211] 2.x: Test cleanup (#6119) * 2.x: Test error printout, local naming, mocking cleanup * Fix additional local variable names * Fix Observers with wrong variable names * Fix nit * More time to MulticastProcessorRefCountedTckTest --- .../InputWithIncrementingInteger.java | 4 +- .../io/reactivex/OperatorFlatMapPerf.java | 6 +- .../java/io/reactivex/OperatorMergePerf.java | 4 +- src/main/java/io/reactivex/Completable.java | 30 +- .../java/io/reactivex/FlowableOperator.java | 4 +- src/main/java/io/reactivex/Observable.java | 48 +- src/main/java/io/reactivex/Single.java | 22 +- .../internal/disposables/EmptyDisposable.java | 42 +- .../observers/QueueDrainObserver.java | 12 +- .../SubscriberCompletableObserver.java | 4 +- .../operators/completable/CompletableAmb.java | 24 +- .../completable/CompletableCache.java | 10 +- .../completable/CompletableConcat.java | 4 +- .../completable/CompletableConcatArray.java | 6 +- .../CompletableConcatIterable.java | 8 +- .../completable/CompletableCreate.java | 6 +- .../completable/CompletableDefer.java | 6 +- .../completable/CompletableDelay.java | 4 +- .../completable/CompletableDisposeOn.java | 16 +- .../completable/CompletableDoFinally.java | 4 +- .../completable/CompletableDoOnEvent.java | 4 +- .../completable/CompletableEmpty.java | 4 +- .../completable/CompletableError.java | 4 +- .../completable/CompletableErrorSupplier.java | 4 +- .../completable/CompletableFromAction.java | 8 +- .../completable/CompletableFromCallable.java | 8 +- .../CompletableFromObservable.java | 4 +- .../completable/CompletableFromRunnable.java | 8 +- .../completable/CompletableFromSingle.java | 4 +- .../completable/CompletableLift.java | 4 +- .../completable/CompletableMerge.java | 4 +- .../completable/CompletableMergeArray.java | 6 +- .../CompletableMergeDelayErrorArray.java | 14 +- .../CompletableMergeDelayErrorIterable.java | 12 +- .../completable/CompletableMergeIterable.java | 8 +- .../completable/CompletableNever.java | 4 +- .../completable/CompletableObserveOn.java | 4 +- .../CompletableOnErrorComplete.java | 20 +- .../completable/CompletablePeek.java | 4 +- .../completable/CompletableResumeNext.java | 22 +- .../completable/CompletableSubscribeOn.java | 6 +- .../CompletableTakeUntilCompletable.java | 6 +- .../completable/CompletableTimeout.java | 30 +- .../completable/CompletableTimer.java | 6 +- .../completable/CompletableToSingle.java | 4 +- .../flowable/BlockingFlowableNext.java | 14 +- .../operators/flowable/FlowableAllSingle.java | 4 +- .../operators/flowable/FlowableAnySingle.java | 4 +- .../flowable/FlowableCollectSingle.java | 6 +- .../flowable/FlowableCountSingle.java | 4 +- .../operators/flowable/FlowableDistinct.java | 6 +- .../flowable/FlowableElementAtMaybe.java | 4 +- .../flowable/FlowableElementAtSingle.java | 4 +- .../flowable/FlowableFlatMapCompletable.java | 8 +- .../FlowableMergeWithCompletable.java | 6 +- .../flowable/FlowableMergeWithMaybe.java | 6 +- .../flowable/FlowableMergeWithSingle.java | 6 +- .../operators/flowable/FlowableReplay.java | 12 +- .../flowable/FlowableSequenceEqualSingle.java | 6 +- .../flowable/FlowableSingleMaybe.java | 4 +- .../flowable/FlowableSingleSingle.java | 4 +- .../flowable/FlowableToListSingle.java | 6 +- .../internal/operators/maybe/MaybeCreate.java | 6 +- .../maybe/MaybeDelayWithCompletable.java | 4 +- .../operators/maybe/MaybeDoAfterSuccess.java | 4 +- .../operators/maybe/MaybeDoFinally.java | 4 +- .../maybe/MaybeFlatMapCompletable.java | 6 +- .../maybe/MaybeFlatMapIterableObservable.java | 4 +- .../operators/maybe/MaybeToObservable.java | 4 +- .../mixed/CompletableAndThenObservable.java | 6 +- .../mixed/FlowableConcatMapCompletable.java | 4 +- .../mixed/FlowableSwitchMapCompletable.java | 4 +- .../mixed/MaybeFlatMapObservable.java | 6 +- .../mixed/ObservableConcatMapCompletable.java | 6 +- .../mixed/ObservableConcatMapMaybe.java | 6 +- .../mixed/ObservableConcatMapSingle.java | 6 +- .../mixed/ObservableSwitchMapCompletable.java | 6 +- .../mixed/ObservableSwitchMapMaybe.java | 6 +- .../mixed/ObservableSwitchMapSingle.java | 6 +- .../mixed/SingleFlatMapObservable.java | 6 +- .../operators/observable/ObservableAmb.java | 12 +- .../observable/ObservableCombineLatest.java | 10 +- .../observable/ObservableConcatMap.java | 8 +- .../operators/observable/ObservableDefer.java | 6 +- .../operators/observable/ObservableDelay.java | 8 +- .../observable/ObservableDetach.java | 4 +- .../ObservableDistinctUntilChanged.java | 4 +- .../observable/ObservableDoAfterNext.java | 4 +- .../observable/ObservableDoFinally.java | 4 +- .../operators/observable/ObservableError.java | 4 +- .../observable/ObservableFilter.java | 4 +- .../observable/ObservableFlatMapMaybe.java | 4 +- .../observable/ObservableFlatMapSingle.java | 4 +- .../observable/ObservableFromArray.java | 6 +- .../observable/ObservableFromCallable.java | 8 +- .../observable/ObservableFromFuture.java | 8 +- .../observable/ObservableFromIterable.java | 12 +- .../observable/ObservableGenerate.java | 8 +- .../observable/ObservableGroupBy.java | 8 +- .../observable/ObservableGroupJoin.java | 6 +- .../observable/ObservableInterval.java | 6 +- .../observable/ObservableIntervalRange.java | 6 +- .../operators/observable/ObservableJoin.java | 6 +- .../operators/observable/ObservableJust.java | 6 +- .../operators/observable/ObservableLift.java | 8 +- .../observable/ObservableRefCount.java | 4 +- .../observable/ObservableRepeat.java | 6 +- .../observable/ObservableRepeatUntil.java | 6 +- .../ObservableRetryBiPredicate.java | 6 +- .../observable/ObservableRetryPredicate.java | 6 +- .../observable/ObservableScalarXMap.java | 14 +- .../observable/ObservableSequenceEqual.java | 22 +- .../ObservableSequenceEqualSingle.java | 22 +- .../operators/observable/ObservableSkip.java | 4 +- .../observable/ObservableSkipLast.java | 4 +- .../observable/ObservableSkipWhile.java | 4 +- .../observable/ObservableSubscribeOn.java | 6 +- .../observable/ObservableTakeLastOne.java | 4 +- .../ObservableTakeUntilPredicate.java | 4 +- .../observable/ObservableThrottleLatest.java | 4 +- .../observable/ObservableTimeout.java | 10 +- .../observable/ObservableTimeoutTimed.java | 10 +- .../operators/observable/ObservableTimer.java | 6 +- .../operators/observable/ObservableUsing.java | 10 +- .../ObservableWithLatestFromMany.java | 14 +- .../operators/observable/ObservableZip.java | 6 +- .../internal/operators/single/SingleAmb.java | 22 +- .../operators/single/SingleCache.java | 10 +- .../operators/single/SingleContains.java | 20 +- .../operators/single/SingleCreate.java | 6 +- .../operators/single/SingleDefer.java | 6 +- .../operators/single/SingleDelay.java | 16 +- .../single/SingleDelayWithCompletable.java | 4 +- .../single/SingleDelayWithObservable.java | 4 +- .../single/SingleDelayWithPublisher.java | 4 +- .../single/SingleDelayWithSingle.java | 4 +- .../single/SingleDoAfterSuccess.java | 4 +- .../single/SingleDoAfterTerminate.java | 4 +- .../operators/single/SingleDoFinally.java | 4 +- .../operators/single/SingleDoOnDispose.java | 4 +- .../operators/single/SingleDoOnError.java | 16 +- .../operators/single/SingleDoOnEvent.java | 18 +- .../operators/single/SingleDoOnSubscribe.java | 4 +- .../operators/single/SingleDoOnSuccess.java | 19 +- .../operators/single/SingleEquals.java | 18 +- .../operators/single/SingleError.java | 4 +- .../single/SingleFlatMapCompletable.java | 6 +- .../SingleFlatMapIterableObservable.java | 4 +- .../operators/single/SingleFromPublisher.java | 4 +- .../internal/operators/single/SingleHide.java | 4 +- .../internal/operators/single/SingleJust.java | 6 +- .../internal/operators/single/SingleLift.java | 6 +- .../operators/single/SingleNever.java | 4 +- .../operators/single/SingleObserveOn.java | 4 +- .../operators/single/SingleOnErrorReturn.java | 4 +- .../operators/single/SingleResumeNext.java | 4 +- .../operators/single/SingleSubscribeOn.java | 6 +- .../operators/single/SingleTimeout.java | 6 +- .../operators/single/SingleTimer.java | 6 +- .../operators/single/SingleToObservable.java | 4 +- .../operators/single/SingleUsing.java | 8 +- .../internal/util/NotificationLite.java | 22 +- .../internal/util/QueueDrainHelper.java | 10 +- .../io/reactivex/plugins/RxJavaPlugins.java | 8 +- .../io/reactivex/subjects/AsyncSubject.java | 8 +- .../reactivex/CheckLocalVariablesInTests.java | 85 ++ .../reactivex/ParamValidationCheckerTest.java | 8 +- src/test/java/io/reactivex/TestHelper.java | 80 +- .../completable/CompletableTest.java | 198 +++-- .../reactivex/exceptions/ExceptionsTest.java | 26 +- .../flowable/FlowableCollectTest.java | 6 +- .../flowable/FlowableConcatTests.java | 54 +- .../flowable/FlowableConversionTest.java | 14 +- .../flowable/FlowableCovarianceTest.java | 8 +- .../flowable/FlowableErrorHandlingTests.java | 14 +- .../flowable/FlowableMergeTests.java | 24 +- .../reactivex/flowable/FlowableNullTests.java | 62 +- .../flowable/FlowableReduceTests.java | 8 +- .../flowable/FlowableSubscriberTest.java | 55 +- .../io/reactivex/flowable/FlowableTests.java | 377 ++++----- .../flowable/FlowableThrottleLastTests.java | 14 +- .../FlowableThrottleWithTimeoutTests.java | 14 +- .../observers/DeferredScalarObserverTest.java | 190 +++-- .../observers/FutureObserverTest.java | 128 +-- .../observers/FutureSingleObserverTest.java | 51 +- .../observers/LambdaObserverTest.java | 160 ++-- .../completable/CompletableConcatTest.java | 49 +- .../completable/CompletableCreateTest.java | 115 +-- .../completable/CompletableDoOnTest.java | 8 +- .../completable/CompletableLiftTest.java | 11 +- .../completable/CompletableMergeTest.java | 36 +- .../completable/CompletableTakeUntilTest.java | 24 +- .../completable/CompletableUnsafeTest.java | 19 +- .../completable/CompletableUsingTest.java | 88 +- .../AbstractFlowableWithUpstreamTest.java | 4 +- .../flowable/BlockingFlowableNextTest.java | 14 +- .../BlockingFlowableToFutureTest.java | 8 +- .../BlockingFlowableToIteratorTest.java | 8 +- .../operators/flowable/FlowableAllTest.java | 94 +-- .../operators/flowable/FlowableAmbTest.java | 67 +- .../operators/flowable/FlowableAnyTest.java | 210 ++--- .../flowable/FlowableAsObservableTest.java | 24 +- .../flowable/FlowableBlockingTest.java | 6 +- .../flowable/FlowableBufferTest.java | 487 +++++------ .../operators/flowable/FlowableCacheTest.java | 28 +- .../operators/flowable/FlowableCastTest.java | 24 +- .../flowable/FlowableCombineLatestTest.java | 238 +++--- .../flowable/FlowableConcatMapEagerTest.java | 12 +- .../flowable/FlowableConcatTest.java | 280 +++---- .../FlowableConcatWithCompletableTest.java | 46 +- .../operators/flowable/FlowableCountTest.java | 8 +- .../flowable/FlowableCreateTest.java | 761 ++++++++++-------- .../flowable/FlowableDebounceTest.java | 68 +- .../flowable/FlowableDefaultIfEmptyTest.java | 42 +- .../operators/flowable/FlowableDeferTest.java | 39 +- .../FlowableDelaySubscriptionOtherTest.java | 14 +- .../operators/flowable/FlowableDelayTest.java | 380 ++++----- .../flowable/FlowableDematerializeTest.java | 104 +-- .../flowable/FlowableDetachTest.java | 4 +- .../flowable/FlowableDistinctTest.java | 16 +- .../FlowableDoAfterTerminateTest.java | 40 +- .../flowable/FlowableDoOnEachTest.java | 74 +- .../flowable/FlowableDoOnLifecycleTest.java | 4 +- .../flowable/FlowableDoOnSubscribeTest.java | 26 +- .../flowable/FlowableElementAtTest.java | 24 +- .../flowable/FlowableFilterTest.java | 12 +- .../operators/flowable/FlowableFirstTest.java | 192 ++--- .../FlowableFlatMapCompletableTest.java | 28 +- .../flowable/FlowableFlatMapMaybeTest.java | 8 +- .../flowable/FlowableFlatMapSingleTest.java | 8 +- .../flowable/FlowableFlatMapTest.java | 147 ++-- .../flowable/FlowableFlattenIterableTest.java | 4 +- .../flowable/FlowableFromCallableTest.java | 38 +- .../flowable/FlowableFromIterableTest.java | 58 +- .../flowable/FlowableFromSourceTest.java | 157 ++-- .../flowable/FlowableGroupByTest.java | 69 +- .../flowable/FlowableGroupJoinTest.java | 163 ++-- .../operators/flowable/FlowableHideTest.java | 24 +- .../flowable/FlowableIgnoreElementsTest.java | 8 +- .../operators/flowable/FlowableJoinTest.java | 136 ++-- .../operators/flowable/FlowableLastTest.java | 72 +- .../operators/flowable/FlowableLiftTest.java | 9 +- .../flowable/FlowableMapNotificationTest.java | 8 +- .../operators/flowable/FlowableMapTest.java | 44 +- .../flowable/FlowableMaterializeTest.java | 14 +- .../flowable/FlowableMergeDelayErrorTest.java | 390 ++++----- .../FlowableMergeMaxConcurrentTest.java | 7 - .../operators/flowable/FlowableMergeTest.java | 238 +++--- .../flowable/FlowableObserveOnTest.java | 195 +++-- ...wableOnErrorResumeNextViaFlowableTest.java | 77 +- ...wableOnErrorResumeNextViaFunctionTest.java | 101 ++- .../flowable/FlowableOnErrorReturnTest.java | 48 +- ...eOnExceptionResumeNextViaFlowableTest.java | 126 +-- .../flowable/FlowablePublishFunctionTest.java | 36 +- .../flowable/FlowablePublishTest.java | 114 +-- .../flowable/FlowableRangeLongTest.java | 42 +- .../operators/flowable/FlowableRangeTest.java | 42 +- .../flowable/FlowableReduceTest.java | 52 +- .../flowable/FlowableRefCountTest.java | 299 ++++--- .../flowable/FlowableRepeatTest.java | 72 +- .../flowable/FlowableReplayTest.java | 274 +++---- .../operators/flowable/FlowableRetryTest.java | 278 ++++--- .../FlowableRetryWithPredicateTest.java | 244 +++--- .../flowable/FlowableSampleTest.java | 160 ++-- .../operators/flowable/FlowableScanTest.java | 90 +-- .../flowable/FlowableSequenceEqualTest.java | 126 +-- .../flowable/FlowableSerializeTest.java | 52 +- .../flowable/FlowableSingleTest.java | 222 ++--- .../flowable/FlowableSkipLastTest.java | 91 ++- .../flowable/FlowableSkipLastTimedTest.java | 62 +- .../operators/flowable/FlowableSkipTest.java | 100 +-- .../flowable/FlowableSkipTimedTest.java | 68 +- .../flowable/FlowableSkipUntilTest.java | 68 +- .../flowable/FlowableSkipWhileTest.java | 16 +- .../flowable/FlowableSubscribeOnTest.java | 10 +- .../flowable/FlowableSwitchIfEmptyTest.java | 12 +- .../flowable/FlowableSwitchTest.java | 386 ++++----- .../flowable/FlowableTakeLastOneTest.java | 4 +- .../flowable/FlowableTakeLastTest.java | 69 +- .../flowable/FlowableTakeLastTimedTest.java | 68 +- .../operators/flowable/FlowableTakeTest.java | 146 ++-- .../flowable/FlowableTakeTimedTest.java | 54 +- .../FlowableTakeUntilPredicateTest.java | 90 +-- .../flowable/FlowableTakeUntilTest.java | 14 +- .../flowable/FlowableTakeWhileTest.java | 124 +-- .../flowable/FlowableThrottleFirstTest.java | 92 +-- .../flowable/FlowableTimeIntervalTest.java | 32 +- .../flowable/FlowableTimeoutTests.java | 184 ++--- .../FlowableTimeoutWithSelectorTest.java | 180 +++-- .../operators/flowable/FlowableTimerTest.java | 40 +- .../flowable/FlowableTimestampTest.java | 32 +- .../flowable/FlowableToFutureTest.java | 36 +- .../flowable/FlowableToListTest.java | 87 +- .../operators/flowable/FlowableToMapTest.java | 52 +- .../flowable/FlowableToMultimapTest.java | 68 +- .../flowable/FlowableToSortedListTest.java | 42 +- .../flowable/FlowableUnsubscribeOnTest.java | 22 +- .../operators/flowable/FlowableUsingTest.java | 76 +- .../FlowableWindowWithFlowableTest.java | 242 +++--- .../flowable/FlowableWindowWithSizeTest.java | 26 +- ...lowableWindowWithStartEndFlowableTest.java | 72 +- .../flowable/FlowableWindowWithTimeTest.java | 123 +-- .../flowable/FlowableWithLatestFromTest.java | 34 +- .../flowable/FlowableZipCompletionTest.java | 32 +- .../flowable/FlowableZipIterableTest.java | 148 ++-- .../operators/flowable/FlowableZipTest.java | 370 ++++----- .../maybe/MaybeDelaySubscriptionTest.java | 12 +- .../operators/maybe/MaybeDoOnEventTest.java | 10 +- .../operators/maybe/MaybeUsingTest.java | 6 +- .../mixed/ObservableConcatMapMaybeTest.java | 8 +- .../mixed/ObservableConcatMapSingleTest.java | 8 +- .../ObservableSwitchMapCompletableTest.java | 8 +- .../mixed/ObservableSwitchMapMaybeTest.java | 16 +- .../mixed/ObservableSwitchMapSingleTest.java | 16 +- .../observable/ObservableAnyTest.java | 40 +- .../observable/ObservableBufferTest.java | 64 +- .../ObservableCombineLatestTest.java | 4 +- .../observable/ObservableConcatTest.java | 10 +- .../ObservableConcatWithCompletableTest.java | 8 +- .../ObservableConcatWithMaybeTest.java | 16 +- .../ObservableConcatWithSingleTest.java | 16 +- .../observable/ObservableDebounceTest.java | 8 +- .../observable/ObservableDeferTest.java | 3 +- .../ObservableDistinctUntilChangedTest.java | 14 +- .../observable/ObservableDoOnEachTest.java | 60 +- .../ObservableDoOnSubscribeTest.java | 14 +- .../ObservableFlatMapCompletableTest.java | 20 +- .../observable/ObservableGroupByTest.java | 9 +- .../observable/ObservableMergeTest.java | 38 +- .../ObservableMergeWithMaybeTest.java | 10 +- .../ObservableMergeWithSingleTest.java | 10 +- .../observable/ObservableObserveOnTest.java | 9 +- ...vableOnErrorResumeNextViaFunctionTest.java | 6 +- ...bleOnErrorResumeNextViaObservableTest.java | 3 +- .../ObservableOnErrorReturnTest.java | 9 +- .../observable/ObservablePublishTest.java | 4 +- .../observable/ObservableRefCountTest.java | 28 +- .../observable/ObservableReplayTest.java | 4 +- .../observable/ObservableRetryTest.java | 25 +- .../ObservableRetryWithPredicateTest.java | 12 +- .../observable/ObservableScalarXMapTest.java | 14 +- .../ObservableSequenceEqualTest.java | 4 +- .../observable/ObservableSubscribeOnTest.java | 8 +- .../observable/ObservableSwitchTest.java | 6 +- .../observable/ObservableTakeLastOneTest.java | 30 +- .../observable/ObservableTakeTest.java | 6 +- .../ObservableTimeoutWithSelectorTest.java | 38 +- .../observable/ObservableToListTest.java | 18 +- .../ObservableToSortedListTest.java | 8 +- .../ObservableWindowWithSizeTest.java | 6 +- ...vableWindowWithStartEndObservableTest.java | 10 +- .../operators/single/SingleDelayTest.java | 8 +- .../operators/single/SingleDoOnTest.java | 8 +- .../operators/single/SingleLiftTest.java | 8 +- .../operators/single/SingleMiscTest.java | 6 +- .../subscribers/BoundedSubscriberTest.java | 48 +- .../subscribers/LambdaSubscriberTest.java | 48 +- .../SubscriberResourceWrapperTest.java | 4 +- .../util/HalfSerializerObserverTest.java | 32 +- .../java/io/reactivex/maybe/MaybeTest.java | 4 +- .../observable/ObservableNullTests.java | 2 +- .../observable/ObservableSubscriberTest.java | 2 +- .../reactivex/observable/ObservableTest.java | 26 +- .../reactivex/observers/SafeObserverTest.java | 8 +- .../observers/SerializedObserverTest.java | 6 +- .../reactivex/observers/TestObserverTest.java | 86 +- .../reactivex/plugins/RxJavaPluginsTest.java | 2 +- .../processors/AsyncProcessorTest.java | 88 +- .../processors/BehaviorProcessorTest.java | 194 ++--- .../processors/PublishProcessorTest.java | 108 +-- ...ReplayProcessorBoundedConcurrencyTest.java | 12 +- .../ReplayProcessorConcurrencyTest.java | 12 +- .../processors/ReplayProcessorTest.java | 184 ++--- .../AbstractSchedulerConcurrencyTests.java | 14 +- .../schedulers/AbstractSchedulerTests.java | 34 +- .../schedulers/CachedThreadSchedulerTest.java | 8 +- .../schedulers/ComputationSchedulerTests.java | 16 +- .../schedulers/TrampolineSchedulerTest.java | 12 +- .../io/reactivex/single/SingleNullTests.java | 2 +- .../java/io/reactivex/single/SingleTest.java | 42 +- .../subscribers/SafeSubscriberTest.java | 52 +- .../subscribers/SerializedSubscriberTest.java | 82 +- .../subscribers/TestSubscriberTest.java | 86 +- .../MulticastProcessorRefCountedTckTest.java | 2 +- 384 files changed, 8395 insertions(+), 7778 deletions(-) diff --git a/src/jmh/java/io/reactivex/InputWithIncrementingInteger.java b/src/jmh/java/io/reactivex/InputWithIncrementingInteger.java index 8a784de957..b5ce98e407 100644 --- a/src/jmh/java/io/reactivex/InputWithIncrementingInteger.java +++ b/src/jmh/java/io/reactivex/InputWithIncrementingInteger.java @@ -94,7 +94,7 @@ public void subscribe(Subscriber s) { } public Iterable iterable; - public Flowable observable; + public Flowable flowable; public Flowable firehose; public Blackhole bh; @@ -104,7 +104,7 @@ public void subscribe(Subscriber s) { public void setup(final Blackhole bh) { this.bh = bh; final int size = getSize(); - observable = Flowable.range(0, size); + flowable = Flowable.range(0, size); firehose = Flowable.unsafeCreate(new IncrementingPublisher(size)); iterable = new IncrementingIterable(size); diff --git a/src/jmh/java/io/reactivex/OperatorFlatMapPerf.java b/src/jmh/java/io/reactivex/OperatorFlatMapPerf.java index c8ab4aacdf..c1f0ddc11a 100644 --- a/src/jmh/java/io/reactivex/OperatorFlatMapPerf.java +++ b/src/jmh/java/io/reactivex/OperatorFlatMapPerf.java @@ -42,7 +42,7 @@ public int getSize() { @Benchmark public void flatMapIntPassthruSync(Input input) throws InterruptedException { - input.observable.flatMap(new Function>() { + input.flowable.flatMap(new Function>() { @Override public Publisher apply(Integer v) { return Flowable.just(v); @@ -53,7 +53,7 @@ public Publisher apply(Integer v) { @Benchmark public void flatMapIntPassthruAsync(Input input) throws InterruptedException { PerfSubscriber latchedObserver = input.newLatchedObserver(); - input.observable.flatMap(new Function>() { + input.flowable.flatMap(new Function>() { @Override public Publisher apply(Integer i) { return Flowable.just(i).subscribeOn(Schedulers.computation()); @@ -71,7 +71,7 @@ public void flatMapTwoNestedSync(final Input input) throws InterruptedException Flowable.range(1, 2).flatMap(new Function>() { @Override public Publisher apply(Integer i) { - return input.observable; + return input.flowable; } }).subscribe(input.newSubscriber()); } diff --git a/src/jmh/java/io/reactivex/OperatorMergePerf.java b/src/jmh/java/io/reactivex/OperatorMergePerf.java index 29de58de2a..97006c163a 100644 --- a/src/jmh/java/io/reactivex/OperatorMergePerf.java +++ b/src/jmh/java/io/reactivex/OperatorMergePerf.java @@ -68,7 +68,7 @@ public Flowable apply(Integer i) { @Benchmark public void mergeNSyncStreamsOfN(final InputThousand input) throws InterruptedException { - Flowable> os = input.observable.map(new Function>() { + Flowable> os = input.flowable.map(new Function>() { @Override public Flowable apply(Integer i) { return Flowable.range(0, input.size); @@ -85,7 +85,7 @@ public Flowable apply(Integer i) { @Benchmark public void mergeNAsyncStreamsOfN(final InputThousand input) throws InterruptedException { - Flowable> os = input.observable.map(new Function>() { + Flowable> os = input.flowable.map(new Function>() { @Override public Flowable apply(Integer i) { return Flowable.range(0, input.size).subscribeOn(Schedulers.computation()); diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 8993524b46..9a681d8bc5 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -2155,20 +2155,20 @@ public final Completable hide() { */ @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe() { - EmptyCompletableObserver s = new EmptyCompletableObserver(); - subscribe(s); - return s; + EmptyCompletableObserver observer = new EmptyCompletableObserver(); + subscribe(observer); + return observer; } @SchedulerSupport(SchedulerSupport.NONE) @Override - public final void subscribe(CompletableObserver s) { - ObjectHelper.requireNonNull(s, "s is null"); + public final void subscribe(CompletableObserver observer) { + ObjectHelper.requireNonNull(observer, "s is null"); try { - s = RxJavaPlugins.onSubscribe(this, s); + observer = RxJavaPlugins.onSubscribe(this, observer); - subscribeActual(s); + subscribeActual(observer); } catch (NullPointerException ex) { // NOPMD throw ex; } catch (Throwable ex) { @@ -2184,9 +2184,9 @@ public final void subscribe(CompletableObserver s) { *

There is no need to call any of the plugin hooks on the current {@code Completable} instance or * the {@code CompletableObserver}; all hooks and basic safeguards have been * applied by {@link #subscribe(CompletableObserver)} before this method gets called. - * @param s the CompletableObserver instance, never null + * @param observer the CompletableObserver instance, never null */ - protected abstract void subscribeActual(CompletableObserver s); + protected abstract void subscribeActual(CompletableObserver observer); /** * Subscribes a given CompletableObserver (subclass) to this Completable and returns the given @@ -2240,9 +2240,9 @@ public final Disposable subscribe(final Action onComplete, final Consumer { /** * Applies a function to the child Subscriber and returns a new parent Subscriber. - * @param observer the child Subscriber instance + * @param subscriber the child Subscriber instance * @return the parent Subscriber instance * @throws Exception on failure */ @NonNull - Subscriber apply(@NonNull Subscriber observer) throws Exception; + Subscriber apply(@NonNull Subscriber subscriber) throws Exception; } diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 918bfea14c..4d672cea00 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -4982,9 +4982,9 @@ public final R as(@NonNull ObservableConverter converter) { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingFirst() { - BlockingFirstObserver s = new BlockingFirstObserver(); - subscribe(s); - T v = s.blockingGet(); + BlockingFirstObserver observer = new BlockingFirstObserver(); + subscribe(observer); + T v = observer.blockingGet(); if (v != null) { return v; } @@ -5010,9 +5010,9 @@ public final T blockingFirst() { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingFirst(T defaultItem) { - BlockingFirstObserver s = new BlockingFirstObserver(); - subscribe(s); - T v = s.blockingGet(); + BlockingFirstObserver observer = new BlockingFirstObserver(); + subscribe(observer); + T v = observer.blockingGet(); return v != null ? v : defaultItem; } @@ -5119,9 +5119,9 @@ public final Iterable blockingIterable(int bufferSize) { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingLast() { - BlockingLastObserver s = new BlockingLastObserver(); - subscribe(s); - T v = s.blockingGet(); + BlockingLastObserver observer = new BlockingLastObserver(); + subscribe(observer); + T v = observer.blockingGet(); if (v != null) { return v; } @@ -5151,9 +5151,9 @@ public final T blockingLast() { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingLast(T defaultItem) { - BlockingLastObserver s = new BlockingLastObserver(); - subscribe(s); - T v = s.blockingGet(); + BlockingLastObserver observer = new BlockingLastObserver(); + subscribe(observer); + T v = observer.blockingGet(); return v != null ? v : defaultItem; } @@ -10998,16 +10998,16 @@ public final Observable retryWhen( *

Scheduler:
*
{@code safeSubscribe} does not operate by default on a particular {@link Scheduler}.
* - * @param s the incoming Observer instance + * @param observer the incoming Observer instance * @throws NullPointerException if s is null */ @SchedulerSupport(SchedulerSupport.NONE) - public final void safeSubscribe(Observer s) { - ObjectHelper.requireNonNull(s, "s is null"); - if (s instanceof SafeObserver) { - subscribe(s); + public final void safeSubscribe(Observer observer) { + ObjectHelper.requireNonNull(observer, "s is null"); + if (observer instanceof SafeObserver) { + subscribe(observer); } else { - subscribe(new SafeObserver(s)); + subscribe(new SafeObserver(observer)); } } @@ -14072,19 +14072,19 @@ public final Single>> toMultimap( @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Flowable toFlowable(BackpressureStrategy strategy) { - Flowable o = new FlowableFromObservable(this); + Flowable f = new FlowableFromObservable(this); switch (strategy) { case DROP: - return o.onBackpressureDrop(); + return f.onBackpressureDrop(); case LATEST: - return o.onBackpressureLatest(); + return f.onBackpressureLatest(); case MISSING: - return o; + return f; case ERROR: - return RxJavaPlugins.onAssembly(new FlowableOnBackpressureError(o)); + return RxJavaPlugins.onAssembly(new FlowableOnBackpressureError(f)); default: - return o.onBackpressureBuffer(); + return f.onBackpressureBuffer(); } } diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index a42e9eaa5b..17d243f7a1 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -3322,9 +3322,9 @@ public final Disposable subscribe() { public final Disposable subscribe(final BiConsumer onCallback) { ObjectHelper.requireNonNull(onCallback, "onCallback is null"); - BiConsumerSingleObserver s = new BiConsumerSingleObserver(onCallback); - subscribe(s); - return s; + BiConsumerSingleObserver observer = new BiConsumerSingleObserver(onCallback); + subscribe(observer); + return observer; } /** @@ -3376,22 +3376,22 @@ public final Disposable subscribe(final Consumer onSuccess, final Con ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"); ObjectHelper.requireNonNull(onError, "onError is null"); - ConsumerSingleObserver s = new ConsumerSingleObserver(onSuccess, onError); - subscribe(s); - return s; + ConsumerSingleObserver observer = new ConsumerSingleObserver(onSuccess, onError); + subscribe(observer); + return observer; } @SchedulerSupport(SchedulerSupport.NONE) @Override - public final void subscribe(SingleObserver subscriber) { - ObjectHelper.requireNonNull(subscriber, "subscriber is null"); + public final void subscribe(SingleObserver observer) { + ObjectHelper.requireNonNull(observer, "subscriber is null"); - subscriber = RxJavaPlugins.onSubscribe(this, subscriber); + observer = RxJavaPlugins.onSubscribe(this, observer); - ObjectHelper.requireNonNull(subscriber, "subscriber returned by the RxJavaPlugins hook is null"); + ObjectHelper.requireNonNull(observer, "subscriber returned by the RxJavaPlugins hook is null"); try { - subscribeActual(subscriber); + subscribeActual(observer); } catch (NullPointerException ex) { throw ex; } catch (Throwable ex) { diff --git a/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java b/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java index 4ac0d33dbf..1a00840549 100644 --- a/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java +++ b/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java @@ -48,39 +48,39 @@ public boolean isDisposed() { return this == INSTANCE; } - public static void complete(Observer s) { - s.onSubscribe(INSTANCE); - s.onComplete(); + public static void complete(Observer observer) { + observer.onSubscribe(INSTANCE); + observer.onComplete(); } - public static void complete(MaybeObserver s) { - s.onSubscribe(INSTANCE); - s.onComplete(); + public static void complete(MaybeObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onComplete(); } - public static void error(Throwable e, Observer s) { - s.onSubscribe(INSTANCE); - s.onError(e); + public static void error(Throwable e, Observer observer) { + observer.onSubscribe(INSTANCE); + observer.onError(e); } - public static void complete(CompletableObserver s) { - s.onSubscribe(INSTANCE); - s.onComplete(); + public static void complete(CompletableObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onComplete(); } - public static void error(Throwable e, CompletableObserver s) { - s.onSubscribe(INSTANCE); - s.onError(e); + public static void error(Throwable e, CompletableObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onError(e); } - public static void error(Throwable e, SingleObserver s) { - s.onSubscribe(INSTANCE); - s.onError(e); + public static void error(Throwable e, SingleObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onError(e); } - public static void error(Throwable e, MaybeObserver s) { - s.onSubscribe(INSTANCE); - s.onError(e); + public static void error(Throwable e, MaybeObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onError(e); } diff --git a/src/main/java/io/reactivex/internal/observers/QueueDrainObserver.java b/src/main/java/io/reactivex/internal/observers/QueueDrainObserver.java index d906317a2d..366639340a 100644 --- a/src/main/java/io/reactivex/internal/observers/QueueDrainObserver.java +++ b/src/main/java/io/reactivex/internal/observers/QueueDrainObserver.java @@ -62,11 +62,11 @@ public final boolean fastEnter() { } protected final void fastPathEmit(U value, boolean delayError, Disposable dispose) { - final Observer s = actual; + final Observer observer = actual; final SimplePlainQueue q = queue; if (wip.get() == 0 && wip.compareAndSet(0, 1)) { - accept(s, value); + accept(observer, value); if (leave(-1) == 0) { return; } @@ -76,7 +76,7 @@ protected final void fastPathEmit(U value, boolean delayError, Disposable dispos return; } } - QueueDrainHelper.drainLoop(q, s, delayError, dispose, this); + QueueDrainHelper.drainLoop(q, observer, delayError, dispose, this); } /** @@ -86,12 +86,12 @@ protected final void fastPathEmit(U value, boolean delayError, Disposable dispos * @param disposable the resource to dispose if the drain terminates */ protected final void fastPathOrderedEmit(U value, boolean delayError, Disposable disposable) { - final Observer s = actual; + final Observer observer = actual; final SimplePlainQueue q = queue; if (wip.get() == 0 && wip.compareAndSet(0, 1)) { if (q.isEmpty()) { - accept(s, value); + accept(observer, value); if (leave(-1) == 0) { return; } @@ -104,7 +104,7 @@ protected final void fastPathOrderedEmit(U value, boolean delayError, Disposable return; } } - QueueDrainHelper.drainLoop(q, s, delayError, disposable, this); + QueueDrainHelper.drainLoop(q, observer, delayError, disposable, this); } @Override diff --git a/src/main/java/io/reactivex/internal/observers/SubscriberCompletableObserver.java b/src/main/java/io/reactivex/internal/observers/SubscriberCompletableObserver.java index aa0f10c126..425b7c5463 100644 --- a/src/main/java/io/reactivex/internal/observers/SubscriberCompletableObserver.java +++ b/src/main/java/io/reactivex/internal/observers/SubscriberCompletableObserver.java @@ -24,8 +24,8 @@ public final class SubscriberCompletableObserver implements CompletableObserv Disposable d; - public SubscriberCompletableObserver(Subscriber observer) { - this.subscriber = observer; + public SubscriberCompletableObserver(Subscriber subscriber) { + this.subscriber = subscriber; } @Override diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableAmb.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableAmb.java index 82d0abbcc5..cc603acbdc 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableAmb.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableAmb.java @@ -31,7 +31,7 @@ public CompletableAmb(CompletableSource[] sources, Iterable sources, int pre } @Override - public void subscribeActual(CompletableObserver s) { - sources.subscribe(new CompletableConcatSubscriber(s, prefetch)); + public void subscribeActual(CompletableObserver observer) { + sources.subscribe(new CompletableConcatSubscriber(observer, prefetch)); } static final class CompletableConcatSubscriber diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatArray.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatArray.java index 3972a7b31c..f87f2a72ea 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatArray.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatArray.java @@ -27,9 +27,9 @@ public CompletableConcatArray(CompletableSource[] sources) { } @Override - public void subscribeActual(CompletableObserver s) { - ConcatInnerObserver inner = new ConcatInnerObserver(s, sources); - s.onSubscribe(inner.sd); + public void subscribeActual(CompletableObserver observer) { + ConcatInnerObserver inner = new ConcatInnerObserver(observer, sources); + observer.onSubscribe(inner.sd); inner.next(); } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatIterable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatIterable.java index 47f4fad3bc..9ca4d919d8 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatIterable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatIterable.java @@ -30,7 +30,7 @@ public CompletableConcatIterable(Iterable sources) } @Override - public void subscribeActual(CompletableObserver s) { + public void subscribeActual(CompletableObserver observer) { Iterator it; @@ -38,12 +38,12 @@ public void subscribeActual(CompletableObserver s) { it = ObjectHelper.requireNonNull(sources.iterator(), "The iterator returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } - ConcatInnerObserver inner = new ConcatInnerObserver(s, it); - s.onSubscribe(inner.sd); + ConcatInnerObserver inner = new ConcatInnerObserver(observer, it); + observer.onSubscribe(inner.sd); inner.next(); } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableCreate.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableCreate.java index 8e0cc20438..c831d899ae 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableCreate.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableCreate.java @@ -31,9 +31,9 @@ public CompletableCreate(CompletableOnSubscribe source) { } @Override - protected void subscribeActual(CompletableObserver s) { - Emitter parent = new Emitter(s); - s.onSubscribe(parent); + protected void subscribeActual(CompletableObserver observer) { + Emitter parent = new Emitter(observer); + observer.onSubscribe(parent); try { source.subscribe(parent); diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDefer.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDefer.java index b486a3095f..030ca4fd3d 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDefer.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDefer.java @@ -29,18 +29,18 @@ public CompletableDefer(Callable completableSupplie } @Override - protected void subscribeActual(CompletableObserver s) { + protected void subscribeActual(CompletableObserver observer) { CompletableSource c; try { c = ObjectHelper.requireNonNull(completableSupplier.call(), "The completableSupplier returned a null CompletableSource"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } - c.subscribe(s); + c.subscribe(observer); } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDelay.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDelay.java index 79b0a49383..a23fd003f1 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDelay.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDelay.java @@ -41,8 +41,8 @@ public CompletableDelay(CompletableSource source, long delay, TimeUnit unit, Sch } @Override - protected void subscribeActual(final CompletableObserver s) { - source.subscribe(new Delay(s, delay, unit, scheduler, delayError)); + protected void subscribeActual(final CompletableObserver observer) { + source.subscribe(new Delay(observer, delay, unit, scheduler, delayError)); } static final class Delay extends AtomicReference diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDisposeOn.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDisposeOn.java index f8e53d3253..df2cfa5e25 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDisposeOn.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDisposeOn.java @@ -30,12 +30,12 @@ public CompletableDisposeOn(CompletableSource source, Scheduler scheduler) { } @Override - protected void subscribeActual(final CompletableObserver s) { - source.subscribe(new CompletableObserverImplementation(s, scheduler)); + protected void subscribeActual(final CompletableObserver observer) { + source.subscribe(new CompletableObserverImplementation(observer, scheduler)); } static final class CompletableObserverImplementation implements CompletableObserver, Disposable, Runnable { - final CompletableObserver s; + final CompletableObserver downstream; final Scheduler scheduler; @@ -43,8 +43,8 @@ static final class CompletableObserverImplementation implements CompletableObser volatile boolean disposed; - CompletableObserverImplementation(CompletableObserver s, Scheduler scheduler) { - this.s = s; + CompletableObserverImplementation(CompletableObserver observer, Scheduler scheduler) { + this.downstream = observer; this.scheduler = scheduler; } @@ -53,7 +53,7 @@ public void onComplete() { if (disposed) { return; } - s.onComplete(); + downstream.onComplete(); } @Override @@ -62,7 +62,7 @@ public void onError(Throwable e) { RxJavaPlugins.onError(e); return; } - s.onError(e); + downstream.onError(e); } @Override @@ -70,7 +70,7 @@ public void onSubscribe(final Disposable d) { if (DisposableHelper.validate(this.d, d)) { this.d = d; - s.onSubscribe(this); + downstream.onSubscribe(this); } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java index c1b695220a..d74169d91c 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java @@ -39,8 +39,8 @@ public CompletableDoFinally(CompletableSource source, Action onFinally) { } @Override - protected void subscribeActual(CompletableObserver s) { - source.subscribe(new DoFinallyObserver(s, onFinally)); + protected void subscribeActual(CompletableObserver observer) { + source.subscribe(new DoFinallyObserver(observer, onFinally)); } static final class DoFinallyObserver extends AtomicInteger implements CompletableObserver, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDoOnEvent.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDoOnEvent.java index 19d472af94..3499a553a1 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDoOnEvent.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDoOnEvent.java @@ -31,8 +31,8 @@ public CompletableDoOnEvent(final CompletableSource source, final Consumer errorSupplier) { } @Override - protected void subscribeActual(CompletableObserver s) { + protected void subscribeActual(CompletableObserver observer) { Throwable error; try { @@ -39,7 +39,7 @@ protected void subscribeActual(CompletableObserver s) { error = e; } - EmptyDisposable.error(error, s); + EmptyDisposable.error(error, observer); } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromAction.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromAction.java index 1a4652840e..3e49bf0ec6 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromAction.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromAction.java @@ -27,20 +27,20 @@ public CompletableFromAction(Action run) { } @Override - protected void subscribeActual(CompletableObserver s) { + protected void subscribeActual(CompletableObserver observer) { Disposable d = Disposables.empty(); - s.onSubscribe(d); + observer.onSubscribe(d); try { run.run(); } catch (Throwable e) { Exceptions.throwIfFatal(e); if (!d.isDisposed()) { - s.onError(e); + observer.onError(e); } return; } if (!d.isDisposed()) { - s.onComplete(); + observer.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromCallable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromCallable.java index 80bb1a0af0..3dbd3701b5 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromCallable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromCallable.java @@ -28,20 +28,20 @@ public CompletableFromCallable(Callable callable) { } @Override - protected void subscribeActual(CompletableObserver s) { + protected void subscribeActual(CompletableObserver observer) { Disposable d = Disposables.empty(); - s.onSubscribe(d); + observer.onSubscribe(d); try { callable.call(); } catch (Throwable e) { Exceptions.throwIfFatal(e); if (!d.isDisposed()) { - s.onError(e); + observer.onError(e); } return; } if (!d.isDisposed()) { - s.onComplete(); + observer.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromObservable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromObservable.java index 509f173fa4..fdf3523b2f 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromObservable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromObservable.java @@ -25,8 +25,8 @@ public CompletableFromObservable(ObservableSource observable) { } @Override - protected void subscribeActual(final CompletableObserver s) { - observable.subscribe(new CompletableFromObservableObserver(s)); + protected void subscribeActual(final CompletableObserver observer) { + observable.subscribe(new CompletableFromObservableObserver(observer)); } static final class CompletableFromObservableObserver implements Observer { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromRunnable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromRunnable.java index 789483ab8e..981e6d1f1f 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromRunnable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromRunnable.java @@ -28,20 +28,20 @@ public CompletableFromRunnable(Runnable runnable) { } @Override - protected void subscribeActual(CompletableObserver s) { + protected void subscribeActual(CompletableObserver observer) { Disposable d = Disposables.empty(); - s.onSubscribe(d); + observer.onSubscribe(d); try { runnable.run(); } catch (Throwable e) { Exceptions.throwIfFatal(e); if (!d.isDisposed()) { - s.onError(e); + observer.onError(e); } return; } if (!d.isDisposed()) { - s.onComplete(); + observer.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromSingle.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromSingle.java index 1dab2b98d6..251ae5c8f3 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromSingle.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromSingle.java @@ -25,8 +25,8 @@ public CompletableFromSingle(SingleSource single) { } @Override - protected void subscribeActual(final CompletableObserver s) { - single.subscribe(new CompletableFromSingleObserver(s)); + protected void subscribeActual(final CompletableObserver observer) { + single.subscribe(new CompletableFromSingleObserver(observer)); } static final class CompletableFromSingleObserver implements SingleObserver { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableLift.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableLift.java index ccc3616811..25a08d5821 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableLift.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableLift.java @@ -29,11 +29,11 @@ public CompletableLift(CompletableSource source, CompletableOperator onLift) { } @Override - protected void subscribeActual(CompletableObserver s) { + protected void subscribeActual(CompletableObserver observer) { try { // TODO plugin wrapping - CompletableObserver sw = onLift.apply(s); + CompletableObserver sw = onLift.apply(observer); source.subscribe(sw); } catch (NullPointerException ex) { // NOPMD diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMerge.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMerge.java index fa59a499bd..890e036d74 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableMerge.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMerge.java @@ -36,8 +36,8 @@ public CompletableMerge(Publisher source, int maxCo } @Override - public void subscribeActual(CompletableObserver s) { - CompletableMergeSubscriber parent = new CompletableMergeSubscriber(s, maxConcurrency, delayErrors); + public void subscribeActual(CompletableObserver observer) { + CompletableMergeSubscriber parent = new CompletableMergeSubscriber(observer, maxConcurrency, delayErrors); source.subscribe(parent); } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeArray.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeArray.java index 783788c286..64a5b6e8a4 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeArray.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeArray.java @@ -27,12 +27,12 @@ public CompletableMergeArray(CompletableSource[] sources) { } @Override - public void subscribeActual(final CompletableObserver s) { + public void subscribeActual(final CompletableObserver observer) { final CompositeDisposable set = new CompositeDisposable(); final AtomicBoolean once = new AtomicBoolean(); - InnerCompletableObserver shared = new InnerCompletableObserver(s, once, set, sources.length + 1); - s.onSubscribe(set); + InnerCompletableObserver shared = new InnerCompletableObserver(observer, once, set, sources.length + 1); + observer.onSubscribe(set); for (CompletableSource c : sources) { if (set.isDisposed()) { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorArray.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorArray.java index c03939f655..733fa88b40 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorArray.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorArray.java @@ -29,13 +29,13 @@ public CompletableMergeDelayErrorArray(CompletableSource[] sources) { } @Override - public void subscribeActual(final CompletableObserver s) { + public void subscribeActual(final CompletableObserver observer) { final CompositeDisposable set = new CompositeDisposable(); final AtomicInteger wip = new AtomicInteger(sources.length + 1); final AtomicThrowable error = new AtomicThrowable(); - s.onSubscribe(set); + observer.onSubscribe(set); for (CompletableSource c : sources) { if (set.isDisposed()) { @@ -49,15 +49,15 @@ public void subscribeActual(final CompletableObserver s) { continue; } - c.subscribe(new MergeInnerCompletableObserver(s, set, error, wip)); + c.subscribe(new MergeInnerCompletableObserver(observer, set, error, wip)); } if (wip.decrementAndGet() == 0) { Throwable ex = error.terminate(); if (ex == null) { - s.onComplete(); + observer.onComplete(); } else { - s.onError(ex); + observer.onError(ex); } } } @@ -69,9 +69,9 @@ static final class MergeInnerCompletableObserver final AtomicThrowable error; final AtomicInteger wip; - MergeInnerCompletableObserver(CompletableObserver s, CompositeDisposable set, AtomicThrowable error, + MergeInnerCompletableObserver(CompletableObserver observer, CompositeDisposable set, AtomicThrowable error, AtomicInteger wip) { - this.actual = s; + this.actual = observer; this.set = set; this.error = error; this.wip = wip; diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorIterable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorIterable.java index 4593f3223e..40c84d1176 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorIterable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorIterable.java @@ -32,10 +32,10 @@ public CompletableMergeDelayErrorIterable(Iterable } @Override - public void subscribeActual(final CompletableObserver s) { + public void subscribeActual(final CompletableObserver observer) { final CompositeDisposable set = new CompositeDisposable(); - s.onSubscribe(set); + observer.onSubscribe(set); Iterator iterator; @@ -43,7 +43,7 @@ public void subscribeActual(final CompletableObserver s) { iterator = ObjectHelper.requireNonNull(sources.iterator(), "The source iterator returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.onError(e); + observer.onError(e); return; } @@ -89,15 +89,15 @@ public void subscribeActual(final CompletableObserver s) { wip.getAndIncrement(); - c.subscribe(new MergeInnerCompletableObserver(s, set, error, wip)); + c.subscribe(new MergeInnerCompletableObserver(observer, set, error, wip)); } if (wip.decrementAndGet() == 0) { Throwable ex = error.terminate(); if (ex == null) { - s.onComplete(); + observer.onComplete(); } else { - s.onError(ex); + observer.onError(ex); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeIterable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeIterable.java index 32d015a0d4..6c22819e19 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeIterable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeIterable.java @@ -30,10 +30,10 @@ public CompletableMergeIterable(Iterable sources) { } @Override - public void subscribeActual(final CompletableObserver s) { + public void subscribeActual(final CompletableObserver observer) { final CompositeDisposable set = new CompositeDisposable(); - s.onSubscribe(set); + observer.onSubscribe(set); Iterator iterator; @@ -41,13 +41,13 @@ public void subscribeActual(final CompletableObserver s) { iterator = ObjectHelper.requireNonNull(sources.iterator(), "The source iterator returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.onError(e); + observer.onError(e); return; } final AtomicInteger wip = new AtomicInteger(1); - MergeCompletableObserver shared = new MergeCompletableObserver(s, set, wip); + MergeCompletableObserver shared = new MergeCompletableObserver(observer, set, wip); for (;;) { if (set.isDisposed()) { return; diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableNever.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableNever.java index 5874fda6be..73b52d54d2 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableNever.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableNever.java @@ -23,8 +23,8 @@ private CompletableNever() { } @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(EmptyDisposable.NEVER); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(EmptyDisposable.NEVER); } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java index 41f1cfb124..73c86873da 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java @@ -30,8 +30,8 @@ public CompletableObserveOn(CompletableSource source, Scheduler scheduler) { } @Override - protected void subscribeActual(final CompletableObserver s) { - source.subscribe(new ObserveOnCompletableObserver(s, scheduler)); + protected void subscribeActual(final CompletableObserver observer) { + source.subscribe(new ObserveOnCompletableObserver(observer, scheduler)); } static final class ObserveOnCompletableObserver diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableOnErrorComplete.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableOnErrorComplete.java index d4de7495fa..5ff0cc3235 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableOnErrorComplete.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableOnErrorComplete.java @@ -30,22 +30,22 @@ public CompletableOnErrorComplete(CompletableSource source, Predicate on } @Override - protected void subscribeActual(final CompletableObserver s) { + protected void subscribeActual(final CompletableObserver observer) { - source.subscribe(new CompletableObserverImplementation(s)); + source.subscribe(new CompletableObserverImplementation(observer)); } final class CompletableObserverImplementation implements CompletableObserver, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java index 8817843e13..16c46aeb24 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java @@ -34,26 +34,26 @@ public CompletableResumeNext(CompletableSource source, @Override - protected void subscribeActual(final CompletableObserver s) { + protected void subscribeActual(final CompletableObserver observer) { final SequentialDisposable sd = new SequentialDisposable(); - s.onSubscribe(sd); - source.subscribe(new ResumeNext(s, sd)); + observer.onSubscribe(sd); + source.subscribe(new ResumeNext(observer, sd)); } final class ResumeNext implements CompletableObserver { - final CompletableObserver s; + final CompletableObserver downstream; final SequentialDisposable sd; - ResumeNext(CompletableObserver s, SequentialDisposable sd) { - this.s = s; + ResumeNext(CompletableObserver observer, SequentialDisposable sd) { + this.downstream = observer; this.sd = sd; } @Override public void onComplete() { - s.onComplete(); + downstream.onComplete(); } @Override @@ -64,14 +64,14 @@ public void onError(Throwable e) { c = errorMapper.apply(e); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.onError(new CompositeException(ex, e)); + downstream.onError(new CompositeException(ex, e)); return; } if (c == null) { NullPointerException npe = new NullPointerException("The CompletableConsumable returned is null"); npe.initCause(e); - s.onError(npe); + downstream.onError(npe); return; } @@ -87,12 +87,12 @@ final class OnErrorObserver implements CompletableObserver { @Override public void onComplete() { - s.onComplete(); + downstream.onComplete(); } @Override public void onError(Throwable e) { - s.onError(e); + downstream.onError(e); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableSubscribeOn.java index b749d6f529..d386009f22 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableSubscribeOn.java @@ -30,10 +30,10 @@ public CompletableSubscribeOn(CompletableSource source, Scheduler scheduler) { } @Override - protected void subscribeActual(final CompletableObserver s) { + protected void subscribeActual(final CompletableObserver observer) { - final SubscribeOnObserver parent = new SubscribeOnObserver(s, source); - s.onSubscribe(parent); + final SubscribeOnObserver parent = new SubscribeOnObserver(observer, source); + observer.onSubscribe(parent); Disposable f = scheduler.scheduleDirect(parent); diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java index 391795846e..7a27b68f9b 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableTakeUntilCompletable.java @@ -38,9 +38,9 @@ public CompletableTakeUntilCompletable(Completable source, } @Override - protected void subscribeActual(CompletableObserver s) { - TakeUntilMainObserver parent = new TakeUntilMainObserver(s); - s.onSubscribe(parent); + protected void subscribeActual(CompletableObserver observer) { + TakeUntilMainObserver parent = new TakeUntilMainObserver(observer); + observer.onSubscribe(parent); other.subscribe(parent.other); source.subscribe(parent); diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableTimeout.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableTimeout.java index 9788e1cf1c..90d36ad103 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableTimeout.java @@ -38,29 +38,29 @@ public CompletableTimeout(CompletableSource source, long timeout, } @Override - public void subscribeActual(final CompletableObserver s) { + public void subscribeActual(final CompletableObserver observer) { final CompositeDisposable set = new CompositeDisposable(); - s.onSubscribe(set); + observer.onSubscribe(set); final AtomicBoolean once = new AtomicBoolean(); - Disposable timer = scheduler.scheduleDirect(new DisposeTask(once, set, s), timeout, unit); + Disposable timer = scheduler.scheduleDirect(new DisposeTask(once, set, observer), timeout, unit); set.add(timer); - source.subscribe(new TimeOutObserver(set, once, s)); + source.subscribe(new TimeOutObserver(set, once, observer)); } static final class TimeOutObserver implements CompletableObserver { private final CompositeDisposable set; private final AtomicBoolean once; - private final CompletableObserver s; + private final CompletableObserver downstream; - TimeOutObserver(CompositeDisposable set, AtomicBoolean once, CompletableObserver s) { + TimeOutObserver(CompositeDisposable set, AtomicBoolean once, CompletableObserver observer) { this.set = set; this.once = once; - this.s = s; + this.downstream = observer; } @Override @@ -72,7 +72,7 @@ public void onSubscribe(Disposable d) { public void onError(Throwable e) { if (once.compareAndSet(false, true)) { set.dispose(); - s.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -82,7 +82,7 @@ public void onError(Throwable e) { public void onComplete() { if (once.compareAndSet(false, true)) { set.dispose(); - s.onComplete(); + downstream.onComplete(); } } @@ -91,12 +91,12 @@ public void onComplete() { final class DisposeTask implements Runnable { private final AtomicBoolean once; final CompositeDisposable set; - final CompletableObserver s; + final CompletableObserver downstream; - DisposeTask(AtomicBoolean once, CompositeDisposable set, CompletableObserver s) { + DisposeTask(AtomicBoolean once, CompositeDisposable set, CompletableObserver observer) { this.once = once; this.set = set; - this.s = s; + this.downstream = observer; } @Override @@ -104,7 +104,7 @@ public void run() { if (once.compareAndSet(false, true)) { set.clear(); if (other == null) { - s.onError(new TimeoutException()); + downstream.onError(new TimeoutException()); } else { other.subscribe(new DisposeObserver()); } @@ -121,13 +121,13 @@ public void onSubscribe(Disposable d) { @Override public void onError(Throwable e) { set.dispose(); - s.onError(e); + downstream.onError(e); } @Override public void onComplete() { set.dispose(); - s.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableTimer.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableTimer.java index 2435365814..5b85346629 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableTimer.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableTimer.java @@ -36,9 +36,9 @@ public CompletableTimer(long delay, TimeUnit unit, Scheduler scheduler) { } @Override - protected void subscribeActual(final CompletableObserver s) { - TimerDisposable parent = new TimerDisposable(s); - s.onSubscribe(parent); + protected void subscribeActual(final CompletableObserver observer) { + TimerDisposable parent = new TimerDisposable(observer); + observer.onSubscribe(parent); parent.setFuture(scheduler.scheduleDirect(parent, delay, unit)); } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableToSingle.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableToSingle.java index bac12bdbd1..e0e5559723 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableToSingle.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableToSingle.java @@ -34,8 +34,8 @@ public CompletableToSingle(CompletableSource source, } @Override - protected void subscribeActual(final SingleObserver s) { - source.subscribe(new ToSingle(s)); + protected void subscribeActual(final SingleObserver observer) { + source.subscribe(new ToSingle(observer)); } final class ToSingle implements CompletableObserver { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableNext.java b/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableNext.java index 9fd3c09d00..8cd40288e4 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableNext.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableNext.java @@ -48,7 +48,7 @@ public Iterator iterator() { // test needs to access the observer.waiting flag static final class NextIterator implements Iterator { - private final NextSubscriber observer; + private final NextSubscriber subscriber; private final Publisher items; private T next; private boolean hasNext = true; @@ -56,9 +56,9 @@ static final class NextIterator implements Iterator { private Throwable error; private boolean started; - NextIterator(Publisher items, NextSubscriber observer) { + NextIterator(Publisher items, NextSubscriber subscriber) { this.items = items; - this.observer = observer; + this.subscriber = subscriber; } @Override @@ -82,12 +82,12 @@ private boolean moveToNext() { if (!started) { started = true; // if not started, start now - observer.setWaiting(); + subscriber.setWaiting(); Flowable.fromPublisher(items) - .materialize().subscribe(observer); + .materialize().subscribe(subscriber); } - Notification nextNotification = observer.takeNext(); + Notification nextNotification = subscriber.takeNext(); if (nextNotification.isOnNext()) { isNextConsumed = false; next = nextNotification.getValue(); @@ -105,7 +105,7 @@ private boolean moveToNext() { } throw new IllegalStateException("Should not reach here"); } catch (InterruptedException e) { - observer.dispose(); + subscriber.dispose(); error = e; throw ExceptionHelper.wrapOrThrow(e); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java index 9812961382..c3bbc19481 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java @@ -34,8 +34,8 @@ public FlowableAllSingle(Flowable source, Predicate predicate) { } @Override - protected void subscribeActual(SingleObserver s) { - source.subscribe(new AllSubscriber(s, predicate)); + protected void subscribeActual(SingleObserver observer) { + source.subscribe(new AllSubscriber(observer, predicate)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java index 94c0ab9a13..47f2ce4ef2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java @@ -33,8 +33,8 @@ public FlowableAnySingle(Flowable source, Predicate predicate) { } @Override - protected void subscribeActual(SingleObserver s) { - source.subscribe(new AnySubscriber(s, predicate)); + protected void subscribeActual(SingleObserver observer) { + source.subscribe(new AnySubscriber(observer, predicate)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCollectSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCollectSingle.java index aaab14bd23..cda031ebbc 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCollectSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCollectSingle.java @@ -40,16 +40,16 @@ public FlowableCollectSingle(Flowable source, Callable initialSu } @Override - protected void subscribeActual(SingleObserver s) { + protected void subscribeActual(SingleObserver observer) { U u; try { u = ObjectHelper.requireNonNull(initialSupplier.call(), "The initialSupplier returned a null value"); } catch (Throwable e) { - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } - source.subscribe(new CollectSubscriber(s, u, collector)); + source.subscribe(new CollectSubscriber(observer, u, collector)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCountSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCountSingle.java index 97c4c08c49..13bf0bd9a8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCountSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCountSingle.java @@ -30,8 +30,8 @@ public FlowableCountSingle(Flowable source) { } @Override - protected void subscribeActual(SingleObserver s) { - source.subscribe(new CountSubscriber(s)); + protected void subscribeActual(SingleObserver observer) { + source.subscribe(new CountSubscriber(observer)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinct.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinct.java index 7072dd3e43..f12b637737 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinct.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinct.java @@ -41,18 +41,18 @@ public FlowableDistinct(Flowable source, Function keySelector, } @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { Collection collection; try { collection = ObjectHelper.requireNonNull(collectionSupplier.call(), "The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources."); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - EmptySubscription.error(ex, observer); + EmptySubscription.error(ex, subscriber); return; } - source.subscribe(new DistinctSubscriber(observer, keySelector, collection)); + source.subscribe(new DistinctSubscriber(subscriber, keySelector, collection)); } static final class DistinctSubscriber extends BasicFuseableSubscriber { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtMaybe.java index d8907aa310..5293af4722 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtMaybe.java @@ -32,8 +32,8 @@ public FlowableElementAtMaybe(Flowable source, long index) { } @Override - protected void subscribeActual(MaybeObserver s) { - source.subscribe(new ElementAtSubscriber(s, index)); + protected void subscribeActual(MaybeObserver observer) { + source.subscribe(new ElementAtSubscriber(observer, index)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtSingle.java index 874f744010..0a08f47fee 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtSingle.java @@ -37,8 +37,8 @@ public FlowableElementAtSingle(Flowable source, long index, T defaultValue) { } @Override - protected void subscribeActual(SingleObserver s) { - source.subscribe(new ElementAtSubscriber(s, index, defaultValue)); + protected void subscribeActual(SingleObserver observer) { + source.subscribe(new ElementAtSubscriber(observer, index, defaultValue)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletable.java index c1f0a6c1e9..43546d1376 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletable.java @@ -50,8 +50,8 @@ public FlowableFlatMapCompletable(Flowable source, } @Override - protected void subscribeActual(Subscriber observer) { - source.subscribe(new FlatMapCompletableMainSubscriber(observer, mapper, delayErrors, maxConcurrency)); + protected void subscribeActual(Subscriber subscriber) { + source.subscribe(new FlatMapCompletableMainSubscriber(subscriber, mapper, delayErrors, maxConcurrency)); } static final class FlatMapCompletableMainSubscriber extends BasicIntQueueSubscription @@ -74,10 +74,10 @@ static final class FlatMapCompletableMainSubscriber extends BasicIntQueueSubs volatile boolean cancelled; - FlatMapCompletableMainSubscriber(Subscriber observer, + FlatMapCompletableMainSubscriber(Subscriber subscriber, Function mapper, boolean delayErrors, int maxConcurrency) { - this.actual = observer; + this.actual = subscriber; this.mapper = mapper; this.delayErrors = delayErrors; this.errors = new AtomicThrowable(); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java index a62b10b1e2..27f8652ff3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java @@ -40,9 +40,9 @@ public FlowableMergeWithCompletable(Flowable source, CompletableSource other) } @Override - protected void subscribeActual(Subscriber observer) { - MergeWithSubscriber parent = new MergeWithSubscriber(observer); - observer.onSubscribe(parent); + protected void subscribeActual(Subscriber subscriber) { + MergeWithSubscriber parent = new MergeWithSubscriber(subscriber); + subscriber.onSubscribe(parent); source.subscribe(parent); other.subscribe(parent.otherObserver); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java index 97c81551eb..08430c4a70 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java @@ -43,9 +43,9 @@ public FlowableMergeWithMaybe(Flowable source, MaybeSource other } @Override - protected void subscribeActual(Subscriber observer) { - MergeWithObserver parent = new MergeWithObserver(observer); - observer.onSubscribe(parent); + protected void subscribeActual(Subscriber subscriber) { + MergeWithObserver parent = new MergeWithObserver(subscriber); + subscriber.onSubscribe(parent); source.subscribe(parent); other.subscribe(parent.otherObserver); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java index 05bf79f5f2..0fee2fa12c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java @@ -43,9 +43,9 @@ public FlowableMergeWithSingle(Flowable source, SingleSource oth } @Override - protected void subscribeActual(Subscriber observer) { - MergeWithObserver parent = new MergeWithObserver(observer); - observer.onSubscribe(parent); + protected void subscribeActual(Subscriber subscriber) { + MergeWithObserver parent = new MergeWithObserver(subscriber); + subscriber.onSubscribe(parent); source.subscribe(parent); other.subscribe(parent.otherObserver); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java index 64853d362b..7a837f5809 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java @@ -69,8 +69,8 @@ public static Flowable multicastSelector( * @return the new ConnectableObservable instance */ public static ConnectableFlowable observeOn(final ConnectableFlowable cf, final Scheduler scheduler) { - final Flowable observable = cf.observeOn(scheduler); - return RxJavaPlugins.onAssembly(new ConnectableFlowableReplay(cf, observable)); + final Flowable flowable = cf.observeOn(scheduler); + return RxJavaPlugins.onAssembly(new ConnectableFlowableReplay(cf, flowable)); } /** @@ -1141,11 +1141,11 @@ public void accept(Disposable r) { static final class ConnectableFlowableReplay extends ConnectableFlowable { private final ConnectableFlowable cf; - private final Flowable observable; + private final Flowable flowable; - ConnectableFlowableReplay(ConnectableFlowable cf, Flowable observable) { + ConnectableFlowableReplay(ConnectableFlowable cf, Flowable flowable) { this.cf = cf; - this.observable = observable; + this.flowable = flowable; } @Override @@ -1155,7 +1155,7 @@ public void connect(Consumer connection) { @Override protected void subscribeActual(Subscriber s) { - observable.subscribe(s); + flowable.subscribe(s); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java index e9c88c7c7c..cd0d958c49 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java @@ -42,9 +42,9 @@ public FlowableSequenceEqualSingle(Publisher first, Publisher s) { - EqualCoordinator parent = new EqualCoordinator(s, prefetch, comparer); - s.onSubscribe(parent); + public void subscribeActual(SingleObserver observer) { + EqualCoordinator parent = new EqualCoordinator(observer, prefetch, comparer); + observer.onSubscribe(parent); parent.subscribe(first, second); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleMaybe.java index 28ac5bcda1..4fcc466df0 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleMaybe.java @@ -30,8 +30,8 @@ public FlowableSingleMaybe(Flowable source) { } @Override - protected void subscribeActual(MaybeObserver s) { - source.subscribe(new SingleElementSubscriber(s)); + protected void subscribeActual(MaybeObserver observer) { + source.subscribe(new SingleElementSubscriber(observer)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleSingle.java index cb33706362..3ee049ecf2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleSingle.java @@ -35,8 +35,8 @@ public FlowableSingleSingle(Flowable source, T defaultValue) { } @Override - protected void subscribeActual(SingleObserver s) { - source.subscribe(new SingleElementSubscriber(s, defaultValue)); + protected void subscribeActual(SingleObserver observer) { + source.subscribe(new SingleElementSubscriber(observer, defaultValue)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableToListSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableToListSingle.java index 365e9762cd..a0738acf11 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableToListSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableToListSingle.java @@ -45,16 +45,16 @@ public FlowableToListSingle(Flowable source, Callable collectionSupplier) } @Override - protected void subscribeActual(SingleObserver s) { + protected void subscribeActual(SingleObserver observer) { U coll; try { coll = ObjectHelper.requireNonNull(collectionSupplier.call(), "The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources."); } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } - source.subscribe(new ToListSubscriber(s, coll)); + source.subscribe(new ToListSubscriber(observer, coll)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java index e0c42b68ca..4c6de982af 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java @@ -37,9 +37,9 @@ public MaybeCreate(MaybeOnSubscribe source) { } @Override - protected void subscribeActual(MaybeObserver s) { - Emitter parent = new Emitter(s); - s.onSubscribe(parent); + protected void subscribeActual(MaybeObserver observer) { + Emitter parent = new Emitter(observer); + observer.onSubscribe(parent); try { source.subscribe(parent); diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayWithCompletable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayWithCompletable.java index 37dd45fade..a56f8c9360 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayWithCompletable.java @@ -34,8 +34,8 @@ public MaybeDelayWithCompletable(MaybeSource source, CompletableSource other) } @Override - protected void subscribeActual(MaybeObserver subscriber) { - other.subscribe(new OtherObserver(subscriber, source)); + protected void subscribeActual(MaybeObserver observer) { + other.subscribe(new OtherObserver(observer, source)); } static final class OtherObserver diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java index 99c77a7b2b..017412ff41 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java @@ -36,8 +36,8 @@ public MaybeDoAfterSuccess(MaybeSource source, Consumer onAfterSuc } @Override - protected void subscribeActual(MaybeObserver s) { - source.subscribe(new DoAfterObserver(s, onAfterSuccess)); + protected void subscribeActual(MaybeObserver observer) { + source.subscribe(new DoAfterObserver(observer, onAfterSuccess)); } static final class DoAfterObserver implements MaybeObserver, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java index 9bba726878..c1db295b50 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java @@ -38,8 +38,8 @@ public MaybeDoFinally(MaybeSource source, Action onFinally) { } @Override - protected void subscribeActual(MaybeObserver s) { - source.subscribe(new DoFinallyObserver(s, onFinally)); + protected void subscribeActual(MaybeObserver observer) { + source.subscribe(new DoFinallyObserver(observer, onFinally)); } static final class DoFinallyObserver extends AtomicInteger implements MaybeObserver, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletable.java index 6e2c9e1ce6..f0bb42e89d 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletable.java @@ -38,9 +38,9 @@ public MaybeFlatMapCompletable(MaybeSource source, Function parent = new FlatMapCompletableObserver(s, mapper); - s.onSubscribe(parent); + protected void subscribeActual(CompletableObserver observer) { + FlatMapCompletableObserver parent = new FlatMapCompletableObserver(observer, mapper); + observer.onSubscribe(parent); source.subscribe(parent); } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java index 23317717cb..1d3ca89756 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java @@ -43,8 +43,8 @@ public MaybeFlatMapIterableObservable(MaybeSource source, } @Override - protected void subscribeActual(Observer s) { - source.subscribe(new FlatMapIterableObserver(s, mapper)); + protected void subscribeActual(Observer observer) { + source.subscribe(new FlatMapIterableObserver(observer, mapper)); } static final class FlatMapIterableObserver diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java index b0777bf5ac..9b543c6472 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java @@ -39,8 +39,8 @@ public MaybeSource source() { } @Override - protected void subscribeActual(Observer s) { - source.subscribe(create(s)); + protected void subscribeActual(Observer observer) { + source.subscribe(create(observer)); } /** diff --git a/src/main/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservable.java b/src/main/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservable.java index 418f1ebbb8..39f1a79a19 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservable.java @@ -39,9 +39,9 @@ public CompletableAndThenObservable(CompletableSource source, } @Override - protected void subscribeActual(Observer s) { - AndThenObservableObserver parent = new AndThenObservableObserver(s, other); - s.onSubscribe(parent); + protected void subscribeActual(Observer observer) { + AndThenObservableObserver parent = new AndThenObservableObserver(observer, other); + observer.onSubscribe(parent); source.subscribe(parent); } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletable.java index 5e7da33f2e..249d01ef82 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletable.java @@ -57,8 +57,8 @@ public FlowableConcatMapCompletable(Flowable source, } @Override - protected void subscribeActual(CompletableObserver s) { - source.subscribe(new ConcatMapCompletableObserver(s, mapper, errorMode, prefetch)); + protected void subscribeActual(CompletableObserver observer) { + source.subscribe(new ConcatMapCompletableObserver(observer, mapper, errorMode, prefetch)); } static final class ConcatMapCompletableObserver diff --git a/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletable.java index 0bcc6041e0..70294ff3d3 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletable.java @@ -51,8 +51,8 @@ public FlowableSwitchMapCompletable(Flowable source, } @Override - protected void subscribeActual(CompletableObserver s) { - source.subscribe(new SwitchMapCompletableObserver(s, mapper, delayErrors)); + protected void subscribeActual(CompletableObserver observer) { + source.subscribe(new SwitchMapCompletableObserver(observer, mapper, delayErrors)); } static final class SwitchMapCompletableObserver implements FlowableSubscriber, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/mixed/MaybeFlatMapObservable.java b/src/main/java/io/reactivex/internal/operators/mixed/MaybeFlatMapObservable.java index a15c77cba8..533e00addd 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/MaybeFlatMapObservable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/MaybeFlatMapObservable.java @@ -43,9 +43,9 @@ public MaybeFlatMapObservable(MaybeSource source, } @Override - protected void subscribeActual(Observer s) { - FlatMapObserver parent = new FlatMapObserver(s, mapper); - s.onSubscribe(parent); + protected void subscribeActual(Observer observer) { + FlatMapObserver parent = new FlatMapObserver(observer, mapper); + observer.onSubscribe(parent); source.subscribe(parent); } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java index 60151de5c0..48a503c13c 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java @@ -54,9 +54,9 @@ public ObservableConcatMapCompletable(Observable source, } @Override - protected void subscribeActual(CompletableObserver s) { - if (!ScalarXMapZHelper.tryAsCompletable(source, mapper, s)) { - source.subscribe(new ConcatMapCompletableObserver(s, mapper, errorMode, prefetch)); + protected void subscribeActual(CompletableObserver observer) { + if (!ScalarXMapZHelper.tryAsCompletable(source, mapper, observer)) { + source.subscribe(new ConcatMapCompletableObserver(observer, mapper, errorMode, prefetch)); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java index f83388b5b7..1a52327c72 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java @@ -55,9 +55,9 @@ public ObservableConcatMapMaybe(Observable source, } @Override - protected void subscribeActual(Observer s) { - if (!ScalarXMapZHelper.tryAsMaybe(source, mapper, s)) { - source.subscribe(new ConcatMapMaybeMainObserver(s, mapper, prefetch, errorMode)); + protected void subscribeActual(Observer observer) { + if (!ScalarXMapZHelper.tryAsMaybe(source, mapper, observer)) { + source.subscribe(new ConcatMapMaybeMainObserver(observer, mapper, prefetch, errorMode)); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java index faca30b70f..b272f27218 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java @@ -55,9 +55,9 @@ public ObservableConcatMapSingle(Observable source, } @Override - protected void subscribeActual(Observer s) { - if (!ScalarXMapZHelper.tryAsSingle(source, mapper, s)) { - source.subscribe(new ConcatMapSingleMainObserver(s, mapper, prefetch, errorMode)); + protected void subscribeActual(Observer observer) { + if (!ScalarXMapZHelper.tryAsSingle(source, mapper, observer)) { + source.subscribe(new ConcatMapSingleMainObserver(observer, mapper, prefetch, errorMode)); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java index 4482a797c1..7ffe99b707 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java @@ -48,9 +48,9 @@ public ObservableSwitchMapCompletable(Observable source, } @Override - protected void subscribeActual(CompletableObserver s) { - if (!ScalarXMapZHelper.tryAsCompletable(source, mapper, s)) { - source.subscribe(new SwitchMapCompletableObserver(s, mapper, delayErrors)); + protected void subscribeActual(CompletableObserver observer) { + if (!ScalarXMapZHelper.tryAsCompletable(source, mapper, observer)) { + source.subscribe(new SwitchMapCompletableObserver(observer, mapper, delayErrors)); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java index a4e2586f95..d6e904cec2 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java @@ -50,9 +50,9 @@ public ObservableSwitchMapMaybe(Observable source, } @Override - protected void subscribeActual(Observer s) { - if (!ScalarXMapZHelper.tryAsMaybe(source, mapper, s)) { - source.subscribe(new SwitchMapMaybeMainObserver(s, mapper, delayErrors)); + protected void subscribeActual(Observer observer) { + if (!ScalarXMapZHelper.tryAsMaybe(source, mapper, observer)) { + source.subscribe(new SwitchMapMaybeMainObserver(observer, mapper, delayErrors)); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java index 166dce2b74..f739b10161 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java @@ -50,9 +50,9 @@ public ObservableSwitchMapSingle(Observable source, } @Override - protected void subscribeActual(Observer s) { - if (!ScalarXMapZHelper.tryAsSingle(source, mapper, s)) { - source.subscribe(new SwitchMapSingleMainObserver(s, mapper, delayErrors)); + protected void subscribeActual(Observer observer) { + if (!ScalarXMapZHelper.tryAsSingle(source, mapper, observer)) { + source.subscribe(new SwitchMapSingleMainObserver(observer, mapper, delayErrors)); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/SingleFlatMapObservable.java b/src/main/java/io/reactivex/internal/operators/mixed/SingleFlatMapObservable.java index 590a726f89..48d5793185 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/SingleFlatMapObservable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/SingleFlatMapObservable.java @@ -43,9 +43,9 @@ public SingleFlatMapObservable(SingleSource source, } @Override - protected void subscribeActual(Observer s) { - FlatMapObserver parent = new FlatMapObserver(s, mapper); - s.onSubscribe(parent); + protected void subscribeActual(Observer observer) { + FlatMapObserver parent = new FlatMapObserver(observer, mapper); + observer.onSubscribe(parent); source.subscribe(parent); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java index 55abe1499b..65e2493f7e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java @@ -32,7 +32,7 @@ public ObservableAmb(ObservableSource[] sources, Iterable s) { + public void subscribeActual(Observer observer) { ObservableSource[] sources = this.sources; int count = 0; if (sources == null) { @@ -40,7 +40,7 @@ public void subscribeActual(Observer s) { try { for (ObservableSource p : sourcesIterable) { if (p == null) { - EmptyDisposable.error(new NullPointerException("One of the sources is null"), s); + EmptyDisposable.error(new NullPointerException("One of the sources is null"), observer); return; } if (count == sources.length) { @@ -52,7 +52,7 @@ public void subscribeActual(Observer s) { } } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } } else { @@ -60,15 +60,15 @@ public void subscribeActual(Observer s) { } if (count == 0) { - EmptyDisposable.complete(s); + EmptyDisposable.complete(observer); return; } else if (count == 1) { - sources[0].subscribe(s); + sources[0].subscribe(observer); return; } - AmbCoordinator ac = new AmbCoordinator(s, count); + AmbCoordinator ac = new AmbCoordinator(observer, count); ac.subscribe(sources); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java index c8c8dd8fa1..d8ed6175f6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java @@ -46,7 +46,7 @@ public ObservableCombineLatest(ObservableSource[] sources, @Override @SuppressWarnings("unchecked") - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { ObservableSource[] sources = this.sources; int count = 0; if (sources == null) { @@ -64,11 +64,11 @@ public void subscribeActual(Observer s) { } if (count == 0) { - EmptyDisposable.complete(s); + EmptyDisposable.complete(observer); return; } - LatestCoordinator lc = new LatestCoordinator(s, combiner, count, bufferSize, delayError); + LatestCoordinator lc = new LatestCoordinator(observer, combiner, count, bufferSize, delayError); lc.subscribe(sources); } @@ -136,8 +136,8 @@ public boolean isDisposed() { } void cancelSources() { - for (CombinerObserver s : observers) { - s.dispose(); + for (CombinerObserver observer : observers) { + observer.dispose(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java index 8e66db0bdc..f719e0a842 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java @@ -41,17 +41,17 @@ public ObservableConcatMap(ObservableSource source, Function s) { + public void subscribeActual(Observer observer) { - if (ObservableScalarXMap.tryScalarXMapSubscribe(source, s, mapper)) { + if (ObservableScalarXMap.tryScalarXMapSubscribe(source, observer, mapper)) { return; } if (delayErrors == ErrorMode.IMMEDIATE) { - SerializedObserver serial = new SerializedObserver(s); + SerializedObserver serial = new SerializedObserver(observer); source.subscribe(new SourceObserver(serial, mapper, bufferSize)); } else { - source.subscribe(new ConcatMapDelayErrorObserver(s, mapper, bufferSize, delayErrors == ErrorMode.END)); + source.subscribe(new ConcatMapDelayErrorObserver(observer, mapper, bufferSize, delayErrors == ErrorMode.END)); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDefer.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDefer.java index 37996e1332..411530c81f 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDefer.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDefer.java @@ -26,16 +26,16 @@ public ObservableDefer(Callable> supplie this.supplier = supplier; } @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { ObservableSource pub; try { pub = ObjectHelper.requireNonNull(supplier.call(), "null ObservableSource supplied"); } catch (Throwable t) { Exceptions.throwIfFatal(t); - EmptyDisposable.error(t, s); + EmptyDisposable.error(t, observer); return; } - pub.subscribe(s); + pub.subscribe(observer); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDelay.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDelay.java index adfbbd4b3f..8dff7222eb 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDelay.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDelay.java @@ -38,16 +38,16 @@ public ObservableDelay(ObservableSource source, long delay, TimeUnit unit, Sc @Override @SuppressWarnings("unchecked") public void subscribeActual(Observer t) { - Observer s; + Observer observer; if (delayError) { - s = (Observer)t; + observer = (Observer)t; } else { - s = new SerializedObserver(t); + observer = new SerializedObserver(t); } Scheduler.Worker w = scheduler.createWorker(); - source.subscribe(new DelayObserver(s, delay, unit, w, delayError)); + source.subscribe(new DelayObserver(observer, delay, unit, w, delayError)); } static final class DelayObserver implements Observer, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDetach.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDetach.java index 797d06fcd5..b5093e0972 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDetach.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDetach.java @@ -31,8 +31,8 @@ public ObservableDetach(ObservableSource source) { } @Override - protected void subscribeActual(Observer s) { - source.subscribe(new DetachObserver(s)); + protected void subscribeActual(Observer observer) { + source.subscribe(new DetachObserver(observer)); } static final class DetachObserver implements Observer, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChanged.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChanged.java index e5eb1e7cdf..065d121b0a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChanged.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChanged.java @@ -31,8 +31,8 @@ public ObservableDistinctUntilChanged(ObservableSource source, Function s) { - source.subscribe(new DistinctUntilChangedObserver(s, keySelector, comparer)); + protected void subscribeActual(Observer observer) { + source.subscribe(new DistinctUntilChangedObserver(observer, keySelector, comparer)); } static final class DistinctUntilChangedObserver extends BasicFuseableObserver { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java index e1346d2dbe..e2d7760413 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java @@ -34,8 +34,8 @@ public ObservableDoAfterNext(ObservableSource source, Consumer onA } @Override - protected void subscribeActual(Observer s) { - source.subscribe(new DoAfterObserver(s, onAfterNext)); + protected void subscribeActual(Observer observer) { + source.subscribe(new DoAfterObserver(observer, onAfterNext)); } static final class DoAfterObserver extends BasicFuseableObserver { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java index 99720ce5cc..196a8c78e2 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java @@ -39,8 +39,8 @@ public ObservableDoFinally(ObservableSource source, Action onFinally) { } @Override - protected void subscribeActual(Observer s) { - source.subscribe(new DoFinallyObserver(s, onFinally)); + protected void subscribeActual(Observer observer) { + source.subscribe(new DoFinallyObserver(observer, onFinally)); } static final class DoFinallyObserver extends BasicIntQueueDisposable implements Observer { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java index 29076de2b4..bc375ddf38 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java @@ -26,7 +26,7 @@ public ObservableError(Callable errorSupplier) { this.errorSupplier = errorSupplier; } @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { Throwable error; try { error = ObjectHelper.requireNonNull(errorSupplier.call(), "Callable returned null throwable. Null values are generally not allowed in 2.x operators and sources."); @@ -34,6 +34,6 @@ public void subscribeActual(Observer s) { Exceptions.throwIfFatal(t); error = t; } - EmptyDisposable.error(error, s); + EmptyDisposable.error(error, observer); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFilter.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFilter.java index 108c44a88c..cbe8fa3849 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFilter.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFilter.java @@ -26,8 +26,8 @@ public ObservableFilter(ObservableSource source, Predicate predica } @Override - public void subscribeActual(Observer s) { - source.subscribe(new FilterObserver(s, predicate)); + public void subscribeActual(Observer observer) { + source.subscribe(new FilterObserver(observer, predicate)); } static final class FilterObserver extends BasicFuseableObserver { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybe.java index 930f339175..51815b4c1e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybe.java @@ -44,8 +44,8 @@ public ObservableFlatMapMaybe(ObservableSource source, Function s) { - source.subscribe(new FlatMapMaybeObserver(s, mapper, delayErrors)); + protected void subscribeActual(Observer observer) { + source.subscribe(new FlatMapMaybeObserver(observer, mapper, delayErrors)); } static final class FlatMapMaybeObserver diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingle.java index 34f298fa2c..4697d8e106 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingle.java @@ -44,8 +44,8 @@ public ObservableFlatMapSingle(ObservableSource source, Function s) { - source.subscribe(new FlatMapSingleObserver(s, mapper, delayErrors)); + protected void subscribeActual(Observer observer) { + source.subscribe(new FlatMapSingleObserver(observer, mapper, delayErrors)); } static final class FlatMapSingleObserver diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java index 4ac881ceec..bd12bec41c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java @@ -24,10 +24,10 @@ public ObservableFromArray(T[] array) { this.array = array; } @Override - public void subscribeActual(Observer s) { - FromArrayDisposable d = new FromArrayDisposable(s, array); + public void subscribeActual(Observer observer) { + FromArrayDisposable d = new FromArrayDisposable(observer, array); - s.onSubscribe(d); + observer.onSubscribe(d); if (d.fusionMode) { return; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromCallable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromCallable.java index aaa3756ec2..214af8f4d7 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromCallable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromCallable.java @@ -31,9 +31,9 @@ public ObservableFromCallable(Callable callable) { this.callable = callable; } @Override - public void subscribeActual(Observer s) { - DeferredScalarDisposable d = new DeferredScalarDisposable(s); - s.onSubscribe(d); + public void subscribeActual(Observer observer) { + DeferredScalarDisposable d = new DeferredScalarDisposable(observer); + observer.onSubscribe(d); if (d.isDisposed()) { return; } @@ -43,7 +43,7 @@ public void subscribeActual(Observer s) { } catch (Throwable e) { Exceptions.throwIfFatal(e); if (!d.isDisposed()) { - s.onError(e); + observer.onError(e); } else { RxJavaPlugins.onError(e); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromFuture.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromFuture.java index 6a58d50680..ec6e90275d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromFuture.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromFuture.java @@ -32,9 +32,9 @@ public ObservableFromFuture(Future future, long timeout, TimeUnit u } @Override - public void subscribeActual(Observer s) { - DeferredScalarDisposable d = new DeferredScalarDisposable(s); - s.onSubscribe(d); + public void subscribeActual(Observer observer) { + DeferredScalarDisposable d = new DeferredScalarDisposable(observer); + observer.onSubscribe(d); if (!d.isDisposed()) { T v; try { @@ -42,7 +42,7 @@ public void subscribeActual(Observer s) { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); if (!d.isDisposed()) { - s.onError(ex); + observer.onError(ex); } return; } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromIterable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromIterable.java index 3a8b7853d5..ae7638e142 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromIterable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromIterable.java @@ -29,13 +29,13 @@ public ObservableFromIterable(Iterable source) { } @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { Iterator it; try { it = source.iterator(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } boolean hasNext; @@ -43,16 +43,16 @@ public void subscribeActual(Observer s) { hasNext = it.hasNext(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } if (!hasNext) { - EmptyDisposable.complete(s); + EmptyDisposable.complete(observer); return; } - FromIterableDisposable d = new FromIterableDisposable(s, it); - s.onSubscribe(d); + FromIterableDisposable d = new FromIterableDisposable(observer, it); + observer.onSubscribe(d); if (!d.fusionMode) { d.run(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java index 063ad6d980..ac33e689ac 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java @@ -35,19 +35,19 @@ public ObservableGenerate(Callable stateSupplier, BiFunction, S } @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { S state; try { state = stateSupplier.call(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } - GeneratorDisposable gd = new GeneratorDisposable(s, generator, disposeState, state); - s.onSubscribe(gd); + GeneratorDisposable gd = new GeneratorDisposable(observer, generator, disposeState, state); + observer.onSubscribe(gd); gd.run(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java index b2d60f492d..2667401199 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java @@ -247,17 +247,17 @@ public boolean isDisposed() { } @Override - public void subscribe(Observer s) { + public void subscribe(Observer observer) { if (once.compareAndSet(false, true)) { - s.onSubscribe(this); - actual.lazySet(s); + observer.onSubscribe(this); + actual.lazySet(observer); if (cancelled.get()) { actual.lazySet(null); } else { drain(); } } else { - EmptyDisposable.error(new IllegalStateException("Only one Observer allowed!"), s); + EmptyDisposable.error(new IllegalStateException("Only one Observer allowed!"), observer); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java index a6bf21423f..bf012297cd 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java @@ -56,12 +56,12 @@ public ObservableGroupJoin( } @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { GroupJoinDisposable parent = - new GroupJoinDisposable(s, leftEnd, rightEnd, resultSelector); + new GroupJoinDisposable(observer, leftEnd, rightEnd, resultSelector); - s.onSubscribe(parent); + observer.onSubscribe(parent); LeftRightObserver left = new LeftRightObserver(parent, true); parent.disposables.add(left); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java index 7607b62458..ae5038b525 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java @@ -36,9 +36,9 @@ public ObservableInterval(long initialDelay, long period, TimeUnit unit, Schedul } @Override - public void subscribeActual(Observer s) { - IntervalObserver is = new IntervalObserver(s); - s.onSubscribe(is); + public void subscribeActual(Observer observer) { + IntervalObserver is = new IntervalObserver(observer); + observer.onSubscribe(is); Scheduler sch = scheduler; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java index 3fd5396bfd..9d011b3b6b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java @@ -40,9 +40,9 @@ public ObservableIntervalRange(long start, long end, long initialDelay, long per } @Override - public void subscribeActual(Observer s) { - IntervalRangeObserver is = new IntervalRangeObserver(s, start, end); - s.onSubscribe(is); + public void subscribeActual(Observer observer) { + IntervalRangeObserver is = new IntervalRangeObserver(observer, start, end); + observer.onSubscribe(is); Scheduler sch = scheduler; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java index 2485c1cd2a..5cbde302bb 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java @@ -54,13 +54,13 @@ public ObservableJoin( } @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { JoinDisposable parent = new JoinDisposable( - s, leftEnd, rightEnd, resultSelector); + observer, leftEnd, rightEnd, resultSelector); - s.onSubscribe(parent); + observer.onSubscribe(parent); LeftRightObserver left = new LeftRightObserver(parent, true); parent.disposables.add(left); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableJust.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableJust.java index 653fef105b..0ae53fb597 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableJust.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableJust.java @@ -29,9 +29,9 @@ public ObservableJust(final T value) { } @Override - protected void subscribeActual(Observer s) { - ScalarDisposable sd = new ScalarDisposable(s, value); - s.onSubscribe(sd); + protected void subscribeActual(Observer observer) { + ScalarDisposable sd = new ScalarDisposable(observer, value); + observer.onSubscribe(sd); sd.run(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableLift.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableLift.java index ca9c36a697..8cdd918564 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableLift.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableLift.java @@ -37,10 +37,10 @@ public ObservableLift(ObservableSource source, ObservableOperator s) { - Observer observer; + public void subscribeActual(Observer observer) { + Observer liftedObserver; try { - observer = ObjectHelper.requireNonNull(operator.apply(s), "Operator " + operator + " returned a null Observer"); + liftedObserver = ObjectHelper.requireNonNull(operator.apply(observer), "Operator " + operator + " returned a null Observer"); } catch (NullPointerException e) { // NOPMD throw e; } catch (Throwable e) { @@ -54,6 +54,6 @@ public void subscribeActual(Observer s) { throw npe; } - source.subscribe(observer); + source.subscribe(liftedObserver); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java index fd62c1ae60..73b1e0c1db 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java @@ -59,7 +59,7 @@ public ObservableRefCount(ConnectableObservable source, int n, long timeout, } @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { RefConnection conn; @@ -82,7 +82,7 @@ protected void subscribeActual(Observer s) { } } - source.subscribe(new RefCountObserver(s, this, conn)); + source.subscribe(new RefCountObserver(observer, this, conn)); if (connect) { source.connect(conn); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java index f3dce65e80..c5ce8d1763 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java @@ -27,11 +27,11 @@ public ObservableRepeat(Observable source, long count) { } @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { SequentialDisposable sd = new SequentialDisposable(); - s.onSubscribe(sd); + observer.onSubscribe(sd); - RepeatObserver rs = new RepeatObserver(s, count != Long.MAX_VALUE ? count - 1 : Long.MAX_VALUE, sd, source); + RepeatObserver rs = new RepeatObserver(observer, count != Long.MAX_VALUE ? count - 1 : Long.MAX_VALUE, sd, source); rs.subscribeNext(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java index 6f97906ece..595c5e3b03 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java @@ -29,11 +29,11 @@ public ObservableRepeatUntil(Observable source, BooleanSupplier until) { } @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { SequentialDisposable sd = new SequentialDisposable(); - s.onSubscribe(sd); + observer.onSubscribe(sd); - RepeatUntilObserver rs = new RepeatUntilObserver(s, until, sd, source); + RepeatUntilObserver rs = new RepeatUntilObserver(observer, until, sd, source); rs.subscribeNext(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java index 82cfe538d3..cbf1111400 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java @@ -31,11 +31,11 @@ public ObservableRetryBiPredicate( } @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { SequentialDisposable sa = new SequentialDisposable(); - s.onSubscribe(sa); + observer.onSubscribe(sa); - RetryBiObserver rs = new RetryBiObserver(s, predicate, sa, source); + RetryBiObserver rs = new RetryBiObserver(observer, predicate, sa, source); rs.subscribeNext(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java index 33a52d84a0..9c22024a7e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java @@ -33,11 +33,11 @@ public ObservableRetryPredicate(Observable source, } @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { SequentialDisposable sa = new SequentialDisposable(); - s.onSubscribe(sa); + observer.onSubscribe(sa); - RepeatObserver rs = new RepeatObserver(s, count, predicate, sa, source); + RepeatObserver rs = new RepeatObserver(observer, count, predicate, sa, source); rs.subscribeNext(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableScalarXMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableScalarXMap.java index 418e6514f9..d58437900c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableScalarXMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableScalarXMap.java @@ -136,12 +136,12 @@ static final class ScalarXMapObservable extends Observable { @SuppressWarnings("unchecked") @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { ObservableSource other; try { other = ObjectHelper.requireNonNull(mapper.apply(value), "The mapper returned a null ObservableSource"); } catch (Throwable e) { - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } if (other instanceof Callable) { @@ -151,19 +151,19 @@ public void subscribeActual(Observer s) { u = ((Callable)other).call(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - EmptyDisposable.error(ex, s); + EmptyDisposable.error(ex, observer); return; } if (u == null) { - EmptyDisposable.complete(s); + EmptyDisposable.complete(observer); return; } - ScalarDisposable sd = new ScalarDisposable(s, u); - s.onSubscribe(sd); + ScalarDisposable sd = new ScalarDisposable(observer, u); + observer.onSubscribe(sd); sd.run(); } else { - other.subscribe(s); + other.subscribe(observer); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqual.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqual.java index c2bf67f605..aab9dcab05 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqual.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqual.java @@ -37,9 +37,9 @@ public ObservableSequenceEqual(ObservableSource first, ObservableSo } @Override - public void subscribeActual(Observer s) { - EqualCoordinator ec = new EqualCoordinator(s, bufferSize, first, second, comparer); - s.onSubscribe(ec); + public void subscribeActual(Observer observer) { + EqualCoordinator ec = new EqualCoordinator(observer, bufferSize, first, second, comparer); + observer.onSubscribe(ec); ec.subscribe(); } @@ -117,10 +117,10 @@ void drain() { int missed = 1; EqualObserver[] as = observers; - final EqualObserver s1 = as[0]; - final SpscLinkedArrayQueue q1 = s1.queue; - final EqualObserver s2 = as[1]; - final SpscLinkedArrayQueue q2 = s2.queue; + final EqualObserver observer1 = as[0]; + final SpscLinkedArrayQueue q1 = observer1.queue; + final EqualObserver observer2 = as[1]; + final SpscLinkedArrayQueue q2 = observer2.queue; for (;;) { @@ -131,10 +131,10 @@ void drain() { return; } - boolean d1 = s1.done; + boolean d1 = observer1.done; if (d1) { - Throwable e = s1.error; + Throwable e = observer1.error; if (e != null) { cancel(q1, q2); @@ -143,9 +143,9 @@ void drain() { } } - boolean d2 = s2.done; + boolean d2 = observer2.done; if (d2) { - Throwable e = s2.error; + Throwable e = observer2.error; if (e != null) { cancel(q1, q2); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualSingle.java index 8d227e699d..742b7fb39c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualSingle.java @@ -39,9 +39,9 @@ public ObservableSequenceEqualSingle(ObservableSource first, Observ } @Override - public void subscribeActual(SingleObserver s) { - EqualCoordinator ec = new EqualCoordinator(s, bufferSize, first, second, comparer); - s.onSubscribe(ec); + public void subscribeActual(SingleObserver observer) { + EqualCoordinator ec = new EqualCoordinator(observer, bufferSize, first, second, comparer); + observer.onSubscribe(ec); ec.subscribe(); } @@ -124,10 +124,10 @@ void drain() { int missed = 1; EqualObserver[] as = observers; - final EqualObserver s1 = as[0]; - final SpscLinkedArrayQueue q1 = s1.queue; - final EqualObserver s2 = as[1]; - final SpscLinkedArrayQueue q2 = s2.queue; + final EqualObserver observer1 = as[0]; + final SpscLinkedArrayQueue q1 = observer1.queue; + final EqualObserver observer2 = as[1]; + final SpscLinkedArrayQueue q2 = observer2.queue; for (;;) { @@ -138,10 +138,10 @@ void drain() { return; } - boolean d1 = s1.done; + boolean d1 = observer1.done; if (d1) { - Throwable e = s1.error; + Throwable e = observer1.error; if (e != null) { cancel(q1, q2); @@ -150,9 +150,9 @@ void drain() { } } - boolean d2 = s2.done; + boolean d2 = observer2.done; if (d2) { - Throwable e = s2.error; + Throwable e = observer2.error; if (e != null) { cancel(q1, q2); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkip.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkip.java index 944506365a..570c4e8877 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkip.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkip.java @@ -25,8 +25,8 @@ public ObservableSkip(ObservableSource source, long n) { } @Override - public void subscribeActual(Observer s) { - source.subscribe(new SkipObserver(s, n)); + public void subscribeActual(Observer observer) { + source.subscribe(new SkipObserver(observer, n)); } static final class SkipObserver implements Observer, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java index be257cd9c8..f22df6fdf7 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java @@ -28,8 +28,8 @@ public ObservableSkipLast(ObservableSource source, int skip) { } @Override - public void subscribeActual(Observer s) { - source.subscribe(new SkipLastObserver(s, skip)); + public void subscribeActual(Observer observer) { + source.subscribe(new SkipLastObserver(observer, skip)); } static final class SkipLastObserver extends ArrayDeque implements Observer, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java index a46e27b22e..dfe5fd1d9c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java @@ -27,8 +27,8 @@ public ObservableSkipWhile(ObservableSource source, Predicate pred } @Override - public void subscribeActual(Observer s) { - source.subscribe(new SkipWhileObserver(s, predicate)); + public void subscribeActual(Observer observer) { + source.subscribe(new SkipWhileObserver(observer, predicate)); } static final class SkipWhileObserver implements Observer, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSubscribeOn.java index 57f4666b52..c55a224155 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSubscribeOn.java @@ -28,10 +28,10 @@ public ObservableSubscribeOn(ObservableSource source, Scheduler scheduler) { } @Override - public void subscribeActual(final Observer s) { - final SubscribeOnObserver parent = new SubscribeOnObserver(s); + public void subscribeActual(final Observer observer) { + final SubscribeOnObserver parent = new SubscribeOnObserver(observer); - s.onSubscribe(parent); + observer.onSubscribe(parent); parent.setDisposable(scheduler.scheduleDirect(new SubscribeTask(parent))); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastOne.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastOne.java index e0c765ec98..04ad923c28 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastOne.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastOne.java @@ -23,8 +23,8 @@ public ObservableTakeLastOne(ObservableSource source) { } @Override - public void subscribeActual(Observer s) { - source.subscribe(new TakeLastOneObserver(s)); + public void subscribeActual(Observer observer) { + source.subscribe(new TakeLastOneObserver(observer)); } static final class TakeLastOneObserver implements Observer, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicate.java index 8af48da7e0..43cdaf05bd 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicate.java @@ -28,8 +28,8 @@ public ObservableTakeUntilPredicate(ObservableSource source, Predicate s) { - source.subscribe(new TakeUntilPredicateObserver(s, predicate)); + public void subscribeActual(Observer observer) { + source.subscribe(new TakeUntilPredicateObserver(observer, predicate)); } static final class TakeUntilPredicateObserver implements Observer, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java index 41130d56e2..00dda7ad6b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java @@ -52,8 +52,8 @@ public ObservableThrottleLatest(Observable source, } @Override - protected void subscribeActual(Observer s) { - source.subscribe(new ThrottleLatestObserver(s, timeout, unit, scheduler.createWorker(), emitLast)); + protected void subscribeActual(Observer observer) { + source.subscribe(new ThrottleLatestObserver(observer, timeout, unit, scheduler.createWorker(), emitLast)); } static final class ThrottleLatestObserver diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeout.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeout.java index 5cfcb620ba..eeacf6d555 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeout.java @@ -42,15 +42,15 @@ public ObservableTimeout( } @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { if (other == null) { - TimeoutObserver parent = new TimeoutObserver(s, itemTimeoutIndicator); - s.onSubscribe(parent); + TimeoutObserver parent = new TimeoutObserver(observer, itemTimeoutIndicator); + observer.onSubscribe(parent); parent.startFirstTimeout(firstTimeoutIndicator); source.subscribe(parent); } else { - TimeoutFallbackObserver parent = new TimeoutFallbackObserver(s, itemTimeoutIndicator, other); - s.onSubscribe(parent); + TimeoutFallbackObserver parent = new TimeoutFallbackObserver(observer, itemTimeoutIndicator, other); + observer.onSubscribe(parent); parent.startFirstTimeout(firstTimeoutIndicator); source.subscribe(parent); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java index fdca2d3882..45416b9344 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java @@ -37,15 +37,15 @@ public ObservableTimeoutTimed(Observable source, } @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { if (other == null) { - TimeoutObserver parent = new TimeoutObserver(s, timeout, unit, scheduler.createWorker()); - s.onSubscribe(parent); + TimeoutObserver parent = new TimeoutObserver(observer, timeout, unit, scheduler.createWorker()); + observer.onSubscribe(parent); parent.startTimeout(0L); source.subscribe(parent); } else { - TimeoutFallbackObserver parent = new TimeoutFallbackObserver(s, timeout, unit, scheduler.createWorker(), other); - s.onSubscribe(parent); + TimeoutFallbackObserver parent = new TimeoutFallbackObserver(observer, timeout, unit, scheduler.createWorker(), other); + observer.onSubscribe(parent); parent.startTimeout(0L); source.subscribe(parent); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimer.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimer.java index 1414da06f6..01a6a52743 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimer.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimer.java @@ -31,9 +31,9 @@ public ObservableTimer(long delay, TimeUnit unit, Scheduler scheduler) { } @Override - public void subscribeActual(Observer s) { - TimerObserver ios = new TimerObserver(s); - s.onSubscribe(ios); + public void subscribeActual(Observer observer) { + TimerObserver ios = new TimerObserver(observer); + observer.onSubscribe(ios); Disposable d = scheduler.scheduleDirect(ios, delay, unit); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableUsing.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableUsing.java index e29c3e739e..039da6f67c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableUsing.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableUsing.java @@ -41,14 +41,14 @@ public ObservableUsing(Callable resourceSupplier, } @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { D resource; try { resource = resourceSupplier.call(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } @@ -61,14 +61,14 @@ public void subscribeActual(Observer s) { disposer.accept(resource); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - EmptyDisposable.error(new CompositeException(e, ex), s); + EmptyDisposable.error(new CompositeException(e, ex), observer); return; } - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } - UsingObserver us = new UsingObserver(s, resource, disposer, eager); + UsingObserver us = new UsingObserver(observer, resource, disposer, eager); source.subscribe(us); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromMany.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromMany.java index 1578d0e950..b460ad58b1 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromMany.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromMany.java @@ -59,7 +59,7 @@ public ObservableWithLatestFromMany(@NonNull ObservableSource source, @NonNul } @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { ObservableSource[] others = otherArray; int n = 0; if (others == null) { @@ -74,7 +74,7 @@ protected void subscribeActual(Observer s) { } } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - EmptyDisposable.error(ex, s); + EmptyDisposable.error(ex, observer); return; } @@ -83,12 +83,12 @@ protected void subscribeActual(Observer s) { } if (n == 0) { - new ObservableMap(source, new SingletonArrayFunc()).subscribeActual(s); + new ObservableMap(source, new SingletonArrayFunc()).subscribeActual(observer); return; } - WithLatestFromObserver parent = new WithLatestFromObserver(s, combiner, n); - s.onSubscribe(parent); + WithLatestFromObserver parent = new WithLatestFromObserver(observer, combiner, n); + observer.onSubscribe(parent); parent.subscribe(others, n); source.subscribe(parent); @@ -204,8 +204,8 @@ public boolean isDisposed() { @Override public void dispose() { DisposableHelper.dispose(d); - for (WithLatestInnerObserver s : observers) { - s.dispose(); + for (WithLatestInnerObserver observer : observers) { + observer.dispose(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java index 2227849571..923c1a062d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java @@ -46,7 +46,7 @@ public ObservableZip(ObservableSource[] sources, @Override @SuppressWarnings("unchecked") - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { ObservableSource[] sources = this.sources; int count = 0; if (sources == null) { @@ -64,11 +64,11 @@ public void subscribeActual(Observer s) { } if (count == 0) { - EmptyDisposable.complete(s); + EmptyDisposable.complete(observer); return; } - ZipCoordinator zc = new ZipCoordinator(s, zipper, count, delayError); + ZipCoordinator zc = new ZipCoordinator(observer, zipper, count, delayError); zc.subscribe(sources, bufferSize); } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleAmb.java b/src/main/java/io/reactivex/internal/operators/single/SingleAmb.java index d0acba1234..d7508c3a72 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleAmb.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleAmb.java @@ -32,7 +32,7 @@ public SingleAmb(SingleSource[] sources, Iterable s) { + protected void subscribeActual(final SingleObserver observer) { SingleSource[] sources = this.sources; int count = 0; if (sources == null) { @@ -40,7 +40,7 @@ protected void subscribeActual(final SingleObserver s) { try { for (SingleSource element : sourcesIterable) { if (element == null) { - EmptyDisposable.error(new NullPointerException("One of the sources is null"), s); + EmptyDisposable.error(new NullPointerException("One of the sources is null"), observer); return; } if (count == sources.length) { @@ -52,7 +52,7 @@ protected void subscribeActual(final SingleObserver s) { } } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } } else { @@ -61,8 +61,8 @@ protected void subscribeActual(final SingleObserver s) { final CompositeDisposable set = new CompositeDisposable(); - AmbSingleObserver shared = new AmbSingleObserver(s, set); - s.onSubscribe(set); + AmbSingleObserver shared = new AmbSingleObserver(observer, set); + observer.onSubscribe(set); for (int i = 0; i < count; i++) { SingleSource s1 = sources[i]; @@ -74,7 +74,7 @@ protected void subscribeActual(final SingleObserver s) { set.dispose(); Throwable e = new NullPointerException("One of the sources is null"); if (shared.compareAndSet(false, true)) { - s.onError(e); + observer.onError(e); } else { RxJavaPlugins.onError(e); } @@ -91,10 +91,10 @@ static final class AmbSingleObserver extends AtomicBoolean implements SingleO final CompositeDisposable set; - final SingleObserver s; + final SingleObserver downstream; - AmbSingleObserver(SingleObserver s, CompositeDisposable set) { - this.s = s; + AmbSingleObserver(SingleObserver observer, CompositeDisposable set) { + this.downstream = observer; this.set = set; } @@ -107,7 +107,7 @@ public void onSubscribe(Disposable d) { public void onSuccess(T value) { if (compareAndSet(false, true)) { set.dispose(); - s.onSuccess(value); + downstream.onSuccess(value); } } @@ -115,7 +115,7 @@ public void onSuccess(T value) { public void onError(Throwable e) { if (compareAndSet(false, true)) { set.dispose(); - s.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleCache.java b/src/main/java/io/reactivex/internal/operators/single/SingleCache.java index d658f8cd5a..de237efc84 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleCache.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleCache.java @@ -43,9 +43,9 @@ public SingleCache(SingleSource source) { } @Override - protected void subscribeActual(final SingleObserver s) { - CacheDisposable d = new CacheDisposable(s, this); - s.onSubscribe(d); + protected void subscribeActual(final SingleObserver observer) { + CacheDisposable d = new CacheDisposable(observer, this); + observer.onSubscribe(d); if (add(d)) { if (d.isDisposed()) { @@ -54,9 +54,9 @@ protected void subscribeActual(final SingleObserver s) { } else { Throwable ex = error; if (ex != null) { - s.onError(ex); + observer.onError(ex); } else { - s.onSuccess(value); + observer.onSuccess(value); } return; } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleContains.java b/src/main/java/io/reactivex/internal/operators/single/SingleContains.java index b57d8eefbd..c8fb355f48 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleContains.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleContains.java @@ -33,22 +33,22 @@ public SingleContains(SingleSource source, Object value, BiPredicate s) { + protected void subscribeActual(final SingleObserver observer) { - source.subscribe(new Single(s)); + source.subscribe(new ContainsSingleObserver(observer)); } - final class Single implements SingleObserver { + final class ContainsSingleObserver implements SingleObserver { - private final SingleObserver s; + private final SingleObserver downstream; - Single(SingleObserver s) { - this.s = s; + ContainsSingleObserver(SingleObserver observer) { + this.downstream = observer; } @Override public void onSubscribe(Disposable d) { - s.onSubscribe(d); + downstream.onSubscribe(d); } @Override @@ -59,15 +59,15 @@ public void onSuccess(T v) { b = comparer.test(v, value); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.onError(ex); + downstream.onError(ex); return; } - s.onSuccess(b); + downstream.onSuccess(b); } @Override public void onError(Throwable e) { - s.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleCreate.java b/src/main/java/io/reactivex/internal/operators/single/SingleCreate.java index 8bb129bda2..fd52840f89 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleCreate.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleCreate.java @@ -31,9 +31,9 @@ public SingleCreate(SingleOnSubscribe source) { } @Override - protected void subscribeActual(SingleObserver s) { - Emitter parent = new Emitter(s); - s.onSubscribe(parent); + protected void subscribeActual(SingleObserver observer) { + Emitter parent = new Emitter(observer); + observer.onSubscribe(parent); try { source.subscribe(parent); diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDefer.java b/src/main/java/io/reactivex/internal/operators/single/SingleDefer.java index e3ffe8c0ce..0f7a66dc38 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDefer.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDefer.java @@ -29,18 +29,18 @@ public SingleDefer(Callable> singleSupplier) } @Override - protected void subscribeActual(SingleObserver s) { + protected void subscribeActual(SingleObserver observer) { SingleSource next; try { next = ObjectHelper.requireNonNull(singleSupplier.call(), "The singleSupplier returned a null SingleSource"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - EmptyDisposable.error(e, s); + EmptyDisposable.error(e, observer); return; } - next.subscribe(s); + next.subscribe(observer); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelay.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelay.java index c72ca988f6..3ea0104a50 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelay.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelay.java @@ -36,20 +36,20 @@ public SingleDelay(SingleSource source, long time, TimeUnit unit, S } @Override - protected void subscribeActual(final SingleObserver s) { + protected void subscribeActual(final SingleObserver observer) { final SequentialDisposable sd = new SequentialDisposable(); - s.onSubscribe(sd); - source.subscribe(new Delay(sd, s)); + observer.onSubscribe(sd); + source.subscribe(new Delay(sd, observer)); } final class Delay implements SingleObserver { private final SequentialDisposable sd; - final SingleObserver s; + final SingleObserver downstream; - Delay(SequentialDisposable sd, SingleObserver s) { + Delay(SequentialDisposable sd, SingleObserver observer) { this.sd = sd; - this.s = s; + this.downstream = observer; } @Override @@ -76,7 +76,7 @@ final class OnSuccess implements Runnable { @Override public void run() { - s.onSuccess(value); + downstream.onSuccess(value); } } @@ -89,7 +89,7 @@ final class OnError implements Runnable { @Override public void run() { - s.onError(e); + downstream.onError(e); } } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java index 9f4845f51c..4307f4197c 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java @@ -32,8 +32,8 @@ public SingleDelayWithCompletable(SingleSource source, CompletableSource othe } @Override - protected void subscribeActual(SingleObserver subscriber) { - other.subscribe(new OtherObserver(subscriber, source)); + protected void subscribeActual(SingleObserver observer) { + other.subscribe(new OtherObserver(observer, source)); } static final class OtherObserver diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java index 2e1e8fcbfd..d9ec740604 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java @@ -33,8 +33,8 @@ public SingleDelayWithObservable(SingleSource source, ObservableSource oth } @Override - protected void subscribeActual(SingleObserver subscriber) { - other.subscribe(new OtherSubscriber(subscriber, source)); + protected void subscribeActual(SingleObserver observer) { + other.subscribe(new OtherSubscriber(observer, source)); } static final class OtherSubscriber diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java index 88bd1f8085..0928bab13d 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java @@ -36,8 +36,8 @@ public SingleDelayWithPublisher(SingleSource source, Publisher other) { } @Override - protected void subscribeActual(SingleObserver subscriber) { - other.subscribe(new OtherSubscriber(subscriber, source)); + protected void subscribeActual(SingleObserver observer) { + other.subscribe(new OtherSubscriber(observer, source)); } static final class OtherSubscriber diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java index b42f678878..3adc4f9333 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java @@ -32,8 +32,8 @@ public SingleDelayWithSingle(SingleSource source, SingleSource other) { } @Override - protected void subscribeActual(SingleObserver subscriber) { - other.subscribe(new OtherObserver(subscriber, source)); + protected void subscribeActual(SingleObserver observer) { + other.subscribe(new OtherObserver(observer, source)); } static final class OtherObserver diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java index 570def7896..bf2e557c36 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java @@ -38,8 +38,8 @@ public SingleDoAfterSuccess(SingleSource source, Consumer onAfterS } @Override - protected void subscribeActual(SingleObserver s) { - source.subscribe(new DoAfterObserver(s, onAfterSuccess)); + protected void subscribeActual(SingleObserver observer) { + source.subscribe(new DoAfterObserver(observer, onAfterSuccess)); } static final class DoAfterObserver implements SingleObserver, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java index f9d17de184..269902cdc7 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java @@ -40,8 +40,8 @@ public SingleDoAfterTerminate(SingleSource source, Action onAfterTerminate) { } @Override - protected void subscribeActual(SingleObserver s) { - source.subscribe(new DoAfterTerminateObserver(s, onAfterTerminate)); + protected void subscribeActual(SingleObserver observer) { + source.subscribe(new DoAfterTerminateObserver(observer, onAfterTerminate)); } static final class DoAfterTerminateObserver implements SingleObserver, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java index f575e25b7e..f7e6cc3fee 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java @@ -40,8 +40,8 @@ public SingleDoFinally(SingleSource source, Action onFinally) { } @Override - protected void subscribeActual(SingleObserver s) { - source.subscribe(new DoFinallyObserver(s, onFinally)); + protected void subscribeActual(SingleObserver observer) { + source.subscribe(new DoFinallyObserver(observer, onFinally)); } static final class DoFinallyObserver extends AtomicInteger implements SingleObserver, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnDispose.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnDispose.java index 0f31f2abc2..8515d99887 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnDispose.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnDispose.java @@ -33,9 +33,9 @@ public SingleDoOnDispose(SingleSource source, Action onDispose) { } @Override - protected void subscribeActual(final SingleObserver s) { + protected void subscribeActual(final SingleObserver observer) { - source.subscribe(new DoOnDisposeObserver(s, onDispose)); + source.subscribe(new DoOnDisposeObserver(observer, onDispose)); } static final class DoOnDisposeObserver diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnError.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnError.java index bd7bcd0d68..c20eb7fc41 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnError.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnError.java @@ -30,26 +30,26 @@ public SingleDoOnError(SingleSource source, Consumer onErr } @Override - protected void subscribeActual(final SingleObserver s) { + protected void subscribeActual(final SingleObserver observer) { - source.subscribe(new DoOnError(s)); + source.subscribe(new DoOnError(observer)); } final class DoOnError implements SingleObserver { - private final SingleObserver s; + private final SingleObserver downstream; - DoOnError(SingleObserver s) { - this.s = s; + DoOnError(SingleObserver observer) { + this.downstream = observer; } @Override public void onSubscribe(Disposable d) { - s.onSubscribe(d); + downstream.onSubscribe(d); } @Override public void onSuccess(T value) { - s.onSuccess(value); + downstream.onSuccess(value); } @Override @@ -60,7 +60,7 @@ public void onError(Throwable e) { Exceptions.throwIfFatal(ex); e = new CompositeException(e, ex); } - s.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnEvent.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnEvent.java index c262b51ff6..e057642f18 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnEvent.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnEvent.java @@ -32,21 +32,21 @@ public SingleDoOnEvent(SingleSource source, BiConsumer s) { + protected void subscribeActual(final SingleObserver observer) { - source.subscribe(new DoOnEvent(s)); + source.subscribe(new DoOnEvent(observer)); } final class DoOnEvent implements SingleObserver { - private final SingleObserver s; + private final SingleObserver downstream; - DoOnEvent(SingleObserver s) { - this.s = s; + DoOnEvent(SingleObserver observer) { + this.downstream = observer; } @Override public void onSubscribe(Disposable d) { - s.onSubscribe(d); + downstream.onSubscribe(d); } @Override @@ -55,11 +55,11 @@ public void onSuccess(T value) { onEvent.accept(value, null); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.onError(ex); + downstream.onError(ex); return; } - s.onSuccess(value); + downstream.onSuccess(value); } @Override @@ -70,7 +70,7 @@ public void onError(Throwable e) { Exceptions.throwIfFatal(ex); e = new CompositeException(e, ex); } - s.onError(e); + downstream.onError(e); } } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSubscribe.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSubscribe.java index e421a05492..c46c2d819b 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSubscribe.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSubscribe.java @@ -37,8 +37,8 @@ public SingleDoOnSubscribe(SingleSource source, Consumer } @Override - protected void subscribeActual(final SingleObserver s) { - source.subscribe(new DoOnSubscribeSingleObserver(s, onSubscribe)); + protected void subscribeActual(final SingleObserver observer) { + source.subscribe(new DoOnSubscribeSingleObserver(observer, onSubscribe)); } static final class DoOnSubscribeSingleObserver implements SingleObserver { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSuccess.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSuccess.java index 34ee281777..f915c984cd 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSuccess.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSuccess.java @@ -30,21 +30,22 @@ public SingleDoOnSuccess(SingleSource source, Consumer onSuccess) } @Override - protected void subscribeActual(final SingleObserver s) { + protected void subscribeActual(final SingleObserver observer) { - source.subscribe(new DoOnSuccess(s)); + source.subscribe(new DoOnSuccess(observer)); } final class DoOnSuccess implements SingleObserver { - private final SingleObserver s; - DoOnSuccess(SingleObserver s) { - this.s = s; + final SingleObserver downstream; + + DoOnSuccess(SingleObserver observer) { + this.downstream = observer; } @Override public void onSubscribe(Disposable d) { - s.onSubscribe(d); + downstream.onSubscribe(d); } @Override @@ -53,15 +54,15 @@ public void onSuccess(T value) { onSuccess.accept(value); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.onError(ex); + downstream.onError(ex); return; } - s.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - s.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleEquals.java b/src/main/java/io/reactivex/internal/operators/single/SingleEquals.java index 0ed22f4c1b..83c40b1416 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleEquals.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleEquals.java @@ -31,30 +31,30 @@ public SingleEquals(SingleSource first, SingleSource s } @Override - protected void subscribeActual(final SingleObserver s) { + protected void subscribeActual(final SingleObserver observer) { final AtomicInteger count = new AtomicInteger(); final Object[] values = { null, null }; final CompositeDisposable set = new CompositeDisposable(); - s.onSubscribe(set); + observer.onSubscribe(set); - first.subscribe(new InnerObserver(0, set, values, s, count)); - second.subscribe(new InnerObserver(1, set, values, s, count)); + first.subscribe(new InnerObserver(0, set, values, observer, count)); + second.subscribe(new InnerObserver(1, set, values, observer, count)); } static class InnerObserver implements SingleObserver { final int index; final CompositeDisposable set; final Object[] values; - final SingleObserver s; + final SingleObserver downstream; final AtomicInteger count; - InnerObserver(int index, CompositeDisposable set, Object[] values, SingleObserver s, AtomicInteger count) { + InnerObserver(int index, CompositeDisposable set, Object[] values, SingleObserver observer, AtomicInteger count) { this.index = index; this.set = set; this.values = values; - this.s = s; + this.downstream = observer; this.count = count; } @Override @@ -67,7 +67,7 @@ public void onSuccess(T value) { values[index] = value; if (count.incrementAndGet() == 2) { - s.onSuccess(ObjectHelper.equals(values[0], values[1])); + downstream.onSuccess(ObjectHelper.equals(values[0], values[1])); } } @@ -81,7 +81,7 @@ public void onError(Throwable e) { } if (count.compareAndSet(state, 2)) { set.dispose(); - s.onError(e); + downstream.onError(e); return; } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleError.java b/src/main/java/io/reactivex/internal/operators/single/SingleError.java index 689070291f..6a6e1aef5a 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleError.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleError.java @@ -29,7 +29,7 @@ public SingleError(Callable errorSupplier) { } @Override - protected void subscribeActual(SingleObserver s) { + protected void subscribeActual(SingleObserver observer) { Throwable error; try { @@ -39,7 +39,7 @@ protected void subscribeActual(SingleObserver s) { error = e; } - EmptyDisposable.error(error, s); + EmptyDisposable.error(error, observer); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapCompletable.java index 453d8dfeb7..986a831f94 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapCompletable.java @@ -38,9 +38,9 @@ public SingleFlatMapCompletable(SingleSource source, Function parent = new FlatMapCompletableObserver(s, mapper); - s.onSubscribe(parent); + protected void subscribeActual(CompletableObserver observer) { + FlatMapCompletableObserver parent = new FlatMapCompletableObserver(observer, mapper); + observer.onSubscribe(parent); source.subscribe(parent); } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java index a4d75e5765..541e5063ed 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java @@ -43,8 +43,8 @@ public SingleFlatMapIterableObservable(SingleSource source, } @Override - protected void subscribeActual(Observer s) { - source.subscribe(new FlatMapIterableObserver(s, mapper)); + protected void subscribeActual(Observer observer) { + source.subscribe(new FlatMapIterableObserver(observer, mapper)); } static final class FlatMapIterableObserver diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFromPublisher.java b/src/main/java/io/reactivex/internal/operators/single/SingleFromPublisher.java index ecc69b7e92..9543c494c9 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFromPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFromPublisher.java @@ -31,8 +31,8 @@ public SingleFromPublisher(Publisher publisher) { } @Override - protected void subscribeActual(final SingleObserver s) { - publisher.subscribe(new ToSingleObserver(s)); + protected void subscribeActual(final SingleObserver observer) { + publisher.subscribe(new ToSingleObserver(observer)); } static final class ToSingleObserver implements FlowableSubscriber, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleHide.java b/src/main/java/io/reactivex/internal/operators/single/SingleHide.java index 8415eb76b7..27cf6205b2 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleHide.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleHide.java @@ -26,8 +26,8 @@ public SingleHide(SingleSource source) { } @Override - protected void subscribeActual(SingleObserver subscriber) { - source.subscribe(new HideSingleObserver(subscriber)); + protected void subscribeActual(SingleObserver observer) { + source.subscribe(new HideSingleObserver(observer)); } static final class HideSingleObserver implements SingleObserver, Disposable { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleJust.java b/src/main/java/io/reactivex/internal/operators/single/SingleJust.java index 63a0c7fdaa..5e3dfdcd61 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleJust.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleJust.java @@ -25,9 +25,9 @@ public SingleJust(T value) { } @Override - protected void subscribeActual(SingleObserver s) { - s.onSubscribe(Disposables.disposed()); - s.onSuccess(value); + protected void subscribeActual(SingleObserver observer) { + observer.onSubscribe(Disposables.disposed()); + observer.onSuccess(value); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleLift.java b/src/main/java/io/reactivex/internal/operators/single/SingleLift.java index e618020f44..3d55453b8e 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleLift.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleLift.java @@ -30,14 +30,14 @@ public SingleLift(SingleSource source, SingleOperator } @Override - protected void subscribeActual(SingleObserver s) { + protected void subscribeActual(SingleObserver observer) { SingleObserver sr; try { - sr = ObjectHelper.requireNonNull(onLift.apply(s), "The onLift returned a null SingleObserver"); + sr = ObjectHelper.requireNonNull(onLift.apply(observer), "The onLift returned a null SingleObserver"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - EmptyDisposable.error(ex, s); + EmptyDisposable.error(ex, observer); return; } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleNever.java b/src/main/java/io/reactivex/internal/operators/single/SingleNever.java index 0c01773724..a3c46ebc99 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleNever.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleNever.java @@ -23,8 +23,8 @@ private SingleNever() { } @Override - protected void subscribeActual(SingleObserver s) { - s.onSubscribe(EmptyDisposable.NEVER); + protected void subscribeActual(SingleObserver observer) { + observer.onSubscribe(EmptyDisposable.NEVER); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleObserveOn.java b/src/main/java/io/reactivex/internal/operators/single/SingleObserveOn.java index 6d9f3f3331..494fa2c896 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleObserveOn.java @@ -31,8 +31,8 @@ public SingleObserveOn(SingleSource source, Scheduler scheduler) { } @Override - protected void subscribeActual(final SingleObserver s) { - source.subscribe(new ObserveOnSingleObserver(s, scheduler)); + protected void subscribeActual(final SingleObserver observer) { + source.subscribe(new ObserveOnSingleObserver(observer, scheduler)); } static final class ObserveOnSingleObserver extends AtomicReference diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleOnErrorReturn.java b/src/main/java/io/reactivex/internal/operators/single/SingleOnErrorReturn.java index d7f9c4c715..3f1b0588cf 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleOnErrorReturn.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleOnErrorReturn.java @@ -35,9 +35,9 @@ public SingleOnErrorReturn(SingleSource source, @Override - protected void subscribeActual(final SingleObserver s) { + protected void subscribeActual(final SingleObserver observer) { - source.subscribe(new OnErrorReturn(s)); + source.subscribe(new OnErrorReturn(observer)); } final class OnErrorReturn implements SingleObserver { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleResumeNext.java b/src/main/java/io/reactivex/internal/operators/single/SingleResumeNext.java index 51ab16aca1..42133c05f4 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleResumeNext.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleResumeNext.java @@ -35,8 +35,8 @@ public SingleResumeNext(SingleSource source, } @Override - protected void subscribeActual(final SingleObserver s) { - source.subscribe(new ResumeMainSingleObserver(s, nextFunction)); + protected void subscribeActual(final SingleObserver observer) { + source.subscribe(new ResumeMainSingleObserver(observer, nextFunction)); } static final class ResumeMainSingleObserver extends AtomicReference diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/single/SingleSubscribeOn.java index 8401704a0a..68299fef2c 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleSubscribeOn.java @@ -30,9 +30,9 @@ public SingleSubscribeOn(SingleSource source, Scheduler scheduler) } @Override - protected void subscribeActual(final SingleObserver s) { - final SubscribeOnObserver parent = new SubscribeOnObserver(s, source); - s.onSubscribe(parent); + protected void subscribeActual(final SingleObserver observer) { + final SubscribeOnObserver parent = new SubscribeOnObserver(observer, source); + observer.onSubscribe(parent); Disposable f = scheduler.scheduleDirect(parent); diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java b/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java index 4644f1ce10..575d47732a 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java @@ -43,10 +43,10 @@ public SingleTimeout(SingleSource source, long timeout, TimeUnit unit, Schedu } @Override - protected void subscribeActual(final SingleObserver s) { + protected void subscribeActual(final SingleObserver observer) { - TimeoutMainObserver parent = new TimeoutMainObserver(s, other); - s.onSubscribe(parent); + TimeoutMainObserver parent = new TimeoutMainObserver(observer, other); + observer.onSubscribe(parent); DisposableHelper.replace(parent.task, scheduler.scheduleDirect(parent, timeout, unit)); diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleTimer.java b/src/main/java/io/reactivex/internal/operators/single/SingleTimer.java index 17267aacd2..638a8894c5 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleTimer.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleTimer.java @@ -36,9 +36,9 @@ public SingleTimer(long delay, TimeUnit unit, Scheduler scheduler) { } @Override - protected void subscribeActual(final SingleObserver s) { - TimerDisposable parent = new TimerDisposable(s); - s.onSubscribe(parent); + protected void subscribeActual(final SingleObserver observer) { + TimerDisposable parent = new TimerDisposable(observer); + observer.onSubscribe(parent); parent.setFuture(scheduler.scheduleDirect(parent, delay, unit)); } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java b/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java index 332f910476..56d78e0774 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java @@ -31,8 +31,8 @@ public SingleToObservable(SingleSource source) { } @Override - public void subscribeActual(final Observer s) { - source.subscribe(create(s)); + public void subscribeActual(final Observer observer) { + source.subscribe(create(observer)); } /** diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleUsing.java b/src/main/java/io/reactivex/internal/operators/single/SingleUsing.java index 8ffec7773c..e2f93a9110 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleUsing.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleUsing.java @@ -42,7 +42,7 @@ public SingleUsing(Callable resourceSupplier, } @Override - protected void subscribeActual(final SingleObserver s) { + protected void subscribeActual(final SingleObserver observer) { final U resource; // NOPMD @@ -50,7 +50,7 @@ protected void subscribeActual(final SingleObserver s) { resource = resourceSupplier.call(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - EmptyDisposable.error(ex, s); + EmptyDisposable.error(ex, observer); return; } @@ -69,7 +69,7 @@ protected void subscribeActual(final SingleObserver s) { ex = new CompositeException(ex, exc); } } - EmptyDisposable.error(ex, s); + EmptyDisposable.error(ex, observer); if (!eager) { try { disposer.accept(resource); @@ -81,7 +81,7 @@ protected void subscribeActual(final SingleObserver s) { return; } - source.subscribe(new UsingSingleObserver(s, resource, eager, disposer)); + source.subscribe(new UsingSingleObserver(observer, resource, eager, disposer)); } static final class UsingSingleObserver extends diff --git a/src/main/java/io/reactivex/internal/util/NotificationLite.java b/src/main/java/io/reactivex/internal/util/NotificationLite.java index bebc0c342d..68aeb8492e 100644 --- a/src/main/java/io/reactivex/internal/util/NotificationLite.java +++ b/src/main/java/io/reactivex/internal/util/NotificationLite.java @@ -230,20 +230,20 @@ public static boolean accept(Object o, Subscriber s) { *

Does not check for a subscription notification. * @param the expected value type when unwrapped * @param o the notification object - * @param s the Observer to call methods on + * @param observer the Observer to call methods on * @return true if the notification was a terminal event (i.e., complete or error) */ @SuppressWarnings("unchecked") - public static boolean accept(Object o, Observer s) { + public static boolean accept(Object o, Observer observer) { if (o == COMPLETE) { - s.onComplete(); + observer.onComplete(); return true; } else if (o instanceof ErrorNotification) { - s.onError(((ErrorNotification)o).e); + observer.onError(((ErrorNotification)o).e); return true; } - s.onNext((T)o); + observer.onNext((T)o); return false; } @@ -277,25 +277,25 @@ public static boolean acceptFull(Object o, Subscriber s) { * Calls the appropriate Observer method based on the type of the notification. * @param the expected value type when unwrapped * @param o the notification object - * @param s the subscriber to call methods on + * @param observer the subscriber to call methods on * @return true if the notification was a terminal event (i.e., complete or error) * @see #accept(Object, Observer) */ @SuppressWarnings("unchecked") - public static boolean acceptFull(Object o, Observer s) { + public static boolean acceptFull(Object o, Observer observer) { if (o == COMPLETE) { - s.onComplete(); + observer.onComplete(); return true; } else if (o instanceof ErrorNotification) { - s.onError(((ErrorNotification)o).e); + observer.onError(((ErrorNotification)o).e); return true; } else if (o instanceof DisposableNotification) { - s.onSubscribe(((DisposableNotification)o).d); + observer.onSubscribe(((DisposableNotification)o).d); return false; } - s.onNext((T)o); + observer.onNext((T)o); return false; } diff --git a/src/main/java/io/reactivex/internal/util/QueueDrainHelper.java b/src/main/java/io/reactivex/internal/util/QueueDrainHelper.java index 25126b3327..ade0d5fa82 100644 --- a/src/main/java/io/reactivex/internal/util/QueueDrainHelper.java +++ b/src/main/java/io/reactivex/internal/util/QueueDrainHelper.java @@ -158,7 +158,7 @@ public static void drainLoop(SimplePlainQueue q, Observer a } public static boolean checkTerminated(boolean d, boolean empty, - Observer s, boolean delayError, SimpleQueue q, Disposable disposable, ObservableQueueDrain qd) { + Observer observer, boolean delayError, SimpleQueue q, Disposable disposable, ObservableQueueDrain qd) { if (qd.cancelled()) { q.clear(); disposable.dispose(); @@ -173,9 +173,9 @@ public static boolean checkTerminated(boolean d, boolean empty, } Throwable err = qd.error(); if (err != null) { - s.onError(err); + observer.onError(err); } else { - s.onComplete(); + observer.onComplete(); } return true; } @@ -186,14 +186,14 @@ public static boolean checkTerminated(boolean d, boolean empty, if (disposable != null) { disposable.dispose(); } - s.onError(err); + observer.onError(err); return true; } else if (empty) { if (disposable != null) { disposable.dispose(); } - s.onComplete(); + observer.onComplete(); return true; } } diff --git a/src/main/java/io/reactivex/plugins/RxJavaPlugins.java b/src/main/java/io/reactivex/plugins/RxJavaPlugins.java index 4da3a30122..1d3a810cc5 100644 --- a/src/main/java/io/reactivex/plugins/RxJavaPlugins.java +++ b/src/main/java/io/reactivex/plugins/RxJavaPlugins.java @@ -979,17 +979,17 @@ public static CompletableObserver onSubscribe(@NonNull Completable source, @NonN * Calls the associated hook function. * @param the value type * @param source the hook's input value - * @param subscriber the subscriber + * @param observer the subscriber * @return the value returned by the hook */ @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull - public static MaybeObserver onSubscribe(@NonNull Maybe source, @NonNull MaybeObserver subscriber) { + public static MaybeObserver onSubscribe(@NonNull Maybe source, @NonNull MaybeObserver observer) { BiFunction f = onMaybeSubscribe; if (f != null) { - return apply(f, source, subscriber); + return apply(f, source, observer); } - return subscriber; + return observer; } /** diff --git a/src/main/java/io/reactivex/subjects/AsyncSubject.java b/src/main/java/io/reactivex/subjects/AsyncSubject.java index 2a99ab03ad..335b183e1a 100644 --- a/src/main/java/io/reactivex/subjects/AsyncSubject.java +++ b/src/main/java/io/reactivex/subjects/AsyncSubject.java @@ -215,9 +215,9 @@ public Throwable getThrowable() { } @Override - protected void subscribeActual(Observer s) { - AsyncDisposable as = new AsyncDisposable(s, this); - s.onSubscribe(as); + protected void subscribeActual(Observer observer) { + AsyncDisposable as = new AsyncDisposable(observer, this); + observer.onSubscribe(as); if (add(as)) { if (as.isDisposed()) { remove(as); @@ -225,7 +225,7 @@ protected void subscribeActual(Observer s) { } else { Throwable ex = error; if (ex != null) { - s.onError(ex); + observer.onError(ex); } else { T v = value; if (v != null) { diff --git a/src/test/java/io/reactivex/CheckLocalVariablesInTests.java b/src/test/java/io/reactivex/CheckLocalVariablesInTests.java index 9139738b9f..864dfe4362 100644 --- a/src/test/java/io/reactivex/CheckLocalVariablesInTests.java +++ b/src/test/java/io/reactivex/CheckLocalVariablesInTests.java @@ -188,4 +188,89 @@ public void completableSourceAsMs() throws Exception { public void observableAsC() throws Exception { findPattern("Observable<.*>\\s+c\\b"); } + + @Test + public void subscriberAsObserver() throws Exception { + findPattern("Subscriber<.*>\\s+observer[0-9]?\\b"); + } + + @Test + public void subscriberAsO() throws Exception { + findPattern("Subscriber<.*>\\s+o[0-9]?\\b"); + } + + @Test + public void singleAsObservable() throws Exception { + findPattern("Single<.*>\\s+observable\\b"); + } + + @Test + public void singleAsFlowable() throws Exception { + findPattern("Single<.*>\\s+flowable\\b"); + } + + @Test + public void observerAsSubscriber() throws Exception { + findPattern("Observer<.*>\\s+subscriber[0-9]?\\b"); + } + + @Test + public void observerAsS() throws Exception { + findPattern("Observer<.*>\\s+s[0-9]?\\b"); + } + + @Test + public void observerNoArgAsSubscriber() throws Exception { + findPattern("Observer\\s+subscriber[0-9]?\\b"); + } + + @Test + public void observerNoArgAsS() throws Exception { + findPattern("Observer\\s+s[0-9]?\\b"); + } + + @Test + public void flowableAsObservable() throws Exception { + findPattern("Flowable<.*>\\s+observable[0-9]?\\b"); + } + + @Test + public void flowableAsO() throws Exception { + findPattern("Flowable<.*>\\s+o[0-9]?\\b"); + } + + @Test + public void flowableNoArgAsO() throws Exception { + findPattern("Flowable\\s+o[0-9]?\\b"); + } + + @Test + public void flowableNoArgAsObservable() throws Exception { + findPattern("Flowable\\s+observable[0-9]?\\b"); + } + + @Test + public void processorAsSubject() throws Exception { + findPattern("Processor<.*>\\s+subject(0-9)?\\b"); + } + + @Test + public void maybeAsObservable() throws Exception { + findPattern("Maybe<.*>\\s+observable\\b"); + } + + @Test + public void maybeAsFlowable() throws Exception { + findPattern("Maybe<.*>\\s+flowable\\b"); + } + + @Test + public void completableAsObservable() throws Exception { + findPattern("Completable\\s+observable\\b"); + } + + @Test + public void completableAsFlowable() throws Exception { + findPattern("Completable\\s+flowable\\b"); + } } diff --git a/src/test/java/io/reactivex/ParamValidationCheckerTest.java b/src/test/java/io/reactivex/ParamValidationCheckerTest.java index 6a3a430c12..45c6dcafbf 100644 --- a/src/test/java/io/reactivex/ParamValidationCheckerTest.java +++ b/src/test/java/io/reactivex/ParamValidationCheckerTest.java @@ -1140,7 +1140,7 @@ public String toString() { static final class NeverObservable extends Observable { @Override - public void subscribeActual(Observer s) { + public void subscribeActual(Observer observer) { // not invoked, the class is a placeholder default value } @@ -1153,7 +1153,7 @@ public String toString() { static final class NeverSingle extends Single { @Override - public void subscribeActual(SingleObserver s) { + public void subscribeActual(SingleObserver observer) { // not invoked, the class is a placeholder default value } @@ -1166,7 +1166,7 @@ public String toString() { static final class NeverMaybe extends Maybe { @Override - public void subscribeActual(MaybeObserver s) { + public void subscribeActual(MaybeObserver observer) { // not invoked, the class is a placeholder default value } @@ -1178,7 +1178,7 @@ public String toString() { static final class NeverCompletable extends Completable { @Override - public void subscribeActual(CompletableObserver s) { + public void subscribeActual(CompletableObserver observer) { // not invoked, the class is a placeholder default value } diff --git a/src/test/java/io/reactivex/TestHelper.java b/src/test/java/io/reactivex/TestHelper.java index 6ac1e5cc75..cba835fcbd 100644 --- a/src/test/java/io/reactivex/TestHelper.java +++ b/src/test/java/io/reactivex/TestHelper.java @@ -556,18 +556,18 @@ public static void doubleOnSubscribe(Subscriber subscriber) { /** * Calls onSubscribe twice and checks if it doesn't affect the first Disposable while * reporting it to plugin error handler. - * @param subscriber the target + * @param observer the target */ - public static void doubleOnSubscribe(Observer subscriber) { + public static void doubleOnSubscribe(Observer observer) { List errors = trackPluginErrors(); try { Disposable d1 = Disposables.empty(); - subscriber.onSubscribe(d1); + observer.onSubscribe(d1); Disposable d2 = Disposables.empty(); - subscriber.onSubscribe(d2); + observer.onSubscribe(d2); assertFalse(d1.isDisposed()); @@ -582,18 +582,18 @@ public static void doubleOnSubscribe(Observer subscriber) { /** * Calls onSubscribe twice and checks if it doesn't affect the first Disposable while * reporting it to plugin error handler. - * @param subscriber the target + * @param observer the target */ - public static void doubleOnSubscribe(SingleObserver subscriber) { + public static void doubleOnSubscribe(SingleObserver observer) { List errors = trackPluginErrors(); try { Disposable d1 = Disposables.empty(); - subscriber.onSubscribe(d1); + observer.onSubscribe(d1); Disposable d2 = Disposables.empty(); - subscriber.onSubscribe(d2); + observer.onSubscribe(d2); assertFalse(d1.isDisposed()); @@ -608,18 +608,18 @@ public static void doubleOnSubscribe(SingleObserver subscriber) { /** * Calls onSubscribe twice and checks if it doesn't affect the first Disposable while * reporting it to plugin error handler. - * @param subscriber the target + * @param observer the target */ - public static void doubleOnSubscribe(CompletableObserver subscriber) { + public static void doubleOnSubscribe(CompletableObserver observer) { List errors = trackPluginErrors(); try { Disposable d1 = Disposables.empty(); - subscriber.onSubscribe(d1); + observer.onSubscribe(d1); Disposable d2 = Disposables.empty(); - subscriber.onSubscribe(d2); + observer.onSubscribe(d2); assertFalse(d1.isDisposed()); @@ -634,18 +634,18 @@ public static void doubleOnSubscribe(CompletableObserver subscriber) { /** * Calls onSubscribe twice and checks if it doesn't affect the first Disposable while * reporting it to plugin error handler. - * @param subscriber the target + * @param observer the target */ - public static void doubleOnSubscribe(MaybeObserver subscriber) { + public static void doubleOnSubscribe(MaybeObserver observer) { List errors = trackPluginErrors(); try { Disposable d1 = Disposables.empty(); - subscriber.onSubscribe(d1); + observer.onSubscribe(d1); Disposable d2 = Disposables.empty(); - subscriber.onSubscribe(d2); + observer.onSubscribe(d2); assertFalse(d1.isDisposed()); @@ -1692,15 +1692,15 @@ public static void checkDoubleOnSubscribeFlowableToObservable(Function source = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { try { BooleanSubscription d1 = new BooleanSubscription(); - observer.onSubscribe(d1); + subscriber.onSubscribe(d1); BooleanSubscription d2 = new BooleanSubscription(); - observer.onSubscribe(d2); + subscriber.onSubscribe(d2); b[0] = d1.isCancelled(); b[1] = d2.isCancelled(); @@ -1746,15 +1746,15 @@ public static void checkDoubleOnSubscribeFlowableToSingle(Function source = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { try { BooleanSubscription d1 = new BooleanSubscription(); - observer.onSubscribe(d1); + subscriber.onSubscribe(d1); BooleanSubscription d2 = new BooleanSubscription(); - observer.onSubscribe(d2); + subscriber.onSubscribe(d2); b[0] = d1.isCancelled(); b[1] = d2.isCancelled(); @@ -1800,15 +1800,15 @@ public static void checkDoubleOnSubscribeFlowableToMaybe(Function source = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { try { BooleanSubscription d1 = new BooleanSubscription(); - observer.onSubscribe(d1); + subscriber.onSubscribe(d1); BooleanSubscription d2 = new BooleanSubscription(); - observer.onSubscribe(d2); + subscriber.onSubscribe(d2); b[0] = d1.isCancelled(); b[1] = d2.isCancelled(); @@ -1853,15 +1853,15 @@ public static void checkDoubleOnSubscribeFlowableToCompletable(Function source = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { try { BooleanSubscription d1 = new BooleanSubscription(); - observer.onSubscribe(d1); + subscriber.onSubscribe(d1); BooleanSubscription d2 = new BooleanSubscription(); - observer.onSubscribe(d2); + subscriber.onSubscribe(d2); b[0] = d1.isCancelled(); b[1] = d2.isCancelled(); @@ -2669,24 +2669,24 @@ public static void checkBadSourceFlowable(Function, Object> mapp try { Flowable bad = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); if (goodValue != null) { - observer.onNext(goodValue); + subscriber.onNext(goodValue); } if (error) { - observer.onError(new TestException("error")); + subscriber.onError(new TestException("error")); } else { - observer.onComplete(); + subscriber.onComplete(); } if (badValue != null) { - observer.onNext(badValue); + subscriber.onNext(badValue); } - observer.onError(new TestException("second")); - observer.onComplete(); + subscriber.onError(new TestException("second")); + subscriber.onComplete(); } }; @@ -2879,8 +2879,8 @@ public boolean isDisposed() { public static Flowable rejectFlowableFusion() { return new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new QueueSubscription() { + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new QueueSubscription() { @Override public int requestFusion(int mode) { @@ -3042,8 +3042,8 @@ public Observable apply(Observable upstream) { } @Override - protected void subscribeActual(Observer s) { - source.subscribe(new StripBoundaryObserver(s)); + protected void subscribeActual(Observer observer) { + source.subscribe(new StripBoundaryObserver(observer)); } static final class StripBoundaryObserver implements Observer, QueueDisposable { diff --git a/src/test/java/io/reactivex/completable/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java index a595837f29..5dcfa1b531 100644 --- a/src/test/java/io/reactivex/completable/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -106,9 +106,9 @@ static final class NormalCompletable extends AtomicInteger { public final Completable completable = Completable.unsafeCreate(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { + public void subscribe(CompletableObserver observer) { getAndIncrement(); - EmptyDisposable.complete(s); + EmptyDisposable.complete(observer); } }); @@ -131,9 +131,9 @@ static final class ErrorCompletable extends AtomicInteger { public final Completable completable = Completable.unsafeCreate(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { + public void subscribe(CompletableObserver observer) { getAndIncrement(); - EmptyDisposable.error(new TestException(), s); + EmptyDisposable.error(new TestException(), observer); } }); @@ -379,7 +379,7 @@ public void createNull() { public void createOnSubscribeThrowsNPE() { Completable c = Completable.unsafeCreate(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { throw new NullPointerException(); } + public void subscribe(CompletableObserver observer) { throw new NullPointerException(); } }); c.blockingAwait(); @@ -387,10 +387,11 @@ public void createOnSubscribeThrowsNPE() { @Test(timeout = 5000) public void createOnSubscribeThrowsRuntimeException() { + List errors = TestHelper.trackPluginErrors(); try { Completable c = Completable.unsafeCreate(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { + public void subscribe(CompletableObserver observer) { throw new TestException(); } }); @@ -403,6 +404,10 @@ public void subscribe(CompletableObserver s) { ex.printStackTrace(); Assert.fail("Did not wrap the TestException but it returned: " + ex); } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); } } @@ -1799,27 +1804,34 @@ public void doOnDisposeNull() { @Test(timeout = 5000) public void doOnDisposeThrows() { - Completable c = normal.completable.doOnDispose(new Action() { - @Override - public void run() { throw new TestException(); } - }); + List errors = TestHelper.trackPluginErrors(); + try { + Completable c = normal.completable.doOnDispose(new Action() { + @Override + public void run() { throw new TestException(); } + }); - c.subscribe(new CompletableObserver() { - @Override - public void onSubscribe(Disposable d) { - d.dispose(); - } + c.subscribe(new CompletableObserver() { + @Override + public void onSubscribe(Disposable d) { + d.dispose(); + } - @Override - public void onError(Throwable e) { - // ignored - } + @Override + public void onError(Throwable e) { + // ignored + } - @Override - public void onComplete() { - // ignored - } - }); + @Override + public void onComplete() { + // ignored + } + }); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test(timeout = 5000) @@ -2453,8 +2465,8 @@ public void run() { }).retryWhen(new Function, Publisher>() { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - public Publisher apply(Flowable o) { - return (Publisher)o; + public Publisher apply(Flowable f) { + return (Publisher)f; } }); @@ -2589,13 +2601,20 @@ public void accept(Throwable e) { @Test(timeout = 5000) public void subscribeTwoCallbacksOnErrorThrows() { - error.completable.subscribe(new Action() { - @Override - public void run() { } - }, new Consumer() { - @Override - public void accept(Throwable e) { throw new TestException(); } - }); + List errors = TestHelper.trackPluginErrors(); + try { + error.completable.subscribe(new Action() { + @Override + public void run() { } + }, new Consumer() { + @Override + public void accept(Throwable e) { throw new TestException(); } + }); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test(timeout = 5000) @@ -2636,16 +2655,23 @@ public void run() { @Test(timeout = 5000) public void subscribeActionError() { - final AtomicBoolean run = new AtomicBoolean(); + List errors = TestHelper.trackPluginErrors(); + try { + final AtomicBoolean run = new AtomicBoolean(); - error.completable.subscribe(new Action() { - @Override - public void run() { - run.set(true); - } - }); + error.completable.subscribe(new Action() { + @Override + public void run() { + run.set(true); + } + }); - Assert.assertFalse("Completed", run.get()); + Assert.assertFalse("Completed", run.get()); + + TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test(expected = NullPointerException.class) @@ -2701,9 +2727,9 @@ public void subscribeOnNormal() { Completable c = Completable.unsafeCreate(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { + public void subscribe(CompletableObserver observer) { name.set(Thread.currentThread().getName()); - EmptyDisposable.complete(s); + EmptyDisposable.complete(observer); } }).subscribeOn(Schedulers.computation()); @@ -2718,9 +2744,9 @@ public void subscribeOnError() { Completable c = Completable.unsafeCreate(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { + public void subscribe(CompletableObserver observer) { name.set(Thread.currentThread().getName()); - EmptyDisposable.error(new TestException(), s); + EmptyDisposable.error(new TestException(), observer); } }).subscribeOn(Schedulers.computation()); @@ -3468,6 +3494,12 @@ private static void expectUncaughtTestException(Action action) { Thread.UncaughtExceptionHandler originalHandler = Thread.getDefaultUncaughtExceptionHandler(); CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(handler); + RxJavaPlugins.setErrorHandler(new Consumer() { + @Override + public void accept(Throwable error) throws Exception { + Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), error); + } + }); try { action.run(); assertEquals("Should have received exactly 1 exception", 1, handler.count); @@ -3483,6 +3515,7 @@ private static void expectUncaughtTestException(Action action) { throw ExceptionHelper.wrapOrThrow(ex); } finally { Thread.setDefaultUncaughtExceptionHandler(originalHandler); + RxJavaPlugins.setErrorHandler(null); } } @@ -3576,14 +3609,21 @@ public Completable apply(Integer t) { @Test public void subscribeReportsUnsubscribedOnError() { - PublishSubject stringSubject = PublishSubject.create(); - Completable completable = stringSubject.ignoreElements(); + List errors = TestHelper.trackPluginErrors(); + try { + PublishSubject stringSubject = PublishSubject.create(); + Completable completable = stringSubject.ignoreElements(); - Disposable completableSubscription = completable.subscribe(); + Disposable completableSubscription = completable.subscribe(); - stringSubject.onError(new TestException()); + stringSubject.onError(new TestException()); - assertTrue("Not unsubscribed?", completableSubscription.isDisposed()); + assertTrue("Not unsubscribed?", completableSubscription.isDisposed()); + + TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -3627,18 +3667,25 @@ public void run() { @Test public void subscribeActionReportsUnsubscribedOnError() { - PublishSubject stringSubject = PublishSubject.create(); - Completable completable = stringSubject.ignoreElements(); + List errors = TestHelper.trackPluginErrors(); + try { + PublishSubject stringSubject = PublishSubject.create(); + Completable completable = stringSubject.ignoreElements(); - Disposable completableSubscription = completable.subscribe(new Action() { - @Override - public void run() { - } - }); + Disposable completableSubscription = completable.subscribe(new Action() { + @Override + public void run() { + } + }); - stringSubject.onError(new TestException()); + stringSubject.onError(new TestException()); - assertTrue("Not unsubscribed?", completableSubscription.isDisposed()); + assertTrue("Not unsubscribed?", completableSubscription.isDisposed()); + + TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -3715,9 +3762,9 @@ public void andThenSingleError() { Completable.error(e) .andThen(new Single() { @Override - public void subscribeActual(SingleObserver s) { + public void subscribeActual(SingleObserver observer) { hasRun.set(true); - s.onSuccess("foo"); + observer.onSuccess("foo"); } }) .toFlowable().subscribe(ts); @@ -4192,8 +4239,8 @@ public void testHookSubscribeStart() throws Exception { TestSubscriber ts = new TestSubscriber(); Completable completable = Completable.unsafeCreate(new CompletableSource() { - @Override public void subscribe(CompletableObserver s) { - s.onComplete(); + @Override public void subscribe(CompletableObserver observer) { + observer.onComplete(); } }); completable.toFlowable().subscribe(ts); @@ -4589,18 +4636,25 @@ public void accept(final Throwable throwable) throws Exception { @Test public void doOnEventError() { - final AtomicInteger atomicInteger = new AtomicInteger(0); + List errors = TestHelper.trackPluginErrors(); + try { + final AtomicInteger atomicInteger = new AtomicInteger(0); - Completable.error(new RuntimeException()).doOnEvent(new Consumer() { - @Override - public void accept(final Throwable throwable) throws Exception { - if (throwable != null) { - atomicInteger.incrementAndGet(); + Completable.error(new RuntimeException()).doOnEvent(new Consumer() { + @Override + public void accept(final Throwable throwable) throws Exception { + if (throwable != null) { + atomicInteger.incrementAndGet(); + } } - } - }).subscribe(); + }).subscribe(); - assertEquals(1, atomicInteger.get()); + assertEquals(1, atomicInteger.get()); + + TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); + } finally { + RxJavaPlugins.reset(); + } } diff --git a/src/test/java/io/reactivex/exceptions/ExceptionsTest.java b/src/test/java/io/reactivex/exceptions/ExceptionsTest.java index 88a08e8c70..43b316a7f7 100644 --- a/src/test/java/io/reactivex/exceptions/ExceptionsTest.java +++ b/src/test/java/io/reactivex/exceptions/ExceptionsTest.java @@ -318,13 +318,13 @@ public void onNext(Integer integer) { public void testOnErrorExceptionIsThrownFromSubscribe() { Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s1) { + public void subscribe(Observer observer1) { Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s2) { + public void subscribe(Observer observer2) { throw new IllegalArgumentException("original exception"); } - }).subscribe(s1); + }).subscribe(observer1); } } ).subscribe(new OnErrorFailedSubscriber()); @@ -335,13 +335,13 @@ public void subscribe(Observer s2) { public void testOnErrorExceptionIsThrownFromUnsafeSubscribe() { Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s1) { + public void subscribe(Observer observer1) { Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s2) { + public void subscribe(Observer observer2) { throw new IllegalArgumentException("original exception"); } - }).subscribe(s1); + }).subscribe(observer1); } } ).subscribe(new OnErrorFailedSubscriber()); @@ -365,13 +365,13 @@ public void accept(Integer integer) { public void testOnErrorExceptionIsThrownFromSingleSubscribe() { Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(SingleObserver s1) { + public void subscribe(SingleObserver observer1) { Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(SingleObserver s2) { + public void subscribe(SingleObserver observer2) { throw new IllegalArgumentException("original exception"); } - }).subscribe(s1); + }).subscribe(observer1); } } ).toObservable().subscribe(new OnErrorFailedSubscriber()); @@ -382,10 +382,10 @@ public void subscribe(SingleObserver s2) { public void testOnErrorExceptionIsThrownFromSingleUnsafeSubscribe() { Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(final SingleObserver s1) { + public void subscribe(final SingleObserver observer1) { Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(SingleObserver s2) { + public void subscribe(SingleObserver observer2) { throw new IllegalArgumentException("original exception"); } }).toFlowable().subscribe(new FlowableSubscriber() { @@ -401,12 +401,12 @@ public void onComplete() { @Override public void onError(Throwable e) { - s1.onError(e); + observer1.onError(e); } @Override public void onNext(Integer v) { - s1.onSuccess(v); + observer1.onSuccess(v); } }); diff --git a/src/test/java/io/reactivex/flowable/FlowableCollectTest.java b/src/test/java/io/reactivex/flowable/FlowableCollectTest.java index ee88dfac53..09bb562d2b 100644 --- a/src/test/java/io/reactivex/flowable/FlowableCollectTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableCollectTest.java @@ -31,7 +31,7 @@ public final class FlowableCollectTest { @Test public void testCollectToListFlowable() { - Flowable> o = Flowable.just(1, 2, 3) + Flowable> f = Flowable.just(1, 2, 3) .collect(new Callable>() { @Override public List call() { @@ -44,7 +44,7 @@ public void accept(List list, Integer v) { } }).toFlowable(); - List list = o.blockingLast(); + List list = f.blockingLast(); assertEquals(3, list.size()); assertEquals(1, list.get(0).intValue()); @@ -52,7 +52,7 @@ public void accept(List list, Integer v) { assertEquals(3, list.get(2).intValue()); // test multiple subscribe - List list2 = o.blockingLast(); + List list2 = f.blockingLast(); assertEquals(3, list2.size()); assertEquals(1, list2.get(0).intValue()); diff --git a/src/test/java/io/reactivex/flowable/FlowableConcatTests.java b/src/test/java/io/reactivex/flowable/FlowableConcatTests.java index 4a689fe5df..3270204055 100644 --- a/src/test/java/io/reactivex/flowable/FlowableConcatTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableConcatTests.java @@ -26,10 +26,10 @@ public class FlowableConcatTests { @Test public void testConcatSimple() { - Flowable o1 = Flowable.just("one", "two"); - Flowable o2 = Flowable.just("three", "four"); + Flowable f1 = Flowable.just("one", "two"); + Flowable f2 = Flowable.just("three", "four"); - List values = Flowable.concat(o1, o2).toList().blockingGet(); + List values = Flowable.concat(f1, f2).toList().blockingGet(); assertEquals("one", values.get(0)); assertEquals("two", values.get(1)); @@ -39,11 +39,11 @@ public void testConcatSimple() { @Test public void testConcatWithFlowableOfFlowable() { - Flowable o1 = Flowable.just("one", "two"); - Flowable o2 = Flowable.just("three", "four"); - Flowable o3 = Flowable.just("five", "six"); + Flowable f1 = Flowable.just("one", "two"); + Flowable f2 = Flowable.just("three", "four"); + Flowable f3 = Flowable.just("five", "six"); - Flowable> os = Flowable.just(o1, o2, o3); + Flowable> os = Flowable.just(f1, f2, f3); List values = Flowable.concat(os).toList().blockingGet(); @@ -57,12 +57,12 @@ public void testConcatWithFlowableOfFlowable() { @Test public void testConcatWithIterableOfFlowable() { - Flowable o1 = Flowable.just("one", "two"); - Flowable o2 = Flowable.just("three", "four"); - Flowable o3 = Flowable.just("five", "six"); + Flowable f1 = Flowable.just("one", "two"); + Flowable f2 = Flowable.just("three", "four"); + Flowable f3 = Flowable.just("five", "six"); @SuppressWarnings("unchecked") - Iterable> is = Arrays.asList(o1, o2, o3); + Iterable> is = Arrays.asList(f1, f2, f3); List values = Flowable.concat(Flowable.fromIterable(is)).toList().blockingGet(); @@ -81,10 +81,10 @@ public void testConcatCovariance() { Media media = new Media(); HorrorMovie horrorMovie2 = new HorrorMovie(); - Flowable o1 = Flowable. just(horrorMovie1, movie); - Flowable o2 = Flowable.just(media, horrorMovie2); + Flowable f1 = Flowable. just(horrorMovie1, movie); + Flowable f2 = Flowable.just(media, horrorMovie2); - Flowable> os = Flowable.just(o1, o2); + Flowable> os = Flowable.just(f1, f2); List values = Flowable.concat(os).toList().blockingGet(); @@ -103,10 +103,10 @@ public void testConcatCovariance2() { Media media2 = new Media(); HorrorMovie horrorMovie2 = new HorrorMovie(); - Flowable o1 = Flowable.just(horrorMovie1, movie, media1); - Flowable o2 = Flowable.just(media2, horrorMovie2); + Flowable f1 = Flowable.just(horrorMovie1, movie, media1); + Flowable f2 = Flowable.just(media2, horrorMovie2); - Flowable> os = Flowable.just(o1, o2); + Flowable> os = Flowable.just(f1, f2); List values = Flowable.concat(os).toList().blockingGet(); @@ -125,10 +125,10 @@ public void testConcatCovariance3() { Media media = new Media(); HorrorMovie horrorMovie2 = new HorrorMovie(); - Flowable o1 = Flowable.just(horrorMovie1, movie); - Flowable o2 = Flowable.just(media, horrorMovie2); + Flowable f1 = Flowable.just(horrorMovie1, movie); + Flowable f2 = Flowable.just(media, horrorMovie2); - List values = Flowable.concat(o1, o2).toList().blockingGet(); + List values = Flowable.concat(f1, f2).toList().blockingGet(); assertEquals(horrorMovie1, values.get(0)); assertEquals(movie, values.get(1)); @@ -144,19 +144,19 @@ public void testConcatCovariance4() { Media media = new Media(); HorrorMovie horrorMovie2 = new HorrorMovie(); - Flowable o1 = Flowable.unsafeCreate(new Publisher() { + Flowable f1 = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber o) { - o.onNext(horrorMovie1); - o.onNext(movie); + public void subscribe(Subscriber subscriber) { + subscriber.onNext(horrorMovie1); + subscriber.onNext(movie); // o.onNext(new Media()); // correctly doesn't compile - o.onComplete(); + subscriber.onComplete(); } }); - Flowable o2 = Flowable.just(media, horrorMovie2); + Flowable f2 = Flowable.just(media, horrorMovie2); - List values = Flowable.concat(o1, o2).toList().blockingGet(); + List values = Flowable.concat(f1, f2).toList().blockingGet(); assertEquals(horrorMovie1, values.get(0)); assertEquals(movie, values.get(1)); diff --git a/src/test/java/io/reactivex/flowable/FlowableConversionTest.java b/src/test/java/io/reactivex/flowable/FlowableConversionTest.java index 946a3b4742..a7d908111a 100644 --- a/src/test/java/io/reactivex/flowable/FlowableConversionTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableConversionTest.java @@ -115,16 +115,16 @@ public RobotConversionFunc(FlowableOperator operator) { public CylonDetectorObservable apply(final Publisher onSubscribe) { return CylonDetectorObservable.create(new Publisher() { @Override - public void subscribe(Subscriber o) { + public void subscribe(Subscriber subscriber) { try { - Subscriber st = operator.apply(o); + Subscriber st = operator.apply(subscriber); try { onSubscribe.subscribe(st); } catch (Throwable e) { st.onError(e); } } catch (Throwable e) { - o.onError(e); + subscriber.onError(e); } }}); @@ -147,7 +147,7 @@ public Flowable apply(final Publisher onSubscribe) { @Test public void testConversionBetweenObservableClasses() { - final TestObserver subscriber = new TestObserver(new DefaultObserver() { + final TestObserver to = new TestObserver(new DefaultObserver() { @Override public void onComplete() { @@ -196,10 +196,10 @@ public String apply(String a, String n) { return a + n + "\n"; } }) - .subscribe(subscriber); + .subscribe(to); - subscriber.assertNoErrors(); - subscriber.assertComplete(); + to.assertNoErrors(); + to.assertComplete(); } @Test diff --git a/src/test/java/io/reactivex/flowable/FlowableCovarianceTest.java b/src/test/java/io/reactivex/flowable/FlowableCovarianceTest.java index 80e1785eff..812b747750 100644 --- a/src/test/java/io/reactivex/flowable/FlowableCovarianceTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableCovarianceTest.java @@ -56,12 +56,12 @@ public int compare(Media t1, Media t2) { }; // this one would work without the covariance generics - Flowable o = Flowable.just(new Movie(), new TVSeason(), new Album()); - o.toSortedList(sortFunction); + Flowable f = Flowable.just(new Movie(), new TVSeason(), new Album()); + f.toSortedList(sortFunction); // this one would NOT work without the covariance generics - Flowable o2 = Flowable.just(new Movie(), new ActionMovie(), new HorrorMovie()); - o2.toSortedList(sortFunction); + Flowable f2 = Flowable.just(new Movie(), new ActionMovie(), new HorrorMovie()); + f2.toSortedList(sortFunction); } @Test diff --git a/src/test/java/io/reactivex/flowable/FlowableErrorHandlingTests.java b/src/test/java/io/reactivex/flowable/FlowableErrorHandlingTests.java index 91baaf1b9c..e86aa39266 100644 --- a/src/test/java/io/reactivex/flowable/FlowableErrorHandlingTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableErrorHandlingTests.java @@ -35,8 +35,8 @@ public class FlowableErrorHandlingTests { public void testOnNextError() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference caughtError = new AtomicReference(); - Flowable o = Flowable.interval(50, TimeUnit.MILLISECONDS); - Subscriber observer = new DefaultSubscriber() { + Flowable f = Flowable.interval(50, TimeUnit.MILLISECONDS); + Subscriber subscriber = new DefaultSubscriber() { @Override public void onComplete() { @@ -56,7 +56,7 @@ public void onNext(Long args) { throw new RuntimeException("forced failure"); } }; - o.safeSubscribe(observer); + f.safeSubscribe(subscriber); latch.await(2000, TimeUnit.MILLISECONDS); assertNotNull(caughtError.get()); @@ -71,8 +71,8 @@ public void onNext(Long args) { public void testOnNextErrorAcrossThread() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference caughtError = new AtomicReference(); - Flowable o = Flowable.interval(50, TimeUnit.MILLISECONDS); - Subscriber observer = new DefaultSubscriber() { + Flowable f = Flowable.interval(50, TimeUnit.MILLISECONDS); + Subscriber subscriber = new DefaultSubscriber() { @Override public void onComplete() { @@ -92,8 +92,8 @@ public void onNext(Long args) { throw new RuntimeException("forced failure"); } }; - o.observeOn(Schedulers.newThread()) - .safeSubscribe(observer); + f.observeOn(Schedulers.newThread()) + .safeSubscribe(subscriber); latch.await(2000, TimeUnit.MILLISECONDS); assertNotNull(caughtError.get()); diff --git a/src/test/java/io/reactivex/flowable/FlowableMergeTests.java b/src/test/java/io/reactivex/flowable/FlowableMergeTests.java index 46a0278bec..5c96bcf096 100644 --- a/src/test/java/io/reactivex/flowable/FlowableMergeTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableMergeTests.java @@ -38,10 +38,10 @@ public void testCovarianceOfMerge() { @Test public void testMergeCovariance() { - Flowable o1 = Flowable. just(new HorrorMovie(), new Movie()); - Flowable o2 = Flowable.just(new Media(), new HorrorMovie()); + Flowable f1 = Flowable. just(new HorrorMovie(), new Movie()); + Flowable f2 = Flowable.just(new Media(), new HorrorMovie()); - Flowable> os = Flowable.just(o1, o2); + Flowable> os = Flowable.just(f1, f2); List values = Flowable.merge(os).toList().blockingGet(); @@ -50,10 +50,10 @@ public void testMergeCovariance() { @Test public void testMergeCovariance2() { - Flowable o1 = Flowable.just(new HorrorMovie(), new Movie(), new Media()); - Flowable o2 = Flowable.just(new Media(), new HorrorMovie()); + Flowable f1 = Flowable.just(new HorrorMovie(), new Movie(), new Media()); + Flowable f2 = Flowable.just(new Media(), new HorrorMovie()); - Flowable> os = Flowable.just(o1, o2); + Flowable> os = Flowable.just(f1, f2); List values = Flowable.merge(os).toList().blockingGet(); @@ -62,10 +62,10 @@ public void testMergeCovariance2() { @Test public void testMergeCovariance3() { - Flowable o1 = Flowable.just(new HorrorMovie(), new Movie()); - Flowable o2 = Flowable.just(new Media(), new HorrorMovie()); + Flowable f1 = Flowable.just(new HorrorMovie(), new Movie()); + Flowable f2 = Flowable.just(new Media(), new HorrorMovie()); - List values = Flowable.merge(o1, o2).toList().blockingGet(); + List values = Flowable.merge(f1, f2).toList().blockingGet(); assertTrue(values.get(0) instanceof HorrorMovie); assertTrue(values.get(1) instanceof Movie); @@ -76,7 +76,7 @@ public void testMergeCovariance3() { @Test public void testMergeCovariance4() { - Flowable o1 = Flowable.defer(new Callable>() { + Flowable f1 = Flowable.defer(new Callable>() { @Override public Publisher call() { return Flowable.just( @@ -86,9 +86,9 @@ public Publisher call() { } }); - Flowable o2 = Flowable.just(new Media(), new HorrorMovie()); + Flowable f2 = Flowable.just(new Media(), new HorrorMovie()); - List values = Flowable.merge(o1, o2).toList().blockingGet(); + List values = Flowable.merge(f1, f2).toList().blockingGet(); assertTrue(values.get(0) instanceof HorrorMovie); assertTrue(values.get(1) instanceof Movie); diff --git a/src/test/java/io/reactivex/flowable/FlowableNullTests.java b/src/test/java/io/reactivex/flowable/FlowableNullTests.java index b5e5301d91..12c7a9b5c1 100644 --- a/src/test/java/io/reactivex/flowable/FlowableNullTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableNullTests.java @@ -1805,7 +1805,7 @@ public void replaySelectorNull() { public void replaySelectorReturnsNull() { just1.replay(new Function, Publisher>() { @Override - public Publisher apply(Flowable o) { + public Publisher apply(Flowable f) { return null; } }).blockingSubscribe(); @@ -2738,72 +2738,72 @@ public Object apply(Integer a, Integer b) { @Test(expected = NullPointerException.class) public void asyncSubjectOnNextNull() { - FlowableProcessor subject = AsyncProcessor.create(); - subject.onNext(null); - subject.blockingSubscribe(); + FlowableProcessor processor = AsyncProcessor.create(); + processor.onNext(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) public void asyncSubjectOnErrorNull() { - FlowableProcessor subject = AsyncProcessor.create(); - subject.onError(null); - subject.blockingSubscribe(); + FlowableProcessor processor = AsyncProcessor.create(); + processor.onError(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) public void behaviorSubjectOnNextNull() { - FlowableProcessor subject = BehaviorProcessor.create(); - subject.onNext(null); - subject.blockingSubscribe(); + FlowableProcessor processor = BehaviorProcessor.create(); + processor.onNext(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) public void behaviorSubjectOnErrorNull() { - FlowableProcessor subject = BehaviorProcessor.create(); - subject.onError(null); - subject.blockingSubscribe(); + FlowableProcessor processor = BehaviorProcessor.create(); + processor.onError(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) public void publishSubjectOnNextNull() { - FlowableProcessor subject = PublishProcessor.create(); - subject.onNext(null); - subject.blockingSubscribe(); + FlowableProcessor processor = PublishProcessor.create(); + processor.onNext(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) public void publishSubjectOnErrorNull() { - FlowableProcessor subject = PublishProcessor.create(); - subject.onError(null); - subject.blockingSubscribe(); + FlowableProcessor processor = PublishProcessor.create(); + processor.onError(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) public void replaycSubjectOnNextNull() { - FlowableProcessor subject = ReplayProcessor.create(); - subject.onNext(null); - subject.blockingSubscribe(); + FlowableProcessor processor = ReplayProcessor.create(); + processor.onNext(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) public void replaySubjectOnErrorNull() { - FlowableProcessor subject = ReplayProcessor.create(); - subject.onError(null); - subject.blockingSubscribe(); + FlowableProcessor processor = ReplayProcessor.create(); + processor.onError(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) public void serializedcSubjectOnNextNull() { - FlowableProcessor subject = PublishProcessor.create().toSerialized(); - subject.onNext(null); - subject.blockingSubscribe(); + FlowableProcessor processor = PublishProcessor.create().toSerialized(); + processor.onNext(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) public void serializedSubjectOnErrorNull() { - FlowableProcessor subject = PublishProcessor.create().toSerialized(); - subject.onError(null); - subject.blockingSubscribe(); + FlowableProcessor processor = PublishProcessor.create().toSerialized(); + processor.onError(null); + processor.blockingSubscribe(); } @Test(expected = NullPointerException.class) diff --git a/src/test/java/io/reactivex/flowable/FlowableReduceTests.java b/src/test/java/io/reactivex/flowable/FlowableReduceTests.java index b21821e746..e98c56f0f5 100644 --- a/src/test/java/io/reactivex/flowable/FlowableReduceTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableReduceTests.java @@ -25,8 +25,8 @@ public class FlowableReduceTests { @Test public void reduceIntsFlowable() { - Flowable o = Flowable.just(1, 2, 3); - int value = o.reduce(new BiFunction() { + Flowable f = Flowable.just(1, 2, 3); + int value = f.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; @@ -80,8 +80,8 @@ public Movie apply(Movie t1, Movie t2) { @Test public void reduceInts() { - Flowable o = Flowable.just(1, 2, 3); - int value = o.reduce(new BiFunction() { + Flowable f = Flowable.just(1, 2, 3); + int value = f.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; diff --git a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java index c944d63092..b01c2886ac 100644 --- a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java @@ -602,33 +602,40 @@ public boolean test(Integer v) throws Exception { @Test public void suppressAfterCompleteEvents() { - final TestSubscriber ts = new TestSubscriber(); - ts.onSubscribe(new BooleanSubscription()); + List errors = TestHelper.trackPluginErrors(); + try { + final TestSubscriber ts = new TestSubscriber(); + ts.onSubscribe(new BooleanSubscription()); + + ForEachWhileSubscriber s = new ForEachWhileSubscriber(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + ts.onNext(v); + return true; + } + }, new Consumer() { + @Override + public void accept(Throwable e) throws Exception { + ts.onError(e); + } + }, new Action() { + @Override + public void run() throws Exception { + ts.onComplete(); + } + }); - ForEachWhileSubscriber s = new ForEachWhileSubscriber(new Predicate() { - @Override - public boolean test(Integer v) throws Exception { - ts.onNext(v); - return true; - } - }, new Consumer() { - @Override - public void accept(Throwable e) throws Exception { - ts.onError(e); - } - }, new Action() { - @Override - public void run() throws Exception { - ts.onComplete(); - } - }); + s.onComplete(); + s.onNext(1); + s.onError(new TestException()); + s.onComplete(); - s.onComplete(); - s.onNext(1); - s.onError(new TestException()); - s.onComplete(); + ts.assertResult(); - ts.assertResult(); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/flowable/FlowableTests.java b/src/test/java/io/reactivex/flowable/FlowableTests.java index 84c86a8504..8f45ce3689 100644 --- a/src/test/java/io/reactivex/flowable/FlowableTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableTests.java @@ -27,10 +27,11 @@ import io.reactivex.*; import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.TestException; +import io.reactivex.exceptions.*; import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; @@ -97,24 +98,24 @@ public void fromArityArgs1() { @Test public void testCreate() { - Flowable observable = Flowable.just("one", "two", "three"); + Flowable flowable = Flowable.just("one", "two", "three"); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testCountAFewItemsFlowable() { - Flowable observable = Flowable.just("a", "b", "c", "d"); + Flowable flowable = Flowable.just("a", "b", "c", "d"); - observable.count().toFlowable().subscribe(w); + flowable.count().toFlowable().subscribe(w); // we should be called only once verify(w).onNext(4L); @@ -124,8 +125,8 @@ public void testCountAFewItemsFlowable() { @Test public void testCountZeroItemsFlowable() { - Flowable observable = Flowable.empty(); - observable.count().toFlowable().subscribe(w); + Flowable flowable = Flowable.empty(); + flowable.count().toFlowable().subscribe(w); // we should be called only once verify(w).onNext(0L); verify(w, never()).onError(any(Throwable.class)); @@ -134,14 +135,14 @@ public void testCountZeroItemsFlowable() { @Test public void testCountErrorFlowable() { - Flowable o = Flowable.error(new Callable() { + Flowable f = Flowable.error(new Callable() { @Override public Throwable call() { return new RuntimeException(); } }); - o.count().toFlowable().subscribe(w); + f.count().toFlowable().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onComplete(); verify(w, times(1)).onError(any(RuntimeException.class)); @@ -150,9 +151,9 @@ public Throwable call() { @Test public void testCountAFewItems() { - Flowable observable = Flowable.just("a", "b", "c", "d"); + Flowable flowable = Flowable.just("a", "b", "c", "d"); - observable.count().subscribe(wo); + flowable.count().subscribe(wo); // we should be called only once verify(wo).onSuccess(4L); @@ -161,8 +162,8 @@ public void testCountAFewItems() { @Test public void testCountZeroItems() { - Flowable observable = Flowable.empty(); - observable.count().subscribe(wo); + Flowable flowable = Flowable.empty(); + flowable.count().subscribe(wo); // we should be called only once verify(wo).onSuccess(0L); verify(wo, never()).onError(any(Throwable.class)); @@ -170,22 +171,22 @@ public void testCountZeroItems() { @Test public void testCountError() { - Flowable o = Flowable.error(new Callable() { + Flowable f = Flowable.error(new Callable() { @Override public Throwable call() { return new RuntimeException(); } }); - o.count().subscribe(wo); + f.count().subscribe(wo); verify(wo, never()).onSuccess(anyInt()); verify(wo, times(1)).onError(any(RuntimeException.class)); } @Test public void testTakeFirstWithPredicateOfSome() { - Flowable observable = Flowable.just(1, 3, 5, 4, 6, 3); - observable.filter(IS_EVEN).take(1).subscribe(w); + Flowable flowable = Flowable.just(1, 3, 5, 4, 6, 3); + flowable.filter(IS_EVEN).take(1).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(4); verify(w, times(1)).onComplete(); @@ -194,8 +195,8 @@ public void testTakeFirstWithPredicateOfSome() { @Test public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() { - Flowable observable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); - observable.filter(IS_EVEN).take(1).subscribe(w); + Flowable flowable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); + flowable.filter(IS_EVEN).take(1).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, times(1)).onComplete(); verify(w, never()).onError(any(Throwable.class)); @@ -203,8 +204,8 @@ public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() { @Test public void testTakeFirstOfSome() { - Flowable observable = Flowable.just(1, 2, 3); - observable.take(1).subscribe(w); + Flowable flowable = Flowable.just(1, 2, 3); + flowable.take(1).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(1); verify(w, times(1)).onComplete(); @@ -213,8 +214,8 @@ public void testTakeFirstOfSome() { @Test public void testTakeFirstOfNone() { - Flowable observable = Flowable.empty(); - observable.take(1).subscribe(w); + Flowable flowable = Flowable.empty(); + flowable.take(1).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, times(1)).onComplete(); verify(w, never()).onError(any(Throwable.class)); @@ -222,8 +223,8 @@ public void testTakeFirstOfNone() { @Test public void testFirstOfNoneFlowable() { - Flowable observable = Flowable.empty(); - observable.firstElement().toFlowable().subscribe(w); + Flowable flowable = Flowable.empty(); + flowable.firstElement().toFlowable().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w).onComplete(); verify(w, never()).onError(any(Throwable.class)); @@ -231,8 +232,8 @@ public void testFirstOfNoneFlowable() { @Test public void testFirstWithPredicateOfNoneMatchingThePredicateFlowable() { - Flowable observable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); - observable.filter(IS_EVEN).firstElement().toFlowable().subscribe(w); + Flowable flowable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); + flowable.filter(IS_EVEN).firstElement().toFlowable().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w).onComplete(); verify(w, never()).onError(any(Throwable.class)); @@ -240,8 +241,8 @@ public void testFirstWithPredicateOfNoneMatchingThePredicateFlowable() { @Test public void testFirstOfNone() { - Flowable observable = Flowable.empty(); - observable.firstElement().subscribe(wm); + Flowable flowable = Flowable.empty(); + flowable.firstElement().subscribe(wm); verify(wm, never()).onSuccess(anyInt()); verify(wm).onComplete(); verify(wm, never()).onError(isA(NoSuchElementException.class)); @@ -249,8 +250,8 @@ public void testFirstOfNone() { @Test public void testFirstWithPredicateOfNoneMatchingThePredicate() { - Flowable observable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); - observable.filter(IS_EVEN).firstElement().subscribe(wm); + Flowable flowable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); + flowable.filter(IS_EVEN).firstElement().subscribe(wm); verify(wm, never()).onSuccess(anyInt()); verify(wm, times(1)).onComplete(); verify(wm, never()).onError(isA(NoSuchElementException.class)); @@ -258,8 +259,8 @@ public void testFirstWithPredicateOfNoneMatchingThePredicate() { @Test public void testReduce() { - Flowable observable = Flowable.just(1, 2, 3, 4); - observable.reduce(new BiFunction() { + Flowable flowable = Flowable.just(1, 2, 3, 4); + flowable.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; @@ -274,8 +275,8 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testReduceWithEmptyObservable() { - Flowable observable = Flowable.range(1, 0); - observable.reduce(new BiFunction() { + Flowable flowable = Flowable.range(1, 0); + flowable.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; @@ -293,8 +294,8 @@ public Integer apply(Integer t1, Integer t2) { */ @Test public void testReduceWithEmptyObservableAndSeed() { - Flowable observable = Flowable.range(1, 0); - int value = observable.reduce(1, new BiFunction() { + Flowable flowable = Flowable.range(1, 0); + int value = flowable.reduce(1, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; @@ -307,8 +308,8 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testReduceWithInitialValue() { - Flowable observable = Flowable.just(1, 2, 3, 4); - observable.reduce(50, new BiFunction() { + Flowable flowable = Flowable.just(1, 2, 3, 4); + flowable.reduce(50, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; @@ -323,18 +324,19 @@ public Integer apply(Integer t1, Integer t2) { @Ignore("Throwing is not allowed from the unsafeCreate?!") @Test // FIXME throwing is not allowed from the create?! public void testOnSubscribeFails() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final RuntimeException re = new RuntimeException("bad impl"); - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override public void subscribe(Subscriber s) { throw re; } }); - o.subscribe(observer); - verify(observer, times(0)).onNext(anyString()); - verify(observer, times(0)).onComplete(); - verify(observer, times(1)).onError(re); + f.subscribe(subscriber); + + verify(subscriber, times(0)).onNext(anyString()); + verify(subscriber, times(0)).onComplete(); + verify(subscriber, times(1)).onError(re); } @Test @@ -342,13 +344,13 @@ public void testMaterializeDematerializeChaining() { Flowable obs = Flowable.just(1); Flowable chained = obs.materialize().dematerialize(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - chained.subscribe(observer); + chained.subscribe(subscriber); - verify(observer, times(1)).onNext(1); - verify(observer, times(1)).onComplete(); - verify(observer, times(0)).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(0)).onError(any(Throwable.class)); } /** @@ -494,15 +496,15 @@ public void testPublishLast() throws InterruptedException { final AtomicInteger count = new AtomicInteger(); ConnectableFlowable connectable = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); count.incrementAndGet(); new Thread(new Runnable() { @Override public void run() { - observer.onNext("first"); - observer.onNext("last"); - observer.onComplete(); + subscriber.onNext("first"); + subscriber.onNext("last"); + subscriber.onComplete(); } }).start(); } @@ -530,31 +532,31 @@ public void accept(String value) { @Test public void testReplay() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - ConnectableFlowable o = Flowable.unsafeCreate(new Publisher() { + ConnectableFlowable f = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); new Thread(new Runnable() { @Override public void run() { counter.incrementAndGet(); - observer.onNext("one"); - observer.onComplete(); + subscriber.onNext("one"); + subscriber.onComplete(); } }).start(); } }).replay(); // we connect immediately and it will emit the value - Disposable s = o.connect(); + Disposable s = f.connect(); try { // we then expect the following 2 subscriptions to get that same value final CountDownLatch latch = new CountDownLatch(2); // subscribe once - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { assertEquals("one", v); @@ -563,7 +565,7 @@ public void accept(String v) { }); // subscribe again - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { assertEquals("one", v); @@ -583,16 +585,16 @@ public void accept(String v) { @Test public void testCache() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); new Thread(new Runnable() { @Override public void run() { counter.incrementAndGet(); - observer.onNext("one"); - observer.onComplete(); + subscriber.onNext("one"); + subscriber.onComplete(); } }).start(); } @@ -602,7 +604,7 @@ public void run() { final CountDownLatch latch = new CountDownLatch(2); // subscribe once - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { assertEquals("one", v); @@ -611,7 +613,7 @@ public void accept(String v) { }); // subscribe again - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { assertEquals("one", v); @@ -628,16 +630,16 @@ public void accept(String v) { @Test public void testCacheWithCapacity() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); new Thread(new Runnable() { @Override public void run() { counter.incrementAndGet(); - observer.onNext("one"); - observer.onComplete(); + subscriber.onNext("one"); + subscriber.onComplete(); } }).start(); } @@ -647,7 +649,7 @@ public void run() { final CountDownLatch latch = new CountDownLatch(2); // subscribe once - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { assertEquals("one", v); @@ -656,7 +658,7 @@ public void accept(String v) { }); // subscribe again - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { assertEquals("one", v); @@ -709,13 +711,13 @@ public void testErrorThrownWithoutErrorHandlerAsynchronous() throws InterruptedE final AtomicReference exception = new AtomicReference(); Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); new Thread(new Runnable() { @Override public void run() { try { - observer.onError(new Error("failure")); + subscriber.onError(new Error("failure")); } catch (Throwable e) { // without an onError handler it has to just throw on whatever thread invokes it exception.set(e); @@ -768,19 +770,18 @@ public void onNext(String v) { @Test public void testOfType() { - Flowable observable = Flowable.just(1, "abc", false, 2L).ofType(String.class); + Flowable flowable = Flowable.just(1, "abc", false, 2L).ofType(String.class); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, never()).onNext(1); - verify(observer, times(1)).onNext("abc"); - verify(observer, never()).onNext(false); - verify(observer, never()).onNext(2L); - verify(observer, never()).onError( - any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onNext(1); + verify(subscriber, times(1)).onNext("abc"); + verify(subscriber, never()).onNext(false); + verify(subscriber, never()).onNext(2L); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -791,89 +792,84 @@ public void testOfTypeWithPolymorphism() { l2.add(2); @SuppressWarnings("rawtypes") - Flowable observable = Flowable. just(l1, l2, "123").ofType(List.class); + Flowable flowable = Flowable. just(l1, l2, "123").ofType(List.class); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(l1); - verify(observer, times(1)).onNext(l2); - verify(observer, never()).onNext("123"); - verify(observer, never()).onError( - any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(l1); + verify(subscriber, times(1)).onNext(l2); + verify(subscriber, never()).onNext("123"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testContainsFlowable() { - Flowable observable = Flowable.just("a", "b", "c").contains("b").toFlowable(); + Flowable flowable = Flowable.just("a", "b", "c").contains("b").toFlowable(); - FlowableSubscriber observer = TestHelper.mockSubscriber(); + FlowableSubscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(true); - verify(observer, never()).onNext(false); - verify(observer, never()).onError( - any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(true); + verify(subscriber, never()).onNext(false); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testContainsWithInexistenceFlowable() { - Flowable observable = Flowable.just("a", "b").contains("c").toFlowable(); + Flowable flowable = Flowable.just("a", "b").contains("c").toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(false); - verify(observer, never()).onNext(true); - verify(observer, never()).onError( - any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(false); + verify(subscriber, never()).onNext(true); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @Ignore("null values are not allowed") public void testContainsWithNullFlowable() { - Flowable observable = Flowable.just("a", "b", null).contains(null).toFlowable(); + Flowable flowable = Flowable.just("a", "b", null).contains(null).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(true); - verify(observer, never()).onNext(false); - verify(observer, never()).onError( - any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(true); + verify(subscriber, never()).onNext(false); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testContainsWithEmptyObservableFlowable() { - Flowable observable = Flowable. empty().contains("a").toFlowable(); + Flowable flowable = Flowable. empty().contains("a").toFlowable(); - FlowableSubscriber observer = TestHelper.mockSubscriber(); + FlowableSubscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(false); - verify(observer, never()).onNext(true); - verify(observer, never()).onError( - any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(false); + verify(subscriber, never()).onNext(true); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testContains() { - Single observable = Flowable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c" + Single single = Flowable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c" SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(true); verify(observer, never()).onSuccess(false); @@ -883,11 +879,11 @@ public void testContains() { @Test public void testContainsWithInexistence() { - Single observable = Flowable.just("a", "b").contains("c"); // FIXME null values are not allowed, removed + Single single = Flowable.just("a", "b").contains("c"); // FIXME null values are not allowed, removed SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onSuccess(true); @@ -898,11 +894,11 @@ public void testContainsWithInexistence() { @Test @Ignore("null values are not allowed") public void testContainsWithNull() { - Single observable = Flowable.just("a", "b", null).contains(null); + Single single = Flowable.just("a", "b", null).contains(null); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(true); verify(observer, never()).onSuccess(false); @@ -912,11 +908,11 @@ public void testContainsWithNull() { @Test public void testContainsWithEmptyObservable() { - Single observable = Flowable. empty().contains("a"); + Single single = Flowable. empty().contains("a"); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onSuccess(true); @@ -926,24 +922,24 @@ public void testContainsWithEmptyObservable() { @Test public void testIgnoreElementsFlowable() { - Flowable observable = Flowable.just(1, 2, 3).ignoreElements().toFlowable(); + Flowable flowable = Flowable.just(1, 2, 3).ignoreElements().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, never()).onNext(any(Integer.class)); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onNext(any(Integer.class)); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testIgnoreElements() { - Completable observable = Flowable.just(1, 2, 3).ignoreElements(); + Completable completable = Flowable.just(1, 2, 3).ignoreElements(); CompletableObserver observer = TestHelper.mockCompletableObserver(); - observable.subscribe(observer); + completable.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); @@ -952,58 +948,58 @@ public void testIgnoreElements() { @Test public void testJustWithScheduler() { TestScheduler scheduler = new TestScheduler(); - Flowable observable = Flowable.fromArray(1, 2).subscribeOn(scheduler); + Flowable flowable = Flowable.fromArray(1, 2).subscribeOn(scheduler); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testStartWithWithScheduler() { TestScheduler scheduler = new TestScheduler(); - Flowable observable = Flowable.just(3, 4).startWith(Arrays.asList(1, 2)).subscribeOn(scheduler); + Flowable flowable = Flowable.just(3, 4).startWith(Arrays.asList(1, 2)).subscribeOn(scheduler); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onNext(3); - inOrder.verify(observer, times(1)).onNext(4); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onNext(3); + inOrder.verify(subscriber, times(1)).onNext(4); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testRangeWithScheduler() { TestScheduler scheduler = new TestScheduler(); - Flowable observable = Flowable.range(3, 4).subscribeOn(scheduler); + Flowable flowable = Flowable.range(3, 4).subscribeOn(scheduler); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(3); - inOrder.verify(observer, times(1)).onNext(4); - inOrder.verify(observer, times(1)).onNext(5); - inOrder.verify(observer, times(1)).onNext(6); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(3); + inOrder.verify(subscriber, times(1)).onNext(4); + inOrder.verify(subscriber, times(1)).onNext(5); + inOrder.verify(subscriber, times(1)).onNext(6); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -1075,18 +1071,25 @@ public String apply(Integer v) { @Test public void testErrorThrownIssue1685() { - FlowableProcessor subject = ReplayProcessor.create(); + List errors = TestHelper.trackPluginErrors(); + try { + FlowableProcessor processor = ReplayProcessor.create(); - Flowable.error(new RuntimeException("oops")) - .materialize() - .delay(1, TimeUnit.SECONDS) - .dematerialize() - .subscribe(subject); + Flowable.error(new RuntimeException("oops")) + .materialize() + .delay(1, TimeUnit.SECONDS) + .dematerialize() + .subscribe(processor); - subject.subscribe(); - subject.materialize().blockingFirst(); + processor.subscribe(); + processor.materialize().blockingFirst(); - System.out.println("Done"); + System.out.println("Done"); + + TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/flowable/FlowableThrottleLastTests.java b/src/test/java/io/reactivex/flowable/FlowableThrottleLastTests.java index 2dfc9d373f..8d249e6c23 100644 --- a/src/test/java/io/reactivex/flowable/FlowableThrottleLastTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableThrottleLastTests.java @@ -29,11 +29,11 @@ public class FlowableThrottleLastTests { @Test public void testThrottle() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); TestScheduler s = new TestScheduler(); PublishProcessor o = PublishProcessor.create(); - o.throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(observer); + o.throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(subscriber); // send events with simulated time increments s.advanceTimeTo(0, TimeUnit.MILLISECONDS); @@ -51,11 +51,11 @@ public void testThrottle() { s.advanceTimeTo(1501, TimeUnit.MILLISECONDS); o.onComplete(); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onNext(2); - inOrder.verify(observer).onNext(6); - inOrder.verify(observer).onNext(7); - inOrder.verify(observer).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(6); + inOrder.verify(subscriber).onNext(7); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); } } diff --git a/src/test/java/io/reactivex/flowable/FlowableThrottleWithTimeoutTests.java b/src/test/java/io/reactivex/flowable/FlowableThrottleWithTimeoutTests.java index 4635332b3c..339d7f4316 100644 --- a/src/test/java/io/reactivex/flowable/FlowableThrottleWithTimeoutTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableThrottleWithTimeoutTests.java @@ -29,12 +29,12 @@ public class FlowableThrottleWithTimeoutTests { @Test public void testThrottle() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); TestScheduler s = new TestScheduler(); PublishProcessor o = PublishProcessor.create(); o.throttleWithTimeout(500, TimeUnit.MILLISECONDS, s) - .subscribe(observer); + .subscribe(subscriber); // send events with simulated time increments s.advanceTimeTo(0, TimeUnit.MILLISECONDS); @@ -52,11 +52,11 @@ public void testThrottle() { s.advanceTimeTo(1800, TimeUnit.MILLISECONDS); o.onComplete(); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onNext(2); - inOrder.verify(observer).onNext(6); - inOrder.verify(observer).onNext(7); - inOrder.verify(observer).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(6); + inOrder.verify(subscriber).onNext(7); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); } diff --git a/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java b/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java index 75918d345a..07d279d162 100644 --- a/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java @@ -15,13 +15,16 @@ import static org.junit.Assert.*; +import java.util.List; + import org.junit.Test; import io.reactivex.*; import io.reactivex.disposables.*; -import io.reactivex.exceptions.TestException; +import io.reactivex.exceptions.*; import io.reactivex.internal.fuseable.*; import io.reactivex.observers.*; +import io.reactivex.plugins.RxJavaPlugins; public class DeferredScalarObserverTest { @@ -44,20 +47,27 @@ public void onNext(Integer value) { @Test public void normal() { - TestObserver to = new TestObserver(); + List errors = TestHelper.trackPluginErrors(); + try { + TestObserver to = new TestObserver(); - TakeFirst source = new TakeFirst(to); + TakeFirst source = new TakeFirst(to); - source.onSubscribe(Disposables.empty()); + source.onSubscribe(Disposables.empty()); - Disposable d = Disposables.empty(); - source.onSubscribe(d); + Disposable d = Disposables.empty(); + source.onSubscribe(d); - assertTrue(d.isDisposed()); + assertTrue(d.isDisposed()); - source.onNext(1); + source.onNext(1); - to.assertResult(1); + to.assertResult(1); + + TestHelper.assertError(errors, 0, ProtocolViolationException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -105,48 +115,62 @@ public void dispose() { @Test public void fused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + List errors = TestHelper.trackPluginErrors(); + try { + TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); - TakeFirst source = new TakeFirst(to); + TakeFirst source = new TakeFirst(to); - Disposable d = Disposables.empty(); + Disposable d = Disposables.empty(); - source.onSubscribe(d); + source.onSubscribe(d); - to.assertOf(ObserverFusion.assertFuseable()); - to.assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)); + to.assertOf(ObserverFusion.assertFuseable()); + to.assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)); - source.onNext(1); - source.onNext(1); - source.onError(new TestException()); - source.onComplete(); + source.onNext(1); + source.onNext(1); + source.onError(new TestException()); + source.onComplete(); - assertTrue(d.isDisposed()); + assertTrue(d.isDisposed()); - to.assertResult(1); + to.assertResult(1); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void fusedReject() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + List errors = TestHelper.trackPluginErrors(); + try { + TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); - TakeFirst source = new TakeFirst(to); + TakeFirst source = new TakeFirst(to); - Disposable d = Disposables.empty(); + Disposable d = Disposables.empty(); - source.onSubscribe(d); + source.onSubscribe(d); - to.assertOf(ObserverFusion.assertFuseable()); - to.assertOf(ObserverFusion.assertFusionMode(QueueFuseable.NONE)); + to.assertOf(ObserverFusion.assertFuseable()); + to.assertOf(ObserverFusion.assertFusionMode(QueueFuseable.NONE)); - source.onNext(1); - source.onNext(1); - source.onError(new TestException()); - source.onComplete(); + source.onNext(1); + source.onNext(1); + source.onError(new TestException()); + source.onComplete(); - assertTrue(d.isDisposed()); + assertTrue(d.isDisposed()); - to.assertResult(1); + to.assertResult(1); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } static final class TakeLast extends DeferredScalarObserver { @@ -167,74 +191,102 @@ public void onNext(Integer value) { @Test public void nonfusedTerminateMore() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.NONE); + List errors = TestHelper.trackPluginErrors(); + try { + TestObserver to = ObserverFusion.newTest(QueueFuseable.NONE); - TakeLast source = new TakeLast(to); + TakeLast source = new TakeLast(to); - Disposable d = Disposables.empty(); + Disposable d = Disposables.empty(); - source.onSubscribe(d); + source.onSubscribe(d); - source.onNext(1); - source.onComplete(); - source.onComplete(); - source.onError(new TestException()); + source.onNext(1); + source.onComplete(); + source.onComplete(); + source.onError(new TestException()); - to.assertResult(1); + to.assertResult(1); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void nonfusedError() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.NONE); + List errors = TestHelper.trackPluginErrors(); + try { + TestObserver to = ObserverFusion.newTest(QueueFuseable.NONE); - TakeLast source = new TakeLast(to); + TakeLast source = new TakeLast(to); - Disposable d = Disposables.empty(); + Disposable d = Disposables.empty(); - source.onSubscribe(d); + source.onSubscribe(d); - source.onNext(1); - source.onError(new TestException()); - source.onError(new TestException()); - source.onComplete(); + source.onNext(1); + source.onError(new TestException()); + source.onError(new TestException("second")); + source.onComplete(); - to.assertFailure(TestException.class); + to.assertFailure(TestException.class); + + TestHelper.assertUndeliverable(errors, 0, TestException.class, "second"); + } finally { + RxJavaPlugins.reset(); + } } @Test public void fusedTerminateMore() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + List errors = TestHelper.trackPluginErrors(); + try { + TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); - TakeLast source = new TakeLast(to); + TakeLast source = new TakeLast(to); - Disposable d = Disposables.empty(); + Disposable d = Disposables.empty(); - source.onSubscribe(d); + source.onSubscribe(d); - source.onNext(1); - source.onComplete(); - source.onComplete(); - source.onError(new TestException()); + source.onNext(1); + source.onComplete(); + source.onComplete(); + source.onError(new TestException()); - to.assertResult(1); + to.assertResult(1); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void fusedError() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + List errors = TestHelper.trackPluginErrors(); + try { + TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); - TakeLast source = new TakeLast(to); + TakeLast source = new TakeLast(to); - Disposable d = Disposables.empty(); + Disposable d = Disposables.empty(); - source.onSubscribe(d); + source.onSubscribe(d); - source.onNext(1); - source.onError(new TestException()); - source.onError(new TestException()); - source.onComplete(); + source.onNext(1); + source.onError(new TestException()); + source.onError(new TestException("second")); + source.onComplete(); - to.assertFailure(TestException.class); + to.assertFailure(TestException.class); + + TestHelper.assertUndeliverable(errors, 0, TestException.class, "second"); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java b/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java index 917a156f14..90fe6c3910 100644 --- a/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java @@ -213,83 +213,115 @@ public void run() { @Test public void onCompleteCancelRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final FutureSubscriber fo = new FutureSubscriber(); - - if (i % 3 == 0) { - fo.onSubscribe(new BooleanSubscription()); - } - - if (i % 2 == 0) { - fo.onNext(1); - } + RxJavaPlugins.setErrorHandler(Functions.emptyConsumer()); + try { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final FutureSubscriber fo = new FutureSubscriber(); - Runnable r1 = new Runnable() { - @Override - public void run() { - fo.cancel(false); + if (i % 3 == 0) { + fo.onSubscribe(new BooleanSubscription()); } - }; - Runnable r2 = new Runnable() { - @Override - public void run() { - fo.onComplete(); + if (i % 2 == 0) { + fo.onNext(1); } - }; - TestHelper.race(r1, r2); + Runnable r1 = new Runnable() { + @Override + public void run() { + fo.cancel(false); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + fo.onComplete(); + } + }; + + TestHelper.race(r1, r2); + } + } finally { + RxJavaPlugins.reset(); } } @Test public void onErrorOnComplete() throws Exception { - fo.onError(new TestException("One")); - fo.onComplete(); - + List errors = TestHelper.trackPluginErrors(); try { - fo.get(5, TimeUnit.MILLISECONDS); - } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof TestException); - assertEquals("One", ex.getCause().getMessage()); + fo.onError(new TestException("One")); + fo.onComplete(); + + try { + fo.get(5, TimeUnit.MILLISECONDS); + } catch (ExecutionException ex) { + assertTrue(ex.toString(), ex.getCause() instanceof TestException); + assertEquals("One", ex.getCause().getMessage()); + } + + TestHelper.assertUndeliverable(errors, 0, NoSuchElementException.class); + } finally { + RxJavaPlugins.reset(); } } @Test public void onCompleteOnError() throws Exception { - fo.onComplete(); - fo.onError(new TestException("One")); - + List errors = TestHelper.trackPluginErrors(); try { - assertNull(fo.get(5, TimeUnit.MILLISECONDS)); - } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof NoSuchElementException); + fo.onComplete(); + fo.onError(new TestException("One")); + + try { + assertNull(fo.get(5, TimeUnit.MILLISECONDS)); + } catch (ExecutionException ex) { + assertTrue(ex.toString(), ex.getCause() instanceof NoSuchElementException); + } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); } } @Test public void cancelOnError() throws Exception { - fo.cancel(true); - fo.onError(new TestException("One")); - + List errors = TestHelper.trackPluginErrors(); try { - fo.get(5, TimeUnit.MILLISECONDS); - fail("Should have thrown"); - } catch (CancellationException ex) { - // expected + fo.cancel(true); + fo.onError(new TestException("One")); + + try { + fo.get(5, TimeUnit.MILLISECONDS); + fail("Should have thrown"); + } catch (CancellationException ex) { + // expected + } + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); } } @Test public void cancelOnComplete() throws Exception { - fo.cancel(true); - fo.onComplete(); - + List errors = TestHelper.trackPluginErrors(); try { - fo.get(5, TimeUnit.MILLISECONDS); - fail("Should have thrown"); - } catch (CancellationException ex) { - // expected + fo.cancel(true); + fo.onComplete(); + + try { + fo.get(5, TimeUnit.MILLISECONDS); + fail("Should have thrown"); + } catch (CancellationException ex) { + // expected + } + + TestHelper.assertUndeliverable(errors, 0, NoSuchElementException.class); + } finally { + RxJavaPlugins.reset(); } } diff --git a/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java b/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java index cd52919537..1dc0451434 100644 --- a/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java @@ -22,6 +22,8 @@ import io.reactivex.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.internal.functions.Functions; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; public class FutureSingleObserverTest { @@ -156,28 +158,33 @@ public void run() { @Test public void onErrorCancelRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishSubject ps = PublishSubject.create(); - - final Future f = ps.single(-99).toFuture(); - - final TestException ex = new TestException(); - - Runnable r1 = new Runnable() { - @Override - public void run() { - f.cancel(true); - } - }; - - Runnable r2 = new Runnable() { - @Override - public void run() { - ps.onError(ex); - } - }; - - TestHelper.race(r1, r2); + RxJavaPlugins.setErrorHandler(Functions.emptyConsumer()); + try { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishSubject ps = PublishSubject.create(); + + final Future f = ps.single(-99).toFuture(); + + final TestException ex = new TestException(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + f.cancel(true); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + ps.onError(ex); + } + }; + + TestHelper.race(r1, r2); + } + } finally { + RxJavaPlugins.reset(); } } } diff --git a/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java b/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java index 94fe4cb4c1..3171f8e8df 100644 --- a/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java @@ -196,92 +196,106 @@ public void accept(Disposable s) throws Exception { @Test public void badSourceOnSubscribe() { - Observable source = new Observable() { - @Override - public void subscribeActual(Observer s) { - Disposable s1 = Disposables.empty(); - s.onSubscribe(s1); - Disposable s2 = Disposables.empty(); - s.onSubscribe(s2); + List errors = TestHelper.trackPluginErrors(); + try { + Observable source = new Observable() { + @Override + public void subscribeActual(Observer observer) { + Disposable s1 = Disposables.empty(); + observer.onSubscribe(s1); + Disposable s2 = Disposables.empty(); + observer.onSubscribe(s2); - assertFalse(s1.isDisposed()); - assertTrue(s2.isDisposed()); + assertFalse(s1.isDisposed()); + assertTrue(s2.isDisposed()); - s.onNext(1); - s.onComplete(); - } - }; + observer.onNext(1); + observer.onComplete(); + } + }; - final List received = new ArrayList(); + final List received = new ArrayList(); - LambdaObserver o = new LambdaObserver(new Consumer() { - @Override - public void accept(Object v) throws Exception { - received.add(v); - } - }, - new Consumer() { - @Override - public void accept(Throwable e) throws Exception { - received.add(e); - } - }, new Action() { - @Override - public void run() throws Exception { - received.add(100); - } - }, new Consumer() { - @Override - public void accept(Disposable s) throws Exception { - } - }); + LambdaObserver o = new LambdaObserver(new Consumer() { + @Override + public void accept(Object v) throws Exception { + received.add(v); + } + }, + new Consumer() { + @Override + public void accept(Throwable e) throws Exception { + received.add(e); + } + }, new Action() { + @Override + public void run() throws Exception { + received.add(100); + } + }, new Consumer() { + @Override + public void accept(Disposable s) throws Exception { + } + }); + + source.subscribe(o); - source.subscribe(o); + assertEquals(Arrays.asList(1, 100), received); - assertEquals(Arrays.asList(1, 100), received); + TestHelper.assertError(errors, 0, ProtocolViolationException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void badSourceEmitAfterDone() { - Observable source = new Observable() { - @Override - public void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - - s.onNext(1); - s.onComplete(); - s.onNext(2); - s.onError(new TestException()); - s.onComplete(); - } - }; + List errors = TestHelper.trackPluginErrors(); + try { + Observable source = new Observable() { + @Override + public void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + + observer.onNext(1); + observer.onComplete(); + observer.onNext(2); + observer.onError(new TestException()); + observer.onComplete(); + } + }; - final List received = new ArrayList(); + final List received = new ArrayList(); - LambdaObserver o = new LambdaObserver(new Consumer() { - @Override - public void accept(Object v) throws Exception { - received.add(v); - } - }, - new Consumer() { - @Override - public void accept(Throwable e) throws Exception { - received.add(e); - } - }, new Action() { - @Override - public void run() throws Exception { - received.add(100); - } - }, new Consumer() { - @Override - public void accept(Disposable s) throws Exception { - } - }); + LambdaObserver o = new LambdaObserver(new Consumer() { + @Override + public void accept(Object v) throws Exception { + received.add(v); + } + }, + new Consumer() { + @Override + public void accept(Throwable e) throws Exception { + received.add(e); + } + }, new Action() { + @Override + public void run() throws Exception { + received.add(100); + } + }, new Consumer() { + @Override + public void accept(Disposable s) throws Exception { + } + }); + + source.subscribe(o); - source.subscribe(o); + assertEquals(Arrays.asList(1, 100), received); - assertEquals(Arrays.asList(1, 100), received); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableConcatTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableConcatTest.java index 218180b4a7..47c21fff85 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableConcatTest.java @@ -35,21 +35,28 @@ public class CompletableConcatTest { @Test public void overflowReported() { - Completable.concat( - Flowable.fromPublisher(new Publisher() { - @Override - public void subscribe(Subscriber s) { - s.onSubscribe(new BooleanSubscription()); - s.onNext(Completable.never()); - s.onNext(Completable.never()); - s.onNext(Completable.never()); - s.onNext(Completable.never()); - s.onComplete(); - } - }), 1 - ) - .test() - .assertFailure(MissingBackpressureException.class); + List errors = TestHelper.trackPluginErrors(); + try { + Completable.concat( + Flowable.fromPublisher(new Publisher() { + @Override + public void subscribe(Subscriber s) { + s.onSubscribe(new BooleanSubscription()); + s.onNext(Completable.never()); + s.onNext(Completable.never()); + s.onNext(Completable.never()); + s.onNext(Completable.never()); + s.onComplete(); + } + }), 1 + ) + .test() + .assertFailure(MissingBackpressureException.class); + + TestHelper.assertError(errors, 0, MissingBackpressureException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -163,10 +170,10 @@ public void arrayFirstCancels() { Completable.concatArray(new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); to.cancel(); - s.onComplete(); + observer.onComplete(); } }, Completable.complete()) .subscribe(to); @@ -187,10 +194,10 @@ public void iterableFirstCancels() { Completable.concat(Arrays.asList(new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); to.cancel(); - s.onComplete(); + observer.onComplete(); } }, Completable.complete())) .subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableCreateTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableCreateTest.java index 13b64091fe..33f50adc5b 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableCreateTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableCreateTest.java @@ -35,70 +35,91 @@ public void nullArgument() { @Test public void basic() { - final Disposable d = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); - Completable.create(new CompletableOnSubscribe() { - @Override - public void subscribe(CompletableEmitter e) throws Exception { - e.setDisposable(d); + Completable.create(new CompletableOnSubscribe() { + @Override + public void subscribe(CompletableEmitter e) throws Exception { + e.setDisposable(d); - e.onComplete(); - e.onError(new TestException()); - e.onComplete(); - } - }) - .test() - .assertResult(); + e.onComplete(); + e.onError(new TestException()); + e.onComplete(); + } + }) + .test() + .assertResult(); + + assertTrue(d.isDisposed()); - assertTrue(d.isDisposed()); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithCancellable() { - final Disposable d1 = Disposables.empty(); - final Disposable d2 = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d1 = Disposables.empty(); + final Disposable d2 = Disposables.empty(); - Completable.create(new CompletableOnSubscribe() { - @Override - public void subscribe(CompletableEmitter e) throws Exception { - e.setDisposable(d1); - e.setCancellable(new Cancellable() { - @Override - public void cancel() throws Exception { - d2.dispose(); - } - }); + Completable.create(new CompletableOnSubscribe() { + @Override + public void subscribe(CompletableEmitter e) throws Exception { + e.setDisposable(d1); + e.setCancellable(new Cancellable() { + @Override + public void cancel() throws Exception { + d2.dispose(); + } + }); - e.onComplete(); - e.onError(new TestException()); - e.onComplete(); - } - }) - .test() - .assertResult(); + e.onComplete(); + e.onError(new TestException()); + e.onComplete(); + } + }) + .test() + .assertResult(); + + assertTrue(d1.isDisposed()); + assertTrue(d2.isDisposed()); - assertTrue(d1.isDisposed()); - assertTrue(d2.isDisposed()); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithError() { - final Disposable d = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); - Completable.create(new CompletableOnSubscribe() { - @Override - public void subscribe(CompletableEmitter e) throws Exception { - e.setDisposable(d); + Completable.create(new CompletableOnSubscribe() { + @Override + public void subscribe(CompletableEmitter e) throws Exception { + e.setDisposable(d); - e.onError(new TestException()); - e.onComplete(); - e.onError(new TestException()); - } - }) - .test() - .assertFailure(TestException.class); + e.onError(new TestException()); + e.onComplete(); + e.onError(new TestException("second")); + } + }) + .test() + .assertFailure(TestException.class); - assertTrue(d.isDisposed()); + assertTrue(d.isDisposed()); + + TestHelper.assertUndeliverable(errors, 0, TestException.class, "second"); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java index b2082c96d5..91f904ce56 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java @@ -85,10 +85,10 @@ public void onSubscribeCrash() { new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(bs); - s.onError(new TestException("Second")); - s.onComplete(); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(bs); + observer.onError(new TestException("Second")); + observer.onComplete(); } } .doOnSubscribe(new Consumer() { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableLiftTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableLiftTest.java index 39e7cd1935..da78bc0bcf 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableLiftTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableLiftTest.java @@ -13,16 +13,19 @@ package io.reactivex.internal.operators.completable; -import static org.junit.Assert.*; +import java.util.List; + import org.junit.Test; import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.plugins.RxJavaPlugins; public class CompletableLiftTest { @Test public void callbackThrows() { + List errors = TestHelper.trackPluginErrors(); try { Completable.complete() .lift(new CompletableOperator() { @@ -32,8 +35,10 @@ public CompletableObserver apply(CompletableObserver o) throws Exception { } }) .test(); - } catch (NullPointerException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof TestException); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); } } } diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeTest.java index d386969ad9..588dda88f9 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeTest.java @@ -46,9 +46,9 @@ public void cancelAfterFirst() { Completable.mergeArray(new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - s.onComplete(); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); to.cancel(); } }, Completable.complete()) @@ -63,9 +63,9 @@ public void cancelAfterFirstDelayError() { Completable.mergeArrayDelayError(new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - s.onComplete(); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); to.cancel(); } }, Completable.complete()) @@ -82,10 +82,10 @@ public void onErrorAfterComplete() { Completable.mergeArrayDelayError(Completable.complete(), new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - s.onComplete(); - co[0] = s; + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); + co[0] = observer; } }) .test() @@ -408,10 +408,10 @@ public void innerDoubleOnError() { final CompletableObserver[] o = { null }; Completable.mergeDelayError(Flowable.just(new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - s.onError(new TestException("First")); - o[0] = s; + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onError(new TestException("First")); + o[0] = observer; } })) .test() @@ -431,13 +431,13 @@ public void innerIsDisposed() { Completable.mergeDelayError(Flowable.just(new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - assertFalse(((Disposable)s).isDisposed()); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + assertFalse(((Disposable)observer).isDisposed()); to.dispose(); - assertTrue(((Disposable)s).isDisposed()); + assertTrue(((Disposable)observer).isDisposed()); } })) .subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java index 586e0c3207..abf64f32f0 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java @@ -143,9 +143,9 @@ public void mainErrorLate() { new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - s.onError(new TestException()); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onError(new TestException()); } }.takeUntil(Completable.complete()) .test() @@ -165,9 +165,9 @@ public void mainCompleteLate() { new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - s.onComplete(); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); } }.takeUntil(Completable.complete()) .test() @@ -190,9 +190,9 @@ public void otherErrorLate() { Completable.complete() .takeUntil(new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - ref.set(s); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + ref.set(observer); } }) .test() @@ -217,9 +217,9 @@ public void otherCompleteLate() { Completable.complete() .takeUntil(new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - ref.set(s); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + ref.set(observer); } }) .test() diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableUnsafeTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableUnsafeTest.java index ed2ec31e9f..518e81c3a9 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableUnsafeTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableUnsafeTest.java @@ -14,10 +14,14 @@ package io.reactivex.internal.operators.completable; import static org.junit.Assert.*; + +import java.util.List; + import org.junit.Test; import io.reactivex.*; import io.reactivex.disposables.Disposables; +import io.reactivex.plugins.RxJavaPlugins; public class CompletableUnsafeTest { @@ -36,9 +40,9 @@ public void wrapCustomCompletable() { Completable.wrap(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); - s.onComplete(); + public void subscribe(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); } }) .test() @@ -49,7 +53,7 @@ public void subscribe(CompletableObserver s) { public void unsafeCreateThrowsNPE() { Completable.unsafeCreate(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { + public void subscribe(CompletableObserver observer) { throw new NullPointerException(); } }).test(); @@ -57,10 +61,11 @@ public void subscribe(CompletableObserver s) { @Test public void unsafeCreateThrowsIAE() { + List errors = TestHelper.trackPluginErrors(); try { Completable.unsafeCreate(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { + public void subscribe(CompletableObserver observer) { throw new IllegalArgumentException(); } }).test(); @@ -69,6 +74,10 @@ public void subscribe(CompletableObserver s) { if (!(ex.getCause() instanceof IllegalArgumentException)) { fail(ex.toString() + ": should have thrown NPA(IAE)"); } + + TestHelper.assertError(errors, 0, IllegalArgumentException.class); + } finally { + RxJavaPlugins.reset(); } } } diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java index 30c1965120..598abdd29c 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java @@ -24,6 +24,7 @@ import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; @@ -410,14 +411,14 @@ public Object call() throws Exception { public CompletableSource apply(Object v) throws Exception { return Completable.wrap(new CompletableSource() { @Override - public void subscribe(CompletableObserver s) { + public void subscribe(CompletableObserver observer) { Disposable d1 = Disposables.empty(); - s.onSubscribe(d1); + observer.onSubscribe(d1); Disposable d2 = Disposables.empty(); - s.onSubscribe(d2); + observer.onSubscribe(d2); assertFalse(d1.isDisposed()); @@ -482,44 +483,49 @@ public void run() { @Test public void errorDisposeRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - - final PublishSubject ps = PublishSubject.create(); - - final TestObserver to = Completable.using(new Callable() { - @Override - public Object call() throws Exception { - return 1; - } - }, new Function() { - @Override - public CompletableSource apply(Object v) throws Exception { - return ps.ignoreElements(); - } - }, new Consumer() { - @Override - public void accept(Object d) throws Exception { - } - }, true) - .test(); - - final TestException ex = new TestException(); - - Runnable r1 = new Runnable() { - @Override - public void run() { - to.cancel(); - } - }; - - Runnable r2 = new Runnable() { - @Override - public void run() { - ps.onError(ex); - } - }; - - TestHelper.race(r1, r2); + RxJavaPlugins.setErrorHandler(Functions.emptyConsumer()); + try { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final PublishSubject ps = PublishSubject.create(); + + final TestObserver to = Completable.using(new Callable() { + @Override + public Object call() throws Exception { + return 1; + } + }, new Function() { + @Override + public CompletableSource apply(Object v) throws Exception { + return ps.ignoreElements(); + } + }, new Consumer() { + @Override + public void accept(Object d) throws Exception { + } + }, true) + .test(); + + final TestException ex = new TestException(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + to.cancel(); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + ps.onError(ex); + } + }; + + TestHelper.race(r1, r2); + } + } finally { + RxJavaPlugins.reset(); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/AbstractFlowableWithUpstreamTest.java b/src/test/java/io/reactivex/internal/operators/flowable/AbstractFlowableWithUpstreamTest.java index c3ade57ce8..d1d6a0b5d3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/AbstractFlowableWithUpstreamTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/AbstractFlowableWithUpstreamTest.java @@ -26,8 +26,8 @@ public class AbstractFlowableWithUpstreamTest { @SuppressWarnings("unchecked") @Test public void source() { - Flowable o = Flowable.just(1); + Flowable f = Flowable.just(1); - assertSame(o, ((HasUpstreamPublisher)o.map(Functions.identity())).source()); + assertSame(f, ((HasUpstreamPublisher)f.map(Functions.identity())).source()); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java index 356355ab46..32ee150cf3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java @@ -241,20 +241,20 @@ public void testNoBufferingOrBlockingOfSequence() throws Throwable { final Flowable obs = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber o) { - o.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); task.replace(Schedulers.single().scheduleDirect(new Runnable() { @Override public void run() { try { while (running.get() && !task.isDisposed()) { - o.onNext(count.incrementAndGet()); + subscriber.onNext(count.incrementAndGet()); timeHasPassed.countDown(); } - o.onComplete(); + subscriber.onComplete(); } catch (Throwable e) { - o.onError(e); + subscriber.onError(e); } finally { finished.countDown(); } @@ -308,9 +308,9 @@ public void run() { @Test /* (timeout = 8000) */ public void testSingleSourceManyIterators() throws InterruptedException { - Flowable o = Flowable.interval(250, TimeUnit.MILLISECONDS); + Flowable f = Flowable.interval(250, TimeUnit.MILLISECONDS); PublishProcessor terminal = PublishProcessor.create(); - Flowable source = o.takeUntil(terminal); + Flowable source = f.takeUntil(terminal); Iterable iter = source.blockingNext(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToFutureTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToFutureTest.java index 87752f2b11..d90b0b2f43 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToFutureTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToFutureTest.java @@ -69,10 +69,10 @@ public void testToFutureWithException() { Flowable obs = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext("one"); - observer.onError(new TestException()); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("one"); + subscriber.onError(new TestException()); } }); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java index 239aed218d..412d59ac5f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java @@ -51,10 +51,10 @@ public void testToIteratorWithException() { Flowable obs = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext("one"); - observer.onError(new TestException()); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("one"); + subscriber.onError(new TestException()); } }); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java index 9f578b2d2d..7ab08915d2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java @@ -114,8 +114,8 @@ public boolean test(String s) { @Test public void testFollowingFirst() { - Flowable o = Flowable.fromArray(1, 3, 5, 6); - Single allOdd = o.all(new Predicate() { + Flowable f = Flowable.fromArray(1, 3, 5, 6); + Single allOdd = f.all(new Predicate() { @Override public boolean test(Integer i) { return i % 2 == 1; @@ -203,7 +203,7 @@ public boolean test(String v) { public void testAllFlowable() { Flowable obs = Flowable.just("one", "two", "six"); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); obs.all(new Predicate() { @Override @@ -212,19 +212,19 @@ public boolean test(String s) { } }) .toFlowable() - .subscribe(observer); + .subscribe(subscriber); - verify(observer).onSubscribe((Subscription)any()); - verify(observer).onNext(true); - verify(observer).onComplete(); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe((Subscription)any()); + verify(subscriber).onNext(true); + verify(subscriber).onComplete(); + verifyNoMoreInteractions(subscriber); } @Test public void testNotAllFlowable() { Flowable obs = Flowable.just("one", "two", "three", "six"); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); obs.all(new Predicate() { @Override @@ -233,19 +233,19 @@ public boolean test(String s) { } }) .toFlowable() - .subscribe(observer); + .subscribe(subscriber); - verify(observer).onSubscribe((Subscription)any()); - verify(observer).onNext(false); - verify(observer).onComplete(); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe((Subscription)any()); + verify(subscriber).onNext(false); + verify(subscriber).onComplete(); + verifyNoMoreInteractions(subscriber); } @Test public void testEmptyFlowable() { Flowable obs = Flowable.empty(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); obs.all(new Predicate() { @Override @@ -254,12 +254,12 @@ public boolean test(String s) { } }) .toFlowable() - .subscribe(observer); + .subscribe(subscriber); - verify(observer).onSubscribe((Subscription)any()); - verify(observer).onNext(true); - verify(observer).onComplete(); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe((Subscription)any()); + verify(subscriber).onNext(true); + verify(subscriber).onComplete(); + verifyNoMoreInteractions(subscriber); } @Test @@ -267,7 +267,7 @@ public void testErrorFlowable() { Throwable error = new Throwable(); Flowable obs = Flowable.error(error); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); obs.all(new Predicate() { @Override @@ -276,17 +276,17 @@ public boolean test(String s) { } }) .toFlowable() - .subscribe(observer); + .subscribe(subscriber); - verify(observer).onSubscribe((Subscription)any()); - verify(observer).onError(error); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe((Subscription)any()); + verify(subscriber).onError(error); + verifyNoMoreInteractions(subscriber); } @Test public void testFollowingFirstFlowable() { - Flowable o = Flowable.fromArray(1, 3, 5, 6); - Flowable allOdd = o.all(new Predicate() { + Flowable f = Flowable.fromArray(1, 3, 5, 6); + Flowable allOdd = f.all(new Predicate() { @Override public boolean test(Integer i) { return i % 2 == 1; @@ -391,13 +391,13 @@ public void predicateThrows() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onNext(2); - observer.onError(new TestException()); - observer.onComplete(); + subscriber.onNext(1); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .all(new Predicate() { @@ -422,13 +422,13 @@ public void predicateThrowsObservable() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onNext(2); - observer.onError(new TestException()); - observer.onComplete(); + subscriber.onNext(1); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .all(new Predicate() { @@ -451,15 +451,15 @@ public boolean test(Integer v) throws Exception { public void badSource() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.all(Functions.alwaysTrue()); + public Object apply(Flowable f) throws Exception { + return f.all(Functions.alwaysTrue()); } }, false, 1, 1, true); TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.all(Functions.alwaysTrue()).toFlowable(); + public Object apply(Flowable f) throws Exception { + return f.all(Functions.alwaysTrue()).toFlowable(); } }, false, 1, 1, true); } @@ -468,14 +468,14 @@ public Object apply(Flowable o) throws Exception { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>() { @Override - public Publisher apply(Flowable o) throws Exception { - return o.all(Functions.alwaysTrue()).toFlowable(); + public Publisher apply(Flowable f) throws Exception { + return f.all(Functions.alwaysTrue()).toFlowable(); } }); TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function, Single>() { @Override - public Single apply(Flowable o) throws Exception { - return o.all(Functions.alwaysTrue()); + public Single apply(Flowable f) throws Exception { + return f.all(Functions.alwaysTrue()); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java index 839d04e3e1..9e68ec3948 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java @@ -102,21 +102,20 @@ public void testAmb() { "3", "33", "333", "3333" }, 3000, null); @SuppressWarnings("unchecked") - Flowable o = Flowable.ambArray(flowable1, + Flowable f = Flowable.ambArray(flowable1, flowable2, flowable3); - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); - o.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + f.subscribe(subscriber); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("2"); - inOrder.verify(observer, times(1)).onNext("22"); - inOrder.verify(observer, times(1)).onNext("222"); - inOrder.verify(observer, times(1)).onNext("2222"); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("2"); + inOrder.verify(subscriber, times(1)).onNext("22"); + inOrder.verify(subscriber, times(1)).onNext("222"); + inOrder.verify(subscriber, times(1)).onNext("2222"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -132,21 +131,20 @@ public void testAmb2() { 3000, new IOException("fake exception")); @SuppressWarnings("unchecked") - Flowable o = Flowable.ambArray(flowable1, + Flowable f = Flowable.ambArray(flowable1, flowable2, flowable3); - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); - o.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + f.subscribe(subscriber); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("2"); - inOrder.verify(observer, times(1)).onNext("22"); - inOrder.verify(observer, times(1)).onNext("222"); - inOrder.verify(observer, times(1)).onNext("2222"); - inOrder.verify(observer, times(1)).onError(expectedException); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("2"); + inOrder.verify(subscriber, times(1)).onNext("22"); + inOrder.verify(subscriber, times(1)).onNext("222"); + inOrder.verify(subscriber, times(1)).onNext("2222"); + inOrder.verify(subscriber, times(1)).onError(expectedException); inOrder.verifyNoMoreInteractions(); } @@ -160,16 +158,15 @@ public void testAmb3() { "3" }, 3000, null); @SuppressWarnings("unchecked") - Flowable o = Flowable.ambArray(flowable1, + Flowable f = Flowable.ambArray(flowable1, flowable2, flowable3); - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); - o.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + f.subscribe(subscriber); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -180,7 +177,7 @@ public void testProducerRequestThroughAmb() { ts.request(3); final AtomicLong requested1 = new AtomicLong(); final AtomicLong requested2 = new AtomicLong(); - Flowable o1 = Flowable.unsafeCreate(new Publisher() { + Flowable f1 = Flowable.unsafeCreate(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -200,7 +197,7 @@ public void cancel() { } }); - Flowable o2 = Flowable.unsafeCreate(new Publisher() { + Flowable f2 = Flowable.unsafeCreate(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -220,7 +217,7 @@ public void cancel() { } }); - Flowable.ambArray(o1, o2).subscribe(ts); + Flowable.ambArray(f1, f2).subscribe(ts); assertEquals(3, requested1.get()); assertEquals(3, requested2.get()); } @@ -252,13 +249,13 @@ public void accept(Subscription s) { }; //this aync stream should emit first - Flowable o1 = Flowable.just(1).doOnSubscribe(incrementer) + Flowable f1 = Flowable.just(1).doOnSubscribe(incrementer) .delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); //this stream emits second - Flowable o2 = Flowable.just(1).doOnSubscribe(incrementer) + Flowable f2 = Flowable.just(1).doOnSubscribe(incrementer) .delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber(); - Flowable.ambArray(o1, o2).subscribe(ts); + Flowable.ambArray(f1, f2).subscribe(ts); ts.request(1); ts.awaitTerminalEvent(5, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -269,14 +266,14 @@ public void accept(Subscription s) { @Test public void testSecondaryRequestsPropagatedToChildren() throws InterruptedException { //this aync stream should emit first - Flowable o1 = Flowable.fromArray(1, 2, 3) + Flowable f1 = Flowable.fromArray(1, 2, 3) .delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); //this stream emits second - Flowable o2 = Flowable.fromArray(4, 5, 6) + Flowable f2 = Flowable.fromArray(4, 5, 6) .delay(200, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber(1L); - Flowable.ambArray(o1, o2).subscribe(ts); + Flowable.ambArray(f1, f2).subscribe(ts); // before first emission request 20 more // this request should suffice to emit all ts.request(20); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java index 90d05f7ac1..76bd59591a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java @@ -38,7 +38,7 @@ public class FlowableAnyTest { @Test public void testAnyWithTwoItems() { Flowable w = Flowable.just(1, 2); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -47,7 +47,7 @@ public boolean test(Integer v) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(false); verify(observer, times(1)).onSuccess(true); @@ -57,11 +57,11 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithTwoItems() { Flowable w = Flowable.just(1, 2); - Single observable = w.isEmpty(); + Single single = w.isEmpty(); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(true); verify(observer, times(1)).onSuccess(false); @@ -71,7 +71,7 @@ public void testIsEmptyWithTwoItems() { @Test public void testAnyWithOneItem() { Flowable w = Flowable.just(1); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -80,7 +80,7 @@ public boolean test(Integer v) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(false); verify(observer, times(1)).onSuccess(true); @@ -90,11 +90,11 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithOneItem() { Flowable w = Flowable.just(1); - Single observable = w.isEmpty(); + Single single = w.isEmpty(); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(true); verify(observer, times(1)).onSuccess(false); @@ -104,7 +104,7 @@ public void testIsEmptyWithOneItem() { @Test public void testAnyWithEmpty() { Flowable w = Flowable.empty(); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -113,7 +113,7 @@ public boolean test(Integer v) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onSuccess(true); @@ -123,11 +123,11 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithEmpty() { Flowable w = Flowable.empty(); - Single observable = w.isEmpty(); + Single single = w.isEmpty(); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(true); verify(observer, never()).onSuccess(false); @@ -137,7 +137,7 @@ public void testIsEmptyWithEmpty() { @Test public void testAnyWithPredicate1() { Flowable w = Flowable.just(1, 2, 3); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; @@ -146,7 +146,7 @@ public boolean test(Integer t1) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(false); verify(observer, times(1)).onSuccess(true); @@ -156,7 +156,7 @@ public boolean test(Integer t1) { @Test public void testExists1() { Flowable w = Flowable.just(1, 2, 3); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; @@ -165,7 +165,7 @@ public boolean test(Integer t1) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(false); verify(observer, times(1)).onSuccess(true); @@ -175,7 +175,7 @@ public boolean test(Integer t1) { @Test public void testAnyWithPredicate2() { Flowable w = Flowable.just(1, 2, 3); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 1; @@ -184,7 +184,7 @@ public boolean test(Integer t1) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onSuccess(true); @@ -195,7 +195,7 @@ public boolean test(Integer t1) { public void testAnyWithEmptyAndPredicate() { // If the source is empty, always output false. Flowable w = Flowable.empty(); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer t) { return true; @@ -204,7 +204,7 @@ public boolean test(Integer t) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onSuccess(true); @@ -213,8 +213,8 @@ public boolean test(Integer t) { @Test public void testWithFollowingFirst() { - Flowable o = Flowable.fromArray(1, 3, 5, 6); - Single anyEven = o.any(new Predicate() { + Flowable f = Flowable.fromArray(1, 3, 5, 6); + Single anyEven = f.any(new Predicate() { @Override public boolean test(Integer i) { return i % 2 == 0; @@ -293,7 +293,7 @@ public boolean test(String v) { @Test public void testAnyWithTwoItemsFlowable() { Flowable w = Flowable.just(1, 2); - Flowable observable = w.any(new Predicate() { + Flowable flowable = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -302,59 +302,59 @@ public boolean test(Integer v) { .toFlowable() ; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, never()).onNext(false); - verify(observer, times(1)).onNext(true); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onNext(false); + verify(subscriber, times(1)).onNext(true); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testIsEmptyWithTwoItemsFlowable() { Flowable w = Flowable.just(1, 2); - Flowable observable = w.isEmpty().toFlowable(); + Flowable flowable = w.isEmpty().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, never()).onNext(true); - verify(observer, times(1)).onNext(false); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onNext(true); + verify(subscriber, times(1)).onNext(false); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testAnyWithOneItemFlowable() { Flowable w = Flowable.just(1); - Flowable observable = w.any(new Predicate() { + Flowable flowable = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; } }).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, never()).onNext(false); - verify(observer, times(1)).onNext(true); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onNext(false); + verify(subscriber, times(1)).onNext(true); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testIsEmptyWithOneItemFlowable() { Flowable w = Flowable.just(1); - Single observable = w.isEmpty(); + Single single = w.isEmpty(); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(true); verify(observer, times(1)).onSuccess(false); @@ -364,123 +364,123 @@ public void testIsEmptyWithOneItemFlowable() { @Test public void testAnyWithEmptyFlowable() { Flowable w = Flowable.empty(); - Flowable observable = w.any(new Predicate() { + Flowable flowable = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; } }).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(false); - verify(observer, never()).onNext(true); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(false); + verify(subscriber, never()).onNext(true); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testIsEmptyWithEmptyFlowable() { Flowable w = Flowable.empty(); - Flowable observable = w.isEmpty().toFlowable(); + Flowable flowable = w.isEmpty().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(true); - verify(observer, never()).onNext(false); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(true); + verify(subscriber, never()).onNext(false); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testAnyWithPredicate1Flowable() { Flowable w = Flowable.just(1, 2, 3); - Flowable observable = w.any(new Predicate() { + Flowable flowable = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; } }).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, never()).onNext(false); - verify(observer, times(1)).onNext(true); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onNext(false); + verify(subscriber, times(1)).onNext(true); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testExists1Flowable() { Flowable w = Flowable.just(1, 2, 3); - Flowable observable = w.any(new Predicate() { + Flowable flowable = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; } }).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, never()).onNext(false); - verify(observer, times(1)).onNext(true); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onNext(false); + verify(subscriber, times(1)).onNext(true); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testAnyWithPredicate2Flowable() { Flowable w = Flowable.just(1, 2, 3); - Flowable observable = w.any(new Predicate() { + Flowable flowable = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 1; } }).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(false); - verify(observer, never()).onNext(true); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(false); + verify(subscriber, never()).onNext(true); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testAnyWithEmptyAndPredicateFlowable() { // If the source is empty, always output false. Flowable w = Flowable.empty(); - Flowable observable = w.any(new Predicate() { + Flowable flowable = w.any(new Predicate() { @Override public boolean test(Integer t) { return true; } }).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(false); - verify(observer, never()).onNext(true); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(false); + verify(subscriber, never()).onNext(true); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testWithFollowingFirstFlowable() { - Flowable o = Flowable.fromArray(1, 3, 5, 6); - Flowable anyEven = o.any(new Predicate() { + Flowable f = Flowable.fromArray(1, 3, 5, 6); + Flowable anyEven = f.any(new Predicate() { @Override public boolean test(Integer i) { return i % 2 == 0; @@ -566,15 +566,15 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>() { @Override - public Publisher apply(Flowable o) throws Exception { - return o.any(Functions.alwaysTrue()).toFlowable(); + public Publisher apply(Flowable f) throws Exception { + return f.any(Functions.alwaysTrue()).toFlowable(); } }); TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function, Single>() { @Override - public Single apply(Flowable o) throws Exception { - return o.any(Functions.alwaysTrue()); + public Single apply(Flowable f) throws Exception { + return f.any(Functions.alwaysTrue()); } }); } @@ -585,13 +585,13 @@ public void predicateThrowsSuppressOthers() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onNext(2); - observer.onError(new IOException()); - observer.onComplete(); + subscriber.onNext(1); + subscriber.onNext(2); + subscriber.onError(new IOException()); + subscriber.onComplete(); } } .any(new Predicate() { @@ -616,13 +616,13 @@ public void badSourceSingle() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException("First")); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException("First")); - observer.onNext(1); - observer.onError(new TestException("Second")); - observer.onComplete(); + subscriber.onNext(1); + subscriber.onError(new TestException("Second")); + subscriber.onComplete(); } } .any(Functions.alwaysTrue()) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java index ad90e3a15c..23cf4ecf02 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java @@ -14,15 +14,16 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertFalse; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import org.junit.Test; +import org.mockito.Mockito; import org.reactivestreams.Subscriber; import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.processors.PublishProcessor; -import io.reactivex.subscribers.DefaultSubscriber; public class FlowableAsObservableTest { @Test @@ -33,16 +34,16 @@ public void testHiding() { assertFalse(dst instanceof PublishProcessor); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - dst.subscribe(o); + dst.subscribe(subscriber); src.onNext(1); src.onComplete(); - verify(o).onNext(1); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testHidingError() { @@ -52,15 +53,14 @@ public void testHidingError() { assertFalse(dst instanceof PublishProcessor); - @SuppressWarnings("unchecked") - DefaultSubscriber o = mock(DefaultSubscriber.class); + Subscriber subscriber = TestHelper.mockSubscriber(); - dst.subscribe(o); + dst.subscribe(subscriber); src.onError(new TestException()); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onNext(Mockito.any()); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java index 88fa5e11cb..2ed817df9a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java @@ -489,9 +489,9 @@ public void run() { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - s[0] = observer; + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + s[0] = subscriber; } }.blockingSubscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java index c8c75031bc..aa8c3ef23c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java @@ -42,13 +42,13 @@ public class FlowableBufferTest { - private Subscriber> observer; + private Subscriber> subscriber; private TestScheduler scheduler; private Scheduler.Worker innerScheduler; @Before public void before() { - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); scheduler = new TestScheduler(); innerScheduler = scheduler.createWorker(); } @@ -58,37 +58,37 @@ public void testComplete() { Flowable source = Flowable.empty(); Flowable> buffered = source.buffer(3, 3); - buffered.subscribe(observer); + buffered.subscribe(subscriber); - Mockito.verify(observer, Mockito.never()).onNext(Mockito.anyList()); - Mockito.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); - Mockito.verify(observer, Mockito.times(1)).onComplete(); + Mockito.verify(subscriber, Mockito.never()).onNext(Mockito.anyList()); + Mockito.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class)); + Mockito.verify(subscriber, Mockito.times(1)).onComplete(); } @Test public void testSkipAndCountOverlappingBuffers() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext("one"); - observer.onNext("two"); - observer.onNext("three"); - observer.onNext("four"); - observer.onNext("five"); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("one"); + subscriber.onNext("two"); + subscriber.onNext("three"); + subscriber.onNext("four"); + subscriber.onNext("five"); } }); Flowable> buffered = source.buffer(3, 1); - buffered.subscribe(observer); + buffered.subscribe(subscriber); - InOrder inOrder = Mockito.inOrder(observer); - inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two", "three")); - inOrder.verify(observer, Mockito.times(1)).onNext(list("two", "three", "four")); - inOrder.verify(observer, Mockito.times(1)).onNext(list("three", "four", "five")); - inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyList()); - inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); - inOrder.verify(observer, Mockito.never()).onComplete(); + InOrder inOrder = Mockito.inOrder(subscriber); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("one", "two", "three")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("two", "three", "four")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("three", "four", "five")); + inOrder.verify(subscriber, Mockito.never()).onNext(Mockito.anyList()); + inOrder.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class)); + inOrder.verify(subscriber, Mockito.never()).onComplete(); } @Test @@ -96,14 +96,14 @@ public void testSkipAndCountGaplessBuffers() { Flowable source = Flowable.just("one", "two", "three", "four", "five"); Flowable> buffered = source.buffer(3, 3); - buffered.subscribe(observer); + buffered.subscribe(subscriber); - InOrder inOrder = Mockito.inOrder(observer); - inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two", "three")); - inOrder.verify(observer, Mockito.times(1)).onNext(list("four", "five")); - inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyList()); - inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); - inOrder.verify(observer, Mockito.times(1)).onComplete(); + InOrder inOrder = Mockito.inOrder(subscriber); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("one", "two", "three")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("four", "five")); + inOrder.verify(subscriber, Mockito.never()).onNext(Mockito.anyList()); + inOrder.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class)); + inOrder.verify(subscriber, Mockito.times(1)).onComplete(); } @Test @@ -111,104 +111,104 @@ public void testSkipAndCountBuffersWithGaps() { Flowable source = Flowable.just("one", "two", "three", "four", "five"); Flowable> buffered = source.buffer(2, 3); - buffered.subscribe(observer); + buffered.subscribe(subscriber); - InOrder inOrder = Mockito.inOrder(observer); - inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two")); - inOrder.verify(observer, Mockito.times(1)).onNext(list("four", "five")); - inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyList()); - inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); - inOrder.verify(observer, Mockito.times(1)).onComplete(); + InOrder inOrder = Mockito.inOrder(subscriber); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("one", "two")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("four", "five")); + inOrder.verify(subscriber, Mockito.never()).onNext(Mockito.anyList()); + inOrder.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class)); + inOrder.verify(subscriber, Mockito.times(1)).onComplete(); } @Test public void testTimedAndCount() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, "one", 10); - push(observer, "two", 90); - push(observer, "three", 110); - push(observer, "four", 190); - push(observer, "five", 210); - complete(observer, 250); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 10); + push(subscriber, "two", 90); + push(subscriber, "three", 110); + push(subscriber, "four", 190); + push(subscriber, "five", 210); + complete(subscriber, 250); } }); Flowable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, scheduler, 2); - buffered.subscribe(observer); + buffered.subscribe(subscriber); - InOrder inOrder = Mockito.inOrder(observer); + InOrder inOrder = Mockito.inOrder(subscriber); scheduler.advanceTimeTo(100, TimeUnit.MILLISECONDS); - inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("one", "two")); scheduler.advanceTimeTo(200, TimeUnit.MILLISECONDS); - inOrder.verify(observer, Mockito.times(1)).onNext(list("three", "four")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("three", "four")); scheduler.advanceTimeTo(300, TimeUnit.MILLISECONDS); - inOrder.verify(observer, Mockito.times(1)).onNext(list("five")); - inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyList()); - inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); - inOrder.verify(observer, Mockito.times(1)).onComplete(); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("five")); + inOrder.verify(subscriber, Mockito.never()).onNext(Mockito.anyList()); + inOrder.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class)); + inOrder.verify(subscriber, Mockito.times(1)).onComplete(); } @Test public void testTimed() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, "one", 97); - push(observer, "two", 98); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 97); + push(subscriber, "two", 98); /** * Changed from 100. Because scheduling the cut to 100ms happens before this * Flowable even runs due how lift works, pushing at 100ms would execute after the * buffer cut. */ - push(observer, "three", 99); - push(observer, "four", 101); - push(observer, "five", 102); - complete(observer, 150); + push(subscriber, "three", 99); + push(subscriber, "four", 101); + push(subscriber, "five", 102); + complete(subscriber, 150); } }); Flowable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); - buffered.subscribe(observer); + buffered.subscribe(subscriber); - InOrder inOrder = Mockito.inOrder(observer); + InOrder inOrder = Mockito.inOrder(subscriber); scheduler.advanceTimeTo(101, TimeUnit.MILLISECONDS); - inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two", "three")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("one", "two", "three")); scheduler.advanceTimeTo(201, TimeUnit.MILLISECONDS); - inOrder.verify(observer, Mockito.times(1)).onNext(list("four", "five")); - inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyList()); - inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); - inOrder.verify(observer, Mockito.times(1)).onComplete(); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("four", "five")); + inOrder.verify(subscriber, Mockito.never()).onNext(Mockito.anyList()); + inOrder.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class)); + inOrder.verify(subscriber, Mockito.times(1)).onComplete(); } @Test public void testFlowableBasedOpenerAndCloser() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, "one", 10); - push(observer, "two", 60); - push(observer, "three", 110); - push(observer, "four", 160); - push(observer, "five", 210); - complete(observer, 500); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 10); + push(subscriber, "two", 60); + push(subscriber, "three", 110); + push(subscriber, "four", 160); + push(subscriber, "five", 210); + complete(subscriber, 500); } }); Flowable openings = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, new Object(), 50); - push(observer, new Object(), 200); - complete(observer, 250); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, new Object(), 50); + push(subscriber, new Object(), 200); + complete(subscriber, 250); } }); @@ -217,39 +217,39 @@ public void subscribe(Subscriber observer) { public Flowable apply(Object opening) { return Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, new Object(), 100); - complete(observer, 101); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, new Object(), 100); + complete(subscriber, 101); } }); } }; Flowable> buffered = source.buffer(openings, closer); - buffered.subscribe(observer); + buffered.subscribe(subscriber); - InOrder inOrder = Mockito.inOrder(observer); + InOrder inOrder = Mockito.inOrder(subscriber); scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS); - inOrder.verify(observer, Mockito.times(1)).onNext(list("two", "three")); - inOrder.verify(observer, Mockito.times(1)).onNext(list("five")); - inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyList()); - inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); - inOrder.verify(observer, Mockito.times(1)).onComplete(); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("two", "three")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("five")); + inOrder.verify(subscriber, Mockito.never()).onNext(Mockito.anyList()); + inOrder.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class)); + inOrder.verify(subscriber, Mockito.times(1)).onComplete(); } @Test public void testFlowableBasedCloser() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, "one", 10); - push(observer, "two", 60); - push(observer, "three", 110); - push(observer, "four", 160); - push(observer, "five", 210); - complete(observer, 250); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 10); + push(subscriber, "two", 60); + push(subscriber, "three", 110); + push(subscriber, "four", 160); + push(subscriber, "five", 210); + complete(subscriber, 250); } }); @@ -258,28 +258,28 @@ public void subscribe(Subscriber observer) { public Flowable call() { return Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, new Object(), 100); - push(observer, new Object(), 200); - push(observer, new Object(), 300); - complete(observer, 301); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, new Object(), 100); + push(subscriber, new Object(), 200); + push(subscriber, new Object(), 300); + complete(subscriber, 301); } }); } }; Flowable> buffered = source.buffer(closer); - buffered.subscribe(observer); + buffered.subscribe(subscriber); - InOrder inOrder = Mockito.inOrder(observer); + InOrder inOrder = Mockito.inOrder(subscriber); scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS); - inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two")); - inOrder.verify(observer, Mockito.times(1)).onNext(list("three", "four")); - inOrder.verify(observer, Mockito.times(1)).onNext(list("five")); - inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyList()); - inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); - inOrder.verify(observer, Mockito.times(1)).onComplete(); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("one", "two")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("three", "four")); + inOrder.verify(subscriber, Mockito.times(1)).onNext(list("five")); + inOrder.verify(subscriber, Mockito.never()).onNext(Mockito.anyList()); + inOrder.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class)); + inOrder.verify(subscriber, Mockito.times(1)).onComplete(); } @Test @@ -324,20 +324,20 @@ private List list(String... args) { return list; } - private void push(final Subscriber observer, final T value, int delay) { + private void push(final Subscriber subscriber, final T value, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onNext(value); + subscriber.onNext(value); } }, delay, TimeUnit.MILLISECONDS); } - private void complete(final Subscriber observer, int delay) { + private void complete(final Subscriber subscriber, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onComplete(); + subscriber.onComplete(); } }, delay, TimeUnit.MILLISECONDS); } @@ -346,8 +346,8 @@ public void run() { public void testBufferStopsWhenUnsubscribed1() { Flowable source = Flowable.never(); - Subscriber> o = TestHelper.mockSubscriber(); - TestSubscriber> ts = new TestSubscriber>(o, 0L); + Subscriber> subscriber = TestHelper.mockSubscriber(); + TestSubscriber> ts = new TestSubscriber>(subscriber, 0L); source.buffer(100, 200, TimeUnit.MILLISECONDS, scheduler) .doOnNext(new Consumer>() { @@ -358,11 +358,11 @@ public void accept(List pv) { }) .subscribe(ts); - InOrder inOrder = Mockito.inOrder(o); + InOrder inOrder = Mockito.inOrder(subscriber); scheduler.advanceTimeBy(1001, TimeUnit.MILLISECONDS); - inOrder.verify(o, times(5)).onNext(Arrays. asList()); + inOrder.verify(subscriber, times(5)).onNext(Arrays. asList()); ts.dispose(); @@ -376,10 +376,10 @@ public void bufferWithBONormal1() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = Mockito.inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = Mockito.inOrder(subscriber); - source.buffer(boundary).subscribe(o); + source.buffer(boundary).subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -387,23 +387,23 @@ public void bufferWithBONormal1() { boundary.onNext(1); - inOrder.verify(o, times(1)).onNext(Arrays.asList(1, 2, 3)); + inOrder.verify(subscriber, times(1)).onNext(Arrays.asList(1, 2, 3)); source.onNext(4); source.onNext(5); boundary.onNext(2); - inOrder.verify(o, times(1)).onNext(Arrays.asList(4, 5)); + inOrder.verify(subscriber, times(1)).onNext(Arrays.asList(4, 5)); source.onNext(6); boundary.onComplete(); - inOrder.verify(o, times(1)).onNext(Arrays.asList(6)); + inOrder.verify(subscriber, times(1)).onNext(Arrays.asList(6)); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -411,18 +411,18 @@ public void bufferWithBOEmptyLastViaBoundary() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = Mockito.inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = Mockito.inOrder(subscriber); - source.buffer(boundary).subscribe(o); + source.buffer(boundary).subscribe(subscriber); boundary.onComplete(); - inOrder.verify(o, times(1)).onNext(Arrays.asList()); + inOrder.verify(subscriber, times(1)).onNext(Arrays.asList()); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -430,18 +430,18 @@ public void bufferWithBOEmptyLastViaSource() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = Mockito.inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = Mockito.inOrder(subscriber); - source.buffer(boundary).subscribe(o); + source.buffer(boundary).subscribe(subscriber); source.onComplete(); - inOrder.verify(o, times(1)).onNext(Arrays.asList()); + inOrder.verify(subscriber, times(1)).onNext(Arrays.asList()); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -449,19 +449,19 @@ public void bufferWithBOEmptyLastViaBoth() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = Mockito.inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = Mockito.inOrder(subscriber); - source.buffer(boundary).subscribe(o); + source.buffer(boundary).subscribe(subscriber); source.onComplete(); boundary.onComplete(); - inOrder.verify(o, times(1)).onNext(Arrays.asList()); + inOrder.verify(subscriber, times(1)).onNext(Arrays.asList()); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -469,15 +469,15 @@ public void bufferWithBOSourceThrows() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.buffer(boundary).subscribe(o); + source.buffer(boundary).subscribe(subscriber); source.onNext(1); source.onError(new TestException()); - verify(o).onError(any(TestException.class)); - verify(o, never()).onComplete(); - verify(o, never()).onNext(any()); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -485,16 +485,16 @@ public void bufferWithBOBoundaryThrows() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.buffer(boundary).subscribe(o); + source.buffer(boundary).subscribe(subscriber); source.onNext(1); boundary.onError(new TestException()); - verify(o).onError(any(TestException.class)); - verify(o, never()).onComplete(); - verify(o, never()).onNext(any()); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test(timeout = 2000) public void bufferWithSizeTake1() { @@ -502,13 +502,13 @@ public void bufferWithSizeTake1() { Flowable> result = source.buffer(2).take(1); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 1)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 1)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test(timeout = 2000) @@ -517,13 +517,13 @@ public void bufferWithSizeSkipTake1() { Flowable> result = source.buffer(2, 3).take(1); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 1)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 1)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test(timeout = 2000) public void bufferWithTimeTake1() { @@ -531,15 +531,15 @@ public void bufferWithTimeTake1() { Flowable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler).take(1); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); scheduler.advanceTimeBy(5, TimeUnit.SECONDS); - verify(o).onNext(Arrays.asList(0L, 1L)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(0L, 1L)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test(timeout = 2000) public void bufferWithTimeSkipTake2() { @@ -547,18 +547,19 @@ public void bufferWithTimeSkipTake2() { Flowable> result = source.buffer(100, 60, TimeUnit.MILLISECONDS, scheduler).take(2); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); scheduler.advanceTimeBy(5, TimeUnit.SECONDS); - inOrder.verify(o).onNext(Arrays.asList(0L, 1L)); - inOrder.verify(o).onNext(Arrays.asList(1L, 2L)); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(Arrays.asList(0L, 1L)); + inOrder.verify(subscriber).onNext(Arrays.asList(1L, 2L)); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } + @Test(timeout = 2000) public void bufferWithBoundaryTake2() { Flowable boundary = Flowable.interval(60, 60, TimeUnit.MILLISECONDS, scheduler); @@ -566,17 +567,17 @@ public void bufferWithBoundaryTake2() { Flowable> result = source.buffer(boundary).take(2); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); scheduler.advanceTimeBy(5, TimeUnit.SECONDS); - inOrder.verify(o).onNext(Arrays.asList(0L)); - inOrder.verify(o).onNext(Arrays.asList(1L)); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(Arrays.asList(0L)); + inOrder.verify(subscriber).onNext(Arrays.asList(1L)); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @@ -594,8 +595,8 @@ public Flowable apply(Long t1) { Flowable> result = source.buffer(start, end).take(2); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); result .doOnNext(new Consumer>() { @@ -604,14 +605,14 @@ public void accept(List pv) { System.out.println(pv); } }) - .subscribe(o); + .subscribe(subscriber); scheduler.advanceTimeBy(5, TimeUnit.SECONDS); - inOrder.verify(o).onNext(Arrays.asList(1L, 2L, 3L)); - inOrder.verify(o).onNext(Arrays.asList(3L, 4L)); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(Arrays.asList(1L, 2L, 3L)); + inOrder.verify(subscriber).onNext(Arrays.asList(3L, 4L)); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void bufferWithSizeThrows() { @@ -619,22 +620,22 @@ public void bufferWithSizeThrows() { Flowable> result = source.buffer(2); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); source.onNext(3); source.onError(new TestException()); - inOrder.verify(o).onNext(Arrays.asList(1, 2)); - inOrder.verify(o).onError(any(TestException.class)); + inOrder.verify(subscriber).onNext(Arrays.asList(1, 2)); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(Arrays.asList(3)); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(Arrays.asList(3)); + verify(subscriber, never()).onComplete(); } @@ -644,10 +645,10 @@ public void bufferWithTimeThrows() { Flowable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -656,11 +657,11 @@ public void bufferWithTimeThrows() { source.onError(new TestException()); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); - inOrder.verify(o).onNext(Arrays.asList(1, 2)); - inOrder.verify(o).onError(any(TestException.class)); + inOrder.verify(subscriber).onNext(Arrays.asList(1, 2)); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(Arrays.asList(3)); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(Arrays.asList(3)); + verify(subscriber, never()).onComplete(); } @@ -670,17 +671,17 @@ public void bufferWithTimeAndSize() { Flowable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler, 2).take(3); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); scheduler.advanceTimeBy(5, TimeUnit.SECONDS); - inOrder.verify(o).onNext(Arrays.asList(0L, 1L)); - inOrder.verify(o).onNext(Arrays.asList(2L)); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(Arrays.asList(0L, 1L)); + inOrder.verify(subscriber).onNext(Arrays.asList(2L)); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void bufferWithStartEndStartThrows() { @@ -697,18 +698,18 @@ public Flowable apply(Integer t1) { Flowable> result = source.buffer(start, end); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); start.onNext(1); source.onNext(1); source.onNext(2); start.onError(new TestException()); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } @Test public void bufferWithStartEndEndFunctionThrows() { @@ -725,17 +726,17 @@ public Flowable apply(Integer t1) { Flowable> result = source.buffer(start, end); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); start.onNext(1); source.onNext(1); source.onNext(2); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } @Test public void bufferWithStartEndEndThrows() { @@ -752,17 +753,17 @@ public Flowable apply(Integer t1) { Flowable> result = source.buffer(start, end); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); start.onNext(1); source.onNext(1); source.onNext(2); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } @Test @@ -992,22 +993,22 @@ public void onNext(List t) { } @Test(timeout = 3000) public void testBufferWithTimeDoesntUnsubscribeDownstream() throws InterruptedException { - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); final CountDownLatch cdl = new CountDownLatch(1); ResourceSubscriber s = new ResourceSubscriber() { @Override public void onNext(Object t) { - o.onNext(t); + subscriber.onNext(t); } @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); cdl.countDown(); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); cdl.countDown(); } }; @@ -1016,9 +1017,9 @@ public void onComplete() { cdl.await(); - verify(o).onNext(Arrays.asList(1)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); assertFalse(s.isDisposed()); } @@ -2480,20 +2481,20 @@ public List call() throws Exception { public void bufferExactBoundaryBadSource() { Flowable pp = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onComplete(); - observer.onNext(1); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); + subscriber.onNext(1); + subscriber.onComplete(); } }; final AtomicReference> ref = new AtomicReference>(); Flowable b = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - ref.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + ref.set(subscriber); } }; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java index 2524d5eb28..c26e612e09 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java @@ -84,19 +84,19 @@ public void testColdReplayBackpressure() { @Test public void testCache() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); new Thread(new Runnable() { @Override public void run() { counter.incrementAndGet(); System.out.println("published observable being executed"); - observer.onNext("one"); - observer.onComplete(); + subscriber.onNext("one"); + subscriber.onComplete(); } }).start(); } @@ -106,7 +106,7 @@ public void run() { final CountDownLatch latch = new CountDownLatch(2); // subscribe once - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { assertEquals("one", v); @@ -116,7 +116,7 @@ public void accept(String v) { }); // subscribe again - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { assertEquals("one", v); @@ -134,10 +134,10 @@ public void accept(String v) { @Test public void testUnsubscribeSource() throws Exception { Action unsubscribe = mock(Action.class); - Flowable o = Flowable.just(1).doOnCancel(unsubscribe).cache(); - o.subscribe(); - o.subscribe(); - o.subscribe(); + Flowable f = Flowable.just(1).doOnCancel(unsubscribe).cache(); + f.subscribe(); + f.subscribe(); + f.subscribe(); verify(unsubscribe, times(1)).run(); } @@ -305,11 +305,11 @@ public void dispose() { @Test public void disposeOnArrival2() { - Flowable o = PublishProcessor.create().cache(); + Flowable f = PublishProcessor.create().cache(); - o.test(); + f.test(); - o.test(0L, true) + f.test(0L, true) .assertEmpty(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCastTest.java index 370f32d18a..4506f67afe 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCastTest.java @@ -27,30 +27,28 @@ public class FlowableCastTest { @Test public void testCast() { Flowable source = Flowable.just(1, 2); - Flowable observable = source.cast(Integer.class); + Flowable flowable = source.cast(Integer.class); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext(1); - verify(observer, times(1)).onNext(1); - verify(observer, never()).onError( - any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onNext(1); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testCastWithWrongType() { Flowable source = Flowable.just(1, 2); - Flowable observable = source.cast(Boolean.class); + Flowable flowable = source.cast(Boolean.class); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onError( - any(ClassCastException.class)); + verify(subscriber, times(1)).onError(any(ClassCastException.class)); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java index dd95488500..0599234015 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java @@ -178,16 +178,16 @@ public void testCombineLatest2Types() { BiFunction combineLatestFunction = getConcatStringIntegerCombineLatestFunction(); /* define an Observer to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable w = Flowable.combineLatest(Flowable.just("one", "two"), Flowable.just(2, 3, 4), combineLatestFunction); - w.subscribe(observer); + w.subscribe(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("two2"); - verify(observer, times(1)).onNext("two3"); - verify(observer, times(1)).onNext("two4"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("two2"); + verify(subscriber, times(1)).onNext("two3"); + verify(subscriber, times(1)).onNext("two4"); } @Test @@ -195,14 +195,14 @@ public void testCombineLatest3TypesA() { Function3 combineLatestFunction = getConcatStringIntegerIntArrayCombineLatestFunction(); /* define an Observer to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable w = Flowable.combineLatest(Flowable.just("one", "two"), Flowable.just(2), Flowable.just(new int[] { 4, 5, 6 }), combineLatestFunction); - w.subscribe(observer); + w.subscribe(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("two2[4, 5, 6]"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("two2[4, 5, 6]"); } @Test @@ -210,15 +210,15 @@ public void testCombineLatest3TypesB() { Function3 combineLatestFunction = getConcatStringIntegerIntArrayCombineLatestFunction(); /* define an Observer to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); 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); + w.subscribe(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("one2[4, 5, 6]"); - verify(observer, times(1)).onNext("one2[7, 8]"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one2[4, 5, 6]"); + verify(subscriber, times(1)).onNext("one2[7, 8]"); } private Function3 getConcat3StringsCombineLatestFunction() { @@ -285,33 +285,33 @@ public void combineSimple() { Flowable source = Flowable.combineLatest(a, b, or); - Subscriber observer = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.subscribe(observer); + source.subscribe(subscriber); a.onNext(1); - inOrder.verify(observer, never()).onNext(any()); + inOrder.verify(subscriber, never()).onNext(any()); a.onNext(2); - inOrder.verify(observer, never()).onNext(any()); + inOrder.verify(subscriber, never()).onNext(any()); b.onNext(0x10); - inOrder.verify(observer, times(1)).onNext(0x12); + inOrder.verify(subscriber, times(1)).onNext(0x12); b.onNext(0x20); - inOrder.verify(observer, times(1)).onNext(0x22); + inOrder.verify(subscriber, times(1)).onNext(0x22); b.onComplete(); - inOrder.verify(observer, never()).onComplete(); + inOrder.verify(subscriber, never()).onComplete(); a.onComplete(); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); a.onNext(3); b.onNext(0x30); @@ -319,7 +319,7 @@ public void combineSimple() { b.onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -329,44 +329,44 @@ public void combineMultipleObservers() { Flowable source = Flowable.combineLatest(a, b, or); - Subscriber observer1 = TestHelper.mockSubscriber(); + Subscriber subscriber1 = TestHelper.mockSubscriber(); - Subscriber observer2 = TestHelper.mockSubscriber(); + Subscriber subscriber2 = TestHelper.mockSubscriber(); - InOrder inOrder1 = inOrder(observer1); - InOrder inOrder2 = inOrder(observer2); + InOrder inOrder1 = inOrder(subscriber1); + InOrder inOrder2 = inOrder(subscriber2); - source.subscribe(observer1); - source.subscribe(observer2); + source.subscribe(subscriber1); + source.subscribe(subscriber2); a.onNext(1); - inOrder1.verify(observer1, never()).onNext(any()); - inOrder2.verify(observer2, never()).onNext(any()); + inOrder1.verify(subscriber1, never()).onNext(any()); + inOrder2.verify(subscriber2, never()).onNext(any()); a.onNext(2); - inOrder1.verify(observer1, never()).onNext(any()); - inOrder2.verify(observer2, never()).onNext(any()); + inOrder1.verify(subscriber1, never()).onNext(any()); + inOrder2.verify(subscriber2, never()).onNext(any()); b.onNext(0x10); - inOrder1.verify(observer1, times(1)).onNext(0x12); - inOrder2.verify(observer2, times(1)).onNext(0x12); + inOrder1.verify(subscriber1, times(1)).onNext(0x12); + inOrder2.verify(subscriber2, times(1)).onNext(0x12); b.onNext(0x20); - inOrder1.verify(observer1, times(1)).onNext(0x22); - inOrder2.verify(observer2, times(1)).onNext(0x22); + inOrder1.verify(subscriber1, times(1)).onNext(0x22); + inOrder2.verify(subscriber2, times(1)).onNext(0x22); b.onComplete(); - inOrder1.verify(observer1, never()).onComplete(); - inOrder2.verify(observer2, never()).onComplete(); + inOrder1.verify(subscriber1, never()).onComplete(); + inOrder2.verify(subscriber2, never()).onComplete(); a.onComplete(); - inOrder1.verify(observer1, times(1)).onComplete(); - inOrder2.verify(observer2, times(1)).onComplete(); + inOrder1.verify(subscriber1, times(1)).onComplete(); + inOrder2.verify(subscriber2, times(1)).onComplete(); a.onNext(3); b.onNext(0x30); @@ -375,8 +375,8 @@ public void combineMultipleObservers() { inOrder1.verifyNoMoreInteractions(); inOrder2.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); - verify(observer2, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); + verify(subscriber2, never()).onError(any(Throwable.class)); } @Test @@ -386,19 +386,19 @@ public void testFirstNeverProduces() { Flowable source = Flowable.combineLatest(a, b, or); - Subscriber observer = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.subscribe(observer); + source.subscribe(subscriber); b.onNext(0x10); b.onNext(0x20); a.onComplete(); - inOrder.verify(observer, times(1)).onComplete(); - verify(observer, never()).onNext(any()); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -408,10 +408,10 @@ public void testSecondNeverProduces() { Flowable source = Flowable.combineLatest(a, b, or); - Subscriber observer = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.subscribe(observer); + source.subscribe(subscriber); a.onNext(0x1); a.onNext(0x2); @@ -419,9 +419,9 @@ public void testSecondNeverProduces() { b.onComplete(); a.onComplete(); - inOrder.verify(observer, times(1)).onComplete(); - verify(observer, never()).onNext(any()); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } public void test0Sources() { @@ -449,13 +449,13 @@ public List apply(Object[] args) { Flowable> result = Flowable.combineLatest(sources, func); - Subscriber> o = TestHelper.mockSubscriber(); + Subscriber> subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(values); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(values); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } } @@ -480,7 +480,7 @@ public List apply(Object[] args) { Flowable> result = Flowable.combineLatest(sources, func); - final Subscriber> o = TestHelper.mockSubscriber(); + final Subscriber> subscriber = TestHelper.mockSubscriber(); final CountDownLatch cdl = new CountDownLatch(1); @@ -488,18 +488,18 @@ public List apply(Object[] args) { @Override public void onNext(List t) { - o.onNext(t); + subscriber.onNext(t); } @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); cdl.countDown(); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); cdl.countDown(); } }; @@ -508,9 +508,9 @@ public void onComplete() { cdl.await(); - verify(o).onNext(values); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(values); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } } @@ -527,13 +527,13 @@ public List apply(Integer t1, Integer t2) { } }); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 2)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 2)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -550,13 +550,13 @@ public List apply(Integer t1, Integer t2, Integer t3) { } }); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 2, 3)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 2, 3)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -574,13 +574,13 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4) { } }); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 2, 3, 4)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 2, 3, 4)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -599,13 +599,13 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 2, 3, 4, 5)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 2, 3, 4, 5)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -625,13 +625,13 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 2, 3, 4, 5, 6)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 2, 3, 4, 5, 6)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -652,13 +652,13 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 2, 3, 4, 5, 6, 7)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 2, 3, 4, 5, 6, 7)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -680,13 +680,13 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -709,13 +709,13 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -730,13 +730,13 @@ public Object apply(Object[] args) { }); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onComplete(); - verify(o, never()).onNext(any()); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @@ -808,14 +808,14 @@ public void testCombineLatestRequestOverflow() throws InterruptedException { @SuppressWarnings("unchecked") List> sources = Arrays.asList(Flowable.fromArray(1, 2, 3, 4), Flowable.fromArray(5,6,7,8)); - Flowable o = Flowable.combineLatest(sources,new Function() { + Flowable f = 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 DefaultSubscriber() { + f.subscribeOn(Schedulers.computation()).subscribe(new DefaultSubscriber() { @Override public void onStart() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java index 90c0c59691..39a9427181 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java @@ -588,11 +588,11 @@ public Flowable apply(Integer t) { @Test public void testReentrantWork() { - final PublishProcessor subject = PublishProcessor.create(); + final PublishProcessor processor = PublishProcessor.create(); final AtomicBoolean once = new AtomicBoolean(); - subject.concatMapEager(new Function>() { + processor.concatMapEager(new Function>() { @Override public Flowable apply(Integer t) { return Flowable.just(t); @@ -602,13 +602,13 @@ public Flowable apply(Integer t) { @Override public void accept(Integer t) { if (once.compareAndSet(false, true)) { - subject.onNext(2); + processor.onNext(2); } } }) .subscribe(ts); - subject.onNext(1); + processor.onNext(1); ts.assertNoErrors(); ts.assertNotComplete(); @@ -1051,8 +1051,8 @@ public Flowable apply(Integer v) throws Exception { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.concatMapEager(new Function>() { + public Flowable apply(Flowable f) throws Exception { + return f.concatMapEager(new Function>() { @Override public Flowable apply(Object v) throws Exception { return Flowable.just(v); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java index 82c8765f85..7c53083548 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java @@ -41,7 +41,7 @@ public class FlowableConcatTest { @Test public void testConcat() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; @@ -50,14 +50,14 @@ public void testConcat() { final Flowable even = Flowable.fromArray(e); Flowable concat = Flowable.concat(odds, even); - concat.subscribe(observer); + concat.subscribe(subscriber); - verify(observer, times(7)).onNext(anyString()); + verify(subscriber, times(7)).onNext(anyString()); } @Test public void testConcatWithList() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; @@ -68,14 +68,14 @@ public void testConcatWithList() { list.add(odds); list.add(even); Flowable concat = Flowable.concat(Flowable.fromIterable(list)); - concat.subscribe(observer); + concat.subscribe(subscriber); - verify(observer, times(7)).onNext(anyString()); + verify(subscriber, times(7)).onNext(anyString()); } @Test public void testConcatObservableOfObservables() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; @@ -83,23 +83,23 @@ public void testConcatObservableOfObservables() { final Flowable odds = Flowable.fromArray(o); final Flowable even = Flowable.fromArray(e); - Flowable> observableOfObservables = Flowable.unsafeCreate(new Publisher>() { + Flowable> flowableOfFlowables = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); // simulate what would happen in an observable - observer.onNext(odds); - observer.onNext(even); - observer.onComplete(); + subscriber.onNext(odds); + subscriber.onNext(even); + subscriber.onComplete(); } }); - Flowable concat = Flowable.concat(observableOfObservables); + Flowable concat = Flowable.concat(flowableOfFlowables); - concat.subscribe(observer); + concat.subscribe(subscriber); - verify(observer, times(7)).onNext(anyString()); + verify(subscriber, times(7)).onNext(anyString()); } /** @@ -107,12 +107,12 @@ public void subscribe(Subscriber> observer) { */ @Test public void testSimpleAsyncConcat() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); TestObservable o1 = new TestObservable("one", "two", "three"); TestObservable o2 = new TestObservable("four", "five", "six"); - Flowable.concat(Flowable.unsafeCreate(o1), Flowable.unsafeCreate(o2)).subscribe(observer); + Flowable.concat(Flowable.unsafeCreate(o1), Flowable.unsafeCreate(o2)).subscribe(subscriber); try { // wait for async observables to complete @@ -122,13 +122,13 @@ public void testSimpleAsyncConcat() { throw new RuntimeException("failed waiting on threads"); } - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, times(1)).onNext("four"); - inOrder.verify(observer, times(1)).onNext("five"); - inOrder.verify(observer, times(1)).onNext("six"); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, times(1)).onNext("four"); + inOrder.verify(subscriber, times(1)).onNext("five"); + inOrder.verify(subscriber, times(1)).onNext("six"); } @Test @@ -147,7 +147,7 @@ public void testNestedAsyncConcatLoop() throws Throwable { */ @Test public void testNestedAsyncConcat() throws InterruptedException { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final TestObservable o1 = new TestObservable("one", "two", "three"); final TestObservable o2 = new TestObservable("four", "five", "six"); @@ -162,9 +162,9 @@ public void testNestedAsyncConcat() throws InterruptedException { Flowable> observableOfObservables = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(final Subscriber> observer) { + public void subscribe(final Subscriber> subscriber) { final Disposable d = Disposables.empty(); - observer.onSubscribe(new Subscription() { + subscriber.onSubscribe(new Subscription() { @Override public void request(long n) { @@ -182,30 +182,30 @@ public void run() { // emit first if (!d.isDisposed()) { System.out.println("Emit o1"); - observer.onNext(Flowable.unsafeCreate(o1)); + subscriber.onNext(Flowable.unsafeCreate(o1)); } // emit second if (!d.isDisposed()) { System.out.println("Emit o2"); - observer.onNext(Flowable.unsafeCreate(o2)); + subscriber.onNext(Flowable.unsafeCreate(o2)); } // wait until sometime later and emit third try { allowThird.await(); } catch (InterruptedException e) { - observer.onError(e); + subscriber.onError(e); } if (!d.isDisposed()) { System.out.println("Emit o3"); - observer.onNext(Flowable.unsafeCreate(o3)); + subscriber.onNext(Flowable.unsafeCreate(o3)); } } catch (Throwable e) { - observer.onError(e); + subscriber.onError(e); } finally { System.out.println("Done parent Flowable"); - observer.onComplete(); + subscriber.onComplete(); parentHasFinished.countDown(); } } @@ -215,7 +215,7 @@ public void run() { } }); - Flowable.concat(observableOfObservables).subscribe(observer); + Flowable.concat(observableOfObservables).subscribe(subscriber); // wait for parent to start parentHasStarted.await(); @@ -230,20 +230,20 @@ public void run() { throw new RuntimeException("failed waiting on threads", e); } - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, times(1)).onNext("four"); - inOrder.verify(observer, times(1)).onNext("five"); - inOrder.verify(observer, times(1)).onNext("six"); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, times(1)).onNext("four"); + inOrder.verify(subscriber, times(1)).onNext("five"); + inOrder.verify(subscriber, times(1)).onNext("six"); // we shouldn't have the following 3 yet - inOrder.verify(observer, never()).onNext("seven"); - inOrder.verify(observer, never()).onNext("eight"); - inOrder.verify(observer, never()).onNext("nine"); + inOrder.verify(subscriber, never()).onNext("seven"); + inOrder.verify(subscriber, never()).onNext("eight"); + inOrder.verify(subscriber, never()).onNext("nine"); // we should not be completed yet - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); // now allow the third allowThird.countDown(); @@ -264,17 +264,17 @@ public void run() { throw new RuntimeException("failed waiting on threads", e); } - inOrder.verify(observer, times(1)).onNext("seven"); - inOrder.verify(observer, times(1)).onNext("eight"); - inOrder.verify(observer, times(1)).onNext("nine"); + inOrder.verify(subscriber, times(1)).onNext("seven"); + inOrder.verify(subscriber, times(1)).onNext("eight"); + inOrder.verify(subscriber, times(1)).onNext("nine"); - verify(observer, never()).onError(any(Throwable.class)); - inOrder.verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onComplete(); } @Test public void testBlockedObservableOfObservables() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; @@ -285,7 +285,7 @@ public void testBlockedObservableOfObservables() { @SuppressWarnings("unchecked") TestObservable> observableOfObservables = new TestObservable>(callOnce, okToContinue, odds, even); Flowable concatF = Flowable.concat(Flowable.unsafeCreate(observableOfObservables)); - concatF.subscribe(observer); + concatF.subscribe(subscriber); try { //Block main thread to allow observables to serve up o1. callOnce.await(); @@ -294,10 +294,10 @@ public void testBlockedObservableOfObservables() { fail(ex.getMessage()); } // The concated observable should have served up all of the odds. - verify(observer, times(1)).onNext("1"); - verify(observer, times(1)).onNext("3"); - verify(observer, times(1)).onNext("5"); - verify(observer, times(1)).onNext("7"); + verify(subscriber, times(1)).onNext("1"); + verify(subscriber, times(1)).onNext("3"); + verify(subscriber, times(1)).onNext("5"); + verify(subscriber, times(1)).onNext("7"); try { // unblock observables so it can serve up o2 and complete @@ -308,9 +308,9 @@ public void testBlockedObservableOfObservables() { fail(ex.getMessage()); } // The concatenated observable should now have served up all the evens. - verify(observer, times(1)).onNext("2"); - verify(observer, times(1)).onNext("4"); - verify(observer, times(1)).onNext("6"); + verify(subscriber, times(1)).onNext("2"); + verify(subscriber, times(1)).onNext("4"); + verify(subscriber, times(1)).onNext("6"); } @Test @@ -319,13 +319,13 @@ public void testConcatConcurrentWithInfinity() { //This observable will send "hello" MAX_VALUE time. final TestObservable w2 = new TestObservable("hello", Integer.MAX_VALUE); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); @SuppressWarnings("unchecked") TestObservable> observableOfObservables = new TestObservable>(Flowable.unsafeCreate(w1), Flowable.unsafeCreate(w2)); Flowable concatF = Flowable.concat(Flowable.unsafeCreate(observableOfObservables)); - concatF.take(50).subscribe(observer); + concatF.take(50).subscribe(subscriber); //Wait for the thread to start up. try { @@ -335,13 +335,13 @@ public void testConcatConcurrentWithInfinity() { e.printStackTrace(); } - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, times(47)).onNext("hello"); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, times(47)).onNext("hello"); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -353,24 +353,24 @@ public void testConcatNonBlockingObservables() { final TestObservable w1 = new TestObservable(null, okToContinueW1, "one", "two", "three"); final TestObservable w2 = new TestObservable(null, okToContinueW2, "four", "five", "six"); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable> observableOfObservables = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); // simulate what would happen in an observable - observer.onNext(Flowable.unsafeCreate(w1)); - observer.onNext(Flowable.unsafeCreate(w2)); - observer.onComplete(); + subscriber.onNext(Flowable.unsafeCreate(w1)); + subscriber.onNext(Flowable.unsafeCreate(w2)); + subscriber.onComplete(); } }); Flowable concat = Flowable.concat(observableOfObservables); - concat.subscribe(observer); + concat.subscribe(subscriber); - verify(observer, times(0)).onComplete(); + verify(subscriber, times(0)).onComplete(); try { // release both threads @@ -383,14 +383,14 @@ public void subscribe(Subscriber> observer) { e.printStackTrace(); } - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, times(1)).onNext("four"); - inOrder.verify(observer, times(1)).onNext("five"); - inOrder.verify(observer, times(1)).onNext("six"); - verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, times(1)).onNext("four"); + inOrder.verify(subscriber, times(1)).onNext("five"); + inOrder.verify(subscriber, times(1)).onNext("six"); + verify(subscriber, times(1)).onComplete(); } @@ -404,8 +404,8 @@ public void testConcatUnsubscribe() { final TestObservable w1 = new TestObservable("one", "two", "three"); final TestObservable w2 = new TestObservable(callOnce, okToContinue, "four", "five", "six"); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer, 0L); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber, 0L); final Flowable concat = Flowable.concat(Flowable.unsafeCreate(w1), Flowable.unsafeCreate(w2)); @@ -425,14 +425,14 @@ public void testConcatUnsubscribe() { fail(e.getMessage()); } - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, times(1)).onNext("four"); - inOrder.verify(observer, never()).onNext("five"); - inOrder.verify(observer, never()).onNext("six"); - inOrder.verify(observer, never()).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, times(1)).onNext("four"); + inOrder.verify(subscriber, never()).onNext("five"); + inOrder.verify(subscriber, never()).onNext("six"); + inOrder.verify(subscriber, never()).onComplete(); } @@ -446,8 +446,8 @@ public void testConcatUnsubscribeConcurrent() { final TestObservable w1 = new TestObservable("one", "two", "three"); final TestObservable w2 = new TestObservable(callOnce, okToContinue, "four", "five", "six"); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer, 0L); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber, 0L); @SuppressWarnings("unchecked") TestObservable> observableOfObservables = new TestObservable>(Flowable.unsafeCreate(w1), Flowable.unsafeCreate(w2)); @@ -470,15 +470,15 @@ public void testConcatUnsubscribeConcurrent() { fail(e.getMessage()); } - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, times(1)).onNext("four"); - inOrder.verify(observer, never()).onNext("five"); - inOrder.verify(observer, never()).onNext("six"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, times(1)).onNext("four"); + inOrder.verify(subscriber, never()).onNext("five"); + inOrder.verify(subscriber, never()).onNext("six"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } private static class TestObservable implements Publisher { @@ -526,8 +526,8 @@ public void cancel() { } @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(s); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(s); t = new Thread(new Runnable() { @Override @@ -535,9 +535,9 @@ public void run() { try { while (count < size && subscribed) { if (null != values) { - observer.onNext(values.get(count)); + subscriber.onNext(values.get(count)); } else { - observer.onNext(seed); + subscriber.onNext(seed); } count++; //Unblock the main thread to call unsubscribe. @@ -550,7 +550,7 @@ public void run() { } } if (subscribed) { - observer.onComplete(); + subscriber.onComplete(); } } catch (InterruptedException e) { e.printStackTrace(); @@ -571,45 +571,45 @@ void waitForThreadDone() throws InterruptedException { @Test public void testMultipleObservers() { - Subscriber o1 = TestHelper.mockSubscriber(); - Subscriber o2 = TestHelper.mockSubscriber(); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + Subscriber subscriber2 = TestHelper.mockSubscriber(); TestScheduler s = new TestScheduler(); Flowable timer = Flowable.interval(500, TimeUnit.MILLISECONDS, s).take(2); - Flowable o = Flowable.concat(timer, timer); + Flowable f = Flowable.concat(timer, timer); - o.subscribe(o1); - o.subscribe(o2); + f.subscribe(subscriber1); + f.subscribe(subscriber2); - InOrder inOrder1 = inOrder(o1); - InOrder inOrder2 = inOrder(o2); + InOrder inOrder1 = inOrder(subscriber1); + InOrder inOrder2 = inOrder(subscriber2); s.advanceTimeBy(500, TimeUnit.MILLISECONDS); - inOrder1.verify(o1, times(1)).onNext(0L); - inOrder2.verify(o2, times(1)).onNext(0L); + inOrder1.verify(subscriber1, times(1)).onNext(0L); + inOrder2.verify(subscriber2, times(1)).onNext(0L); s.advanceTimeBy(500, TimeUnit.MILLISECONDS); - inOrder1.verify(o1, times(1)).onNext(1L); - inOrder2.verify(o2, times(1)).onNext(1L); + inOrder1.verify(subscriber1, times(1)).onNext(1L); + inOrder2.verify(subscriber2, times(1)).onNext(1L); s.advanceTimeBy(500, TimeUnit.MILLISECONDS); - inOrder1.verify(o1, times(1)).onNext(0L); - inOrder2.verify(o2, times(1)).onNext(0L); + inOrder1.verify(subscriber1, times(1)).onNext(0L); + inOrder2.verify(subscriber2, times(1)).onNext(0L); s.advanceTimeBy(500, TimeUnit.MILLISECONDS); - inOrder1.verify(o1, times(1)).onNext(1L); - inOrder2.verify(o2, times(1)).onNext(1L); + inOrder1.verify(subscriber1, times(1)).onNext(1L); + inOrder2.verify(subscriber2, times(1)).onNext(1L); - inOrder1.verify(o1, times(1)).onComplete(); - inOrder2.verify(o2, times(1)).onComplete(); + inOrder1.verify(subscriber1, times(1)).onComplete(); + inOrder2.verify(subscriber2, times(1)).onComplete(); - verify(o1, never()).onError(any(Throwable.class)); - verify(o2, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); + verify(subscriber2, never()).onError(any(Throwable.class)); } @Test @@ -705,7 +705,7 @@ public void testInnerBackpressureWithoutAlignedBoundaries() { // https://github.com/ReactiveX/RxJava/issues/1818 @Test public void testConcatWithNonCompliantSourceDoubleOnComplete() { - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -718,7 +718,7 @@ public void subscribe(Subscriber s) { }); TestSubscriber ts = new TestSubscriber(); - Flowable.concat(o, o).subscribe(ts); + Flowable.concat(f, f).subscribe(ts); ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); ts.assertTerminated(); ts.assertNoErrors(); @@ -733,12 +733,12 @@ public void testIssue2890NoStackoverflow() throws InterruptedException { Function> func = new Function>() { @Override public Flowable apply(Integer t) { - Flowable observable = Flowable.just(t) + Flowable flowable = Flowable.just(t) .subscribeOn(sch) ; - FlowableProcessor subject = UnicastProcessor.create(); - observable.subscribe(subject); - return subject; + FlowableProcessor processor = UnicastProcessor.create(); + flowable.subscribe(processor); + return processor; } }; @@ -778,10 +778,10 @@ public void onError(Throwable e) { @Test public void testRequestOverflowDoesNotStallStream() { - Flowable o1 = Flowable.just(1,2,3); - Flowable o2 = Flowable.just(4,5,6); + Flowable f1 = Flowable.just(1,2,3); + Flowable f2 = Flowable.just(4,5,6); final AtomicBoolean completed = new AtomicBoolean(false); - o1.concatWith(o2).subscribe(new DefaultSubscriber() { + f1.concatWith(f2).subscribe(new DefaultSubscriber() { @Override public void onComplete() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletableTest.java index d186e2fcd4..681f9d91f3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletableTest.java @@ -15,13 +15,16 @@ import static org.junit.Assert.*; +import java.util.List; + import org.junit.Test; import org.reactivestreams.Subscriber; import io.reactivex.*; -import io.reactivex.exceptions.TestException; +import io.reactivex.exceptions.*; import io.reactivex.functions.Action; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.CompletableSubject; import io.reactivex.subscribers.TestSubscriber; @@ -104,22 +107,29 @@ public void cancelOther() { @Test public void badSource() { - new Flowable() { - @Override - protected void subscribeActual(Subscriber s) { - BooleanSubscription bs1 = new BooleanSubscription(); - s.onSubscribe(bs1); - - BooleanSubscription bs2 = new BooleanSubscription(); - s.onSubscribe(bs2); - - assertFalse(bs1.isCancelled()); - assertTrue(bs2.isCancelled()); - - s.onComplete(); - } - }.concatWith(Completable.complete()) - .test() - .assertResult(); + List errors = TestHelper.trackPluginErrors(); + try { + new Flowable() { + @Override + protected void subscribeActual(Subscriber s) { + BooleanSubscription bs1 = new BooleanSubscription(); + s.onSubscribe(bs1); + + BooleanSubscription bs2 = new BooleanSubscription(); + s.onSubscribe(bs2); + + assertFalse(bs1.isCancelled()); + assertTrue(bs2.isCancelled()); + + s.onComplete(); + } + }.concatWith(Completable.complete()) + .test() + .assertResult(); + + TestHelper.assertError(errors, 0, ProtocolViolationException.class); + } finally { + RxJavaPlugins.reset(); + } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java index a84389310a..e11fb643eb 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java @@ -51,15 +51,15 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.count().toFlowable(); + public Flowable apply(Flowable f) throws Exception { + return f.count().toFlowable(); } }); TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function, SingleSource>() { @Override - public SingleSource apply(Flowable o) throws Exception { - return o.count(); + public SingleSource apply(Flowable f) throws Exception { + return f.count(); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java index bbdff04d1c..ba4c9933a9 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java @@ -48,151 +48,189 @@ public void subscribe(FlowableEmitter s) throws Exception { } @Test public void basic() { - final Disposable d = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e.setDisposable(d); - - e.onNext(1); - e.onNext(2); - e.onNext(3); - e.onComplete(); - e.onError(new TestException()); - e.onNext(4); - e.onError(new TestException()); - e.onComplete(); - } - }, BackpressureStrategy.BUFFER) - .test() - .assertResult(1, 2, 3); + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e.setDisposable(d); + + e.onNext(1); + e.onNext(2); + e.onNext(3); + e.onComplete(); + e.onError(new TestException("first")); + e.onNext(4); + e.onError(new TestException("second")); + e.onComplete(); + } + }, BackpressureStrategy.BUFFER) + .test() + .assertResult(1, 2, 3); - assertTrue(d.isDisposed()); + assertTrue(d.isDisposed()); + + TestHelper.assertUndeliverable(errors, 0, TestException.class, "first"); + TestHelper.assertUndeliverable(errors, 1, TestException.class, "second"); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithCancellable() { - final Disposable d1 = Disposables.empty(); - final Disposable d2 = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d1 = Disposables.empty(); + final Disposable d2 = Disposables.empty(); - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e.setDisposable(d1); - e.setCancellable(new Cancellable() { - @Override - public void cancel() throws Exception { - d2.dispose(); - } - }); - - e.onNext(1); - e.onNext(2); - e.onNext(3); - e.onComplete(); - e.onError(new TestException()); - e.onNext(4); - e.onError(new TestException()); - e.onComplete(); - } - }, BackpressureStrategy.BUFFER) - .test() - .assertResult(1, 2, 3); + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e.setDisposable(d1); + e.setCancellable(new Cancellable() { + @Override + public void cancel() throws Exception { + d2.dispose(); + } + }); + + e.onNext(1); + e.onNext(2); + e.onNext(3); + e.onComplete(); + e.onError(new TestException("first")); + e.onNext(4); + e.onError(new TestException("second")); + e.onComplete(); + } + }, BackpressureStrategy.BUFFER) + .test() + .assertResult(1, 2, 3); + + assertTrue(d1.isDisposed()); + assertTrue(d2.isDisposed()); - assertTrue(d1.isDisposed()); - assertTrue(d2.isDisposed()); + TestHelper.assertUndeliverable(errors, 0, TestException.class, "first"); + TestHelper.assertUndeliverable(errors, 1, TestException.class, "second"); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithError() { - final Disposable d = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e.setDisposable(d); - - e.onNext(1); - e.onNext(2); - e.onNext(3); - e.onError(new TestException()); - e.onComplete(); - e.onNext(4); - e.onError(new TestException()); - } - }, BackpressureStrategy.BUFFER) - .test() - .assertFailure(TestException.class, 1, 2, 3); + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e.setDisposable(d); + + e.onNext(1); + e.onNext(2); + e.onNext(3); + e.onError(new TestException()); + e.onComplete(); + e.onNext(4); + e.onError(new TestException("second")); + } + }, BackpressureStrategy.BUFFER) + .test() + .assertFailure(TestException.class, 1, 2, 3); + + assertTrue(d.isDisposed()); - assertTrue(d.isDisposed()); + TestHelper.assertUndeliverable(errors, 0, TestException.class, "second"); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicSerialized() { - final Disposable d = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e = e.serialize(); - - e.setDisposable(d); - - e.onNext(1); - e.onNext(2); - e.onNext(3); - e.onComplete(); - e.onError(new TestException()); - e.onNext(4); - e.onError(new TestException()); - e.onComplete(); - } - }, BackpressureStrategy.BUFFER) - .test() - .assertResult(1, 2, 3); + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e = e.serialize(); + + e.setDisposable(d); + + e.onNext(1); + e.onNext(2); + e.onNext(3); + e.onComplete(); + e.onError(new TestException("first")); + e.onNext(4); + e.onError(new TestException("second")); + e.onComplete(); + } + }, BackpressureStrategy.BUFFER) + .test() + .assertResult(1, 2, 3); + + assertTrue(d.isDisposed()); - assertTrue(d.isDisposed()); + TestHelper.assertUndeliverable(errors, 0, TestException.class, "first"); + TestHelper.assertUndeliverable(errors, 1, TestException.class, "second"); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithErrorSerialized() { - final Disposable d = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e = e.serialize(); - - e.setDisposable(d); - - e.onNext(1); - e.onNext(2); - e.onNext(3); - e.onError(new TestException()); - e.onComplete(); - e.onNext(4); - e.onError(new TestException()); - } - }, BackpressureStrategy.BUFFER) - .test() - .assertFailure(TestException.class, 1, 2, 3); + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e = e.serialize(); + + e.setDisposable(d); - assertTrue(d.isDisposed()); + e.onNext(1); + e.onNext(2); + e.onNext(3); + e.onError(new TestException()); + e.onComplete(); + e.onNext(4); + e.onError(new TestException("second")); + } + }, BackpressureStrategy.BUFFER) + .test() + .assertFailure(TestException.class, 1, 2, 3); + + assertTrue(d.isDisposed()); + + TestHelper.assertUndeliverable(errors, 0, TestException.class, "second"); + } finally { + RxJavaPlugins.reset(); + } } @Test public void wrap() { Flowable.fromPublisher(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onNext(2); - observer.onNext(3); - observer.onNext(4); - observer.onNext(5); - observer.onComplete(); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(1); + subscriber.onNext(2); + subscriber.onNext(3); + subscriber.onNext(4); + subscriber.onNext(5); + subscriber.onComplete(); } }) .test() @@ -203,14 +241,14 @@ public void subscribe(Subscriber observer) { public void unsafe() { Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onNext(2); - observer.onNext(3); - observer.onNext(4); - observer.onNext(5); - observer.onComplete(); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(1); + subscriber.onNext(2); + subscriber.onNext(3); + subscriber.onNext(4); + subscriber.onNext(5); + subscriber.onComplete(); } }) .test() @@ -224,237 +262,308 @@ public void unsafeWithFlowable() { @Test public void createNullValueBuffer() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + final Throwable[] error = { null }; + + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.BUFFER) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.BUFFER) + .test() + .assertFailure(NullPointerException.class); + + assertNull(error[0]); - assertNull(error[0]); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void createNullValueLatest() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.LATEST) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.LATEST) + .test() + .assertFailure(NullPointerException.class); + + assertNull(error[0]); - assertNull(error[0]); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void createNullValueError() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.ERROR) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.ERROR) + .test() + .assertFailure(NullPointerException.class); + + assertNull(error[0]); - assertNull(error[0]); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void createNullValueDrop() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.DROP) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.DROP) + .test() + .assertFailure(NullPointerException.class); + + assertNull(error[0]); - assertNull(error[0]); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void createNullValueMissing() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.MISSING) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.MISSING) + .test() + .assertFailure(NullPointerException.class); - assertNull(error[0]); + assertNull(error[0]); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void createNullValueBufferSerialized() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e = e.serialize(); - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e = e.serialize(); + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.BUFFER) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.BUFFER) + .test() + .assertFailure(NullPointerException.class); + + assertNull(error[0]); - assertNull(error[0]); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void createNullValueLatestSerialized() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e = e.serialize(); - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e = e.serialize(); + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.LATEST) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.LATEST) + .test() + .assertFailure(NullPointerException.class); - assertNull(error[0]); + assertNull(error[0]); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void createNullValueErrorSerialized() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e = e.serialize(); - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e = e.serialize(); + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.ERROR) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.ERROR) + .test() + .assertFailure(NullPointerException.class); + + assertNull(error[0]); - assertNull(error[0]); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void createNullValueDropSerialized() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e = e.serialize(); - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e = e.serialize(); + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.DROP) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.DROP) + .test() + .assertFailure(NullPointerException.class); - assertNull(error[0]); + assertNull(error[0]); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void createNullValueMissingSerialized() { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e = e.serialize(); - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e = e.serialize(); + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, BackpressureStrategy.MISSING) - .test() - .assertFailure(NullPointerException.class); + }, BackpressureStrategy.MISSING) + .test() + .assertFailure(NullPointerException.class); + + assertNull(error[0]); - assertNull(error[0]); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -630,25 +739,32 @@ public void subscribe(FlowableEmitter e) throws Exception { @Test public void createNullValue() { for (BackpressureStrategy m : BackpressureStrategy.values()) { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, m) - .test() - .assertFailure(NullPointerException.class); + }, m) + .test() + .assertFailure(NullPointerException.class); - assertNull(error[0]); + assertNull(error[0]); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } } @@ -736,26 +852,33 @@ public void onComplete() { @Test public void createNullValueSerialized() { for (BackpressureStrategy m : BackpressureStrategy.values()) { - final Throwable[] error = { null }; + List errors = TestHelper.trackPluginErrors(); + try { + final Throwable[] error = { null }; - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) throws Exception { - e = e.serialize(); - try { - e.onNext(null); - e.onNext(1); - e.onError(new TestException()); - e.onComplete(); - } catch (Throwable ex) { - error[0] = ex; + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter e) throws Exception { + e = e.serialize(); + try { + e.onNext(null); + e.onNext(1); + e.onError(new TestException()); + e.onComplete(); + } catch (Throwable ex) { + error[0] = ex; + } } - } - }, m) - .test() - .assertFailure(NullPointerException.class); + }, m) + .test() + .assertFailure(NullPointerException.class); - assertNull(error[0]); + assertNull(error[0]); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java index c152929e1a..40348b0ee6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java @@ -171,10 +171,10 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.debounce(debounceSel).subscribe(o); + source.debounce(debounceSel).subscribe(subscriber); source.onNext(1); debouncer.onNext(1); @@ -188,12 +188,12 @@ public Flowable apply(Integer t1) { source.onNext(5); source.onComplete(); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(4); - inOrder.verify(o).onNext(5); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(4); + inOrder.verify(subscriber).onNext(5); + inOrder.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -207,15 +207,15 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.debounce(debounceSel).subscribe(o); + source.debounce(debounceSel).subscribe(subscriber); source.onNext(1); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } @Test @@ -229,32 +229,32 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.debounce(debounceSel).subscribe(o); + source.debounce(debounceSel).subscribe(subscriber); source.onNext(1); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } @Test public void debounceTimedLastIsNotLost() { PublishProcessor source = PublishProcessor.create(); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.debounce(100, TimeUnit.MILLISECONDS, scheduler).subscribe(o); + source.debounce(100, TimeUnit.MILLISECONDS, scheduler).subscribe(subscriber); source.onNext(1); source.onComplete(); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - verify(o).onNext(1); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void debounceSelectorLastIsNotLost() { @@ -269,18 +269,18 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.debounce(debounceSel).subscribe(o); + source.debounce(debounceSel).subscribe(subscriber); source.onNext(1); source.onComplete(); debouncer.onComplete(); - verify(o).onNext(1); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -363,8 +363,8 @@ protected void subscribeActual(Subscriber subscriber) { public void badSourceSelector() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.debounce(new Function>() { + public Object apply(Flowable f) throws Exception { + return f.debounce(new Function>() { @Override public Flowable apply(Integer v) throws Exception { return Flowable.timer(1, TimeUnit.SECONDS); @@ -375,11 +375,11 @@ public Flowable apply(Integer v) throws Exception { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(final Flowable o) throws Exception { + public Object apply(final Flowable f) throws Exception { return Flowable.just(1).debounce(new Function>() { @Override public Flowable apply(Integer v) throws Exception { - return o; + return f; } }); } @@ -415,8 +415,8 @@ public void backpressureNoRequestTimed() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.debounce(Functions.justFunction(Flowable.never())); + public Flowable apply(Flowable f) throws Exception { + return f.debounce(Functions.justFunction(Flowable.never())); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java index 24b41502e9..fa6b123a15 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java @@ -27,38 +27,38 @@ public class FlowableDefaultIfEmptyTest { @Test public void testDefaultIfEmpty() { Flowable source = Flowable.just(1, 2, 3); - Flowable observable = source.defaultIfEmpty(10); + Flowable flowable = source.defaultIfEmpty(10); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, never()).onNext(10); - verify(observer).onNext(1); - verify(observer).onNext(2); - verify(observer).onNext(3); - verify(observer).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(10); + verify(subscriber).onNext(1); + verify(subscriber).onNext(2); + verify(subscriber).onNext(3); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testDefaultIfEmptyWithEmpty() { Flowable source = Flowable.empty(); - Flowable observable = source.defaultIfEmpty(10); + Flowable flowable = source.defaultIfEmpty(10); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer).onNext(10); - verify(observer).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(10); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @Ignore("Subscribers should not throw") public void testEmptyButClientThrows() { - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); Flowable.empty().defaultIfEmpty(1).subscribe(new DefaultSubscriber() { @Override @@ -68,18 +68,18 @@ public void onNext(Integer t) { @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }); - verify(o).onError(any(TestException.class)); - verify(o, never()).onNext(any(Integer.class)); - verify(o, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any(Integer.class)); + verify(subscriber, never()).onComplete(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDeferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDeferTest.java index 2d3cabc7a9..8d46e9c34e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDeferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDeferTest.java @@ -22,7 +22,6 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; -import io.reactivex.subscribers.DefaultSubscriber; @SuppressWarnings("unchecked") public class FlowableDeferTest { @@ -40,25 +39,25 @@ public void testDefer() throws Throwable { verifyZeroInteractions(factory); - Subscriber firstObserver = TestHelper.mockSubscriber(); - deferred.subscribe(firstObserver); + Subscriber firstSubscriber = TestHelper.mockSubscriber(); + deferred.subscribe(firstSubscriber); verify(factory, times(1)).call(); - verify(firstObserver, times(1)).onNext("one"); - verify(firstObserver, times(1)).onNext("two"); - verify(firstObserver, times(0)).onNext("three"); - verify(firstObserver, times(0)).onNext("four"); - verify(firstObserver, times(1)).onComplete(); + verify(firstSubscriber, times(1)).onNext("one"); + verify(firstSubscriber, times(1)).onNext("two"); + verify(firstSubscriber, times(0)).onNext("three"); + verify(firstSubscriber, times(0)).onNext("four"); + verify(firstSubscriber, times(1)).onComplete(); - Subscriber secondObserver = TestHelper.mockSubscriber(); - deferred.subscribe(secondObserver); + Subscriber secondSubscriber = TestHelper.mockSubscriber(); + deferred.subscribe(secondSubscriber); verify(factory, times(2)).call(); - verify(secondObserver, times(0)).onNext("one"); - verify(secondObserver, times(0)).onNext("two"); - verify(secondObserver, times(1)).onNext("three"); - verify(secondObserver, times(1)).onNext("four"); - verify(secondObserver, times(1)).onComplete(); + verify(secondSubscriber, times(0)).onNext("one"); + verify(secondSubscriber, times(0)).onNext("two"); + verify(secondSubscriber, times(1)).onNext("three"); + verify(secondSubscriber, times(1)).onNext("four"); + verify(secondSubscriber, times(1)).onComplete(); } @@ -70,12 +69,12 @@ public void testDeferFunctionThrows() throws Exception { Flowable result = Flowable.defer(factory); - DefaultSubscriber o = mock(DefaultSubscriber.class); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onError(any(TestException.class)); - verify(o, never()).onNext(any(String.class)); - verify(o, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, never()).onComplete(); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOtherTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOtherTest.java index 9e23acf0ee..e61c3f7905 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOtherTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOtherTest.java @@ -316,8 +316,8 @@ public void otherNull() { public void badSourceOther() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return Flowable.just(1).delaySubscription(o); + public Object apply(Flowable f) throws Exception { + return Flowable.just(1).delaySubscription(f); } }, false, 1, 1, 1); } @@ -327,8 +327,8 @@ public void afterDelayNoInterrupt() { ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); try { for (Scheduler s : new Scheduler[] { Schedulers.single(), Schedulers.computation(), Schedulers.newThread(), Schedulers.io(), Schedulers.from(exec) }) { - final TestSubscriber observer = TestSubscriber.create(); - observer.withTag(s.getClass().getSimpleName()); + final TestSubscriber ts = TestSubscriber.create(); + ts.withTag(s.getClass().getSimpleName()); Flowable.create(new FlowableOnSubscribe() { @Override @@ -338,10 +338,10 @@ public void subscribe(FlowableEmitter emitter) throws Exception { } }, BackpressureStrategy.MISSING) .delaySubscription(100, TimeUnit.MILLISECONDS, s) - .subscribe(observer); + .subscribe(ts); - observer.awaitTerminalEvent(); - observer.assertValue(false); + ts.awaitTerminalEvent(); + ts.assertValue(false); } } finally { exec.shutdown(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java index d86f5f5469..401b9c62b4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java @@ -34,15 +34,15 @@ import io.reactivex.subscribers.*; public class FlowableDelayTest { - private Subscriber observer; - private Subscriber observer2; + private Subscriber subscriber; + private Subscriber subscriber2; private TestScheduler scheduler; @Before public void before() { - observer = TestHelper.mockSubscriber(); - observer2 = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); + subscriber2 = TestHelper.mockSubscriber(); scheduler = new TestScheduler(); } @@ -51,69 +51,69 @@ public void before() { public void testDelay() { Flowable source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); Flowable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); - delayed.subscribe(observer); + delayed.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS); - verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(1500L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(0L); - inOrder.verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext(0L); + inOrder.verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(2400L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(2500L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(1L); - inOrder.verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext(1L); + inOrder.verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(3400L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(3500L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(2L); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext(2L); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testLongDelay() { Flowable source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); Flowable delayed = source.delay(5L, TimeUnit.SECONDS, scheduler); - delayed.subscribe(observer); + delayed.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(5999L, TimeUnit.MILLISECONDS); - verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(6000L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(0L); + inOrder.verify(subscriber, times(1)).onNext(0L); scheduler.advanceTimeTo(6999L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyLong()); + inOrder.verify(subscriber, never()).onNext(anyLong()); scheduler.advanceTimeTo(7000L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(1L); + inOrder.verify(subscriber, times(1)).onNext(1L); scheduler.advanceTimeTo(7999L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyLong()); + inOrder.verify(subscriber, never()).onNext(anyLong()); scheduler.advanceTimeTo(8000L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(2L); - inOrder.verify(observer, times(1)).onComplete(); - inOrder.verify(observer, never()).onNext(anyLong()); - inOrder.verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext(2L); + inOrder.verify(subscriber, times(1)).onComplete(); + inOrder.verify(subscriber, never()).onNext(anyLong()); + inOrder.verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -129,103 +129,103 @@ public Long apply(Long value) { } }); Flowable delayed = source.delay(1L, TimeUnit.SECONDS, scheduler); - delayed.subscribe(observer); + delayed.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(1999L, TimeUnit.MILLISECONDS); - verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(2000L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onError(any(Throwable.class)); - inOrder.verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); scheduler.advanceTimeTo(5000L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyLong()); - inOrder.verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext(anyLong()); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); } @Test public void testDelayWithMultipleSubscriptions() { Flowable source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); Flowable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); - delayed.subscribe(observer); - delayed.subscribe(observer2); + delayed.subscribe(subscriber); + delayed.subscribe(subscriber2); - InOrder inOrder = inOrder(observer); - InOrder inOrder2 = inOrder(observer2); + InOrder inOrder = inOrder(subscriber); + InOrder inOrder2 = inOrder(subscriber2); scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS); - verify(observer, never()).onNext(anyLong()); - verify(observer2, never()).onNext(anyLong()); + verify(subscriber, never()).onNext(anyLong()); + verify(subscriber2, never()).onNext(anyLong()); scheduler.advanceTimeTo(1500L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(0L); - inOrder2.verify(observer2, times(1)).onNext(0L); + inOrder.verify(subscriber, times(1)).onNext(0L); + inOrder2.verify(subscriber2, times(1)).onNext(0L); scheduler.advanceTimeTo(2499L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyLong()); - inOrder2.verify(observer2, never()).onNext(anyLong()); + inOrder.verify(subscriber, never()).onNext(anyLong()); + inOrder2.verify(subscriber2, never()).onNext(anyLong()); scheduler.advanceTimeTo(2500L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(1L); - inOrder2.verify(observer2, times(1)).onNext(1L); + inOrder.verify(subscriber, times(1)).onNext(1L); + inOrder2.verify(subscriber2, times(1)).onNext(1L); - verify(observer, never()).onComplete(); - verify(observer2, never()).onComplete(); + verify(subscriber, never()).onComplete(); + verify(subscriber2, never()).onComplete(); scheduler.advanceTimeTo(3500L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(2L); - inOrder2.verify(observer2, times(1)).onNext(2L); - inOrder.verify(observer, never()).onNext(anyLong()); - inOrder2.verify(observer2, never()).onNext(anyLong()); - inOrder.verify(observer, times(1)).onComplete(); - inOrder2.verify(observer2, times(1)).onComplete(); - - verify(observer, never()).onError(any(Throwable.class)); - verify(observer2, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext(2L); + inOrder2.verify(subscriber2, times(1)).onNext(2L); + inOrder.verify(subscriber, never()).onNext(anyLong()); + inOrder2.verify(subscriber2, never()).onNext(anyLong()); + inOrder.verify(subscriber, times(1)).onComplete(); + inOrder2.verify(subscriber2, times(1)).onComplete(); + + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber2, never()).onError(any(Throwable.class)); } @Test public void testDelaySubscription() { Flowable result = Flowable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); - inOrder.verify(o, never()).onNext(any()); - inOrder.verify(o, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext(any()); + inOrder.verify(subscriber, never()).onComplete(); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); - inOrder.verify(o, times(1)).onNext(1); - inOrder.verify(o, times(1)).onNext(2); - inOrder.verify(o, times(1)).onNext(3); - inOrder.verify(o, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onNext(3); + inOrder.verify(subscriber, times(1)).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testDelaySubscriptionCancelBeforeTime() { Flowable result = Flowable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); result.subscribe(ts); ts.dispose(); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -245,22 +245,22 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(delayFunc).subscribe(o); + source.delay(delayFunc).subscribe(subscriber); for (int i = 0; i < n; i++) { source.onNext(i); delays.get(i).onNext(i); - inOrder.verify(o).onNext(i); + inOrder.verify(subscriber).onNext(i); } source.onComplete(); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -275,18 +275,18 @@ public Flowable apply(Integer t1) { return delay; } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(delayFunc).subscribe(o); + source.delay(delayFunc).subscribe(subscriber); source.onNext(1); delay.onNext(1); delay.onNext(2); - inOrder.verify(o).onNext(1); + inOrder.verify(subscriber).onNext(1); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -301,18 +301,18 @@ public Flowable apply(Integer t1) { return delay; } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(delayFunc).subscribe(o); + source.delay(delayFunc).subscribe(subscriber); source.onNext(1); source.onError(new TestException()); delay.onNext(1); - inOrder.verify(o).onError(any(TestException.class)); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -326,16 +326,16 @@ public Flowable apply(Integer t1) { throw new TestException(); } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(delayFunc).subscribe(o); + source.delay(delayFunc).subscribe(subscriber); source.onNext(1); - inOrder.verify(o).onError(any(TestException.class)); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -350,17 +350,17 @@ public Flowable apply(Integer t1) { return delay; } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(delayFunc).subscribe(o); + source.delay(delayFunc).subscribe(subscriber); source.onNext(1); delay.onError(new TestException()); - inOrder.verify(o).onError(any(TestException.class)); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -375,10 +375,10 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(delay, delayFunc).subscribe(o); + source.delay(delay, delayFunc).subscribe(subscriber); source.onNext(1); delay.onNext(1); @@ -386,10 +386,10 @@ public Flowable apply(Integer t1) { source.onNext(2); delay.onNext(2); - inOrder.verify(o).onNext(2); + inOrder.verify(subscriber).onNext(2); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onError(any(Throwable.class)); - verify(o, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); } @Test @@ -410,20 +410,20 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(Flowable.defer(subFunc), delayFunc).subscribe(o); + source.delay(Flowable.defer(subFunc), delayFunc).subscribe(subscriber); source.onNext(1); delay.onNext(1); source.onNext(2); - inOrder.verify(o).onError(any(TestException.class)); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -444,20 +444,20 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(Flowable.defer(subFunc), delayFunc).subscribe(o); + source.delay(Flowable.defer(subFunc), delayFunc).subscribe(subscriber); source.onNext(1); delay.onError(new TestException()); source.onNext(2); - inOrder.verify(o).onError(any(TestException.class)); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -471,18 +471,18 @@ public Flowable apply(Integer t1) { return Flowable.empty(); } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(delayFunc).subscribe(o); + source.delay(delayFunc).subscribe(subscriber); source.onNext(1); source.onComplete(); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -504,10 +504,10 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.delay(Flowable.defer(subFunc), delayFunc).subscribe(o); + source.delay(Flowable.defer(subFunc), delayFunc).subscribe(subscriber); source.onNext(1); sdelay.onComplete(); @@ -515,10 +515,10 @@ public Flowable apply(Integer t1) { source.onNext(2); delay.onNext(2); - inOrder.verify(o).onNext(2); + inOrder.verify(subscriber).onNext(2); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onError(any(Throwable.class)); - verify(o, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); } @Test @@ -535,40 +535,40 @@ public Flowable apply(Long t1) { }; Flowable delayed = source.delay(delayFunc); - delayed.subscribe(observer); + delayed.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS); - verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(1500L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(0L); - inOrder.verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext(0L); + inOrder.verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(2400L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(2500L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(1L); - inOrder.verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext(1L); + inOrder.verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(3400L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(3500L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(2L); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext(2L); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -589,27 +589,27 @@ public Flowable apply(Integer t1) { } }); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); for (int i = 0; i < n; i++) { source.onNext(i); } source.onComplete(); - inOrder.verify(o, never()).onNext(anyInt()); - inOrder.verify(o, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext(anyInt()); + inOrder.verify(subscriber, never()).onComplete(); for (int i = n - 1; i >= 0; i--) { subjects.get(i).onComplete(); - inOrder.verify(o).onNext(i); + inOrder.verify(subscriber).onNext(i); } - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -624,11 +624,11 @@ public void accept(Notification t1) { } }); - TestSubscriber observer = new TestSubscriber(); - delayed.subscribe(observer); + TestSubscriber ts = new TestSubscriber(); + delayed.subscribe(ts); // all will be delivered after 500ms since range does not delay between them scheduler.advanceTimeBy(500L, TimeUnit.MILLISECONDS); - observer.assertValues(1, 2, 3, 4, 5); + ts.assertValues(1, 2, 3, 4, 5); } @Test @@ -902,16 +902,16 @@ public void delayWithTimeDelayError() throws Exception { public void testDelaySubscriptionDisposeBeforeTime() { Flowable result = Flowable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); result.subscribe(ts); ts.dispose(); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -947,15 +947,15 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.delay(1, TimeUnit.SECONDS); + public Flowable apply(Flowable f) throws Exception { + return f.delay(1, TimeUnit.SECONDS); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.delay(Functions.justFunction(Flowable.never())); + public Flowable apply(Flowable f) throws Exception { + return f.delay(Functions.justFunction(Flowable.never())); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java index a3ae8aaf49..f83510f830 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java @@ -35,76 +35,76 @@ public void testDematerialize1() { Flowable> notifications = Flowable.just(1, 2).materialize(); Flowable dematerialize = notifications.dematerialize(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - dematerialize.subscribe(observer); + dematerialize.subscribe(subscriber); - verify(observer, times(1)).onNext(1); - verify(observer, times(1)).onNext(2); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testDematerialize2() { Throwable exception = new Throwable("test"); - Flowable observable = Flowable.error(exception); - Flowable dematerialize = observable.materialize().dematerialize(); + Flowable flowable = Flowable.error(exception); + Flowable dematerialize = flowable.materialize().dematerialize(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - dematerialize.subscribe(observer); + dematerialize.subscribe(subscriber); - verify(observer, times(1)).onError(exception); - verify(observer, times(0)).onComplete(); - verify(observer, times(0)).onNext(any(Integer.class)); + verify(subscriber, times(1)).onError(exception); + verify(subscriber, times(0)).onComplete(); + verify(subscriber, times(0)).onNext(any(Integer.class)); } @Test public void testDematerialize3() { Exception exception = new Exception("test"); - Flowable observable = Flowable.error(exception); - Flowable dematerialize = observable.materialize().dematerialize(); + Flowable flowable = Flowable.error(exception); + Flowable dematerialize = flowable.materialize().dematerialize(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - dematerialize.subscribe(observer); + dematerialize.subscribe(subscriber); - verify(observer, times(1)).onError(exception); - verify(observer, times(0)).onComplete(); - verify(observer, times(0)).onNext(any(Integer.class)); + verify(subscriber, times(1)).onError(exception); + verify(subscriber, times(0)).onComplete(); + verify(subscriber, times(0)).onNext(any(Integer.class)); } @Test public void testErrorPassThru() { Exception exception = new Exception("test"); - Flowable observable = Flowable.error(exception); - Flowable dematerialize = observable.dematerialize(); + Flowable flowable = Flowable.error(exception); + Flowable dematerialize = flowable.dematerialize(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - dematerialize.subscribe(observer); + dematerialize.subscribe(subscriber); - verify(observer, times(1)).onError(exception); - verify(observer, times(0)).onComplete(); - verify(observer, times(0)).onNext(any(Integer.class)); + verify(subscriber, times(1)).onError(exception); + verify(subscriber, times(0)).onComplete(); + verify(subscriber, times(0)).onNext(any(Integer.class)); } @Test public void testCompletePassThru() { - Flowable observable = Flowable.empty(); - Flowable dematerialize = observable.dematerialize(); + Flowable flowable = Flowable.empty(); + Flowable dematerialize = flowable.dematerialize(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + TestSubscriber ts = new TestSubscriber(subscriber); dematerialize.subscribe(ts); System.out.println(ts.errors()); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(0)).onNext(any(Integer.class)); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(0)).onNext(any(Integer.class)); } @Test @@ -113,13 +113,13 @@ public void testHonorsContractWhenCompleted() { Flowable result = source.materialize().dematerialize(); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(1); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -128,13 +128,13 @@ public void testHonorsContractWhenThrows() { Flowable result = source.materialize().dematerialize(); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); - verify(o, never()).onNext(any(Integer.class)); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any(Integer.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } @Test @@ -146,8 +146,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.dematerialize(); + public Flowable apply(Flowable f) throws Exception { + return f.dematerialize(); } }); } @@ -158,12 +158,12 @@ public void eventsAfterDematerializedTerminal() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext(Notification.createOnComplete()); - observer.onNext(Notification.createOnNext(1)); - observer.onNext(Notification.createOnError(new TestException("First"))); - observer.onError(new TestException("Second")); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(Notification.createOnComplete()); + subscriber.onNext(Notification.createOnNext(1)); + subscriber.onNext(Notification.createOnError(new TestException("First"))); + subscriber.onError(new TestException("Second")); } } .dematerialize() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java index d2526adbf2..a42c0d889f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java @@ -169,8 +169,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.onTerminateDetach(); + public Flowable apply(Flowable f) throws Exception { + return f.onTerminateDetach(); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java index 3584224000..fd79f56b9c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java @@ -232,14 +232,14 @@ public void badSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - - observer.onNext(1); - observer.onComplete(); - observer.onNext(2); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + + subscriber.onNext(1); + subscriber.onComplete(); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .distinct() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterTerminateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterTerminateTest.java index 01704a97b6..c8b327fe04 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterTerminateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterTerminateTest.java @@ -18,6 +18,8 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import java.util.List; + import org.junit.*; import org.mockito.Mockito; import org.reactivestreams.Subscriber; @@ -25,21 +27,22 @@ import io.reactivex.*; import io.reactivex.functions.Action; import io.reactivex.internal.util.ExceptionHelper; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; public class FlowableDoAfterTerminateTest { private Action aAction0; - private Subscriber observer; + private Subscriber subscriber; @Before public void before() { aAction0 = Mockito.mock(Action.class); - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); } private void checkActionCalled(Flowable input) { - input.doAfterTerminate(aAction0).subscribe(observer); + input.doAfterTerminate(aAction0).subscribe(subscriber); try { verify(aAction0, times(1)).run(); } catch (Throwable ex) { @@ -82,21 +85,28 @@ public void nullFinallyActionShouldBeCheckedASAP() { @Test public void ifFinallyActionThrowsExceptionShouldNotBeSwallowedAndActionShouldBeCalledOnce() throws Exception { - Action finallyAction = Mockito.mock(Action.class); - doThrow(new IllegalStateException()).when(finallyAction).run(); + List errors = TestHelper.trackPluginErrors(); + try { + Action finallyAction = Mockito.mock(Action.class); + doThrow(new IllegalStateException()).when(finallyAction).run(); + + TestSubscriber testSubscriber = new TestSubscriber(); - TestSubscriber testSubscriber = new TestSubscriber(); + Flowable + .just("value") + .doAfterTerminate(finallyAction) + .subscribe(testSubscriber); - Flowable - .just("value") - .doAfterTerminate(finallyAction) - .subscribe(testSubscriber); + testSubscriber.assertValue("value"); - testSubscriber.assertValue("value"); + verify(finallyAction).run(); - verify(finallyAction).run(); - // Actual result: - // Not only IllegalStateException was swallowed - // But finallyAction was called twice! + TestHelper.assertError(errors, 0, IllegalStateException.class); + // Actual result: + // Not only IllegalStateException was swallowed + // But finallyAction was called twice! + } finally { + RxJavaPlugins.reset(); + } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java index 225859575e..4a9ac3eca2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java @@ -37,35 +37,35 @@ public class FlowableDoOnEachTest { - Subscriber subscribedObserver; - Subscriber sideEffectObserver; + Subscriber subscribedSubscriber; + Subscriber sideEffectSubscriber; @Before public void before() { - subscribedObserver = TestHelper.mockSubscriber(); - sideEffectObserver = TestHelper.mockSubscriber(); + subscribedSubscriber = TestHelper.mockSubscriber(); + sideEffectSubscriber = TestHelper.mockSubscriber(); } @Test public void testDoOnEach() { Flowable base = Flowable.just("a", "b", "c"); - Flowable doOnEach = base.doOnEach(sideEffectObserver); + Flowable doOnEach = base.doOnEach(sideEffectSubscriber); - doOnEach.subscribe(subscribedObserver); + doOnEach.subscribe(subscribedSubscriber); // ensure the leaf observer is still getting called - verify(subscribedObserver, never()).onError(any(Throwable.class)); - verify(subscribedObserver, times(1)).onNext("a"); - verify(subscribedObserver, times(1)).onNext("b"); - verify(subscribedObserver, times(1)).onNext("c"); - verify(subscribedObserver, times(1)).onComplete(); + verify(subscribedSubscriber, never()).onError(any(Throwable.class)); + verify(subscribedSubscriber, times(1)).onNext("a"); + verify(subscribedSubscriber, times(1)).onNext("b"); + verify(subscribedSubscriber, times(1)).onNext("c"); + verify(subscribedSubscriber, times(1)).onComplete(); // ensure our injected observer is getting called - verify(sideEffectObserver, never()).onError(any(Throwable.class)); - verify(sideEffectObserver, times(1)).onNext("a"); - verify(sideEffectObserver, times(1)).onNext("b"); - verify(sideEffectObserver, times(1)).onNext("c"); - verify(sideEffectObserver, times(1)).onComplete(); + verify(sideEffectSubscriber, never()).onError(any(Throwable.class)); + verify(sideEffectSubscriber, times(1)).onNext("a"); + verify(sideEffectSubscriber, times(1)).onNext("b"); + verify(sideEffectSubscriber, times(1)).onNext("c"); + verify(sideEffectSubscriber, times(1)).onComplete(); } @Test @@ -81,20 +81,20 @@ public String apply(String s) { } }); - Flowable doOnEach = errs.doOnEach(sideEffectObserver); + Flowable doOnEach = errs.doOnEach(sideEffectSubscriber); - doOnEach.subscribe(subscribedObserver); - verify(subscribedObserver, times(1)).onNext("one"); - verify(subscribedObserver, never()).onNext("two"); - verify(subscribedObserver, never()).onNext("three"); - verify(subscribedObserver, never()).onComplete(); - verify(subscribedObserver, times(1)).onError(any(Throwable.class)); + doOnEach.subscribe(subscribedSubscriber); + verify(subscribedSubscriber, times(1)).onNext("one"); + verify(subscribedSubscriber, never()).onNext("two"); + verify(subscribedSubscriber, never()).onNext("three"); + verify(subscribedSubscriber, never()).onComplete(); + verify(subscribedSubscriber, times(1)).onError(any(Throwable.class)); - verify(sideEffectObserver, times(1)).onNext("one"); - verify(sideEffectObserver, never()).onNext("two"); - verify(sideEffectObserver, never()).onNext("three"); - verify(sideEffectObserver, never()).onComplete(); - verify(sideEffectObserver, times(1)).onError(any(Throwable.class)); + verify(sideEffectSubscriber, times(1)).onNext("one"); + verify(sideEffectSubscriber, never()).onNext("two"); + verify(sideEffectSubscriber, never()).onNext("three"); + verify(sideEffectSubscriber, never()).onComplete(); + verify(sideEffectSubscriber, times(1)).onError(any(Throwable.class)); } @Test @@ -109,12 +109,12 @@ public void accept(String s) { } }); - doOnEach.subscribe(subscribedObserver); - verify(subscribedObserver, times(1)).onNext("one"); - verify(subscribedObserver, times(1)).onNext("two"); - verify(subscribedObserver, never()).onNext("three"); - verify(subscribedObserver, never()).onComplete(); - verify(subscribedObserver, times(1)).onError(any(Throwable.class)); + doOnEach.subscribe(subscribedSubscriber); + verify(subscribedSubscriber, times(1)).onNext("one"); + verify(subscribedSubscriber, times(1)).onNext("two"); + verify(subscribedSubscriber, never()).onNext("three"); + verify(subscribedSubscriber, never()).onComplete(); + verify(subscribedSubscriber, times(1)).onError(any(Throwable.class)); } @@ -180,7 +180,7 @@ public void testFatalError() { // public Flowable apply(Integer integer) { // return Flowable.create(new Publisher() { // @Override -// public void subscribe(Subscriber o) { +// public void subscribe(Subscriber subscriber) { // throw new NullPointerException("Test NPE"); // } // }); @@ -728,8 +728,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.doOnEach(new TestSubscriber()); + public Flowable apply(Flowable f) throws Exception { + return f.doOnEach(new TestSubscriber()); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java index af309b0e9b..3d23930aaa 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java @@ -48,8 +48,8 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>() { @Override - public Publisher apply(Flowable o) throws Exception { - return o + public Publisher apply(Flowable f) throws Exception { + return f .doOnLifecycle(new Consumer() { @Override public void accept(Subscription s) throws Exception { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnSubscribeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnSubscribeTest.java index 339125c7e8..0b75ec3338 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnSubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnSubscribeTest.java @@ -29,23 +29,23 @@ public class FlowableDoOnSubscribeTest { @Test public void testDoOnSubscribe() throws Exception { final AtomicInteger count = new AtomicInteger(); - Flowable o = Flowable.just(1).doOnSubscribe(new Consumer() { + Flowable f = Flowable.just(1).doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { count.incrementAndGet(); } }); - o.subscribe(); - o.subscribe(); - o.subscribe(); + f.subscribe(); + f.subscribe(); + f.subscribe(); assertEquals(3, count.get()); } @Test public void testDoOnSubscribe2() throws Exception { final AtomicInteger count = new AtomicInteger(); - Flowable o = Flowable.just(1).doOnSubscribe(new Consumer() { + Flowable f = Flowable.just(1).doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { count.incrementAndGet(); @@ -57,7 +57,7 @@ public void accept(Subscription s) { } }); - o.subscribe(); + f.subscribe(); assertEquals(2, count.get()); } @@ -67,7 +67,7 @@ public void testDoOnUnSubscribeWorksWithRefCount() throws Exception { final AtomicInteger countBefore = new AtomicInteger(); final AtomicInteger countAfter = new AtomicInteger(); final AtomicReference> sref = new AtomicReference>(); - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -89,16 +89,16 @@ public void accept(Subscription s) { } }); - o.subscribe(); - o.subscribe(); - o.subscribe(); + f.subscribe(); + f.subscribe(); + f.subscribe(); assertEquals(1, countBefore.get()); assertEquals(1, onSubscribed.get()); assertEquals(3, countAfter.get()); sref.get().onComplete(); - o.subscribe(); - o.subscribe(); - o.subscribe(); + f.subscribe(); + f.subscribe(); + f.subscribe(); assertEquals(2, countBefore.get()); assertEquals(2, onSubscribed.get()); assertEquals(6, countAfter.get()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java index 1b795665ad..e8a395fc3b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java @@ -191,22 +191,22 @@ public void elementAtOrErrorIndex1OnEmptySource() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>() { @Override - public Publisher apply(Flowable o) throws Exception { - return o.elementAt(0).toFlowable(); + public Publisher apply(Flowable f) throws Exception { + return f.elementAt(0).toFlowable(); } }); TestHelper.checkDoubleOnSubscribeFlowableToMaybe(new Function, Maybe>() { @Override - public Maybe apply(Flowable o) throws Exception { - return o.elementAt(0); + public Maybe apply(Flowable f) throws Exception { + return f.elementAt(0); } }); TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function, Single>() { @Override - public Single apply(Flowable o) throws Exception { - return o.elementAt(0, 1); + public Single apply(Flowable f) throws Exception { + return f.elementAt(0, 1); } }); } @@ -338,13 +338,13 @@ public void badSource2() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onNext(2); - observer.onError(new TestException()); - observer.onComplete(); + subscriber.onNext(1); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .elementAt(0, 1) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java index 836ead8bca..85093c4576 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java @@ -66,7 +66,7 @@ public boolean test(String t1) { @Test(timeout = 500) public void testWithBackpressure() throws InterruptedException { Flowable w = Flowable.just("one", "two", "three"); - Flowable o = w.filter(new Predicate() { + Flowable f = w.filter(new Predicate() { @Override public boolean test(String t1) { @@ -100,7 +100,7 @@ public void onNext(String t) { // this means it will only request "one" and "two", expecting to receive them before requesting more ts.request(2); - o.subscribe(ts); + f.subscribe(ts); // this will wait forever unless OperatorTake handles the request(n) on filtered items latch.await(); @@ -113,7 +113,7 @@ public void onNext(String t) { @Test(timeout = 500000) public void testWithBackpressure2() throws InterruptedException { Flowable w = Flowable.range(1, Flowable.bufferSize() * 2); - Flowable o = w.filter(new Predicate() { + Flowable f = w.filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -146,7 +146,7 @@ public void onNext(Integer t) { // this means it will only request 1 item and expect to receive more ts.request(1); - o.subscribe(ts); + f.subscribe(ts); // this will wait forever unless OperatorTake handles the request(n) on filtered items latch.await(); @@ -555,8 +555,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.filter(Functions.alwaysTrue()); + public Flowable apply(Flowable f) throws Exception { + return f.filter(Functions.alwaysTrue()); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFirstTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFirstTest.java index 38c5723726..3d4eacd281 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFirstTest.java @@ -92,46 +92,46 @@ public void testFirstOrElseWithPredicateOfSomeFlowable() { @Test public void testFirstFlowable() { - Flowable observable = Flowable.just(1, 2, 3).firstElement().toFlowable(); + Flowable flowable = Flowable.just(1, 2, 3).firstElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstWithOneElementFlowable() { - Flowable observable = Flowable.just(1).firstElement().toFlowable(); + Flowable flowable = Flowable.just(1).firstElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstWithEmptyFlowable() { - Flowable observable = Flowable. empty().firstElement().toFlowable(); + Flowable flowable = Flowable. empty().firstElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onComplete(); - inOrder.verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onComplete(); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstWithPredicateFlowable() { - Flowable observable = Flowable.just(1, 2, 3, 4, 5, 6) + Flowable flowable = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -140,18 +140,18 @@ public boolean test(Integer t1) { }) .firstElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstWithPredicateAndOneElementFlowable() { - Flowable observable = Flowable.just(1, 2) + Flowable flowable = Flowable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -160,18 +160,18 @@ public boolean test(Integer t1) { }) .firstElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstWithPredicateAndEmptyFlowable() { - Flowable observable = Flowable.just(1) + Flowable flowable = Flowable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -180,59 +180,59 @@ public boolean test(Integer t1) { }) .firstElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onComplete(); - inOrder.verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onComplete(); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstOrDefaultFlowable() { - Flowable observable = Flowable.just(1, 2, 3) + Flowable flowable = Flowable.just(1, 2, 3) .first(4).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstOrDefaultWithOneElementFlowable() { - Flowable observable = Flowable.just(1).first(2).toFlowable(); + Flowable flowable = Flowable.just(1).first(2).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstOrDefaultWithEmptyFlowable() { - Flowable observable = Flowable. empty() + Flowable flowable = Flowable. empty() .first(1).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstOrDefaultWithPredicateFlowable() { - Flowable observable = Flowable.just(1, 2, 3, 4, 5, 6) + Flowable flowable = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -241,18 +241,18 @@ public boolean test(Integer t1) { }) .first(8).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstOrDefaultWithPredicateAndOneElementFlowable() { - Flowable observable = Flowable.just(1, 2) + Flowable flowable = Flowable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -261,18 +261,18 @@ public boolean test(Integer t1) { }) .first(4).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testFirstOrDefaultWithPredicateAndEmptyFlowable() { - Flowable observable = Flowable.just(1) + Flowable flowable = Flowable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -281,12 +281,12 @@ public boolean test(Integer t1) { }) .first(2).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -332,9 +332,9 @@ public void testFirstOrElseWithPredicateOfSome() { @Test public void testFirst() { - Maybe observable = Flowable.just(1, 2, 3).firstElement(); + Maybe maybe = Flowable.just(1, 2, 3).firstElement(); - observable.subscribe(wm); + maybe.subscribe(wm); InOrder inOrder = inOrder(wm); inOrder.verify(wm, times(1)).onSuccess(1); @@ -343,9 +343,9 @@ public void testFirst() { @Test public void testFirstWithOneElement() { - Maybe observable = Flowable.just(1).firstElement(); + Maybe maybe = Flowable.just(1).firstElement(); - observable.subscribe(wm); + maybe.subscribe(wm); InOrder inOrder = inOrder(wm); inOrder.verify(wm, times(1)).onSuccess(1); @@ -354,9 +354,9 @@ public void testFirstWithOneElement() { @Test public void testFirstWithEmpty() { - Maybe observable = Flowable. empty().firstElement(); + Maybe maybe = Flowable. empty().firstElement(); - observable.subscribe(wm); + maybe.subscribe(wm); InOrder inOrder = inOrder(wm); inOrder.verify(wm).onComplete(); @@ -366,7 +366,7 @@ public void testFirstWithEmpty() { @Test public void testFirstWithPredicate() { - Maybe observable = Flowable.just(1, 2, 3, 4, 5, 6) + Maybe maybe = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -375,7 +375,7 @@ public boolean test(Integer t1) { }) .firstElement(); - observable.subscribe(wm); + maybe.subscribe(wm); InOrder inOrder = inOrder(wm); inOrder.verify(wm, times(1)).onSuccess(2); @@ -384,7 +384,7 @@ public boolean test(Integer t1) { @Test public void testFirstWithPredicateAndOneElement() { - Maybe observable = Flowable.just(1, 2) + Maybe maybe = Flowable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -393,7 +393,7 @@ public boolean test(Integer t1) { }) .firstElement(); - observable.subscribe(wm); + maybe.subscribe(wm); InOrder inOrder = inOrder(wm); inOrder.verify(wm, times(1)).onSuccess(2); @@ -402,7 +402,7 @@ public boolean test(Integer t1) { @Test public void testFirstWithPredicateAndEmpty() { - Maybe observable = Flowable.just(1) + Maybe maybe = Flowable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -411,7 +411,7 @@ public boolean test(Integer t1) { }) .firstElement(); - observable.subscribe(wm); + maybe.subscribe(wm); InOrder inOrder = inOrder(wm); inOrder.verify(wm).onComplete(); @@ -421,10 +421,10 @@ public boolean test(Integer t1) { @Test public void testFirstOrDefault() { - Single observable = Flowable.just(1, 2, 3) + Single single = Flowable.just(1, 2, 3) .first(4); - observable.subscribe(wo); + single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(1); @@ -433,9 +433,9 @@ public void testFirstOrDefault() { @Test public void testFirstOrDefaultWithOneElement() { - Single observable = Flowable.just(1).first(2); + Single single = Flowable.just(1).first(2); - observable.subscribe(wo); + single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(1); @@ -444,10 +444,10 @@ public void testFirstOrDefaultWithOneElement() { @Test public void testFirstOrDefaultWithEmpty() { - Single observable = Flowable. empty() + Single single = Flowable. empty() .first(1); - observable.subscribe(wo); + single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(1); @@ -456,7 +456,7 @@ public void testFirstOrDefaultWithEmpty() { @Test public void testFirstOrDefaultWithPredicate() { - Single observable = Flowable.just(1, 2, 3, 4, 5, 6) + Single single = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -465,7 +465,7 @@ public boolean test(Integer t1) { }) .first(8); - observable.subscribe(wo); + single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(2); @@ -474,7 +474,7 @@ public boolean test(Integer t1) { @Test public void testFirstOrDefaultWithPredicateAndOneElement() { - Single observable = Flowable.just(1, 2) + Single single = Flowable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -483,7 +483,7 @@ public boolean test(Integer t1) { }) .first(4); - observable.subscribe(wo); + single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(2); @@ -492,7 +492,7 @@ public boolean test(Integer t1) { @Test public void testFirstOrDefaultWithPredicateAndEmpty() { - Single observable = Flowable.just(1) + Single single = Flowable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -501,7 +501,7 @@ public boolean test(Integer t1) { }) .first(2); - observable.subscribe(wo); + single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(2); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java index 3e7ea75c66..c0ddc1f302 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java @@ -399,8 +399,8 @@ public CompletableSource apply(Integer v) throws Exception { public void badSource() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.flatMapCompletable(new Function() { + public Object apply(Flowable f) throws Exception { + return f.flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); @@ -455,14 +455,14 @@ public void innerObserverFlowable() { public CompletableSource apply(Integer v) throws Exception { return new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); - assertFalse(((Disposable)s).isDisposed()); + assertFalse(((Disposable)observer).isDisposed()); - ((Disposable)s).dispose(); + ((Disposable)observer).dispose(); - assertTrue(((Disposable)s).isDisposed()); + assertTrue(((Disposable)observer).isDisposed()); } }; } @@ -475,8 +475,8 @@ protected void subscribeActual(CompletableObserver s) { public void badSourceFlowable() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.flatMapCompletable(new Function() { + public Object apply(Flowable f) throws Exception { + return f.flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); @@ -494,14 +494,14 @@ public void innerObserver() { public CompletableSource apply(Integer v) throws Exception { return new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); - assertFalse(((Disposable)s).isDisposed()); + assertFalse(((Disposable)observer).isDisposed()); - ((Disposable)s).dispose(); + ((Disposable)observer).dispose(); - assertTrue(((Disposable)s).isDisposed()); + assertTrue(((Disposable)observer).isDisposed()); } }; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java index cee2e89628..eac6c0503f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java @@ -411,10 +411,10 @@ public void badSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException("First")); - observer.onError(new TestException("Second")); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException("First")); + subscriber.onError(new TestException("Second")); } } .flatMapMaybe(Functions.justFunction(Maybe.just(2))) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java index 78217c9330..381d210070 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java @@ -331,10 +331,10 @@ public void badSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException("First")); - observer.onError(new TestException("Second")); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException("First")); + subscriber.onError(new TestException("Second")); } } .flatMapSingle(Functions.justFunction(Single.just(2))) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java index 9b3037a4c2..9cdbfc26af 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java @@ -36,7 +36,7 @@ public class FlowableFlatMapTest { @Test public void testNormal() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final List list = Arrays.asList(1, 2, 3); @@ -56,20 +56,20 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Flowable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); + Flowable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(subscriber); for (Integer s : source) { for (Integer v : list) { - verify(o).onNext(s | v); + verify(subscriber).onNext(s | v); } } - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testCollectionFunctionThrows() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Function> func = new Function>() { @Override @@ -87,16 +87,16 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Flowable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); + Flowable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(subscriber); - verify(o, never()).onComplete(); - verify(o, never()).onNext(any()); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber).onError(any(TestException.class)); } @Test public void testResultFunctionThrows() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final List list = Arrays.asList(1, 2, 3); @@ -116,16 +116,16 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Flowable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); + Flowable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(subscriber); - verify(o, never()).onComplete(); - verify(o, never()).onNext(any()); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber).onError(any(TestException.class)); } @Test public void testMergeError() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Function> func = new Function>() { @Override @@ -143,11 +143,11 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Flowable.fromIterable(source).flatMap(func, resFunc).subscribe(o); + Flowable.fromIterable(source).flatMap(func, resFunc).subscribe(subscriber); - verify(o, never()).onComplete(); - verify(o, never()).onNext(any()); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber).onError(any(TestException.class)); } Function just(final R value) { @@ -178,18 +178,18 @@ public void testFlatMapTransformsNormal() { Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.flatMap(just(onNext), just(onError), just0(onComplete)).subscribe(o); + source.flatMap(just(onNext), just(onError), just0(onComplete)).subscribe(subscriber); - verify(o, times(3)).onNext(1); - verify(o, times(3)).onNext(2); - verify(o, times(3)).onNext(3); - verify(o).onNext(4); - verify(o).onComplete(); + verify(subscriber, times(3)).onNext(1); + verify(subscriber, times(3)).onNext(2); + verify(subscriber, times(3)).onNext(3); + verify(subscriber).onNext(4); + verify(subscriber).onComplete(); - verify(o, never()).onNext(5); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(5); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -204,18 +204,18 @@ Flowable. error(new RuntimeException("Forced failure!")) ); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.flatMap(just(onNext), just(onError), just0(onComplete)).subscribe(o); + source.flatMap(just(onNext), just(onError), just0(onComplete)).subscribe(subscriber); - verify(o, times(3)).onNext(1); - verify(o, times(3)).onNext(2); - verify(o, times(3)).onNext(3); - verify(o).onNext(5); - verify(o).onComplete(); - verify(o, never()).onNext(4); + verify(subscriber, times(3)).onNext(1); + verify(subscriber, times(3)).onNext(2); + verify(subscriber, times(3)).onNext(3); + verify(subscriber).onNext(5); + verify(subscriber).onComplete(); + verify(subscriber, never()).onNext(4); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } Callable funcThrow0(R r) { @@ -238,18 +238,25 @@ public R apply(T t) { @Test public void testFlatMapTransformsOnNextFuncThrows() { - Flowable onComplete = Flowable.fromIterable(Arrays.asList(4)); - Flowable onError = Flowable.fromIterable(Arrays.asList(5)); + List errors = TestHelper.trackPluginErrors(); + try { + Flowable onComplete = Flowable.fromIterable(Arrays.asList(4)); + Flowable onError = Flowable.fromIterable(Arrays.asList(5)); - Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); + Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.flatMap(funcThrow(1, onError), just(onError), just0(onComplete)).subscribe(o); + source.flatMap(funcThrow(1, onError), just(onError), just0(onComplete)).subscribe(subscriber); - verify(o).onError(any(TestException.class)); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -260,13 +267,13 @@ public void testFlatMapTransformsOnErrorFuncThrows() { Flowable source = Flowable.error(new TestException()); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.flatMap(just(onNext), funcThrow((Throwable) null, onError), just0(onComplete)).subscribe(o); + source.flatMap(just(onNext), funcThrow((Throwable) null, onError), just0(onComplete)).subscribe(subscriber); - verify(o).onError(any(CompositeException.class)); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber).onError(any(CompositeException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -277,13 +284,13 @@ public void testFlatMapTransformsOnCompletedFuncThrows() { Flowable source = Flowable.fromIterable(Arrays. asList()); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.flatMap(just(onNext), just(onError), funcThrow0(onComplete)).subscribe(o); + source.flatMap(just(onNext), just(onError), funcThrow0(onComplete)).subscribe(subscriber); - verify(o).onError(any(TestException.class)); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -294,13 +301,13 @@ public void testFlatMapTransformsMergeException() { Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.flatMap(just(onNext), just(onError), funcThrow0(onComplete)).subscribe(o); + source.flatMap(just(onNext), just(onError), funcThrow0(onComplete)).subscribe(subscriber); - verify(o).onError(any(TestException.class)); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } private static Flowable composer(Flowable source, final AtomicInteger subscriptionCount, final int m) { @@ -411,8 +418,8 @@ public void testFlatMapTransformsMaxConcurrentNormal() { Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); - Subscriber o = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); Function> just = just(onNext); Function> just2 = just(onError); @@ -423,14 +430,14 @@ public void testFlatMapTransformsMaxConcurrentNormal() { ts.assertNoErrors(); ts.assertTerminated(); - verify(o, times(3)).onNext(1); - verify(o, times(3)).onNext(2); - verify(o, times(3)).onNext(3); - verify(o).onNext(4); - verify(o).onComplete(); + verify(subscriber, times(3)).onNext(1); + verify(subscriber, times(3)).onNext(2); + verify(subscriber, times(3)).onNext(3); + verify(subscriber).onNext(4); + verify(subscriber).onComplete(); - verify(o, never()).onNext(5); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(5); + verify(subscriber, never()).onError(any(Throwable.class)); } @Ignore("Don't care for any reordering") diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterableTest.java index 8448e1db06..9baf8f2ea7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterableTest.java @@ -583,8 +583,8 @@ public Iterable apply(Object v) throws Exception { public void badSource() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.flatMapIterable(new Function>() { + public Object apply(Flowable f) throws Exception { + return f.flatMapIterable(new Function>() { @Override public Iterable apply(Object v) throws Exception { return Arrays.asList(10, 20); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java index bb51c905aa..f3f5e00fa5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java @@ -58,13 +58,13 @@ public void shouldCallOnNextAndOnCompleted() throws Exception { Flowable fromCallableFlowable = Flowable.fromCallable(func); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - fromCallableFlowable.subscribe(observer); + fromCallableFlowable.subscribe(subscriber); - verify(observer).onNext("test_value"); - verify(observer).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber).onNext("test_value"); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @SuppressWarnings("unchecked") @@ -77,13 +77,13 @@ public void shouldCallOnError() throws Exception { Flowable fromCallableFlowable = Flowable.fromCallable(func); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - fromCallableFlowable.subscribe(observer); + fromCallableFlowable.subscribe(subscriber); - verify(observer, never()).onNext(any()); - verify(observer, never()).onComplete(); - verify(observer).onError(throwable); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(throwable); } @SuppressWarnings("unchecked") @@ -114,9 +114,9 @@ public String answer(InvocationOnMock invocation) throws Throwable { Flowable fromCallableFlowable = Flowable.fromCallable(func); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber outer = new TestSubscriber(observer); + TestSubscriber outer = new TestSubscriber(subscriber); fromCallableFlowable .subscribeOn(Schedulers.computation()) @@ -135,8 +135,8 @@ public String answer(InvocationOnMock invocation) throws Throwable { verify(func).call(); // Observer must not be notified at all - verify(observer).onSubscribe(any(Subscription.class)); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe(any(Subscription.class)); + verifyNoMoreInteractions(subscriber); } @Test @@ -150,13 +150,13 @@ public Object call() throws Exception { } }); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - fromCallableFlowable.subscribe(observer); + fromCallableFlowable.subscribe(subscriber); - verify(observer).onSubscribe(any(Subscription.class)); - verify(observer).onError(checkedException); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe(any(Subscription.class)); + verify(subscriber).onError(checkedException); + verifyNoMoreInteractions(subscriber); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java index f606ee6eb4..421cd9e4c7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java @@ -46,15 +46,15 @@ public void testNull() { public void testListIterable() { Flowable flowable = Flowable.fromIterable(Arrays. asList("one", "two", "three")); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - flowable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } /** @@ -90,30 +90,30 @@ public void remove() { }; Flowable flowable = Flowable.fromIterable(it); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - flowable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext("1"); - verify(observer, times(1)).onNext("2"); - verify(observer, times(1)).onNext("3"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("1"); + verify(subscriber, times(1)).onNext("2"); + verify(subscriber, times(1)).onNext("3"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testObservableFromIterable() { Flowable flowable = Flowable.fromIterable(Arrays. asList("one", "two", "three")); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - flowable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -122,14 +122,14 @@ public void testBackpressureViaRequest() { for (int i = 1; i <= Flowable.bufferSize() + 1; i++) { list.add(i); } - Flowable o = Flowable.fromIterable(list); + Flowable f = Flowable.fromIterable(list); TestSubscriber ts = new TestSubscriber(0L); ts.assertNoValues(); ts.request(1); - o.subscribe(ts); + f.subscribe(ts); ts.assertValue(1); ts.request(2); @@ -142,14 +142,14 @@ public void testBackpressureViaRequest() { @Test public void testNoBackpressure() { - Flowable o = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)); + Flowable f = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)); TestSubscriber ts = new TestSubscriber(0L); ts.assertNoValues(); ts.request(Long.MAX_VALUE); // infinite - o.subscribe(ts); + f.subscribe(ts); ts.assertValues(1, 2, 3, 4, 5); ts.assertTerminated(); @@ -157,12 +157,12 @@ public void testNoBackpressure() { @Test public void testSubscribeMultipleTimes() { - Flowable o = Flowable.fromIterable(Arrays.asList(1, 2, 3)); + Flowable f = Flowable.fromIterable(Arrays.asList(1, 2, 3)); for (int i = 0; i < 10; i++) { TestSubscriber ts = new TestSubscriber(); - o.subscribe(ts); + f.subscribe(ts); ts.assertValues(1, 2, 3); ts.assertNoErrors(); @@ -172,12 +172,12 @@ public void testSubscribeMultipleTimes() { @Test public void testFromIterableRequestOverflow() throws InterruptedException { - Flowable o = Flowable.fromIterable(Arrays.asList(1,2,3,4)); + Flowable f = Flowable.fromIterable(Arrays.asList(1,2,3,4)); final int expectedCount = 4; final CountDownLatch latch = new CountDownLatch(expectedCount); - o.subscribeOn(Schedulers.computation()) + f.subscribeOn(Schedulers.computation()) .subscribe(new DefaultSubscriber() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java index 2aa29ffca8..e1f15bb261 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java @@ -13,12 +13,15 @@ package io.reactivex.internal.operators.flowable; +import java.util.List; + import org.junit.*; import org.reactivestreams.*; import io.reactivex.*; import io.reactivex.exceptions.*; import io.reactivex.functions.Cancellable; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.*; @@ -271,82 +274,116 @@ public void unsubscribedMissing() { @Test public void unsubscribedNoCancelBuffer() { - Flowable.create(sourceNoCancel, BackpressureStrategy.BUFFER).subscribe(ts); - ts.cancel(); + List errors = TestHelper.trackPluginErrors(); + try { + Flowable.create(sourceNoCancel, BackpressureStrategy.BUFFER).subscribe(ts); + ts.cancel(); - sourceNoCancel.onNext(1); - sourceNoCancel.onNext(2); - sourceNoCancel.onError(new TestException()); + sourceNoCancel.onNext(1); + sourceNoCancel.onNext(2); + sourceNoCancel.onError(new TestException()); - ts.request(1); + ts.request(1); - ts.assertNoValues(); - ts.assertNoErrors(); - ts.assertNotComplete(); + ts.assertNoValues(); + ts.assertNoErrors(); + ts.assertNotComplete(); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void unsubscribedNoCancelLatest() { - Flowable.create(sourceNoCancel, BackpressureStrategy.LATEST).subscribe(ts); - ts.cancel(); - - sourceNoCancel.onNext(1); - sourceNoCancel.onNext(2); - sourceNoCancel.onError(new TestException()); - - ts.request(1); - - ts.assertNoValues(); - ts.assertNoErrors(); - ts.assertNotComplete(); + List errors = TestHelper.trackPluginErrors(); + try { + Flowable.create(sourceNoCancel, BackpressureStrategy.LATEST).subscribe(ts); + ts.cancel(); + + sourceNoCancel.onNext(1); + sourceNoCancel.onNext(2); + sourceNoCancel.onError(new TestException()); + + ts.request(1); + + ts.assertNoValues(); + ts.assertNoErrors(); + ts.assertNotComplete(); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void unsubscribedNoCancelError() { - Flowable.create(sourceNoCancel, BackpressureStrategy.ERROR).subscribe(ts); - ts.cancel(); + List errors = TestHelper.trackPluginErrors(); + try { + Flowable.create(sourceNoCancel, BackpressureStrategy.ERROR).subscribe(ts); + ts.cancel(); - sourceNoCancel.onNext(1); - sourceNoCancel.onNext(2); - sourceNoCancel.onError(new TestException()); + sourceNoCancel.onNext(1); + sourceNoCancel.onNext(2); + sourceNoCancel.onError(new TestException()); - ts.request(1); + ts.request(1); - ts.assertNoValues(); - ts.assertNoErrors(); - ts.assertNotComplete(); + ts.assertNoValues(); + ts.assertNoErrors(); + ts.assertNotComplete(); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void unsubscribedNoCancelDrop() { - Flowable.create(sourceNoCancel, BackpressureStrategy.DROP).subscribe(ts); - ts.cancel(); + List errors = TestHelper.trackPluginErrors(); + try { + Flowable.create(sourceNoCancel, BackpressureStrategy.DROP).subscribe(ts); + ts.cancel(); - sourceNoCancel.onNext(1); - sourceNoCancel.onNext(2); - sourceNoCancel.onError(new TestException()); + sourceNoCancel.onNext(1); + sourceNoCancel.onNext(2); + sourceNoCancel.onError(new TestException()); - ts.request(1); + ts.request(1); - ts.assertNoValues(); - ts.assertNoErrors(); - ts.assertNotComplete(); + ts.assertNoValues(); + ts.assertNoErrors(); + ts.assertNotComplete(); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void unsubscribedNoCancelMissing() { - Flowable.create(sourceNoCancel, BackpressureStrategy.MISSING).subscribe(ts); - ts.cancel(); + List errors = TestHelper.trackPluginErrors(); + try { + Flowable.create(sourceNoCancel, BackpressureStrategy.MISSING).subscribe(ts); + ts.cancel(); - sourceNoCancel.onNext(1); - sourceNoCancel.onNext(2); - sourceNoCancel.onError(new TestException()); + sourceNoCancel.onNext(1); + sourceNoCancel.onNext(2); + sourceNoCancel.onError(new TestException()); - ts.request(1); + ts.request(1); - ts.assertNoValues(); - ts.assertNoErrors(); - ts.assertNotComplete(); + ts.assertNoValues(); + ts.assertNoErrors(); + ts.assertNotComplete(); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -622,12 +659,12 @@ public void onNext(Integer t) { static final class PublishAsyncEmitter implements FlowableOnSubscribe, FlowableSubscriber { - final PublishProcessor subject; + final PublishProcessor processor; FlowableEmitter current; PublishAsyncEmitter() { - this.subject = PublishProcessor.create(); + this.processor = PublishProcessor.create(); } long requested() { @@ -658,7 +695,7 @@ public void onNext(Integer v) { }; - subject.subscribe(as); + processor.subscribe(as); t.setCancellable(new Cancellable() { @Override @@ -675,32 +712,32 @@ public void onSubscribe(Subscription s) { @Override public void onNext(Integer t) { - subject.onNext(t); + processor.onNext(t); } @Override public void onError(Throwable e) { - subject.onError(e); + processor.onError(e); } @Override public void onComplete() { - subject.onComplete(); + processor.onComplete(); } } static final class PublishAsyncEmitterNoCancel implements FlowableOnSubscribe, FlowableSubscriber { - final PublishProcessor subject; + final PublishProcessor processor; PublishAsyncEmitterNoCancel() { - this.subject = PublishProcessor.create(); + this.processor = PublishProcessor.create(); } @Override public void subscribe(final FlowableEmitter t) { - subject.subscribe(new FlowableSubscriber() { + processor.subscribe(new FlowableSubscriber() { @Override public void onSubscribe(Subscription s) { @@ -732,17 +769,17 @@ public void onSubscribe(Subscription s) { @Override public void onNext(Integer t) { - subject.onNext(t); + processor.onNext(t); } @Override public void onError(Throwable e) { - subject.onError(e); + processor.onError(e); } @Override public void onComplete() { - subject.onComplete(); + processor.onComplete(); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java index bc2473d93e..022ab3788f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java @@ -102,7 +102,7 @@ public void testEmpty() { @Test public void testError() { Flowable sourceStrings = Flowable.just("one", "two", "three", "four", "five", "six"); - Flowable errorSource = Flowable.error(new RuntimeException("forced failure")); + Flowable errorSource = Flowable.error(new TestException("forced failure")); Flowable source = Flowable.concat(sourceStrings, errorSource); Flowable> grouped = source.groupBy(length); @@ -114,13 +114,13 @@ public void testError() { grouped.flatMap(new Function, Flowable>() { @Override - public Flowable apply(final GroupedFlowable o) { + public Flowable apply(final GroupedFlowable f) { groupCounter.incrementAndGet(); - return o.map(new Function() { + return f.map(new Function() { @Override public String apply(String v) { - return "Event => key: " + o.getKey() + " value: " + v; + return "Event => key: " + f.getKey() + " value: " + v; } }); } @@ -133,7 +133,7 @@ public void onComplete() { @Override public void onError(Throwable e) { - e.printStackTrace(); +// e.printStackTrace(); error.set(e); } @@ -148,22 +148,24 @@ public void onNext(String v) { assertEquals(3, groupCounter.get()); assertEquals(6, eventCounter.get()); assertNotNull(error.get()); + assertTrue("" + error.get(), error.get() instanceof TestException); + assertEquals(error.get().getMessage(), "forced failure"); } - private static Map> toMap(Flowable> observable) { + private static Map> toMap(Flowable> flowable) { final ConcurrentHashMap> result = new ConcurrentHashMap>(); - observable.blockingForEach(new Consumer>() { + flowable.blockingForEach(new Consumer>() { @Override - public void accept(final GroupedFlowable o) { - result.put(o.getKey(), new ConcurrentLinkedQueue()); - o.subscribe(new Consumer() { + public void accept(final GroupedFlowable f) { + result.put(f.getKey(), new ConcurrentLinkedQueue()); + f.subscribe(new Consumer() { @Override public void accept(V v) { - result.get(o.getKey()).add(v); + result.get(f.getKey()).add(v); } }); @@ -191,8 +193,8 @@ public void testGroupedEventStream() throws Throwable { Flowable es = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); System.out.println("*** Subscribing to EventStream ***"); subscribeCounter.incrementAndGet(); new Thread(new Runnable() { @@ -203,9 +205,9 @@ public void run() { Event e = new Event(); e.source = i % groupCount; e.message = "Event-" + i; - observer.onNext(e); + subscriber.onNext(e); } - observer.onComplete(); + subscriber.onComplete(); } }).start(); @@ -998,18 +1000,16 @@ public void testGroupByOnAsynchronousSourceAcceptsMultipleSubscriptions() throws Flowable> stream = source.groupBy(IS_EVEN); // create two observers - @SuppressWarnings("unchecked") - DefaultSubscriber> o1 = mock(DefaultSubscriber.class); - @SuppressWarnings("unchecked") - DefaultSubscriber> o2 = mock(DefaultSubscriber.class); + Subscriber> f1 = TestHelper.mockSubscriber(); + Subscriber> f2 = TestHelper.mockSubscriber(); // subscribe with the observers - stream.subscribe(o1); - stream.subscribe(o2); + stream.subscribe(f1); + stream.subscribe(f2); // check that subscriptions were successful - verify(o1, never()).onError(Mockito. any()); - verify(o2, never()).onError(Mockito. any()); + verify(f1, never()).onError(Mockito. any()); + verify(f2, never()).onError(Mockito. any()); } private static Function IS_EVEN = new Function() { @@ -1227,14 +1227,13 @@ public void accept(GroupedFlowable t1) { inner.get().subscribe(); - @SuppressWarnings("unchecked") - DefaultSubscriber o2 = mock(DefaultSubscriber.class); + Subscriber subscriber2 = TestHelper.mockSubscriber(); - inner.get().subscribe(o2); + inner.get().subscribe(subscriber2); - verify(o2, never()).onComplete(); - verify(o2, never()).onNext(anyInt()); - verify(o2).onError(any(IllegalStateException.class)); + verify(subscriber2, never()).onComplete(); + verify(subscriber2, never()).onNext(anyInt()); + verify(subscriber2).onError(any(IllegalStateException.class)); } @Test @@ -1386,7 +1385,7 @@ public void accept(String s) { @Test public void testGroupByUnsubscribe() { final Subscription s = mock(Subscription.class); - Flowable o = Flowable.unsafeCreate( + Flowable f = Flowable.unsafeCreate( new Publisher() { @Override public void subscribe(Subscriber subscriber) { @@ -1396,7 +1395,7 @@ public void subscribe(Subscriber subscriber) { ); TestSubscriber ts = new TestSubscriber(); - o.groupBy(new Function() { + f.groupBy(new Function() { @Override public Integer apply(Integer integer) { @@ -1427,11 +1426,11 @@ public void onError(Throwable e) { } @Override - public void onNext(GroupedFlowable o) { - if (o.getKey() == 0) { - o.subscribe(inner1); + public void onNext(GroupedFlowable f) { + if (f.getKey() == 0) { + f.subscribe(inner1); } else { - o.subscribe(inner2); + f.subscribe(inner2); } } }); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java index 0d27bc2280..b9e1b4f995 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java @@ -36,7 +36,7 @@ public class FlowableGroupJoinTest { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); BiFunction add = new BiFunction() { @Override @@ -45,20 +45,20 @@ public Integer apply(Integer t1, Integer t2) { } }; - Function> just(final Flowable observable) { + Function> just(final Flowable flowable) { return new Function>() { @Override public Flowable apply(Integer t1) { - return observable; + return flowable; } }; } - Function> just2(final Flowable observable) { + Function> just2(final Flowable flowable) { return new Function>() { @Override public Flowable apply(T t1) { - return observable; + return flowable; } }; } @@ -90,7 +90,7 @@ public void behaveAsJoin() { just(Flowable.never()), just(Flowable.never()), add2)); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); source1.onNext(2); @@ -103,18 +103,18 @@ public void behaveAsJoin() { source1.onComplete(); source2.onComplete(); - verify(observer, times(1)).onNext(17); - verify(observer, times(1)).onNext(18); - verify(observer, times(1)).onNext(20); - verify(observer, times(1)).onNext(33); - verify(observer, times(1)).onNext(34); - verify(observer, times(1)).onNext(36); - verify(observer, times(1)).onNext(65); - verify(observer, times(1)).onNext(66); - verify(observer, times(1)).onNext(68); - - verify(observer, times(1)).onComplete(); //Never emitted? - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext(17); + verify(subscriber, times(1)).onNext(18); + verify(subscriber, times(1)).onNext(20); + verify(subscriber, times(1)).onNext(33); + verify(subscriber, times(1)).onNext(34); + verify(subscriber, times(1)).onNext(36); + verify(subscriber, times(1)).onNext(65); + verify(subscriber, times(1)).onNext(66); + verify(subscriber, times(1)).onNext(68); + + verify(subscriber, times(1)).onComplete(); //Never emitted? + verify(subscriber, never()).onError(any(Throwable.class)); } class Person { @@ -184,19 +184,19 @@ public boolean test(PersonFruit t1) { }).subscribe(new Consumer() { @Override public void accept(PersonFruit t1) { - observer.onNext(Arrays.asList(ppf.person.name, t1.fruit)); + subscriber.onNext(Arrays.asList(ppf.person.name, t1.fruit)); } }); } @Override public void onError(Throwable e) { - observer.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - observer.onComplete(); + subscriber.onComplete(); } @Override @@ -207,12 +207,12 @@ public void onSubscribe(Subscription s) { } ); - verify(observer, times(1)).onNext(Arrays.asList("Joe", "Strawberry")); - verify(observer, times(1)).onNext(Arrays.asList("Joe", "Apple")); - verify(observer, times(1)).onNext(Arrays.asList("Charlie", "Peach")); + verify(subscriber, times(1)).onNext(Arrays.asList("Joe", "Strawberry")); + verify(subscriber, times(1)).onNext(Arrays.asList("Joe", "Apple")); + verify(subscriber, times(1)).onNext(Arrays.asList("Charlie", "Peach")); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -224,14 +224,14 @@ public void leftThrows() { just(Flowable.never()), just(Flowable.never()), add2); - m.subscribe(observer); + m.subscribe(subscriber); source2.onNext(1); source1.onError(new RuntimeException("Forced failure")); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -243,14 +243,14 @@ public void rightThrows() { just(Flowable.never()), just(Flowable.never()), add2); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); source2.onError(new RuntimeException("Forced failure")); - verify(observer, times(1)).onNext(any(Flowable.class)); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); + verify(subscriber, times(1)).onNext(any(Flowable.class)); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); } @Test @@ -263,13 +263,13 @@ public void leftDurationThrows() { Flowable> m = source1.groupJoin(source2, just(duration1), just(Flowable.never()), add2); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -282,13 +282,13 @@ public void rightDurationThrows() { Flowable> m = source1.groupJoin(source2, just(Flowable.never()), just(duration1), add2); - m.subscribe(observer); + m.subscribe(subscriber); source2.onNext(1); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -306,13 +306,13 @@ public Flowable apply(Integer t1) { Flowable> m = source1.groupJoin(source2, fail, just(Flowable.never()), add2); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -330,13 +330,13 @@ public Flowable apply(Integer t1) { Flowable> m = source1.groupJoin(source2, just(Flowable.never()), fail, add2); - m.subscribe(observer); + m.subscribe(subscriber); source2.onNext(1); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -354,14 +354,14 @@ public Integer apply(Integer t1, Flowable t2) { Flowable m = source1.groupJoin(source2, just(Flowable.never()), just(Flowable.never()), fail); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); source2.onNext(2); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -478,31 +478,38 @@ public Flowable apply(Integer r, Flowable l) throws Exception @Test public void innerErrorRight() { - Flowable.just(1) - .groupJoin( - Flowable.just(2), - new Function>() { - @Override - public Flowable apply(Integer left) throws Exception { - return Flowable.never(); - } - }, - new Function>() { - @Override - public Flowable apply(Integer right) throws Exception { - return Flowable.error(new TestException()); - } - }, - new BiFunction, Flowable>() { - @Override - public Flowable apply(Integer r, Flowable l) throws Exception { - return l; + List errors = TestHelper.trackPluginErrors(); + try { + Flowable.just(1) + .groupJoin( + Flowable.just(2), + new Function>() { + @Override + public Flowable apply(Integer left) throws Exception { + return Flowable.never(); + } + }, + new Function>() { + @Override + public Flowable apply(Integer right) throws Exception { + return Flowable.error(new TestException()); + } + }, + new BiFunction, Flowable>() { + @Override + public Flowable apply(Integer r, Flowable l) throws Exception { + return l; + } } - } - ) - .flatMap(Functions.>identity()) - .test() - .assertFailure(TestException.class); + ) + .flatMap(Functions.>identity()) + .test() + .assertFailure(TestException.class); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java index df67bccf02..af85b261c6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java @@ -34,16 +34,16 @@ public void testHiding() { assertFalse(dst instanceof PublishProcessor); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - dst.subscribe(o); + dst.subscribe(subscriber); src.onNext(1); src.onComplete(); - verify(o).onNext(1); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -54,24 +54,24 @@ public void testHidingError() { assertFalse(dst instanceof PublishProcessor); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - dst.subscribe(o); + dst.subscribe(subscriber); src.onError(new TestException()); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } @Test public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) + public Flowable apply(Flowable f) throws Exception { - return o.hide(); + return f.hide(); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java index 6d2d42aeaf..8656afde8d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java @@ -330,17 +330,17 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) + public Flowable apply(Flowable f) throws Exception { - return o.ignoreElements().toFlowable(); + return f.ignoreElements().toFlowable(); } }); TestHelper.checkDoubleOnSubscribeFlowableToCompletable(new Function, Completable>() { @Override - public Completable apply(Flowable o) + public Completable apply(Flowable f) throws Exception { - return o.ignoreElements(); + return f.ignoreElements(); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java index a44b07608f..14a5ec3d59 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java @@ -34,7 +34,7 @@ import io.reactivex.subscribers.TestSubscriber; public class FlowableJoinTest { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); BiFunction add = new BiFunction() { @Override @@ -43,11 +43,11 @@ public Integer apply(Integer t1, Integer t2) { } }; - Function> just(final Flowable observable) { + Function> just(final Flowable flowable) { return new Function>() { @Override public Flowable apply(Integer t1) { - return observable; + return flowable; } }; } @@ -66,7 +66,7 @@ public void normal1() { just(Flowable.never()), just(Flowable.never()), add); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); source1.onNext(2); @@ -79,18 +79,18 @@ public void normal1() { source1.onComplete(); source2.onComplete(); - verify(observer, times(1)).onNext(17); - verify(observer, times(1)).onNext(18); - verify(observer, times(1)).onNext(20); - verify(observer, times(1)).onNext(33); - verify(observer, times(1)).onNext(34); - verify(observer, times(1)).onNext(36); - verify(observer, times(1)).onNext(65); - verify(observer, times(1)).onNext(66); - verify(observer, times(1)).onNext(68); - - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext(17); + verify(subscriber, times(1)).onNext(18); + verify(subscriber, times(1)).onNext(20); + verify(subscriber, times(1)).onNext(33); + verify(subscriber, times(1)).onNext(34); + verify(subscriber, times(1)).onNext(36); + verify(subscriber, times(1)).onNext(65); + verify(subscriber, times(1)).onNext(66); + verify(subscriber, times(1)).onNext(68); + + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -103,7 +103,7 @@ public void normal1WithDuration() { Flowable m = source1.join(source2, just(duration1), just(Flowable.never()), add); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); source1.onNext(2); @@ -117,13 +117,13 @@ public void normal1WithDuration() { source1.onComplete(); source2.onComplete(); - verify(observer, times(1)).onNext(17); - verify(observer, times(1)).onNext(18); - verify(observer, times(1)).onNext(20); - verify(observer, times(1)).onNext(24); + verify(subscriber, times(1)).onNext(17); + verify(subscriber, times(1)).onNext(18); + verify(subscriber, times(1)).onNext(20); + verify(subscriber, times(1)).onNext(24); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @@ -136,7 +136,7 @@ public void normal2() { just(Flowable.never()), just(Flowable.never()), add); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); source1.onNext(2); @@ -148,15 +148,15 @@ public void normal2() { source2.onComplete(); - verify(observer, times(1)).onNext(17); - verify(observer, times(1)).onNext(18); - verify(observer, times(1)).onNext(33); - verify(observer, times(1)).onNext(34); - verify(observer, times(1)).onNext(65); - verify(observer, times(1)).onNext(66); + verify(subscriber, times(1)).onNext(17); + verify(subscriber, times(1)).onNext(18); + verify(subscriber, times(1)).onNext(33); + verify(subscriber, times(1)).onNext(34); + verify(subscriber, times(1)).onNext(65); + verify(subscriber, times(1)).onNext(66); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -168,14 +168,14 @@ public void leftThrows() { just(Flowable.never()), just(Flowable.never()), add); - m.subscribe(observer); + m.subscribe(subscriber); source2.onNext(1); source1.onError(new RuntimeException("Forced failure")); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -187,14 +187,14 @@ public void rightThrows() { just(Flowable.never()), just(Flowable.never()), add); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); source2.onError(new RuntimeException("Forced failure")); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -207,13 +207,13 @@ public void leftDurationThrows() { Flowable m = source1.join(source2, just(duration1), just(Flowable.never()), add); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -226,13 +226,13 @@ public void rightDurationThrows() { Flowable m = source1.join(source2, just(Flowable.never()), just(duration1), add); - m.subscribe(observer); + m.subscribe(subscriber); source2.onNext(1); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -250,13 +250,13 @@ public Flowable apply(Integer t1) { Flowable m = source1.join(source2, fail, just(Flowable.never()), add); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -274,13 +274,13 @@ public Flowable apply(Integer t1) { Flowable m = source1.join(source2, just(Flowable.never()), fail, add); - m.subscribe(observer); + m.subscribe(subscriber); source2.onNext(1); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -298,14 +298,14 @@ public Integer apply(Integer t1, Integer t2) { Flowable m = source1.join(source2, just(Flowable.never()), just(Flowable.never()), fail); - m.subscribe(observer); + m.subscribe(subscriber); source1.onNext(1); source2.onNext(2); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -386,10 +386,10 @@ public void badOuterSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException("First")); - observer.onError(new TestException("Second")); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException("First")); + subscriber.onError(new TestException("Second")); } } .join(Flowable.just(2), @@ -422,10 +422,10 @@ public void badEndSource() { Functions.justFunction(Flowable.never()), Functions.justFunction(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - o[0] = observer; - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException("First")); + protected void subscribeActual(Subscriber subscriber) { + o[0] = subscriber; + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException("First")); } }), new BiFunction() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLastTest.java index 21a0d2935a..517d727903 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLastTest.java @@ -53,10 +53,10 @@ public void testLastViaFlowable() { @Test public void testLast() { - Maybe observable = Flowable.just(1, 2, 3).lastElement(); + Maybe maybe = Flowable.just(1, 2, 3).lastElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(3); @@ -66,10 +66,10 @@ public void testLast() { @Test public void testLastWithOneElement() { - Maybe observable = Flowable.just(1).lastElement(); + Maybe maybe = Flowable.just(1).lastElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); @@ -79,10 +79,10 @@ public void testLastWithOneElement() { @Test public void testLastWithEmpty() { - Maybe observable = Flowable. empty().lastElement(); + Maybe maybe = Flowable. empty().lastElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer).onComplete(); @@ -92,7 +92,7 @@ public void testLastWithEmpty() { @Test public void testLastWithPredicate() { - Maybe observable = Flowable.just(1, 2, 3, 4, 5, 6) + Maybe maybe = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override @@ -103,7 +103,7 @@ public boolean test(Integer t1) { .lastElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(6); @@ -113,7 +113,7 @@ public boolean test(Integer t1) { @Test public void testLastWithPredicateAndOneElement() { - Maybe observable = Flowable.just(1, 2) + Maybe maybe = Flowable.just(1, 2) .filter( new Predicate() { @@ -125,7 +125,7 @@ public boolean test(Integer t1) { .lastElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(2); @@ -135,7 +135,7 @@ public boolean test(Integer t1) { @Test public void testLastWithPredicateAndEmpty() { - Maybe observable = Flowable.just(1) + Maybe maybe = Flowable.just(1) .filter( new Predicate() { @@ -146,7 +146,7 @@ public boolean test(Integer t1) { }).lastElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer).onComplete(); @@ -156,11 +156,11 @@ public boolean test(Integer t1) { @Test public void testLastOrDefault() { - Single observable = Flowable.just(1, 2, 3) + Single single = Flowable.just(1, 2, 3) .last(4); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(3); @@ -170,10 +170,10 @@ public void testLastOrDefault() { @Test public void testLastOrDefaultWithOneElement() { - Single observable = Flowable.just(1).last(2); + Single single = Flowable.just(1).last(2); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); @@ -183,11 +183,11 @@ public void testLastOrDefaultWithOneElement() { @Test public void testLastOrDefaultWithEmpty() { - Single observable = Flowable. empty() + Single single = Flowable. empty() .last(1); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); @@ -197,7 +197,7 @@ public void testLastOrDefaultWithEmpty() { @Test public void testLastOrDefaultWithPredicate() { - Single observable = Flowable.just(1, 2, 3, 4, 5, 6) + Single single = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override @@ -208,7 +208,7 @@ public boolean test(Integer t1) { .last(8); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(6); @@ -218,7 +218,7 @@ public boolean test(Integer t1) { @Test public void testLastOrDefaultWithPredicateAndOneElement() { - Single observable = Flowable.just(1, 2) + Single single = Flowable.just(1, 2) .filter(new Predicate() { @Override @@ -229,7 +229,7 @@ public boolean test(Integer t1) { .last(4); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(2); @@ -239,7 +239,7 @@ public boolean test(Integer t1) { @Test public void testLastOrDefaultWithPredicateAndEmpty() { - Single observable = Flowable.just(1) + Single single = Flowable.just(1) .filter( new Predicate() { @@ -251,7 +251,7 @@ public boolean test(Integer t1) { .last(2); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(2); @@ -312,40 +312,40 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowableToMaybe(new Function, MaybeSource>() { @Override - public MaybeSource apply(Flowable o) throws Exception { - return o.lastElement(); + public MaybeSource apply(Flowable f) throws Exception { + return f.lastElement(); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.lastElement().toFlowable(); + public Flowable apply(Flowable f) throws Exception { + return f.lastElement().toFlowable(); } }); TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function, SingleSource>() { @Override - public SingleSource apply(Flowable o) throws Exception { - return o.lastOrError(); + public SingleSource apply(Flowable f) throws Exception { + return f.lastOrError(); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.lastOrError().toFlowable(); + public Flowable apply(Flowable f) throws Exception { + return f.lastOrError().toFlowable(); } }); TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function, SingleSource>() { @Override - public SingleSource apply(Flowable o) throws Exception { - return o.last(2); + public SingleSource apply(Flowable f) throws Exception { + return f.last(2); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.last(2).toFlowable(); + public Flowable apply(Flowable f) throws Exception { + return f.last(2).toFlowable(); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLiftTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLiftTest.java index 84fe5967a7..bb28c6c597 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLiftTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLiftTest.java @@ -15,21 +15,25 @@ import static org.junit.Assert.*; +import java.util.List; + import org.junit.Test; import org.reactivestreams.Subscriber; import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.plugins.RxJavaPlugins; public class FlowableLiftTest { @Test public void callbackCrash() { + List errors = TestHelper.trackPluginErrors(); try { Flowable.just(1) .lift(new FlowableOperator() { @Override - public Subscriber apply(Subscriber o) throws Exception { + public Subscriber apply(Subscriber subscriber) throws Exception { throw new TestException(); } }) @@ -37,6 +41,9 @@ public Subscriber apply(Subscriber o) throws Ex fail("Should have thrown"); } catch (NullPointerException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapNotificationTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapNotificationTest.java index 245fb9b581..1346e7bc50 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapNotificationTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapNotificationTest.java @@ -153,9 +153,9 @@ public void dispose() { TestHelper.checkDisposed(new Flowable() { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { MapNotificationSubscriber mn = new MapNotificationSubscriber( - observer, + subscriber, Functions.justFunction(Flowable.just(1)), Functions.justFunction(Flowable.just(2)), Functions.justCallable(Flowable.just(3)) @@ -169,8 +169,8 @@ protected void subscribeActual(Subscriber observer) { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.flatMap( + public Flowable apply(Flowable f) throws Exception { + return f.flatMap( Functions.justFunction(Flowable.just(1)), Functions.justFunction(Flowable.just(2)), Functions.justCallable(Flowable.just(3)) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java index 20022bf843..9ebc328d56 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java @@ -57,9 +57,9 @@ public void before() { public void testMap() { Map m1 = getMap("One"); Map m2 = getMap("Two"); - Flowable> observable = Flowable.just(m1, m2); + Flowable> flowable = Flowable.just(m1, m2); - Flowable m = observable.map(new Function, String>() { + Flowable m = flowable.map(new Function, String>() { @Override public String apply(Map map) { return map.get("firstName"); @@ -120,19 +120,19 @@ public String apply(Map map) { public void testMapMany2() { Map m1 = getMap("One"); Map m2 = getMap("Two"); - Flowable> observable1 = Flowable.just(m1, m2); + Flowable> flowable1 = Flowable.just(m1, m2); Map m3 = getMap("Three"); Map m4 = getMap("Four"); - Flowable> observable2 = Flowable.just(m3, m4); + Flowable> flowable2 = Flowable.just(m3, m4); - Flowable>> observable = Flowable.just(observable1, observable2); + Flowable>> f = Flowable.just(flowable1, flowable2); - Flowable m = observable.flatMap(new Function>, Flowable>() { + Flowable m = f.flatMap(new Function>, Flowable>() { @Override - public Flowable apply(Flowable> o) { - return o.map(new Function, String>() { + public Flowable apply(Flowable> f) { + return f.map(new Function, String>() { @Override public String apply(Map map) { @@ -155,12 +155,14 @@ public String apply(Map map) { @Test public void testMapWithError() { + final List errors = new ArrayList(); + 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)) { - throw new RuntimeException("Forced Failure"); + throw new TestException("Forced Failure"); } return s; } @@ -168,7 +170,7 @@ public String apply(String s) { @Override public void accept(Throwable t1) { - t1.printStackTrace(); + errors.add(t1); } }); @@ -178,7 +180,9 @@ public void accept(Throwable t1) { verify(stringSubscriber, never()).onNext("two"); verify(stringSubscriber, never()).onNext("three"); verify(stringSubscriber, never()).onComplete(); - verify(stringSubscriber, times(1)).onError(any(Throwable.class)); + verify(stringSubscriber, times(1)).onError(any(TestException.class)); + + TestHelper.assertError(errors, 0, TestException.class, "Forced Failure"); } @Test(expected = IllegalArgumentException.class) @@ -291,11 +295,11 @@ public void verifyExceptionIsThrownIfThereIsNoExceptionHandler() { // Flowable.OnSubscribe creator = new Flowable.OnSubscribe() { // // @Override -// public void call(Subscriber observer) { -// observer.onNext("a"); -// observer.onNext("b"); -// observer.onNext("c"); -// observer.onComplete(); +// public void call(Subscriber subscriber) { +// subscriber.onNext("a"); +// subscriber.onNext("b"); +// subscriber.onNext("c"); +// subscriber.onComplete(); // } // }; // @@ -630,8 +634,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.map(Functions.identity()); + public Flowable apply(Flowable f) throws Exception { + return f.map(Functions.identity()); } }); } @@ -680,8 +684,8 @@ public void fusedReject() { public void badSource() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.map(Functions.identity()); + public Object apply(Flowable f) throws Exception { + return f.map(Functions.identity()); } }, false, 1, 1, 1); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMaterializeTest.java index e1d3045ea6..b35006ebbf 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMaterializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMaterializeTest.java @@ -233,8 +233,8 @@ private static class TestAsyncErrorObservable implements Publisher { volatile Thread t; @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); t = new Thread(new Runnable() { @Override @@ -247,14 +247,14 @@ public void run() { } catch (Throwable e) { } - observer.onError(new NullPointerException()); + subscriber.onError(new NullPointerException()); return; } else { - observer.onNext(s); + subscriber.onNext(s); } } System.out.println("subscription complete"); - observer.onComplete(); + subscriber.onComplete(); } }); @@ -290,8 +290,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>>() { @Override - public Flowable> apply(Flowable o) throws Exception { - return o.materialize(); + public Flowable> apply(Flowable f) throws Exception { + return f.materialize(); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java index d9be86f909..03300d4dda 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java @@ -34,164 +34,164 @@ public class FlowableMergeDelayErrorTest { - Subscriber stringObserver; + Subscriber stringSubscriber; @Before public void before() { - stringObserver = TestHelper.mockSubscriber(); + stringSubscriber = TestHelper.mockSubscriber(); } @Test public void testErrorDelayed1() { - final Flowable o1 = Flowable.unsafeCreate(new TestErrorFlowable("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.unsafeCreate(new TestErrorFlowable("one", "two", "three")); - - Flowable m = Flowable.mergeDelayError(o1, o2); - m.subscribe(stringObserver); - - verify(stringObserver, times(1)).onError(any(NullPointerException.class)); - verify(stringObserver, never()).onComplete(); - verify(stringObserver, times(1)).onNext("one"); - verify(stringObserver, times(1)).onNext("two"); - verify(stringObserver, times(1)).onNext("three"); - verify(stringObserver, times(1)).onNext("four"); - verify(stringObserver, times(0)).onNext("five"); + final Flowable f1 = Flowable.unsafeCreate(new TestErrorFlowable("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 f2 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); + + Flowable m = Flowable.mergeDelayError(f1, f2); + m.subscribe(stringSubscriber); + + verify(stringSubscriber, times(1)).onError(any(NullPointerException.class)); + verify(stringSubscriber, never()).onComplete(); + verify(stringSubscriber, times(1)).onNext("one"); + verify(stringSubscriber, times(1)).onNext("two"); + verify(stringSubscriber, times(1)).onNext("three"); + verify(stringSubscriber, times(1)).onNext("four"); + verify(stringSubscriber, times(0)).onNext("five"); // despite not expecting it ... we don't do anything to prevent it if the source Flowable keeps sending after onError // inner Flowable errors are considered terminal for that source -// verify(stringObserver, times(1)).onNext("six"); +// verify(stringSubscriber, times(1)).onNext("six"); // inner Flowable errors are considered terminal for that source } @Test public void testErrorDelayed2() { - final Flowable o1 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); - final Flowable o2 = Flowable.unsafeCreate(new TestErrorFlowable("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.unsafeCreate(new TestErrorFlowable("seven", "eight", null)); - final Flowable o4 = Flowable.unsafeCreate(new TestErrorFlowable("nine")); - - Flowable m = Flowable.mergeDelayError(o1, o2, o3, o4); - m.subscribe(stringObserver); - - verify(stringObserver, times(1)).onError(any(CompositeException.class)); - verify(stringObserver, never()).onComplete(); - verify(stringObserver, times(1)).onNext("one"); - verify(stringObserver, times(1)).onNext("two"); - verify(stringObserver, times(1)).onNext("three"); - verify(stringObserver, times(1)).onNext("four"); - verify(stringObserver, times(0)).onNext("five"); + final Flowable f1 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); + final Flowable f2 = Flowable.unsafeCreate(new TestErrorFlowable("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 f3 = Flowable.unsafeCreate(new TestErrorFlowable("seven", "eight", null)); + final Flowable f4 = Flowable.unsafeCreate(new TestErrorFlowable("nine")); + + Flowable m = Flowable.mergeDelayError(f1, f2, f3, f4); + m.subscribe(stringSubscriber); + + verify(stringSubscriber, times(1)).onError(any(CompositeException.class)); + verify(stringSubscriber, never()).onComplete(); + verify(stringSubscriber, times(1)).onNext("one"); + verify(stringSubscriber, times(1)).onNext("two"); + verify(stringSubscriber, times(1)).onNext("three"); + verify(stringSubscriber, times(1)).onNext("four"); + verify(stringSubscriber, times(0)).onNext("five"); // despite not expecting it ... we don't do anything to prevent it if the source Flowable keeps sending after onError // inner Flowable errors are considered terminal for that source -// verify(stringObserver, times(1)).onNext("six"); - verify(stringObserver, times(1)).onNext("seven"); - verify(stringObserver, times(1)).onNext("eight"); - verify(stringObserver, times(1)).onNext("nine"); +// verify(stringSubscriber, times(1)).onNext("six"); + verify(stringSubscriber, times(1)).onNext("seven"); + verify(stringSubscriber, times(1)).onNext("eight"); + verify(stringSubscriber, times(1)).onNext("nine"); } @Test public void testErrorDelayed3() { - final Flowable o1 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); - final Flowable o2 = Flowable.unsafeCreate(new TestErrorFlowable("four", "five", "six")); - final Flowable o3 = Flowable.unsafeCreate(new TestErrorFlowable("seven", "eight", null)); - final Flowable o4 = Flowable.unsafeCreate(new TestErrorFlowable("nine")); + final Flowable f1 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); + final Flowable f2 = Flowable.unsafeCreate(new TestErrorFlowable("four", "five", "six")); + final Flowable f3 = Flowable.unsafeCreate(new TestErrorFlowable("seven", "eight", null)); + final Flowable f4 = Flowable.unsafeCreate(new TestErrorFlowable("nine")); - Flowable m = Flowable.mergeDelayError(o1, o2, o3, o4); - m.subscribe(stringObserver); + Flowable m = Flowable.mergeDelayError(f1, f2, f3, f4); + m.subscribe(stringSubscriber); - verify(stringObserver, times(1)).onError(any(NullPointerException.class)); - verify(stringObserver, never()).onComplete(); - verify(stringObserver, times(1)).onNext("one"); - verify(stringObserver, times(1)).onNext("two"); - verify(stringObserver, times(1)).onNext("three"); - verify(stringObserver, times(1)).onNext("four"); - verify(stringObserver, times(1)).onNext("five"); - verify(stringObserver, times(1)).onNext("six"); - verify(stringObserver, times(1)).onNext("seven"); - verify(stringObserver, times(1)).onNext("eight"); - verify(stringObserver, times(1)).onNext("nine"); + verify(stringSubscriber, times(1)).onError(any(NullPointerException.class)); + verify(stringSubscriber, never()).onComplete(); + verify(stringSubscriber, times(1)).onNext("one"); + verify(stringSubscriber, times(1)).onNext("two"); + verify(stringSubscriber, times(1)).onNext("three"); + verify(stringSubscriber, times(1)).onNext("four"); + verify(stringSubscriber, times(1)).onNext("five"); + verify(stringSubscriber, times(1)).onNext("six"); + verify(stringSubscriber, times(1)).onNext("seven"); + verify(stringSubscriber, times(1)).onNext("eight"); + verify(stringSubscriber, times(1)).onNext("nine"); } @Test public void testErrorDelayed4() { - final Flowable o1 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); - final Flowable o2 = Flowable.unsafeCreate(new TestErrorFlowable("four", "five", "six")); - final Flowable o3 = Flowable.unsafeCreate(new TestErrorFlowable("seven", "eight")); - final Flowable o4 = Flowable.unsafeCreate(new TestErrorFlowable("nine", null)); + final Flowable f1 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); + final Flowable f2 = Flowable.unsafeCreate(new TestErrorFlowable("four", "five", "six")); + final Flowable f3 = Flowable.unsafeCreate(new TestErrorFlowable("seven", "eight")); + final Flowable f4 = Flowable.unsafeCreate(new TestErrorFlowable("nine", null)); - Flowable m = Flowable.mergeDelayError(o1, o2, o3, o4); - m.subscribe(stringObserver); + Flowable m = Flowable.mergeDelayError(f1, f2, f3, f4); + m.subscribe(stringSubscriber); - verify(stringObserver, times(1)).onError(any(NullPointerException.class)); - verify(stringObserver, never()).onComplete(); - verify(stringObserver, times(1)).onNext("one"); - verify(stringObserver, times(1)).onNext("two"); - verify(stringObserver, times(1)).onNext("three"); - verify(stringObserver, times(1)).onNext("four"); - verify(stringObserver, times(1)).onNext("five"); - verify(stringObserver, times(1)).onNext("six"); - verify(stringObserver, times(1)).onNext("seven"); - verify(stringObserver, times(1)).onNext("eight"); - verify(stringObserver, times(1)).onNext("nine"); + verify(stringSubscriber, times(1)).onError(any(NullPointerException.class)); + verify(stringSubscriber, never()).onComplete(); + verify(stringSubscriber, times(1)).onNext("one"); + verify(stringSubscriber, times(1)).onNext("two"); + verify(stringSubscriber, times(1)).onNext("three"); + verify(stringSubscriber, times(1)).onNext("four"); + verify(stringSubscriber, times(1)).onNext("five"); + verify(stringSubscriber, times(1)).onNext("six"); + verify(stringSubscriber, times(1)).onNext("seven"); + verify(stringSubscriber, times(1)).onNext("eight"); + verify(stringSubscriber, times(1)).onNext("nine"); } @Test public void testErrorDelayed4WithThreading() { - final TestAsyncErrorFlowable o1 = new TestAsyncErrorFlowable("one", "two", "three"); - final TestAsyncErrorFlowable o2 = new TestAsyncErrorFlowable("four", "five", "six"); - final TestAsyncErrorFlowable o3 = new TestAsyncErrorFlowable("seven", "eight"); + final TestAsyncErrorFlowable f1 = new TestAsyncErrorFlowable("one", "two", "three"); + final TestAsyncErrorFlowable f2 = new TestAsyncErrorFlowable("four", "five", "six"); + final TestAsyncErrorFlowable f3 = new TestAsyncErrorFlowable("seven", "eight"); // throw the error at the very end so no onComplete will be called after it - final TestAsyncErrorFlowable o4 = new TestAsyncErrorFlowable("nine", null); + final TestAsyncErrorFlowable f4 = new TestAsyncErrorFlowable("nine", null); - Flowable m = Flowable.mergeDelayError(Flowable.unsafeCreate(o1), Flowable.unsafeCreate(o2), Flowable.unsafeCreate(o3), Flowable.unsafeCreate(o4)); - m.subscribe(stringObserver); + Flowable m = Flowable.mergeDelayError(Flowable.unsafeCreate(f1), Flowable.unsafeCreate(f2), Flowable.unsafeCreate(f3), Flowable.unsafeCreate(f4)); + m.subscribe(stringSubscriber); try { - o1.t.join(); - o2.t.join(); - o3.t.join(); - o4.t.join(); + f1.t.join(); + f2.t.join(); + f3.t.join(); + f4.t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } - verify(stringObserver, times(1)).onNext("one"); - verify(stringObserver, times(1)).onNext("two"); - verify(stringObserver, times(1)).onNext("three"); - verify(stringObserver, times(1)).onNext("four"); - verify(stringObserver, times(1)).onNext("five"); - verify(stringObserver, times(1)).onNext("six"); - verify(stringObserver, times(1)).onNext("seven"); - verify(stringObserver, times(1)).onNext("eight"); - verify(stringObserver, times(1)).onNext("nine"); - verify(stringObserver, times(1)).onError(any(NullPointerException.class)); - verify(stringObserver, never()).onComplete(); + verify(stringSubscriber, times(1)).onNext("one"); + verify(stringSubscriber, times(1)).onNext("two"); + verify(stringSubscriber, times(1)).onNext("three"); + verify(stringSubscriber, times(1)).onNext("four"); + verify(stringSubscriber, times(1)).onNext("five"); + verify(stringSubscriber, times(1)).onNext("six"); + verify(stringSubscriber, times(1)).onNext("seven"); + verify(stringSubscriber, times(1)).onNext("eight"); + verify(stringSubscriber, times(1)).onNext("nine"); + verify(stringSubscriber, times(1)).onError(any(NullPointerException.class)); + verify(stringSubscriber, never()).onComplete(); } @Test public void testCompositeErrorDelayed1() { - final Flowable o1 = Flowable.unsafeCreate(new TestErrorFlowable("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.unsafeCreate(new TestErrorFlowable("one", "two", null)); - - Flowable m = Flowable.mergeDelayError(o1, o2); - m.subscribe(stringObserver); - - verify(stringObserver, times(1)).onError(any(Throwable.class)); - verify(stringObserver, never()).onComplete(); - verify(stringObserver, times(1)).onNext("one"); - verify(stringObserver, times(1)).onNext("two"); - verify(stringObserver, times(0)).onNext("three"); - verify(stringObserver, times(1)).onNext("four"); - verify(stringObserver, times(0)).onNext("five"); + final Flowable f1 = Flowable.unsafeCreate(new TestErrorFlowable("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 f2 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", null)); + + Flowable m = Flowable.mergeDelayError(f1, f2); + m.subscribe(stringSubscriber); + + verify(stringSubscriber, times(1)).onError(any(Throwable.class)); + verify(stringSubscriber, never()).onComplete(); + verify(stringSubscriber, times(1)).onNext("one"); + verify(stringSubscriber, times(1)).onNext("two"); + verify(stringSubscriber, times(0)).onNext("three"); + verify(stringSubscriber, times(1)).onNext("four"); + verify(stringSubscriber, times(0)).onNext("five"); // despite not expecting it ... we don't do anything to prevent it if the source Flowable keeps sending after onError // inner Flowable errors are considered terminal for that source -// verify(stringObserver, times(1)).onNext("six"); +// verify(stringSubscriber, times(1)).onNext("six"); } @Test public void testCompositeErrorDelayed2() { - final Flowable o1 = Flowable.unsafeCreate(new TestErrorFlowable("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.unsafeCreate(new TestErrorFlowable("one", "two", null)); + final Flowable f1 = Flowable.unsafeCreate(new TestErrorFlowable("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 f2 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", null)); - Flowable m = Flowable.mergeDelayError(o1, o2); + Flowable m = Flowable.mergeDelayError(f1, f2); CaptureObserver w = new CaptureObserver(); m.subscribe(w); @@ -218,84 +218,84 @@ public void testCompositeErrorDelayed2() { @Test public void testMergeFlowableOfFlowables() { - final Flowable o1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); - final Flowable o2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); Flowable> flowableOfFlowables = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); // simulate what would happen in a Flowable - observer.onNext(o1); - observer.onNext(o2); - observer.onComplete(); + subscriber.onNext(f1); + subscriber.onNext(f2); + subscriber.onComplete(); } }); Flowable m = Flowable.mergeDelayError(flowableOfFlowables); - m.subscribe(stringObserver); + m.subscribe(stringSubscriber); - verify(stringObserver, never()).onError(any(Throwable.class)); - verify(stringObserver, times(1)).onComplete(); - verify(stringObserver, times(2)).onNext("hello"); + verify(stringSubscriber, never()).onError(any(Throwable.class)); + verify(stringSubscriber, times(1)).onComplete(); + verify(stringSubscriber, times(2)).onNext("hello"); } @Test public void testMergeArray() { - final Flowable o1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); - final Flowable o2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); - Flowable m = Flowable.mergeDelayError(o1, o2); - m.subscribe(stringObserver); + Flowable m = Flowable.mergeDelayError(f1, f2); + m.subscribe(stringSubscriber); - verify(stringObserver, never()).onError(any(Throwable.class)); - verify(stringObserver, times(2)).onNext("hello"); - verify(stringObserver, times(1)).onComplete(); + verify(stringSubscriber, never()).onError(any(Throwable.class)); + verify(stringSubscriber, times(2)).onNext("hello"); + verify(stringSubscriber, times(1)).onComplete(); } @Test public void testMergeList() { - final Flowable o1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); - final Flowable o2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); List> listOfFlowables = new ArrayList>(); - listOfFlowables.add(o1); - listOfFlowables.add(o2); + listOfFlowables.add(f1); + listOfFlowables.add(f2); Flowable m = Flowable.mergeDelayError(Flowable.fromIterable(listOfFlowables)); - m.subscribe(stringObserver); + m.subscribe(stringSubscriber); - verify(stringObserver, never()).onError(any(Throwable.class)); - verify(stringObserver, times(1)).onComplete(); - verify(stringObserver, times(2)).onNext("hello"); + verify(stringSubscriber, never()).onError(any(Throwable.class)); + verify(stringSubscriber, times(1)).onComplete(); + verify(stringSubscriber, times(2)).onNext("hello"); } @Test public void testMergeArrayWithThreading() { - final TestASynchronousFlowable o1 = new TestASynchronousFlowable(); - final TestASynchronousFlowable o2 = new TestASynchronousFlowable(); + final TestASynchronousFlowable f1 = new TestASynchronousFlowable(); + final TestASynchronousFlowable f2 = new TestASynchronousFlowable(); - Flowable m = Flowable.mergeDelayError(Flowable.unsafeCreate(o1), Flowable.unsafeCreate(o2)); - m.subscribe(stringObserver); + Flowable m = Flowable.mergeDelayError(Flowable.unsafeCreate(f1), Flowable.unsafeCreate(f2)); + m.subscribe(stringSubscriber); try { - o1.t.join(); - o2.t.join(); + f1.t.join(); + f2.t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } - verify(stringObserver, never()).onError(any(Throwable.class)); - verify(stringObserver, times(2)).onNext("hello"); - verify(stringObserver, times(1)).onComplete(); + verify(stringSubscriber, never()).onError(any(Throwable.class)); + verify(stringSubscriber, times(2)).onNext("hello"); + verify(stringSubscriber, times(1)).onComplete(); } @Test(timeout = 1000L) public void testSynchronousError() { - final Flowable> o1 = Flowable.error(new RuntimeException("unit test")); + final Flowable> f1 = Flowable.error(new RuntimeException("unit test")); final CountDownLatch latch = new CountDownLatch(1); - Flowable.mergeDelayError(o1).subscribe(new DefaultSubscriber() { + Flowable.mergeDelayError(f1).subscribe(new DefaultSubscriber() { @Override public void onComplete() { fail("Expected onError path"); @@ -322,10 +322,10 @@ public void onNext(String s) { private static class TestSynchronousFlowable implements Publisher { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext("hello"); - observer.onComplete(); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("hello"); + subscriber.onComplete(); } } @@ -333,14 +333,14 @@ private static class TestASynchronousFlowable implements Publisher { Thread t; @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); t = new Thread(new Runnable() { @Override public void run() { - observer.onNext("hello"); - observer.onComplete(); + subscriber.onNext("hello"); + subscriber.onComplete(); } }); @@ -357,22 +357,22 @@ private static class TestErrorFlowable implements Publisher { } @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); boolean errorThrown = false; for (String s : valuesToReturn) { if (s == null) { System.out.println("throwing exception"); - observer.onError(new NullPointerException()); + subscriber.onError(new NullPointerException()); errorThrown = true; // purposefully not returning here so it will continue calling onNext // so that we also test that we handle bad sequences like this } else { - observer.onNext(s); + subscriber.onNext(s); } } if (!errorThrown) { - observer.onComplete(); + subscriber.onComplete(); } } } @@ -388,8 +388,8 @@ private static class TestAsyncErrorFlowable implements Publisher { Thread t; @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); t = new Thread(new Runnable() { @Override @@ -402,14 +402,14 @@ public void run() { } catch (Throwable e) { } - observer.onError(new NullPointerException()); + subscriber.onError(new NullPointerException()); return; } else { - observer.onNext(s); + subscriber.onNext(s); } } System.out.println("subscription complete"); - observer.onComplete(); + subscriber.onComplete(); } }); @@ -455,8 +455,8 @@ public void subscribe(Subscriber t1) { Flowable result = Flowable.mergeDelayError(source, Flowable.just(2)); - final Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + final Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); result.subscribe(new DefaultSubscriber() { int calls; @@ -465,17 +465,17 @@ public void onNext(Integer t) { if (calls++ == 0) { throw new TestException(); } - o.onNext(t); + subscriber.onNext(t); } @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }); @@ -484,12 +484,12 @@ public void onComplete() { * If the child onNext throws, why would we keep accepting values from * other sources? */ - inOrder.verify(o).onNext(2); - inOrder.verify(o, never()).onNext(0); - inOrder.verify(o, never()).onNext(1); - inOrder.verify(o, never()).onNext(anyInt()); - inOrder.verify(o).onError(any(TestException.class)); - verify(o, never()).onComplete(); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber, never()).onNext(0); + inOrder.verify(subscriber, never()).onNext(1); + inOrder.verify(subscriber, never()).onNext(anyInt()); + inOrder.verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); } @Test @@ -509,30 +509,30 @@ public void testErrorInParentFlowable() { @Test public void testErrorInParentFlowableDelayed() throws Exception { for (int i = 0; i < 50; i++) { - final TestASynchronous1sDelayedFlowable o1 = new TestASynchronous1sDelayedFlowable(); - final TestASynchronous1sDelayedFlowable o2 = new TestASynchronous1sDelayedFlowable(); + final TestASynchronous1sDelayedFlowable f1 = new TestASynchronous1sDelayedFlowable(); + final TestASynchronous1sDelayedFlowable f2 = new TestASynchronous1sDelayedFlowable(); Flowable> parentFlowable = Flowable.unsafeCreate(new Publisher>() { @Override public void subscribe(Subscriber> op) { op.onSubscribe(new BooleanSubscription()); - op.onNext(Flowable.unsafeCreate(o1)); - op.onNext(Flowable.unsafeCreate(o2)); + op.onNext(Flowable.unsafeCreate(f1)); + op.onNext(Flowable.unsafeCreate(f2)); op.onError(new NullPointerException("throwing exception in parent")); } }); - Subscriber stringObserver = TestHelper.mockSubscriber(); + stringSubscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(stringObserver); + TestSubscriber ts = new TestSubscriber(stringSubscriber); Flowable m = Flowable.mergeDelayError(parentFlowable); m.subscribe(ts); System.out.println("testErrorInParentFlowableDelayed | " + i); ts.awaitTerminalEvent(2000, TimeUnit.MILLISECONDS); ts.assertTerminated(); - verify(stringObserver, times(2)).onNext("hello"); - verify(stringObserver, times(1)).onError(any(NullPointerException.class)); - verify(stringObserver, never()).onComplete(); + verify(stringSubscriber, times(2)).onNext("hello"); + verify(stringSubscriber, times(1)).onError(any(NullPointerException.class)); + verify(stringSubscriber, never()).onComplete(); } } @@ -540,8 +540,8 @@ private static class TestASynchronous1sDelayedFlowable implements Publisher observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); t = new Thread(new Runnable() { @Override @@ -549,10 +549,10 @@ public void run() { try { Thread.sleep(100); } catch (InterruptedException e) { - observer.onError(e); + subscriber.onError(e); } - observer.onNext("hello"); - observer.onComplete(); + subscriber.onNext("hello"); + subscriber.onComplete(); } }); @@ -585,18 +585,18 @@ public void accept(long t1) { // This is pretty much a clone of testMergeList but with the overloaded MergeDelayError for Iterables @Test public void mergeIterable() { - final Flowable o1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); - final Flowable o2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); List> listOfFlowables = new ArrayList>(); - listOfFlowables.add(o1); - listOfFlowables.add(o2); + listOfFlowables.add(f1); + listOfFlowables.add(f2); Flowable m = Flowable.mergeDelayError(listOfFlowables); - m.subscribe(stringObserver); + m.subscribe(stringSubscriber); - verify(stringObserver, never()).onError(any(Throwable.class)); - verify(stringObserver, times(1)).onComplete(); - verify(stringObserver, times(2)).onNext("hello"); + verify(stringSubscriber, never()).onError(any(Throwable.class)); + verify(stringSubscriber, times(1)).onComplete(); + verify(stringSubscriber, times(2)).onNext("hello"); } @SuppressWarnings("unchecked") diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java index 0908334c3f..0973027f3b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java @@ -30,13 +30,6 @@ public class FlowableMergeMaxConcurrentTest { - Subscriber stringObserver; - - @Before - public void before() { - stringObserver = TestHelper.mockSubscriber(); - } - @Test public void testWhenMaxConcurrentIsOne() { for (int i = 0; i < 100; i++) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java index 085b9d1720..e66206c865 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java @@ -40,13 +40,13 @@ public class FlowableMergeTest { - Subscriber stringObserver; + Subscriber stringSubscriber; int count; @Before public void before() { - stringObserver = TestHelper.mockSubscriber(); + stringSubscriber = TestHelper.mockSubscriber(); for (Thread t : Thread.getAllStackTraces().keySet()) { if (t.getName().startsWith("RxNewThread")) { @@ -75,56 +75,56 @@ public void after() { @Test public void testMergeFlowableOfFlowables() { - final Flowable o1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); - final Flowable o2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); Flowable> flowableOfFlowables = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); // simulate what would happen in a Flowable - observer.onNext(o1); - observer.onNext(o2); - observer.onComplete(); + subscriber.onNext(f1); + subscriber.onNext(f2); + subscriber.onComplete(); } }); Flowable m = Flowable.merge(flowableOfFlowables); - m.subscribe(stringObserver); + m.subscribe(stringSubscriber); - verify(stringObserver, never()).onError(any(Throwable.class)); - verify(stringObserver, times(1)).onComplete(); - verify(stringObserver, times(2)).onNext("hello"); + verify(stringSubscriber, never()).onError(any(Throwable.class)); + verify(stringSubscriber, times(1)).onComplete(); + verify(stringSubscriber, times(2)).onNext("hello"); } @Test public void testMergeArray() { - final Flowable o1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); - final Flowable o2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); - Flowable m = Flowable.merge(o1, o2); - m.subscribe(stringObserver); + Flowable m = Flowable.merge(f1, f2); + m.subscribe(stringSubscriber); - verify(stringObserver, never()).onError(any(Throwable.class)); - verify(stringObserver, times(2)).onNext("hello"); - verify(stringObserver, times(1)).onComplete(); + verify(stringSubscriber, never()).onError(any(Throwable.class)); + verify(stringSubscriber, times(2)).onNext("hello"); + verify(stringSubscriber, times(1)).onComplete(); } @Test public void testMergeList() { - final Flowable o1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); - final Flowable o2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f1 = Flowable.unsafeCreate(new TestSynchronousFlowable()); + final Flowable f2 = Flowable.unsafeCreate(new TestSynchronousFlowable()); List> listOfFlowables = new ArrayList>(); - listOfFlowables.add(o1); - listOfFlowables.add(o2); + listOfFlowables.add(f1); + listOfFlowables.add(f2); Flowable m = Flowable.merge(listOfFlowables); - m.subscribe(stringObserver); + m.subscribe(stringSubscriber); - verify(stringObserver, never()).onError(any(Throwable.class)); - verify(stringObserver, times(1)).onComplete(); - verify(stringObserver, times(2)).onNext("hello"); + verify(stringSubscriber, never()).onError(any(Throwable.class)); + verify(stringSubscriber, times(1)).onComplete(); + verify(stringSubscriber, times(2)).onNext("hello"); } @Test(timeout = 1000) @@ -136,7 +136,7 @@ public void testUnSubscribeFlowableOfFlowables() throws InterruptedException { Flowable> source = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(final Subscriber> observer) { + public void subscribe(final Subscriber> subscriber) { // verbose on purpose so I can track the inside of it final Subscription s = new Subscription() { @@ -152,7 +152,7 @@ public void cancel() { } }; - observer.onSubscribe(s); + subscriber.onSubscribe(s); new Thread(new Runnable() { @@ -160,10 +160,10 @@ public void cancel() { public void run() { while (!unsubscribed.get()) { - observer.onNext(Flowable.just(1L, 2L)); + subscriber.onNext(Flowable.just(1L, 2L)); } System.out.println("Done looping after unsubscribe: " + unsubscribed.get()); - observer.onComplete(); + subscriber.onComplete(); // mark that the thread is finished latch.countDown(); @@ -197,19 +197,19 @@ public void accept(Long v) { @Test public void testMergeArrayWithThreading() { - final TestASynchronousFlowable o1 = new TestASynchronousFlowable(); - final TestASynchronousFlowable o2 = new TestASynchronousFlowable(); + final TestASynchronousFlowable f1 = new TestASynchronousFlowable(); + final TestASynchronousFlowable f2 = new TestASynchronousFlowable(); - Flowable m = Flowable.merge(Flowable.unsafeCreate(o1), Flowable.unsafeCreate(o2)); - TestSubscriber ts = new TestSubscriber(stringObserver); + Flowable m = Flowable.merge(Flowable.unsafeCreate(f1), Flowable.unsafeCreate(f2)); + TestSubscriber ts = new TestSubscriber(stringSubscriber); m.subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - verify(stringObserver, never()).onError(any(Throwable.class)); - verify(stringObserver, times(2)).onNext("hello"); - verify(stringObserver, times(1)).onComplete(); + verify(stringSubscriber, never()).onError(any(Throwable.class)); + verify(stringSubscriber, times(2)).onNext("hello"); + verify(stringSubscriber, times(1)).onComplete(); } @Test @@ -222,8 +222,8 @@ public void testSynchronizationOfMultipleSequencesLoop() throws Throwable { @Test public void testSynchronizationOfMultipleSequences() throws Throwable { - final TestASynchronousFlowable o1 = new TestASynchronousFlowable(); - final TestASynchronousFlowable o2 = new TestASynchronousFlowable(); + final TestASynchronousFlowable f1 = new TestASynchronousFlowable(); + final TestASynchronousFlowable f2 = new TestASynchronousFlowable(); // use this latch to cause onNext to wait until we're ready to let it go final CountDownLatch endLatch = new CountDownLatch(1); @@ -233,7 +233,7 @@ public void testSynchronizationOfMultipleSequences() throws Throwable { final AtomicReference error = new AtomicReference(); - Flowable m = Flowable.merge(Flowable.unsafeCreate(o1), Flowable.unsafeCreate(o2)); + Flowable m = Flowable.merge(Flowable.unsafeCreate(f1), Flowable.unsafeCreate(f2)); m.subscribe(new DefaultSubscriber() { @Override @@ -267,8 +267,8 @@ public void onNext(String v) { }); // wait for both Flowables to send (one should be blocked) - o1.onNextBeingSent.await(); - o2.onNextBeingSent.await(); + f1.onNextBeingSent.await(); + f2.onNextBeingSent.await(); // I can't think of a way to know for sure that both threads have or are trying to send onNext // since I can't use a CountDownLatch for "after" onNext since I want to catch during it @@ -295,8 +295,8 @@ public void onNext(String v) { } try { - o1.t.join(); - o2.t.join(); + f1.t.join(); + f2.t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } @@ -311,20 +311,20 @@ 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 Flowable o1 = Flowable.unsafeCreate(new TestErrorFlowable("four", null, "six")); // we expect to lose "six" - final Flowable o2 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); // we expect to lose all of these since o1 is done first and fails + final Flowable f1 = Flowable.unsafeCreate(new TestErrorFlowable("four", null, "six")); // we expect to lose "six" + final Flowable f2 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); // we expect to lose all of these since o1 is done first and fails - Flowable m = Flowable.merge(o1, o2); - m.subscribe(stringObserver); + Flowable m = Flowable.merge(f1, f2); + m.subscribe(stringSubscriber); - verify(stringObserver, times(1)).onError(any(NullPointerException.class)); - verify(stringObserver, never()).onComplete(); - verify(stringObserver, times(0)).onNext("one"); - verify(stringObserver, times(0)).onNext("two"); - verify(stringObserver, times(0)).onNext("three"); - verify(stringObserver, times(1)).onNext("four"); - verify(stringObserver, times(0)).onNext("five"); - verify(stringObserver, times(0)).onNext("six"); + verify(stringSubscriber, times(1)).onError(any(NullPointerException.class)); + verify(stringSubscriber, never()).onComplete(); + verify(stringSubscriber, times(0)).onNext("one"); + verify(stringSubscriber, times(0)).onNext("two"); + verify(stringSubscriber, times(0)).onNext("three"); + verify(stringSubscriber, times(1)).onNext("four"); + verify(stringSubscriber, times(0)).onNext("five"); + verify(stringSubscriber, times(0)).onNext("six"); } /** @@ -333,32 +333,32 @@ public void testError1() { @Test public void testError2() { // we are using synchronous execution to test this exactly rather than non-deterministic concurrent behavior - final Flowable o1 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); - final Flowable o2 = Flowable.unsafeCreate(new TestErrorFlowable("four", null, "six")); // we expect to lose "six" - final Flowable o3 = Flowable.unsafeCreate(new TestErrorFlowable("seven", "eight", null));// we expect to lose all of these since o2 is done first and fails - final Flowable o4 = Flowable.unsafeCreate(new TestErrorFlowable("nine"));// we expect to lose all of these since o2 is done first and fails - - Flowable m = Flowable.merge(o1, o2, o3, o4); - m.subscribe(stringObserver); - - verify(stringObserver, times(1)).onError(any(NullPointerException.class)); - verify(stringObserver, never()).onComplete(); - verify(stringObserver, times(1)).onNext("one"); - verify(stringObserver, times(1)).onNext("two"); - verify(stringObserver, times(1)).onNext("three"); - verify(stringObserver, times(1)).onNext("four"); - verify(stringObserver, times(0)).onNext("five"); - verify(stringObserver, times(0)).onNext("six"); - verify(stringObserver, times(0)).onNext("seven"); - verify(stringObserver, times(0)).onNext("eight"); - verify(stringObserver, times(0)).onNext("nine"); + final Flowable f1 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); + final Flowable f2 = Flowable.unsafeCreate(new TestErrorFlowable("four", null, "six")); // we expect to lose "six" + final Flowable f3 = Flowable.unsafeCreate(new TestErrorFlowable("seven", "eight", null));// we expect to lose all of these since o2 is done first and fails + final Flowable f4 = Flowable.unsafeCreate(new TestErrorFlowable("nine"));// we expect to lose all of these since o2 is done first and fails + + Flowable m = Flowable.merge(f1, f2, f3, f4); + m.subscribe(stringSubscriber); + + verify(stringSubscriber, times(1)).onError(any(NullPointerException.class)); + verify(stringSubscriber, never()).onComplete(); + verify(stringSubscriber, times(1)).onNext("one"); + verify(stringSubscriber, times(1)).onNext("two"); + verify(stringSubscriber, times(1)).onNext("three"); + verify(stringSubscriber, times(1)).onNext("four"); + verify(stringSubscriber, times(0)).onNext("five"); + verify(stringSubscriber, times(0)).onNext("six"); + verify(stringSubscriber, times(0)).onNext("seven"); + verify(stringSubscriber, times(0)).onNext("eight"); + verify(stringSubscriber, times(0)).onNext("nine"); } @Test @Ignore("Subscribe should not throw") public void testThrownErrorHandling() { TestSubscriber ts = new TestSubscriber(); - Flowable o1 = Flowable.unsafeCreate(new Publisher() { + Flowable f1 = Flowable.unsafeCreate(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -367,7 +367,7 @@ public void subscribe(Subscriber s) { }); - Flowable.merge(o1, o1).subscribe(ts); + Flowable.merge(f1, f1).subscribe(ts); ts.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); ts.assertTerminated(); System.out.println("Error: " + ts.errors()); @@ -376,10 +376,10 @@ public void subscribe(Subscriber s) { private static class TestSynchronousFlowable implements Publisher { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext("hello"); - observer.onComplete(); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("hello"); + subscriber.onComplete(); } } @@ -388,20 +388,20 @@ private static class TestASynchronousFlowable implements Publisher { final CountDownLatch onNextBeingSent = new CountDownLatch(1); @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); t = new Thread(new Runnable() { @Override public void run() { onNextBeingSent.countDown(); try { - observer.onNext("hello"); + subscriber.onNext("hello"); // I can't use a countDownLatch to prove we are actually sending 'onNext' // since it will block if synchronized and I'll deadlock - observer.onComplete(); + subscriber.onComplete(); } catch (Exception e) { - observer.onError(e); + subscriber.onError(e); } } @@ -419,17 +419,17 @@ private static class TestErrorFlowable implements Publisher { } @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); for (String s : valuesToReturn) { if (s == null) { System.out.println("throwing exception"); - observer.onError(new NullPointerException()); + subscriber.onError(new NullPointerException()); } else { - observer.onNext(s); + subscriber.onNext(s); } } - observer.onComplete(); + subscriber.onComplete(); } } @@ -437,14 +437,14 @@ public void subscribe(Subscriber observer) { public void testUnsubscribeAsFlowablesComplete() { TestScheduler scheduler1 = new TestScheduler(); AtomicBoolean os1 = new AtomicBoolean(false); - Flowable o1 = createFlowableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); + Flowable f1 = createFlowableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); TestScheduler scheduler2 = new TestScheduler(); AtomicBoolean os2 = new AtomicBoolean(false); - Flowable o2 = createFlowableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); + Flowable f2 = createFlowableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); TestSubscriber ts = new TestSubscriber(); - Flowable.merge(o1, o2).subscribe(ts); + Flowable.merge(f1, f2).subscribe(ts); // we haven't incremented time so nothing should be received yet ts.assertNoValues(); @@ -479,14 +479,14 @@ public void testEarlyUnsubscribe() { for (int i = 0; i < 10; i++) { TestScheduler scheduler1 = new TestScheduler(); AtomicBoolean os1 = new AtomicBoolean(false); - Flowable o1 = createFlowableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); + Flowable f1 = createFlowableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); TestScheduler scheduler2 = new TestScheduler(); AtomicBoolean os2 = new AtomicBoolean(false); - Flowable o2 = createFlowableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); + Flowable f2 = createFlowableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); TestSubscriber ts = new TestSubscriber(); - Flowable.merge(o1, o2).subscribe(ts); + Flowable.merge(f1, f2).subscribe(ts); // we haven't incremented time so nothing should be received yet ts.assertNoValues(); @@ -557,10 +557,10 @@ public void onComplete() { @Test//(timeout = 10000) public void testConcurrency() { - Flowable o = Flowable.range(1, 10000).subscribeOn(Schedulers.newThread()); + Flowable f = Flowable.range(1, 10000).subscribeOn(Schedulers.newThread()); for (int i = 0; i < 10; i++) { - Flowable merge = Flowable.merge(o.onBackpressureBuffer(), o.onBackpressureBuffer(), o.onBackpressureBuffer()); + Flowable merge = Flowable.merge(f.onBackpressureBuffer(), f.onBackpressureBuffer(), f.onBackpressureBuffer()); TestSubscriber ts = new TestSubscriber(); merge.subscribe(ts); @@ -577,7 +577,7 @@ public void testConcurrency() { @Test public void testConcurrencyWithSleeping() { - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override public void subscribe(final Subscriber s) { @@ -613,7 +613,7 @@ public void run() { }); for (int i = 0; i < 10; i++) { - Flowable merge = Flowable.merge(o, o, o); + Flowable merge = Flowable.merge(f, f, f); TestSubscriber ts = new TestSubscriber(); merge.subscribe(ts); @@ -627,7 +627,7 @@ public void run() { @Test public void testConcurrencyWithBrokenOnCompleteContract() { - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override public void subscribe(final Subscriber s) { @@ -660,7 +660,7 @@ public void run() { }); for (int i = 0; i < 10; i++) { - Flowable merge = Flowable.merge(o.onBackpressureBuffer(), o.onBackpressureBuffer(), o.onBackpressureBuffer()); + Flowable merge = Flowable.merge(f.onBackpressureBuffer(), f.onBackpressureBuffer(), f.onBackpressureBuffer()); TestSubscriber ts = new TestSubscriber(); merge.subscribe(ts); @@ -676,9 +676,9 @@ public void run() { @Test public void testBackpressureUpstream() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Flowable o1 = createInfiniteFlowable(generated1).subscribeOn(Schedulers.computation()); + Flowable f1 = createInfiniteFlowable(generated1).subscribeOn(Schedulers.computation()); final AtomicInteger generated2 = new AtomicInteger(); - Flowable o2 = createInfiniteFlowable(generated2).subscribeOn(Schedulers.computation()); + Flowable f2 = createInfiniteFlowable(generated2).subscribeOn(Schedulers.computation()); TestSubscriber testSubscriber = new TestSubscriber() { @Override @@ -688,7 +688,7 @@ public void onNext(Integer t) { } }; - Flowable.merge(o1.take(Flowable.bufferSize() * 2), o2.take(Flowable.bufferSize() * 2)).subscribe(testSubscriber); + Flowable.merge(f1.take(Flowable.bufferSize() * 2), f2.take(Flowable.bufferSize() * 2)).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); @@ -715,7 +715,7 @@ public void testBackpressureUpstream2InLoop() throws InterruptedException { @Test public void testBackpressureUpstream2() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Flowable o1 = createInfiniteFlowable(generated1).subscribeOn(Schedulers.computation()); + Flowable f1 = createInfiniteFlowable(generated1).subscribeOn(Schedulers.computation()); TestSubscriber testSubscriber = new TestSubscriber() { @Override @@ -724,7 +724,7 @@ public void onNext(Integer t) { } }; - Flowable.merge(o1.take(Flowable.bufferSize() * 2), Flowable.just(-99)).subscribe(testSubscriber); + Flowable.merge(f1.take(Flowable.bufferSize() * 2), Flowable.just(-99)).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); List onNextEvents = testSubscriber.values(); @@ -750,9 +750,9 @@ public void onNext(Integer t) { @Test(timeout = 10000) public void testBackpressureDownstreamWithConcurrentStreams() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Flowable o1 = createInfiniteFlowable(generated1).subscribeOn(Schedulers.computation()); + Flowable f1 = createInfiniteFlowable(generated1).subscribeOn(Schedulers.computation()); final AtomicInteger generated2 = new AtomicInteger(); - Flowable o2 = createInfiniteFlowable(generated2).subscribeOn(Schedulers.computation()); + Flowable f2 = createInfiniteFlowable(generated2).subscribeOn(Schedulers.computation()); TestSubscriber testSubscriber = new TestSubscriber() { @Override @@ -770,7 +770,7 @@ public void onNext(Integer t) { } }; - Flowable.merge(o1.take(Flowable.bufferSize() * 2), o2.take(Flowable.bufferSize() * 2)).observeOn(Schedulers.computation()).subscribe(testSubscriber); + Flowable.merge(f1.take(Flowable.bufferSize() * 2), f2.take(Flowable.bufferSize() * 2)).observeOn(Schedulers.computation()).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); @@ -787,7 +787,7 @@ public void onNext(Integer t) { @Test public void testBackpressureBothUpstreamAndDownstreamWithSynchronousScalarFlowables() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Flowable> o1 = createInfiniteFlowable(generated1) + Flowable> f1 = createInfiniteFlowable(generated1) .map(new Function>() { @Override @@ -813,7 +813,7 @@ public void onNext(Integer t) { } }; - Flowable.merge(o1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(testSubscriber); + Flowable.merge(f1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); @@ -841,7 +841,7 @@ public void onNext(Integer t) { @Test(timeout = 5000) public void testBackpressureBothUpstreamAndDownstreamWithRegularFlowables() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Flowable> o1 = createInfiniteFlowable(generated1).map(new Function>() { + Flowable> f1 = createInfiniteFlowable(generated1).map(new Function>() { @Override public Flowable apply(Integer t1) { @@ -868,7 +868,7 @@ public void onNext(Integer t) { } }; - Flowable.merge(o1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(testSubscriber); + Flowable.merge(f1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); @@ -1269,11 +1269,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 - Flowable o = Flowable.fromIterable(Arrays.asList(1,2)) + Flowable f = 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 DefaultSubscriber() { + f.subscribeOn(Schedulers.computation()).subscribe(new DefaultSubscriber() { @Override public void onStart() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java index 3344a30a65..10c6f5bd47 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java @@ -46,13 +46,13 @@ public class FlowableObserveOnTest { */ @Test public void testObserveOn() { - Subscriber observer = TestHelper.mockSubscriber(); - Flowable.just(1, 2, 3).observeOn(ImmediateThinScheduler.INSTANCE).subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + Flowable.just(1, 2, 3).observeOn(ImmediateThinScheduler.INSTANCE).subscribe(subscriber); - verify(observer, times(1)).onNext(1); - verify(observer, times(1)).onNext(2); - verify(observer, times(1)).onNext(3); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, times(1)).onNext(3); + verify(subscriber, times(1)).onComplete(); } @Test @@ -61,10 +61,10 @@ public void testOrdering() throws InterruptedException { // FIXME null values not allowed Flowable obs = Flowable.just("one", "null", "two", "three", "four"); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer); - TestSubscriber ts = new TestSubscriber(observer); + InOrder inOrder = inOrder(subscriber); + TestSubscriber ts = new TestSubscriber(subscriber); obs.observeOn(Schedulers.computation()).subscribe(ts); @@ -76,12 +76,12 @@ public void testOrdering() throws InterruptedException { fail("failed with exception"); } - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(1)).onNext("null"); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, times(1)).onNext("four"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(1)).onNext("null"); + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, times(1)).onNext("four"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -92,7 +92,7 @@ public void testThreadName() throws InterruptedException { // Flowable obs = Flowable.just("one", null, "two", "three", "four"); Flowable obs = Flowable.just("one", "null", "two", "three", "four"); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final String parentThreadName = Thread.currentThread().getName(); final CountDownLatch completedLatch = new CountDownLatch(1); @@ -127,45 +127,45 @@ public void run() { completedLatch.countDown(); } - }).subscribe(observer); + }).subscribe(subscriber); if (!completedLatch.await(1000, TimeUnit.MILLISECONDS)) { fail("timed out waiting"); } - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(5)).onNext(any(String.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(5)).onNext(any(String.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void observeOnTheSameSchedulerTwice() { Scheduler scheduler = ImmediateThinScheduler.INSTANCE; - Flowable o = Flowable.just(1, 2, 3); - Flowable o2 = o.observeOn(scheduler); + Flowable f = Flowable.just(1, 2, 3); + Flowable f2 = f.observeOn(scheduler); - Subscriber observer1 = TestHelper.mockSubscriber(); - Subscriber observer2 = TestHelper.mockSubscriber(); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + Subscriber subscriber2 = TestHelper.mockSubscriber(); - InOrder inOrder1 = inOrder(observer1); - InOrder inOrder2 = inOrder(observer2); + InOrder inOrder1 = inOrder(subscriber1); + InOrder inOrder2 = inOrder(subscriber2); - o2.subscribe(observer1); - o2.subscribe(observer2); + f2.subscribe(subscriber1); + f2.subscribe(subscriber2); - inOrder1.verify(observer1, times(1)).onNext(1); - inOrder1.verify(observer1, times(1)).onNext(2); - inOrder1.verify(observer1, times(1)).onNext(3); - inOrder1.verify(observer1, times(1)).onComplete(); - verify(observer1, never()).onError(any(Throwable.class)); + inOrder1.verify(subscriber1, times(1)).onNext(1); + inOrder1.verify(subscriber1, times(1)).onNext(2); + inOrder1.verify(subscriber1, times(1)).onNext(3); + inOrder1.verify(subscriber1, times(1)).onComplete(); + verify(subscriber1, never()).onError(any(Throwable.class)); inOrder1.verifyNoMoreInteractions(); - inOrder2.verify(observer2, times(1)).onNext(1); - inOrder2.verify(observer2, times(1)).onNext(2); - inOrder2.verify(observer2, times(1)).onNext(3); - inOrder2.verify(observer2, times(1)).onComplete(); - verify(observer2, never()).onError(any(Throwable.class)); + inOrder2.verify(subscriber2, times(1)).onNext(1); + inOrder2.verify(subscriber2, times(1)).onNext(2); + inOrder2.verify(subscriber2, times(1)).onNext(3); + inOrder2.verify(subscriber2, times(1)).onComplete(); + verify(subscriber2, never()).onError(any(Throwable.class)); inOrder2.verifyNoMoreInteractions(); } @@ -174,34 +174,34 @@ public void observeSameOnMultipleSchedulers() { TestScheduler scheduler1 = new TestScheduler(); TestScheduler scheduler2 = new TestScheduler(); - Flowable o = Flowable.just(1, 2, 3); - Flowable o1 = o.observeOn(scheduler1); - Flowable o2 = o.observeOn(scheduler2); + Flowable f = Flowable.just(1, 2, 3); + Flowable f1 = f.observeOn(scheduler1); + Flowable f2 = f.observeOn(scheduler2); - Subscriber observer1 = TestHelper.mockSubscriber(); - Subscriber observer2 = TestHelper.mockSubscriber(); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + Subscriber subscriber2 = TestHelper.mockSubscriber(); - InOrder inOrder1 = inOrder(observer1); - InOrder inOrder2 = inOrder(observer2); + InOrder inOrder1 = inOrder(subscriber1); + InOrder inOrder2 = inOrder(subscriber2); - o1.subscribe(observer1); - o2.subscribe(observer2); + f1.subscribe(subscriber1); + f2.subscribe(subscriber2); scheduler1.advanceTimeBy(1, TimeUnit.SECONDS); scheduler2.advanceTimeBy(1, TimeUnit.SECONDS); - inOrder1.verify(observer1, times(1)).onNext(1); - inOrder1.verify(observer1, times(1)).onNext(2); - inOrder1.verify(observer1, times(1)).onNext(3); - inOrder1.verify(observer1, times(1)).onComplete(); - verify(observer1, never()).onError(any(Throwable.class)); + inOrder1.verify(subscriber1, times(1)).onNext(1); + inOrder1.verify(subscriber1, times(1)).onNext(2); + inOrder1.verify(subscriber1, times(1)).onNext(3); + inOrder1.verify(subscriber1, times(1)).onComplete(); + verify(subscriber1, never()).onError(any(Throwable.class)); inOrder1.verifyNoMoreInteractions(); - inOrder2.verify(observer2, times(1)).onNext(1); - inOrder2.verify(observer2, times(1)).onNext(2); - inOrder2.verify(observer2, times(1)).onNext(3); - inOrder2.verify(observer2, times(1)).onComplete(); - verify(observer2, never()).onError(any(Throwable.class)); + inOrder2.verify(subscriber2, times(1)).onNext(1); + inOrder2.verify(subscriber2, times(1)).onNext(2); + inOrder2.verify(subscriber2, times(1)).onNext(3); + inOrder2.verify(subscriber2, times(1)).onComplete(); + verify(subscriber2, never()).onError(any(Throwable.class)); inOrder2.verifyNoMoreInteractions(); } @@ -366,27 +366,26 @@ public void testDelayedErrorDeliveryWhenSafeSubscriberUnsubscribes() { Flowable source = Flowable.concat(Flowable. error(new TestException()), Flowable.just(1)); - @SuppressWarnings("unchecked") - DefaultSubscriber o = mock(DefaultSubscriber.class); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.observeOn(testScheduler).subscribe(o); + source.observeOn(testScheduler).subscribe(subscriber); - inOrder.verify(o, never()).onError(any(TestException.class)); + inOrder.verify(subscriber, never()).onError(any(TestException.class)); testScheduler.advanceTimeBy(1, TimeUnit.SECONDS); - inOrder.verify(o).onError(any(TestException.class)); - inOrder.verify(o, never()).onNext(anyInt()); - inOrder.verify(o, never()).onComplete(); + inOrder.verify(subscriber).onError(any(TestException.class)); + inOrder.verify(subscriber, never()).onNext(anyInt()); + inOrder.verify(subscriber, never()).onComplete(); } @Test public void testAfterUnsubscribeCalledThenObserverOnNextNeverCalled() { final TestScheduler testScheduler = new TestScheduler(); - final Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + final Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); Flowable.just(1, 2, 3) .observeOn(testScheduler) @@ -395,11 +394,11 @@ public void testAfterUnsubscribeCalledThenObserverOnNextNeverCalled() { ts.dispose(); testScheduler.advanceTimeBy(1, TimeUnit.SECONDS); - final InOrder inOrder = inOrder(observer); + final InOrder inOrder = inOrder(subscriber); - inOrder.verify(observer, never()).onNext(anyInt()); - inOrder.verify(observer, never()).onError(any(Exception.class)); - inOrder.verify(observer, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext(anyInt()); + inOrder.verify(subscriber, never()).onError(any(Exception.class)); + inOrder.verify(subscriber, never()).onComplete(); } @Test @@ -538,13 +537,13 @@ public void testQueueFullEmitsError() { Flowable flowable = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber o) { - o.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); for (int i = 0; i < Flowable.bufferSize() + 10; i++) { - o.onNext(i); + subscriber.onNext(i); } latch.countDown(); - o.onComplete(); + subscriber.onComplete(); } }); @@ -601,7 +600,7 @@ public void testAsyncChild() { @Test public void testOnErrorCutsAheadOfOnNext() { for (int i = 0; i < 50; i++) { - final PublishProcessor subject = PublishProcessor.create(); + final PublishProcessor processor = PublishProcessor.create(); final AtomicLong counter = new AtomicLong(); TestSubscriber ts = new TestSubscriber(new DefaultSubscriber() { @@ -626,11 +625,11 @@ public void onNext(Long t) { } }); - subject.observeOn(Schedulers.computation()).subscribe(ts); + processor.observeOn(Schedulers.computation()).subscribe(ts); // this will blow up with backpressure while (counter.get() < 102400) { - subject.onNext(counter.get()); + processor.onNext(counter.get()); counter.incrementAndGet(); } @@ -1151,8 +1150,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.observeOn(new TestScheduler()); + public Flowable apply(Flowable f) throws Exception { + return f.observeOn(new TestScheduler()); } }); } @@ -1164,12 +1163,12 @@ public void badSource() { TestScheduler scheduler = new TestScheduler(); TestSubscriber ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onComplete(); - observer.onNext(1); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); + subscriber.onNext(1); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .observeOn(scheduler) @@ -1344,11 +1343,11 @@ public void onComplete() { public void nonFusedPollThrows() { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); @SuppressWarnings("unchecked") - BaseObserveOnSubscriber oo = (BaseObserveOnSubscriber)observer; + BaseObserveOnSubscriber oo = (BaseObserveOnSubscriber)subscriber; oo.sourceMode = QueueFuseable.SYNC; oo.requested.lazySet(1); @@ -1395,11 +1394,11 @@ public void clear() { public void conditionalNonFusedPollThrows() { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); @SuppressWarnings("unchecked") - BaseObserveOnSubscriber oo = (BaseObserveOnSubscriber)observer; + BaseObserveOnSubscriber oo = (BaseObserveOnSubscriber)subscriber; oo.sourceMode = QueueFuseable.SYNC; oo.requested.lazySet(1); @@ -1447,11 +1446,11 @@ public void clear() { public void asycFusedPollThrows() { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); @SuppressWarnings("unchecked") - BaseObserveOnSubscriber oo = (BaseObserveOnSubscriber)observer; + BaseObserveOnSubscriber oo = (BaseObserveOnSubscriber)subscriber; oo.sourceMode = QueueFuseable.ASYNC; oo.requested.lazySet(1); @@ -1498,11 +1497,11 @@ public void clear() { public void conditionalAsyncFusedPollThrows() { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); @SuppressWarnings("unchecked") - BaseObserveOnSubscriber oo = (BaseObserveOnSubscriber)observer; + BaseObserveOnSubscriber oo = (BaseObserveOnSubscriber)subscriber; oo.sourceMode = QueueFuseable.ASYNC; oo.requested.lazySet(1); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java index 86c12e3304..ed8b3b6aba 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java @@ -36,10 +36,10 @@ public void testResumeNext() { TestObservable f = new TestObservable(s, "one", "fail", "two", "three"); Flowable w = Flowable.unsafeCreate(f); Flowable resume = Flowable.just("twoResume", "threeResume"); - Flowable observable = w.onErrorResumeNext(resume); + Flowable flowable = w.onErrorResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); try { f.t.join(); @@ -47,13 +47,13 @@ public void testResumeNext() { fail(e.getMessage()); } - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("one"); - verify(observer, Mockito.never()).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, times(1)).onNext("twoResume"); - verify(observer, times(1)).onNext("threeResume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, Mockito.never()).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, times(1)).onNext("twoResume"); + verify(subscriber, times(1)).onNext("threeResume"); } @Test @@ -78,11 +78,11 @@ public String apply(String s) { } }); - Flowable observable = w.onErrorResumeNext(resume); + Flowable flowable = w.onErrorResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); try { f.t.join(); @@ -90,13 +90,13 @@ public String apply(String s) { fail(e.getMessage()); } - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("one"); - verify(observer, Mockito.never()).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, times(1)).onNext("twoResume"); - verify(observer, times(1)).onNext("threeResume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, Mockito.never()).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, times(1)).onNext("twoResume"); + verify(subscriber, times(1)).onNext("threeResume"); } @Test @@ -111,14 +111,14 @@ public void subscribe(Subscriber t1) { }); Flowable resume = Flowable.just("resume"); - Flowable observable = testObservable.onErrorResumeNext(resume); + Flowable flowable = testObservable.onErrorResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("resume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("resume"); } @Test @@ -133,18 +133,17 @@ public void subscribe(Subscriber t1) { }); Flowable resume = Flowable.just("resume"); - Flowable observable = testObservable.subscribeOn(Schedulers.io()).onErrorResumeNext(resume); + Flowable flowable = testObservable.subscribeOn(Schedulers.io()).onErrorResumeNext(resume); - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); - TestSubscriber ts = new TestSubscriber(observer, Long.MAX_VALUE); - observable.subscribe(ts); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber, Long.MAX_VALUE); + flowable.subscribe(ts); ts.awaitTerminalEvent(); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("resume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("resume"); } static final class TestObservable implements Publisher { @@ -159,9 +158,9 @@ static final class TestObservable implements Publisher { } @Override - public void subscribe(final Subscriber observer) { + public void subscribe(final Subscriber subscriber) { System.out.println("TestObservable subscribed to ..."); - observer.onSubscribe(s); + subscriber.onSubscribe(s); t = new Thread(new Runnable() { @Override @@ -173,13 +172,13 @@ public void run() { throw new RuntimeException("Forced Failure"); } System.out.println("TestObservable onNext: " + s); - observer.onNext(s); + subscriber.onNext(s); } System.out.println("TestObservable onComplete"); - observer.onComplete(); + subscriber.onComplete(); } catch (Throwable e) { System.out.println("TestObservable onError: " + e); - observer.onError(e); + subscriber.onError(e); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java index 8d55d06f96..06f10e835d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; @@ -40,12 +41,12 @@ public void testResumeNextWithSynchronousExecution() { Flowable w = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext("one"); - observer.onError(new Throwable("injected failure")); - observer.onNext("two"); - observer.onNext("three"); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("one"); + subscriber.onError(new Throwable("injected failure")); + subscriber.onNext("two"); + subscriber.onNext("three"); } }); @@ -58,19 +59,19 @@ public Flowable apply(Throwable t1) { } }; - Flowable observable = w.onErrorResumeNext(resume); + Flowable flowable = w.onErrorResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("one"); - verify(observer, Mockito.never()).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, times(1)).onNext("twoResume"); - verify(observer, times(1)).onNext("threeResume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, Mockito.never()).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, times(1)).onNext("twoResume"); + verify(subscriber, times(1)).onNext("threeResume"); assertNotNull(receivedException.get()); } @@ -88,11 +89,11 @@ public Flowable apply(Throwable t1) { } }; - Flowable observable = Flowable.unsafeCreate(w).onErrorResumeNext(resume); + Flowable flowable = Flowable.unsafeCreate(w).onErrorResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); try { w.t.join(); @@ -100,13 +101,13 @@ public Flowable apply(Throwable t1) { fail(e.getMessage()); } - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("one"); - verify(observer, Mockito.never()).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, times(1)).onNext("twoResume"); - verify(observer, times(1)).onNext("threeResume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, Mockito.never()).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, times(1)).onNext("twoResume"); + verify(subscriber, times(1)).onNext("threeResume"); assertNotNull(receivedException.get()); } @@ -125,11 +126,10 @@ public Flowable apply(Throwable t1) { } }; - Flowable observable = Flowable.unsafeCreate(w).onErrorResumeNext(resume); + Flowable flowable = Flowable.unsafeCreate(w).onErrorResumeNext(resume); - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); try { w.t.join(); @@ -138,11 +138,11 @@ public Flowable apply(Throwable t1) { } // we should get the "one" value before the error - verify(observer, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("one"); // we should have received an onError call on the Observer since the resume function threw an exception - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, times(0)).onComplete(); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, times(0)).onComplete(); } /** @@ -251,7 +251,7 @@ public String apply(String s) { } }); - Flowable observable = w.onErrorResumeNext(new Function>() { + Flowable flowable = w.onErrorResumeNext(new Function>() { @Override public Flowable apply(Throwable t1) { @@ -260,20 +260,19 @@ public Flowable apply(Throwable t1) { }); - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); + Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer, Long.MAX_VALUE); - observable.subscribe(ts); + TestSubscriber ts = new TestSubscriber(subscriber, Long.MAX_VALUE); + flowable.subscribe(ts); ts.awaitTerminalEvent(); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("one"); - verify(observer, Mockito.never()).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, times(1)).onNext("twoResume"); - verify(observer, times(1)).onNext("threeResume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, Mockito.never()).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, times(1)).onNext("twoResume"); + verify(subscriber, times(1)).onNext("threeResume"); } private static class TestFlowable implements Publisher { @@ -286,9 +285,9 @@ private static class TestFlowable implements Publisher { } @Override - public void subscribe(final Subscriber observer) { + public void subscribe(final Subscriber subscriber) { System.out.println("TestFlowable subscribed to ..."); - observer.onSubscribe(new BooleanSubscription()); + subscriber.onSubscribe(new BooleanSubscription()); t = new Thread(new Runnable() { @Override @@ -297,11 +296,11 @@ public void run() { System.out.println("running TestFlowable thread"); for (String s : values) { System.out.println("TestFlowable onNext: " + s); - observer.onNext(s); + subscriber.onNext(s); } throw new RuntimeException("Forced Failure"); } catch (Throwable e) { - observer.onError(e); + subscriber.onError(e); } } @@ -382,9 +381,9 @@ public Flowable apply(Throwable v) { public void badOtherSource() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { + public Object apply(Flowable f) throws Exception { return Flowable.error(new IOException()) - .onErrorResumeNext(Functions.justFunction(o)); + .onErrorResumeNext(Functions.justFunction(f)); } }, false, 1, 1, 1); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java index a22c4055e2..9bcc27d5f3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java @@ -38,7 +38,7 @@ public void testResumeNext() { Flowable w = Flowable.unsafeCreate(f); final AtomicReference capturedException = new AtomicReference(); - Flowable observable = w.onErrorReturn(new Function() { + Flowable flowable = w.onErrorReturn(new Function() { @Override public String apply(Throwable e) { @@ -48,8 +48,8 @@ public String apply(Throwable e) { }); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); try { f.t.join(); @@ -57,10 +57,10 @@ public String apply(Throwable e) { fail(e.getMessage()); } - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("failure"); - verify(observer, times(1)).onComplete(); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("failure"); + verify(subscriber, times(1)).onComplete(); assertNotNull(capturedException.get()); } @@ -73,7 +73,7 @@ public void testFunctionThrowsError() { Flowable w = Flowable.unsafeCreate(f); final AtomicReference capturedException = new AtomicReference(); - Flowable observable = w.onErrorReturn(new Function() { + Flowable flowable = w.onErrorReturn(new Function() { @Override public String apply(Throwable e) { @@ -83,9 +83,8 @@ public String apply(Throwable e) { }); - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); try { f.t.join(); @@ -94,11 +93,11 @@ public String apply(Throwable e) { } // we should get the "one" value before the error - verify(observer, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("one"); // we should have received an onError call on the Observer since the resume function threw an exception - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, times(0)).onComplete(); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, times(0)).onComplete(); assertNotNull(capturedException.get()); } @@ -120,7 +119,7 @@ public String apply(String s) { } }); - Flowable observable = w.onErrorReturn(new Function() { + Flowable flowable = w.onErrorReturn(new Function() { @Override public String apply(Throwable t1) { @@ -129,18 +128,17 @@ public String apply(Throwable t1) { }); - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); - TestSubscriber ts = new TestSubscriber(observer, Long.MAX_VALUE); - observable.subscribe(ts); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber, Long.MAX_VALUE); + flowable.subscribe(ts); ts.awaitTerminalEvent(); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("one"); - verify(observer, Mockito.never()).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, times(1)).onNext("resume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, Mockito.never()).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, times(1)).onNext("resume"); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java index 6c6b8c9962..3da05ffedf 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java @@ -36,10 +36,10 @@ public void testResumeNextWithException() { TestObservable f = new TestObservable("one", "EXCEPTION", "two", "three"); Flowable w = Flowable.unsafeCreate(f); Flowable resume = Flowable.just("twoResume", "threeResume"); - Flowable observable = w.onExceptionResumeNext(resume); + Flowable flowable = w.onExceptionResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); try { f.t.join(); @@ -47,15 +47,15 @@ public void testResumeNextWithException() { fail(e.getMessage()); } - verify(observer).onSubscribe((Subscription)any()); - verify(observer, times(1)).onNext("one"); - verify(observer, Mockito.never()).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, times(1)).onNext("twoResume"); - verify(observer, times(1)).onNext("threeResume"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe((Subscription)any()); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, Mockito.never()).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, times(1)).onNext("twoResume"); + verify(subscriber, times(1)).onNext("threeResume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verifyNoMoreInteractions(subscriber); } @Test @@ -64,10 +64,10 @@ public void testResumeNextWithRuntimeException() { TestObservable f = new TestObservable("one", "RUNTIMEEXCEPTION", "two", "three"); Flowable w = Flowable.unsafeCreate(f); Flowable resume = Flowable.just("twoResume", "threeResume"); - Flowable observable = w.onExceptionResumeNext(resume); + Flowable flowable = w.onExceptionResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); try { f.t.join(); @@ -75,15 +75,15 @@ public void testResumeNextWithRuntimeException() { fail(e.getMessage()); } - verify(observer).onSubscribe((Subscription)any()); - verify(observer, times(1)).onNext("one"); - verify(observer, Mockito.never()).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, times(1)).onNext("twoResume"); - verify(observer, times(1)).onNext("threeResume"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe((Subscription)any()); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, Mockito.never()).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, times(1)).onNext("twoResume"); + verify(subscriber, times(1)).onNext("threeResume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verifyNoMoreInteractions(subscriber); } @Test @@ -92,10 +92,10 @@ public void testThrowablePassesThru() { TestObservable f = new TestObservable("one", "THROWABLE", "two", "three"); Flowable w = Flowable.unsafeCreate(f); Flowable resume = Flowable.just("twoResume", "threeResume"); - Flowable observable = w.onExceptionResumeNext(resume); + Flowable flowable = w.onExceptionResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); try { f.t.join(); @@ -103,15 +103,15 @@ public void testThrowablePassesThru() { fail(e.getMessage()); } - verify(observer).onSubscribe((Subscription)any()); - verify(observer, times(1)).onNext("one"); - verify(observer, never()).onNext("two"); - verify(observer, never()).onNext("three"); - verify(observer, never()).onNext("twoResume"); - verify(observer, never()).onNext("threeResume"); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe((Subscription)any()); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onNext("two"); + verify(subscriber, never()).onNext("three"); + verify(subscriber, never()).onNext("twoResume"); + verify(subscriber, never()).onNext("threeResume"); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verifyNoMoreInteractions(subscriber); } @Test @@ -120,10 +120,10 @@ public void testErrorPassesThru() { TestObservable f = new TestObservable("one", "ERROR", "two", "three"); Flowable w = Flowable.unsafeCreate(f); Flowable resume = Flowable.just("twoResume", "threeResume"); - Flowable observable = w.onExceptionResumeNext(resume); + Flowable flowable = w.onExceptionResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); try { f.t.join(); @@ -131,15 +131,15 @@ public void testErrorPassesThru() { fail(e.getMessage()); } - verify(observer).onSubscribe((Subscription)any()); - verify(observer, times(1)).onNext("one"); - verify(observer, never()).onNext("two"); - verify(observer, never()).onNext("three"); - verify(observer, never()).onNext("twoResume"); - verify(observer, never()).onNext("threeResume"); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verifyNoMoreInteractions(observer); + verify(subscriber).onSubscribe((Subscription)any()); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onNext("two"); + verify(subscriber, never()).onNext("three"); + verify(subscriber, never()).onNext("twoResume"); + verify(subscriber, never()).onNext("threeResume"); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verifyNoMoreInteractions(subscriber); } @Test @@ -163,10 +163,10 @@ public String apply(String s) { } }); - Flowable observable = w.onExceptionResumeNext(resume); + Flowable flowable = w.onExceptionResumeNext(resume); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); try { // if the thread gets started (which it shouldn't if it's working correctly) @@ -177,13 +177,13 @@ public String apply(String s) { fail(e.getMessage()); } - verify(observer, times(1)).onNext("one"); - verify(observer, never()).onNext("two"); - verify(observer, never()).onNext("three"); - verify(observer, times(1)).onNext("twoResume"); - verify(observer, times(1)).onNext("threeResume"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onNext("two"); + verify(subscriber, never()).onNext("three"); + verify(subscriber, times(1)).onNext("twoResume"); + verify(subscriber, times(1)).onNext("threeResume"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @@ -226,8 +226,8 @@ private static class TestObservable implements Publisher { } @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); System.out.println("TestObservable subscribed to ..."); t = new Thread(new Runnable() { @@ -246,13 +246,13 @@ public void run() { throw new Throwable("Forced Throwable"); } System.out.println("TestObservable onNext: " + s); - observer.onNext(s); + subscriber.onNext(s); } System.out.println("TestObservable onComplete"); - observer.onComplete(); + subscriber.onComplete(); } catch (Throwable e) { System.out.println("TestObservable onError: " + e); - observer.onError(e); + subscriber.onError(e); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java index 8dfb7584aa..039114d1c7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java @@ -41,8 +41,8 @@ public void concatTakeFirstLastCompletes() { Flowable.range(1, 3).publish(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return Flowable.concat(o.take(5), o.takeLast(5)); + public Flowable apply(Flowable f) { + return Flowable.concat(f.take(5), f.takeLast(5)); } }).subscribe(ts); @@ -57,8 +57,8 @@ public void concatTakeFirstLastBackpressureCompletes() { Flowable.range(1, 6).publish(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return Flowable.concat(o.take(5), o.takeLast(5)); + public Flowable apply(Flowable f) { + return Flowable.concat(f.take(5), f.takeLast(5)); } }).subscribe(ts); @@ -88,8 +88,8 @@ public void canBeCancelled() { pp.publish(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return Flowable.concat(o.take(5), o.takeLast(5)); + public Flowable apply(Flowable f) { + return Flowable.concat(f.take(5), f.takeLast(5)); } }).subscribe(ts); @@ -124,8 +124,8 @@ public void takeCompletes() { pp.publish(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return o.take(1); + public Flowable apply(Flowable f) { + return f.take(1); } }).subscribe(ts); @@ -155,8 +155,8 @@ public void onStart() { pp.publish(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return o.take(1); + public Flowable apply(Flowable f) { + return f.take(1); } }).subscribe(ts); @@ -171,8 +171,8 @@ public void takeCompletesUnsafe() { pp.publish(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return o.take(1); + public Flowable apply(Flowable f) { + return f.take(1); } }).subscribe(ts); @@ -193,8 +193,8 @@ public void directCompletesUnsafe() { pp.publish(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return o; + public Flowable apply(Flowable f) { + return f; } }).subscribe(ts); @@ -216,8 +216,8 @@ public void overflowMissingBackpressureException() { pp.publish(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return o; + public Flowable apply(Flowable f) { + return f; } }).subscribe(ts); @@ -242,8 +242,8 @@ public void overflowMissingBackpressureExceptionDelayed() { new FlowablePublishMulticast(pp, new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return o; + public Flowable apply(Flowable f) { + return f; } }, Flowable.bufferSize(), true).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java index 4c65265cb1..32c906a692 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java @@ -42,18 +42,18 @@ public class FlowablePublishTest { @Test public void testPublish() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - ConnectableFlowable o = Flowable.unsafeCreate(new Publisher() { + ConnectableFlowable f = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); new Thread(new Runnable() { @Override public void run() { counter.incrementAndGet(); - observer.onNext("one"); - observer.onComplete(); + subscriber.onNext("one"); + subscriber.onComplete(); } }).start(); } @@ -62,7 +62,7 @@ public void run() { final CountDownLatch latch = new CountDownLatch(2); // subscribe once - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { @@ -72,7 +72,7 @@ public void accept(String v) { }); // subscribe again - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { @@ -81,7 +81,7 @@ public void accept(String v) { } }); - Disposable s = o.connect(); + Disposable s = f.connect(); try { if (!latch.await(1000, TimeUnit.MILLISECONDS)) { fail("subscriptions did not receive values"); @@ -508,9 +508,9 @@ public void testObserveOn() { @Test public void source() { - Flowable o = Flowable.never(); + Flowable f = Flowable.never(); - assertSame(o, (((HasUpstreamPublisher)o.publish()).source())); + assertSame(f, (((HasUpstreamPublisher)f.publish()).source())); } @Test @@ -651,13 +651,13 @@ public void badSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onComplete(); - observer.onNext(2); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(1); + subscriber.onComplete(); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .publish() @@ -832,47 +832,61 @@ public Object apply(Integer v) throws Exception { @Test public void dryRunCrash() { - final TestSubscriber ts = new TestSubscriber(1L) { - @Override - public void onNext(Object t) { - super.onNext(t); - onComplete(); - cancel(); - } - }; + List errors = TestHelper.trackPluginErrors(); + try { + final TestSubscriber ts = new TestSubscriber(1L) { + @Override + public void onNext(Object t) { + super.onNext(t); + onComplete(); + cancel(); + } + }; - Flowable.range(1, 10) - .map(new Function() { - @Override - public Object apply(Integer v) throws Exception { - if (v == 2) { - throw new TestException(); + Flowable.range(1, 10) + .map(new Function() { + @Override + public Object apply(Integer v) throws Exception { + if (v == 2) { + throw new TestException(); + } + return v; } - return v; - } - }) - .publish() - .autoConnect() - .subscribe(ts); + }) + .publish() + .autoConnect() + .subscribe(ts); - ts - .assertResult(1); + ts + .assertResult(1); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void overflowQueue() { - Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter s) throws Exception { - for (int i = 0; i < 10; i++) { - s.onNext(i); + List errors = TestHelper.trackPluginErrors(); + try { + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter s) throws Exception { + for (int i = 0; i < 10; i++) { + s.onNext(i); + } } - } - }, BackpressureStrategy.MISSING) - .publish(8) - .autoConnect() - .test(0L) - .assertFailure(MissingBackpressureException.class); + }, BackpressureStrategy.MISSING) + .publish(8) + .autoConnect() + .test(0L) + .assertFailure(MissingBackpressureException.class); + + TestHelper.assertError(errors, 0, MissingBackpressureException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java index bf6130b027..f97febd9e2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java @@ -33,21 +33,21 @@ public class FlowableRangeLongTest { @Test public void testRangeStartAt2Count3() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.rangeLong(2, 3).subscribe(observer); + Flowable.rangeLong(2, 3).subscribe(subscriber); - verify(observer, times(1)).onNext(2L); - verify(observer, times(1)).onNext(3L); - verify(observer, times(1)).onNext(4L); - verify(observer, never()).onNext(5L); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(2L); + verify(subscriber, times(1)).onNext(3L); + verify(subscriber, times(1)).onNext(4L); + verify(subscriber, never()).onNext(5L); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testRangeUnsubscribe() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final AtomicInteger count = new AtomicInteger(); @@ -57,14 +57,14 @@ public void accept(Long t1) { count.incrementAndGet(); } }) - .take(3).subscribe(observer); - - verify(observer, times(1)).onNext(1L); - verify(observer, times(1)).onNext(2L); - verify(observer, times(1)).onNext(3L); - verify(observer, never()).onNext(4L); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + .take(3).subscribe(subscriber); + + verify(subscriber, times(1)).onNext(1L); + verify(subscriber, times(1)).onNext(2L); + verify(subscriber, times(1)).onNext(3L); + verify(subscriber, never()).onNext(4L); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); assertEquals(3, count.get()); } @@ -95,14 +95,14 @@ public void testRangeWithOverflow5() { @Test public void testBackpressureViaRequest() { - Flowable o = Flowable.rangeLong(1, Flowable.bufferSize()); + Flowable f = Flowable.rangeLong(1, Flowable.bufferSize()); TestSubscriber ts = new TestSubscriber(0L); ts.assertNoValues(); ts.request(1); - o.subscribe(ts); + f.subscribe(ts); ts.assertValue(1L); @@ -123,14 +123,14 @@ public void testNoBackpressure() { list.add(i); } - Flowable o = Flowable.rangeLong(1, list.size()); + Flowable f = Flowable.rangeLong(1, list.size()); TestSubscriber ts = new TestSubscriber(0L); ts.assertNoValues(); ts.request(Long.MAX_VALUE); // infinite - o.subscribe(ts); + f.subscribe(ts); ts.assertValueSequence(list); ts.assertTerminated(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java index d6e2821d84..36a345c617 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java @@ -33,21 +33,21 @@ public class FlowableRangeTest { @Test public void testRangeStartAt2Count3() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.range(2, 3).subscribe(observer); + Flowable.range(2, 3).subscribe(subscriber); - verify(observer, times(1)).onNext(2); - verify(observer, times(1)).onNext(3); - verify(observer, times(1)).onNext(4); - verify(observer, never()).onNext(5); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, times(1)).onNext(3); + verify(subscriber, times(1)).onNext(4); + verify(subscriber, never()).onNext(5); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testRangeUnsubscribe() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final AtomicInteger count = new AtomicInteger(); @@ -57,14 +57,14 @@ public void accept(Integer t1) { count.incrementAndGet(); } }) - .take(3).subscribe(observer); - - verify(observer, times(1)).onNext(1); - verify(observer, times(1)).onNext(2); - verify(observer, times(1)).onNext(3); - verify(observer, never()).onNext(4); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + .take(3).subscribe(subscriber); + + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, times(1)).onNext(3); + verify(subscriber, never()).onNext(4); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); assertEquals(3, count.get()); } @@ -95,14 +95,14 @@ public void testRangeWithOverflow5() { @Test public void testBackpressureViaRequest() { - Flowable o = Flowable.range(1, Flowable.bufferSize()); + Flowable f = Flowable.range(1, Flowable.bufferSize()); TestSubscriber ts = new TestSubscriber(0L); ts.assertNoValues(); ts.request(1); - o.subscribe(ts); + f.subscribe(ts); ts.assertValue(1); @@ -123,14 +123,14 @@ public void testNoBackpressure() { list.add(i); } - Flowable o = Flowable.range(1, list.size()); + Flowable f = Flowable.range(1, list.size()); TestSubscriber ts = new TestSubscriber(0L); ts.assertNoValues(); ts.request(Long.MAX_VALUE); // infinite - o.subscribe(ts); + f.subscribe(ts); ts.assertValueSequence(list); ts.assertTerminated(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java index 63e80b3822..12425aed42 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java @@ -34,13 +34,13 @@ import io.reactivex.subscribers.TestSubscriber; public class FlowableReduceTest { - Subscriber observer; + Subscriber subscriber; SingleObserver singleObserver; @Before public void before() { - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); singleObserver = TestHelper.mockSingleObserver(); } @@ -62,11 +62,11 @@ public Integer apply(Integer v) { } }); - result.subscribe(observer); + result.subscribe(subscriber); - verify(observer).onNext(1 + 2 + 3 + 4 + 5); - verify(observer).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1 + 2 + 3 + 4 + 5); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -80,11 +80,11 @@ public Integer apply(Integer v) { } }); - result.subscribe(observer); + result.subscribe(subscriber); - verify(observer, never()).onNext(any()); - verify(observer, never()).onComplete(); - verify(observer, times(1)).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onError(any(TestException.class)); } @Test @@ -104,11 +104,11 @@ public Integer apply(Integer v) { } }); - result.subscribe(observer); + result.subscribe(subscriber); - verify(observer, never()).onNext(any()); - verify(observer, never()).onComplete(); - verify(observer, times(1)).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onError(any(TestException.class)); } @Test @@ -125,11 +125,11 @@ public Integer apply(Integer t1) { Flowable result = Flowable.just(1, 2, 3, 4, 5) .reduce(0, sum).toFlowable().map(error); - result.subscribe(observer); + result.subscribe(subscriber); - verify(observer, never()).onNext(any()); - verify(observer, never()).onComplete(); - verify(observer, times(1)).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onError(any(TestException.class)); } @Test @@ -476,9 +476,9 @@ static String blockingOp(Integer x, Integer y) { public void seedDoubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function, SingleSource>() { @Override - public SingleSource apply(Flowable o) + public SingleSource apply(Flowable f) throws Exception { - return o.reduce(0, new BiFunction() { + return f.reduce(0, new BiFunction() { @Override public Integer apply(Integer a, Integer b) throws Exception { return a; @@ -504,12 +504,12 @@ public void seedBadSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onComplete(); - observer.onNext(1); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); + subscriber.onNext(1); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .reduce(0, new BiFunction() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java index d91f4706d6..acb93684d6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java @@ -229,7 +229,7 @@ public void testConnectUnsubscribe() throws InterruptedException { final CountDownLatch unsubscribeLatch = new CountDownLatch(1); final CountDownLatch subscribeLatch = new CountDownLatch(1); - Flowable o = synchronousInterval() + Flowable f = synchronousInterval() .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -248,7 +248,7 @@ public void run() { }); TestSubscriber s = new TestSubscriber(); - o.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(s); + f.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(s); System.out.println("send unsubscribe"); // wait until connected subscribeLatch.await(); @@ -275,7 +275,7 @@ public void testConnectUnsubscribeRaceConditionLoop() throws InterruptedExceptio @Test public void testConnectUnsubscribeRaceCondition() throws InterruptedException { final AtomicInteger subUnsubCount = new AtomicInteger(); - Flowable o = synchronousInterval() + Flowable f = synchronousInterval() .doOnCancel(new Action() { @Override public void run() { @@ -294,7 +294,7 @@ public void accept(Subscription s) { TestSubscriber s = new TestSubscriber(); - o.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(s); + f.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(s); System.out.println("send unsubscribe"); // now immediately unsubscribe while subscribeOn is racing to subscribe s.dispose(); @@ -347,11 +347,11 @@ public void cancel() { public void onlyFirstShouldSubscribeAndLastUnsubscribe() { final AtomicInteger subscriptionCount = new AtomicInteger(); final AtomicInteger unsubscriptionCount = new AtomicInteger(); - Flowable observable = Flowable.unsafeCreate(new Publisher() { + Flowable flowable = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { + public void subscribe(Subscriber subscriber) { subscriptionCount.incrementAndGet(); - observer.onSubscribe(new Subscription() { + subscriber.onSubscribe(new Subscription() { @Override public void request(long n) { @@ -364,7 +364,7 @@ public void cancel() { }); } }); - Flowable refCounted = observable.publish().refCount(); + Flowable refCounted = flowable.publish().refCount(); Disposable first = refCounted.subscribe(); assertEquals(1, subscriptionCount.get()); @@ -465,17 +465,17 @@ public void accept(Long t1) { public void testAlreadyUnsubscribedClient() { Subscriber done = CancelledSubscriber.INSTANCE; - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable result = Flowable.just(1).publish().refCount(); result.subscribe(done); - result.subscribe(o); + result.subscribe(subscriber); - verify(o).onNext(1); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -484,12 +484,12 @@ public void testAlreadyUnsubscribedInterleavesWithClient() { Subscriber done = CancelledSubscriber.INSTANCE; - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); Flowable result = source.publish().refCount(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); @@ -498,17 +498,17 @@ public void testAlreadyUnsubscribedInterleavesWithClient() { source.onNext(2); source.onComplete(); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testConnectDisconnectConnectAndSubjectState() { - Flowable o1 = Flowable.just(10); - Flowable o2 = Flowable.just(20); - Flowable combined = Flowable.combineLatest(o1, o2, new BiFunction() { + Flowable f1 = Flowable.just(10); + Flowable f2 = Flowable.just(20); + Flowable combined = Flowable.combineLatest(f1, f2, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; @@ -533,70 +533,77 @@ public Integer apply(Integer t1, Integer t2) { @Test(timeout = 10000) public void testUpstreamErrorAllowsRetry() throws InterruptedException { - final AtomicInteger intervalSubscribed = new AtomicInteger(); - Flowable interval = - Flowable.interval(200,TimeUnit.MILLISECONDS) - .doOnSubscribe(new Consumer() { - @Override - public void accept(Subscription s) { - System.out.println("Subscribing to interval " + intervalSubscribed.incrementAndGet()); - } - } - ) - .flatMap(new Function>() { - @Override - public Publisher apply(Long t1) { - return Flowable.defer(new Callable>() { - @Override - public Publisher call() { - return Flowable.error(new Exception("Some exception")); + List errors = TestHelper.trackPluginErrors(); + try { + final AtomicInteger intervalSubscribed = new AtomicInteger(); + Flowable interval = + Flowable.interval(200,TimeUnit.MILLISECONDS) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) { + System.out.println("Subscribing to interval " + intervalSubscribed.incrementAndGet()); } - }); } - }) - .onErrorResumeNext(new Function>() { - @Override - public Publisher apply(Throwable t1) { - return Flowable.error(t1); - } - }) - .publish() - .refCount(); + ) + .flatMap(new Function>() { + @Override + public Publisher apply(Long t1) { + return Flowable.defer(new Callable>() { + @Override + public Publisher call() { + return Flowable.error(new TestException("Some exception")); + } + }); + } + }) + .onErrorResumeNext(new Function>() { + @Override + public Publisher apply(Throwable t1) { + return Flowable.error(t1); + } + }) + .publish() + .refCount(); + + interval + .doOnError(new Consumer() { + @Override + public void accept(Throwable t1) { + System.out.println("Subscriber 1 onError: " + t1); + } + }) + .retry(5) + .subscribe(new Consumer() { + @Override + public void accept(String t1) { + System.out.println("Subscriber 1: " + t1); + } + }); + Thread.sleep(100); + interval + .doOnError(new Consumer() { + @Override + public void accept(Throwable t1) { + System.out.println("Subscriber 2 onError: " + t1); + } + }) + .retry(5) + .subscribe(new Consumer() { + @Override + public void accept(String t1) { + System.out.println("Subscriber 2: " + t1); + } + }); - interval - .doOnError(new Consumer() { - @Override - public void accept(Throwable t1) { - System.out.println("Subscriber 1 onError: " + t1); - } - }) - .retry(5) - .subscribe(new Consumer() { - @Override - public void accept(String t1) { - System.out.println("Subscriber 1: " + t1); - } - }); - Thread.sleep(100); - interval - .doOnError(new Consumer() { - @Override - public void accept(Throwable t1) { - System.out.println("Subscriber 2 onError: " + t1); - } - }) - .retry(5) - .subscribe(new Consumer() { - @Override - public void accept(String t1) { - System.out.println("Subscriber 2: " + t1); - } - }); + Thread.sleep(1300); - Thread.sleep(1300); + System.out.println(intervalSubscribed.get()); + assertEquals(6, intervalSubscribed.get()); - System.out.println(intervalSubscribed.get()); - assertEquals(6, intervalSubscribed.get()); + TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); + } finally { + RxJavaPlugins.reset(); + } } private enum CancelledSubscriber implements FlowableSubscriber { @@ -624,20 +631,20 @@ public void disposed() { @Test public void noOpConnect() { final int[] calls = { 0 }; - Flowable o = new ConnectableFlowable() { + Flowable f = new ConnectableFlowable() { @Override public void connect(Consumer connection) { calls[0]++; } @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); } }.refCount(); - o.test(); - o.test(); + f.test(); + f.test(); assertEquals(1, calls[0]); } @@ -804,7 +811,7 @@ public void connect(Consumer connection) { } @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { throw new TestException("subscribeActual"); } } @@ -831,8 +838,8 @@ public void connect(Consumer connection) { } @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); } } @@ -844,21 +851,28 @@ public void connect(Consumer connection) { } @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); } } @Test public void badSourceSubscribe() { - BadFlowableSubscribe bo = new BadFlowableSubscribe(); - + List errors = TestHelper.trackPluginErrors(); try { - bo.refCount() - .test(); - fail("Should have thrown"); - } catch (NullPointerException ex) { - assertTrue(ex.getCause() instanceof TestException); + BadFlowableSubscribe bo = new BadFlowableSubscribe(); + + try { + bo.refCount() + .test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); } } @@ -877,14 +891,21 @@ public void badSourceDispose() { @Test public void badSourceConnect() { - BadFlowableConnect bf = new BadFlowableConnect(); - + List errors = TestHelper.trackPluginErrors(); try { - bf.refCount() - .test(); - fail("Should have thrown"); - } catch (NullPointerException ex) { - assertTrue(ex.getCause() instanceof TestException); + BadFlowableConnect bf = new BadFlowableConnect(); + + try { + bf.refCount() + .test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); } } @@ -902,9 +923,9 @@ public void connect(Consumer connection) { } @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { if (++count == 1) { - observer.onSubscribe(new BooleanSubscription()); + subscriber.onSubscribe(new BooleanSubscription()); } else { throw new TestException("subscribeActual"); } @@ -913,15 +934,22 @@ protected void subscribeActual(Subscriber observer) { @Test public void badSourceSubscribe2() { - BadFlowableSubscribe2 bf = new BadFlowableSubscribe2(); - - Flowable o = bf.refCount(); - o.test(); + List errors = TestHelper.trackPluginErrors(); try { - o.test(); - fail("Should have thrown"); - } catch (NullPointerException ex) { - assertTrue(ex.getCause() instanceof TestException); + BadFlowableSubscribe2 bf = new BadFlowableSubscribe2(); + + Flowable f = bf.refCount(); + f.test(); + try { + f.test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); } } @@ -938,9 +966,9 @@ public void connect(Consumer connection) { } @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); } @Override @@ -956,14 +984,21 @@ public boolean isDisposed() { @Test public void badSourceCompleteDisconnect() { - BadFlowableConnect2 bf = new BadFlowableConnect2(); - + List errors = TestHelper.trackPluginErrors(); try { - bf.refCount() - .test(); - fail("Should have thrown"); - } catch (NullPointerException ex) { - assertTrue(ex.getCause() instanceof TestException); + BadFlowableConnect2 bf = new BadFlowableConnect2(); + + try { + bf.refCount() + .test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); } } @@ -1181,12 +1216,12 @@ public void connect(Consumer connection) { } @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onSubscribe(new BooleanSubscription()); - observer.onComplete(); - observer.onComplete(); - observer.onError(new TestException()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); + subscriber.onComplete(); + subscriber.onError(new TestException()); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java index b74221fdea..82cec69233 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java @@ -42,9 +42,9 @@ public void testRepetition() { int value = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber o) { - o.onNext(count.incrementAndGet()); - o.onComplete(); + public void subscribe(final Subscriber subscriber) { + subscriber.onNext(count.incrementAndGet()); + subscriber.onComplete(); } }).repeat().subscribeOn(Schedulers.computation()) .take(num).blockingLast(); @@ -100,58 +100,58 @@ public Integer apply(Integer t1) { @Test(timeout = 2000) public void testRepeatAndTake() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.just(1).repeat().take(10).subscribe(o); + Flowable.just(1).repeat().take(10).subscribe(subscriber); - verify(o, times(10)).onNext(1); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, times(10)).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test(timeout = 2000) public void testRepeatLimited() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.just(1).repeat(10).subscribe(o); + Flowable.just(1).repeat(10).subscribe(subscriber); - verify(o, times(10)).onNext(1); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, times(10)).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test(timeout = 2000) public void testRepeatError() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.error(new TestException()).repeat(10).subscribe(o); + Flowable.error(new TestException()).repeat(10).subscribe(subscriber); - verify(o).onError(any(TestException.class)); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test(timeout = 2000) public void testRepeatZero() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.just(1).repeat(0).subscribe(o); + Flowable.just(1).repeat(0).subscribe(subscriber); - verify(o).onComplete(); - verify(o, never()).onNext(any()); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test(timeout = 2000) public void testRepeatOne() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.just(1).repeat(1).subscribe(o); + Flowable.just(1).repeat(1).subscribe(subscriber); - verify(o).onComplete(); - verify(o, times(1)).onNext(any()); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); + verify(subscriber, times(1)).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } /** Issue #2587. */ @@ -216,8 +216,8 @@ public void repeatWhenDefaultScheduler() { Flowable.just(1).repeatWhen((Function)new Function() { @Override - public Flowable apply(Flowable o) { - return o.take(2); + public Flowable apply(Flowable f) { + return f.take(2); } }).subscribe(ts); @@ -235,8 +235,8 @@ public void repeatWhenTrampolineScheduler() { Flowable.just(1).subscribeOn(Schedulers.trampoline()) .repeatWhen((Function)new Function() { @Override - public Flowable apply(Flowable o) { - return o.take(2); + public Flowable apply(Flowable f) { + return f.take(2); } }).subscribe(ts); @@ -323,7 +323,7 @@ public boolean getAsBoolean() throws Exception { @Test public void shouldDisposeInnerObservable() { - final PublishProcessor subject = PublishProcessor.create(); + final PublishProcessor processor = PublishProcessor.create(); final Disposable disposable = Flowable.just("Leak") .repeatWhen(new Function, Flowable>() { @Override @@ -331,16 +331,16 @@ public Flowable apply(Flowable completions) throws Exception { return completions.switchMap(new Function>() { @Override public Flowable apply(Object ignore) throws Exception { - return subject; + return processor; } }); } }) .subscribe(); - assertTrue(subject.hasSubscribers()); + assertTrue(processor.hasSubscribers()); disposable.dispose(); - assertFalse(subject.hasSubscribers()); + assertFalse(processor.hasSubscribers()); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java index 5941a8f4e2..137565dae4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java @@ -50,40 +50,40 @@ public void testBufferedReplay() { cf.connect(); { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); + cf.subscribe(subscriber1); source.onNext(1); source.onNext(2); source.onNext(3); - inOrder.verify(observer1, times(1)).onNext(1); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(3); + inOrder.verify(subscriber1, times(1)).onNext(1); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(3); source.onNext(4); source.onComplete(); - inOrder.verify(observer1, times(1)).onNext(4); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onNext(4); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); + cf.subscribe(subscriber1); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(3); - inOrder.verify(observer1, times(1)).onNext(4); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(3); + inOrder.verify(subscriber1, times(1)).onNext(4); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } } @@ -95,10 +95,10 @@ public void testBufferedWindowReplay() { cf.connect(); { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); + cf.subscribe(subscriber1); source.onNext(1); scheduler.advanceTimeBy(10, TimeUnit.MILLISECONDS); @@ -107,33 +107,33 @@ public void testBufferedWindowReplay() { source.onNext(3); scheduler.advanceTimeBy(10, TimeUnit.MILLISECONDS); - inOrder.verify(observer1, times(1)).onNext(1); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(3); + inOrder.verify(subscriber1, times(1)).onNext(1); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(3); source.onNext(4); source.onNext(5); scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); - inOrder.verify(observer1, times(1)).onNext(4); + inOrder.verify(subscriber1, times(1)).onNext(4); - inOrder.verify(observer1, times(1)).onNext(5); + inOrder.verify(subscriber1, times(1)).onNext(5); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); + cf.subscribe(subscriber1); - inOrder.verify(observer1, times(1)).onNext(4); - inOrder.verify(observer1, times(1)).onNext(5); + inOrder.verify(subscriber1, times(1)).onNext(4); + inOrder.verify(subscriber1, times(1)).onNext(5); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } } @@ -147,10 +147,10 @@ public void testWindowedReplay() { cf.connect(); { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); + cf.subscribe(subscriber1); source.onNext(1); scheduler.advanceTimeBy(60, TimeUnit.MILLISECONDS); @@ -161,25 +161,25 @@ public void testWindowedReplay() { source.onComplete(); scheduler.advanceTimeBy(60, TimeUnit.MILLISECONDS); - inOrder.verify(observer1, times(1)).onNext(1); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(3); + inOrder.verify(subscriber1, times(1)).onNext(1); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(3); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); - inOrder.verify(observer1, never()).onNext(3); + cf.subscribe(subscriber1); + inOrder.verify(subscriber1, never()).onNext(3); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } } @@ -208,37 +208,37 @@ public Flowable apply(Flowable t1) { Flowable co = source.replay(selector); { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - co.subscribe(observer1); + co.subscribe(subscriber1); source.onNext(1); source.onNext(2); source.onNext(3); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(4); - inOrder.verify(observer1, times(1)).onNext(6); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(4); + inOrder.verify(subscriber1, times(1)).onNext(6); source.onNext(4); source.onComplete(); - inOrder.verify(observer1, times(1)).onNext(8); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onNext(8); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - co.subscribe(observer1); + co.subscribe(subscriber1); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } @@ -270,37 +270,37 @@ public Flowable apply(Flowable t1) { Flowable co = source.replay(selector, 3); { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - co.subscribe(observer1); + co.subscribe(subscriber1); source.onNext(1); source.onNext(2); source.onNext(3); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(4); - inOrder.verify(observer1, times(1)).onNext(6); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(4); + inOrder.verify(subscriber1, times(1)).onNext(6); source.onNext(4); source.onComplete(); - inOrder.verify(observer1, times(1)).onNext(8); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onNext(8); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - co.subscribe(observer1); + co.subscribe(subscriber1); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } } @@ -332,10 +332,10 @@ public Flowable apply(Flowable t1) { Flowable co = source.replay(selector, 100, TimeUnit.MILLISECONDS, scheduler); { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - co.subscribe(observer1); + co.subscribe(subscriber1); source.onNext(1); scheduler.advanceTimeBy(60, TimeUnit.MILLISECONDS); @@ -346,24 +346,24 @@ public Flowable apply(Flowable t1) { source.onComplete(); scheduler.advanceTimeBy(60, TimeUnit.MILLISECONDS); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(4); - inOrder.verify(observer1, times(1)).onNext(6); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(4); + inOrder.verify(subscriber1, times(1)).onNext(6); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - co.subscribe(observer1); + co.subscribe(subscriber1); - inOrder.verify(observer1, times(1)).onComplete(); + inOrder.verify(subscriber1, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onError(any(Throwable.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); } } @@ -375,41 +375,41 @@ public void testBufferedReplayError() { cf.connect(); { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); + cf.subscribe(subscriber1); source.onNext(1); source.onNext(2); source.onNext(3); - inOrder.verify(observer1, times(1)).onNext(1); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(3); + inOrder.verify(subscriber1, times(1)).onNext(1); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(3); source.onNext(4); source.onError(new RuntimeException("Forced failure")); - inOrder.verify(observer1, times(1)).onNext(4); - inOrder.verify(observer1, times(1)).onError(any(RuntimeException.class)); + inOrder.verify(subscriber1, times(1)).onNext(4); + inOrder.verify(subscriber1, times(1)).onError(any(RuntimeException.class)); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onComplete(); + verify(subscriber1, never()).onComplete(); } { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); + cf.subscribe(subscriber1); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(3); - inOrder.verify(observer1, times(1)).onNext(4); - inOrder.verify(observer1, times(1)).onError(any(RuntimeException.class)); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(3); + inOrder.verify(subscriber1, times(1)).onNext(4); + inOrder.verify(subscriber1, times(1)).onError(any(RuntimeException.class)); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onComplete(); + verify(subscriber1, never()).onComplete(); } } @@ -423,10 +423,10 @@ public void testWindowedReplayError() { cf.connect(); { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); + cf.subscribe(subscriber1); source.onNext(1); scheduler.advanceTimeBy(60, TimeUnit.MILLISECONDS); @@ -437,25 +437,25 @@ public void testWindowedReplayError() { source.onError(new RuntimeException("Forced failure")); scheduler.advanceTimeBy(60, TimeUnit.MILLISECONDS); - inOrder.verify(observer1, times(1)).onNext(1); - inOrder.verify(observer1, times(1)).onNext(2); - inOrder.verify(observer1, times(1)).onNext(3); + inOrder.verify(subscriber1, times(1)).onNext(1); + inOrder.verify(subscriber1, times(1)).onNext(2); + inOrder.verify(subscriber1, times(1)).onNext(3); - inOrder.verify(observer1, times(1)).onError(any(RuntimeException.class)); + inOrder.verify(subscriber1, times(1)).onError(any(RuntimeException.class)); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onComplete(); + verify(subscriber1, never()).onComplete(); } { - Subscriber observer1 = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber1); - cf.subscribe(observer1); - inOrder.verify(observer1, never()).onNext(3); + cf.subscribe(subscriber1); + inOrder.verify(subscriber1, never()).onNext(3); - inOrder.verify(observer1, times(1)).onError(any(RuntimeException.class)); + inOrder.verify(subscriber1, times(1)).onError(any(RuntimeException.class)); inOrder.verifyNoMoreInteractions(); - verify(observer1, never()).onComplete(); + verify(subscriber1, never()).onComplete(); } } @@ -474,8 +474,8 @@ public void accept(Integer v) { Flowable result = source.replay( new Function, Flowable>() { @Override - public Flowable apply(Flowable o) { - return o.take(2); + public Flowable apply(Flowable f) { + return f.take(2); } }); @@ -900,19 +900,19 @@ public void testColdReplayBackpressure() { @Test public void testCache() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); new Thread(new Runnable() { @Override public void run() { counter.incrementAndGet(); System.out.println("published observable being executed"); - observer.onNext("one"); - observer.onComplete(); + subscriber.onNext("one"); + subscriber.onComplete(); } }).start(); } @@ -922,7 +922,7 @@ public void run() { final CountDownLatch latch = new CountDownLatch(2); // subscribe once - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { @@ -933,7 +933,7 @@ public void accept(String v) { }); // subscribe again - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String v) { @@ -952,10 +952,10 @@ public void accept(String v) { @Test public void testUnsubscribeSource() throws Exception { Action unsubscribe = mock(Action.class); - Flowable o = Flowable.just(1).doOnCancel(unsubscribe).cache(); - o.subscribe(); - o.subscribe(); - o.subscribe(); + Flowable f = Flowable.just(1).doOnCancel(unsubscribe).cache(); + f.subscribe(); + f.subscribe(); + f.subscribe(); verify(unsubscribe, times(1)).run(); } @@ -1425,12 +1425,12 @@ public void badSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException("First")); - observer.onNext(1); - observer.onError(new TestException("Second")); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException("First")); + subscriber.onNext(1); + subscriber.onError(new TestException("Second")); + subscriber.onComplete(); } }.replay() .autoConnect() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java index 062470229d..e7a2bb8eaa 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java @@ -111,29 +111,29 @@ public static class Tuple { @Test public void testRetryIndefinitely() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); int numRetries = 20; Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(numRetries)); - origin.retry().subscribe(new TestSubscriber(observer)); + origin.retry().subscribe(new TestSubscriber(subscriber)); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // should show 3 attempts - inOrder.verify(observer, times(numRetries + 1)).onNext("beginningEveryTime"); + inOrder.verify(subscriber, times(numRetries + 1)).onNext("beginningEveryTime"); // should have no errors - inOrder.verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); // should have a single success - inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); + inOrder.verify(subscriber, times(1)).onNext("onSuccessOnly"); // should have a single successful onComplete - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testSchedulingNotificationHandler() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); int numRetries = 2; Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(numRetries)); - TestSubscriber subscriber = new TestSubscriber(observer); + TestSubscriber ts = new TestSubscriber(subscriber); origin.retryWhen(new Function, Flowable>() { @Override public Flowable apply(Flowable t1) { @@ -151,24 +151,24 @@ public void accept(Throwable e) { e.printStackTrace(); } }) - .subscribe(subscriber); + .subscribe(ts); - subscriber.awaitTerminalEvent(); - InOrder inOrder = inOrder(observer); + ts.awaitTerminalEvent(); + InOrder inOrder = inOrder(subscriber); // should show 3 attempts - inOrder.verify(observer, times(1 + numRetries)).onNext("beginningEveryTime"); + inOrder.verify(subscriber, times(1 + numRetries)).onNext("beginningEveryTime"); // should have no errors - inOrder.verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); // should have a single success - inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); + inOrder.verify(subscriber, times(1)).onNext("onSuccessOnly"); // should have a single successful onComplete - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testOnNextFromNotificationHandler() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); int numRetries = 2; Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(numRetries)); origin.retryWhen(new Function, Flowable>() { @@ -182,58 +182,58 @@ public Integer apply(Throwable t1) { } }).startWith(0).cast(Object.class); } - }).subscribe(observer); + }).subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // should show 3 attempts - inOrder.verify(observer, times(numRetries + 1)).onNext("beginningEveryTime"); + inOrder.verify(subscriber, times(numRetries + 1)).onNext("beginningEveryTime"); // should have no errors - inOrder.verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); // should have a single success - inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); + inOrder.verify(subscriber, times(1)).onNext("onSuccessOnly"); // should have a single successful onComplete - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testOnCompletedFromNotificationHandler() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(1)); - TestSubscriber subscriber = new TestSubscriber(observer); + TestSubscriber ts = new TestSubscriber(subscriber); origin.retryWhen(new Function, Flowable>() { @Override public Flowable apply(Flowable t1) { return Flowable.empty(); } - }).subscribe(subscriber); + }).subscribe(ts); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onSubscribe((Subscription)notNull()); - inOrder.verify(observer, never()).onNext("beginningEveryTime"); - inOrder.verify(observer, never()).onNext("onSuccessOnly"); - inOrder.verify(observer, times(1)).onComplete(); - inOrder.verify(observer, never()).onError(any(Exception.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onSubscribe((Subscription)notNull()); + inOrder.verify(subscriber, never()).onNext("beginningEveryTime"); + inOrder.verify(subscriber, never()).onNext("onSuccessOnly"); + inOrder.verify(subscriber, times(1)).onComplete(); + inOrder.verify(subscriber, never()).onError(any(Exception.class)); inOrder.verifyNoMoreInteractions(); } @Test public void testOnErrorFromNotificationHandler() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(2)); origin.retryWhen(new Function, Flowable>() { @Override public Flowable apply(Flowable t1) { return Flowable.error(new RuntimeException()); } - }).subscribe(observer); - - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onSubscribe((Subscription)notNull()); - inOrder.verify(observer, never()).onNext("beginningEveryTime"); - inOrder.verify(observer, never()).onNext("onSuccessOnly"); - inOrder.verify(observer, never()).onComplete(); - inOrder.verify(observer, times(1)).onError(any(RuntimeException.class)); + }).subscribe(subscriber); + + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onSubscribe((Subscription)notNull()); + inOrder.verify(subscriber, never()).onNext("beginningEveryTime"); + inOrder.verify(subscriber, never()).onNext("onSuccessOnly"); + inOrder.verify(subscriber, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onError(any(RuntimeException.class)); inOrder.verifyNoMoreInteractions(); } @@ -270,71 +270,71 @@ public Object apply(Throwable o, Integer integer) { @Test public void testOriginFails() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(1)); - origin.subscribe(observer); + origin.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("beginningEveryTime"); - inOrder.verify(observer, times(1)).onError(any(RuntimeException.class)); - inOrder.verify(observer, never()).onNext("onSuccessOnly"); - inOrder.verify(observer, never()).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("beginningEveryTime"); + inOrder.verify(subscriber, times(1)).onError(any(RuntimeException.class)); + inOrder.verify(subscriber, never()).onNext("onSuccessOnly"); + inOrder.verify(subscriber, never()).onComplete(); } @Test public void testRetryFail() { int numRetries = 1; int numFailures = 2; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(numFailures)); - origin.retry(numRetries).subscribe(observer); + origin.retry(numRetries).subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // should show 2 attempts (first time fail, second time (1st retry) fail) - inOrder.verify(observer, times(1 + numRetries)).onNext("beginningEveryTime"); + inOrder.verify(subscriber, times(1 + numRetries)).onNext("beginningEveryTime"); // should only retry once, fail again and emit onError - inOrder.verify(observer, times(1)).onError(any(RuntimeException.class)); + inOrder.verify(subscriber, times(1)).onError(any(RuntimeException.class)); // no success - inOrder.verify(observer, never()).onNext("onSuccessOnly"); - inOrder.verify(observer, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext("onSuccessOnly"); + inOrder.verify(subscriber, never()).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testRetrySuccess() { int numFailures = 1; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(numFailures)); - origin.retry(3).subscribe(observer); + origin.retry(3).subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // should show 3 attempts - inOrder.verify(observer, times(1 + numFailures)).onNext("beginningEveryTime"); + inOrder.verify(subscriber, times(1 + numFailures)).onNext("beginningEveryTime"); // should have no errors - inOrder.verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); // should have a single success - inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); + inOrder.verify(subscriber, times(1)).onNext("onSuccessOnly"); // should have a single successful onComplete - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testInfiniteRetry() { int numFailures = 20; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(numFailures)); - origin.retry().subscribe(observer); + origin.retry().subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // should show 3 attempts - inOrder.verify(observer, times(1 + numFailures)).onNext("beginningEveryTime"); + inOrder.verify(subscriber, times(1 + numFailures)).onNext("beginningEveryTime"); // should have no errors - inOrder.verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); // should have a single success - inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); + inOrder.verify(subscriber, times(1)).onNext("onSuccessOnly"); // should have a single successful onComplete - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -356,8 +356,8 @@ public void testRetrySubscribesAgainAfterError() throws Exception { doThrow(new RuntimeException()).when(throwException).accept(Mockito.anyInt()); // create a retrying observable based on a PublishProcessor - PublishProcessor subject = PublishProcessor.create(); - subject + PublishProcessor processor = PublishProcessor.create(); + processor // record item .doOnNext(record) // throw a RuntimeException @@ -369,13 +369,13 @@ public void testRetrySubscribesAgainAfterError() throws Exception { inOrder.verifyNoMoreInteractions(); - subject.onNext(1); + processor.onNext(1); inOrder.verify(record).accept(1); - subject.onNext(2); + processor.onNext(2); inOrder.verify(record).accept(2); - subject.onNext(3); + processor.onNext(3); inOrder.verify(record).accept(3); inOrder.verifyNoMoreInteractions(); @@ -391,8 +391,8 @@ public static class FuncWithErrors implements Publisher { } @Override - public void subscribe(final Subscriber o) { - o.onSubscribe(new Subscription() { + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new Subscription() { final AtomicLong req = new AtomicLong(); // 0 = not set, 1 = fast path, 2 = backpressure final AtomicInteger path = new AtomicInteger(0); @@ -401,30 +401,30 @@ public void subscribe(final Subscriber o) { @Override public void request(long n) { if (n == Long.MAX_VALUE && path.compareAndSet(0, 1)) { - o.onNext("beginningEveryTime"); + subscriber.onNext("beginningEveryTime"); int i = count.getAndIncrement(); if (i < numFailures) { - o.onError(new RuntimeException("forced failure: " + (i + 1))); + subscriber.onError(new RuntimeException("forced failure: " + (i + 1))); } else { - o.onNext("onSuccessOnly"); - o.onComplete(); + subscriber.onNext("onSuccessOnly"); + subscriber.onComplete(); } return; } if (n > 0 && req.getAndAdd(n) == 0 && (path.get() == 2 || path.compareAndSet(0, 2)) && !done) { int i = count.getAndIncrement(); if (i < numFailures) { - o.onNext("beginningEveryTime"); - o.onError(new RuntimeException("forced failure: " + (i + 1))); + subscriber.onNext("beginningEveryTime"); + subscriber.onError(new RuntimeException("forced failure: " + (i + 1))); done = true; } else { do { if (i == numFailures) { - o.onNext("beginningEveryTime"); + subscriber.onNext("beginningEveryTime"); } else if (i > numFailures) { - o.onNext("onSuccessOnly"); - o.onComplete(); + subscriber.onNext("onSuccessOnly"); + subscriber.onComplete(); done = true; break; } @@ -444,17 +444,17 @@ public void cancel() { @Test public void testUnsubscribeFromRetry() { - PublishProcessor subject = PublishProcessor.create(); + PublishProcessor processor = PublishProcessor.create(); final AtomicInteger count = new AtomicInteger(0); - Disposable sub = subject.retry().subscribe(new Consumer() { + Disposable sub = processor.retry().subscribe(new Consumer() { @Override public void accept(Integer n) { count.incrementAndGet(); } }); - subject.onNext(1); + processor.onNext(1); sub.dispose(); - subject.onNext(2); + processor.onNext(2); assertEquals(1, count.get()); } @@ -614,7 +614,7 @@ public void run() { } /** Observer for listener on seperate thread. */ - static final class AsyncObserver extends DefaultSubscriber { + static final class AsyncSubscriber extends DefaultSubscriber { protected CountDownLatch latch = new CountDownLatch(1); @@ -624,7 +624,7 @@ static final class AsyncObserver extends DefaultSubscriber { * Wrap existing Observer. * @param target the target subscriber */ - AsyncObserver(Subscriber target) { + AsyncSubscriber(Subscriber target) { this.target = target; } @@ -660,23 +660,22 @@ public void onNext(T v) { @Test(timeout = 10000) public void testUnsubscribeAfterError() { - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); + Subscriber subscriber = TestHelper.mockSubscriber(); // Flowable that always fails after 100ms SlowFlowable so = new SlowFlowable(100, 0); - Flowable o = Flowable.unsafeCreate(so).retry(5); + Flowable f = Flowable.unsafeCreate(so).retry(5); - AsyncObserver async = new AsyncObserver(observer); + AsyncSubscriber async = new AsyncSubscriber(subscriber); - o.subscribe(async); + f.subscribe(async); async.await(); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // Should fail once - inOrder.verify(observer, times(1)).onError(any(Throwable.class)); - inOrder.verify(observer, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onComplete(); assertEquals("Start 6 threads, retry 5 then fail on 6", 6, so.efforts.get()); assertEquals("Only 1 active subscription", 1, so.maxActive.get()); @@ -685,25 +684,24 @@ public void testUnsubscribeAfterError() { @Test//(timeout = 10000) public void testTimeoutWithRetry() { - @SuppressWarnings("unchecked") - DefaultSubscriber observer = mock(DefaultSubscriber.class); + Subscriber subscriber = TestHelper.mockSubscriber(); // Flowable that sends every 100ms (timeout fails instead) - SlowFlowable so = new SlowFlowable(100, 10); - Flowable o = Flowable.unsafeCreate(so).timeout(80, TimeUnit.MILLISECONDS).retry(5); + SlowFlowable sf = new SlowFlowable(100, 10); + Flowable f = Flowable.unsafeCreate(sf).timeout(80, TimeUnit.MILLISECONDS).retry(5); - AsyncObserver async = new AsyncObserver(observer); + AsyncSubscriber async = new AsyncSubscriber(subscriber); - o.subscribe(async); + f.subscribe(async); async.await(); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // Should fail once - inOrder.verify(observer, times(1)).onError(any(Throwable.class)); - inOrder.verify(observer, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onComplete(); - assertEquals("Start 6 threads, retry 5 then fail on 6", 6, so.efforts.get()); + assertEquals("Start 6 threads, retry 5 then fail on 6", 6, sf.efforts.get()); } @Test//(timeout = 15000) @@ -712,21 +710,21 @@ public void testRetryWithBackpressure() throws InterruptedException { for (int j = 0;j < NUM_LOOPS; j++) { final int numRetries = Flowable.bufferSize() * 2; for (int i = 0; i < 400; i++) { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(numRetries)); - TestSubscriber ts = new TestSubscriber(observer); + TestSubscriber ts = new TestSubscriber(subscriber); origin.retry().observeOn(Schedulers.computation()).subscribe(ts); ts.awaitTerminalEvent(5, TimeUnit.SECONDS); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // should have no errors - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); // should show numRetries attempts - inOrder.verify(observer, times(numRetries + 1)).onNext("beginningEveryTime"); + inOrder.verify(subscriber, times(numRetries + 1)).onNext("beginningEveryTime"); // should have a single success - inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); + inOrder.verify(subscriber, times(1)).onNext("onSuccessOnly"); // should have a single successful onComplete - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } } @@ -833,7 +831,7 @@ static StringBuilder sequenceFrequency(Iterable it) { } @Test//(timeout = 3000) public void testIssue1900() throws InterruptedException { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final int NUM_MSG = 1034; final AtomicInteger count = new AtomicInteger(); @@ -858,34 +856,34 @@ public Flowable apply(GroupedFlowable t1) { return t1.take(1); } }) - .subscribe(new TestSubscriber(observer)); + .subscribe(new TestSubscriber(subscriber)); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // should show 3 attempts - inOrder.verify(observer, times(NUM_MSG)).onNext(any(java.lang.String.class)); + inOrder.verify(subscriber, times(NUM_MSG)).onNext(any(java.lang.String.class)); // // should have no errors - inOrder.verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); // should have a single success //inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); // should have a single successful onComplete - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test//(timeout = 3000) public void testIssue1900SourceNotSupportingBackpressure() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); final int NUM_MSG = 1034; final AtomicInteger count = new AtomicInteger(); Flowable origin = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber o) { - o.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); for (int i = 0; i < NUM_MSG; i++) { - o.onNext("msg:" + count.incrementAndGet()); + subscriber.onNext("msg:" + count.incrementAndGet()); } - o.onComplete(); + subscriber.onComplete(); } }); @@ -902,17 +900,17 @@ public Flowable apply(GroupedFlowable t1) { return t1.take(1); } }) - .subscribe(new TestSubscriber(observer)); + .subscribe(new TestSubscriber(subscriber)); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // should show 3 attempts - inOrder.verify(observer, times(NUM_MSG)).onNext(any(java.lang.String.class)); + inOrder.verify(subscriber, times(NUM_MSG)).onNext(any(java.lang.String.class)); // // should have no errors - inOrder.verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); // should have a single success //inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); // should have a single successful onComplete - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -925,8 +923,8 @@ public void retryWhenDefaultScheduler() { .concatWith(Flowable.error(new TestException())) .retryWhen((Function)new Function() { @Override - public Flowable apply(Flowable o) { - return o.take(2); + public Flowable apply(Flowable f) { + return f.take(2); } }).subscribe(ts); @@ -946,8 +944,8 @@ public void retryWhenTrampolineScheduler() { .subscribeOn(Schedulers.trampoline()) .retryWhen((Function)new Function() { @Override - public Flowable apply(Flowable o) { - return o.take(2); + public Flowable apply(Flowable f) { + return f.take(2); } }).subscribe(ts); @@ -1002,7 +1000,7 @@ public boolean getAsBoolean() throws Exception { @Test public void shouldDisposeInnerObservable() { - final PublishProcessor subject = PublishProcessor.create(); + final PublishProcessor processor = PublishProcessor.create(); final Disposable disposable = Flowable.error(new RuntimeException("Leak")) .retryWhen(new Function, Flowable>() { @Override @@ -1010,15 +1008,15 @@ public Flowable apply(Flowable errors) throws Exception { return errors.switchMap(new Function>() { @Override public Flowable apply(Throwable ignore) throws Exception { - return subject; + return processor; } }); } }) .subscribe(); - assertTrue(subject.hasSubscribers()); + assertTrue(processor.hasSubscribers()); disposable.dispose(); - assertFalse(subject.hasSubscribers()); + assertFalse(processor.hasSubscribers()); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java index 72a9f518ce..1f9f8c0736 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java @@ -32,6 +32,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.*; @@ -58,16 +59,16 @@ public boolean test(Integer t1, Throwable t2) { public void testWithNothingToRetry() { Flowable source = Flowable.range(0, 3); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.retry(retryTwice).subscribe(o); + source.retry(retryTwice).subscribe(subscriber); - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testRetryTwice() { @@ -89,20 +90,19 @@ public void subscribe(Subscriber t1) { } }); - @SuppressWarnings("unchecked") - DefaultSubscriber o = mock(DefaultSubscriber.class); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.retry(retryTwice).subscribe(o); + source.retry(retryTwice).subscribe(subscriber); - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onNext(3); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -117,20 +117,19 @@ public void subscribe(Subscriber t1) { } }); - @SuppressWarnings("unchecked") - DefaultSubscriber o = mock(DefaultSubscriber.class); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.retry(retryTwice).subscribe(o); + source.retry(retryTwice).subscribe(subscriber); - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onError(any(TestException.class)); - verify(o, never()).onComplete(); + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); } @Test @@ -153,20 +152,19 @@ public void subscribe(Subscriber t1) { } }); - @SuppressWarnings("unchecked") - DefaultSubscriber o = mock(DefaultSubscriber.class); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.retry(retryOnTestException).subscribe(o); + source.retry(retryOnTestException).subscribe(subscriber); - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onNext(3); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testRetryOnSpecificExceptionAndNotOther() { @@ -190,60 +188,59 @@ public void subscribe(Subscriber t1) { } }); - @SuppressWarnings("unchecked") - DefaultSubscriber o = mock(DefaultSubscriber.class); - InOrder inOrder = inOrder(o); - - source.retry(retryOnTestException).subscribe(o); - - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(0); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onNext(3); - inOrder.verify(o).onError(te); - verify(o, never()).onError(ioe); - verify(o, never()).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); + + source.retry(retryOnTestException).subscribe(subscriber); + + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(0); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber).onError(te); + verify(subscriber, never()).onError(ioe); + verify(subscriber, never()).onComplete(); } @Test public void testUnsubscribeFromRetry() { - PublishProcessor subject = PublishProcessor.create(); + PublishProcessor processor = PublishProcessor.create(); final AtomicInteger count = new AtomicInteger(0); - Disposable sub = subject.retry(retryTwice).subscribe(new Consumer() { + Disposable sub = processor.retry(retryTwice).subscribe(new Consumer() { @Override public void accept(Integer n) { count.incrementAndGet(); } }); - subject.onNext(1); + processor.onNext(1); sub.dispose(); - subject.onNext(2); + processor.onNext(2); assertEquals(1, count.get()); } @Test(timeout = 10000) public void testUnsubscribeAfterError() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); // Flowable that always fails after 100ms FlowableRetryTest.SlowFlowable so = new FlowableRetryTest.SlowFlowable(100, 0); - Flowable o = Flowable + Flowable f = Flowable .unsafeCreate(so) .retry(retry5); - FlowableRetryTest.AsyncObserver async = new FlowableRetryTest.AsyncObserver(observer); + FlowableRetryTest.AsyncSubscriber async = new FlowableRetryTest.AsyncSubscriber(subscriber); - o.subscribe(async); + f.subscribe(async); async.await(); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // Should fail once - inOrder.verify(observer, times(1)).onError(any(Throwable.class)); - inOrder.verify(observer, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onComplete(); assertEquals("Start 6 threads, retry 5 then fail on 6", 6, so.efforts.get()); assertEquals("Only 1 active subscription", 1, so.maxActive.get()); @@ -252,25 +249,25 @@ public void testUnsubscribeAfterError() { @Test(timeout = 10000) public void testTimeoutWithRetry() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); // Flowable that sends every 100ms (timeout fails instead) FlowableRetryTest.SlowFlowable so = new FlowableRetryTest.SlowFlowable(100, 10); - Flowable o = Flowable + Flowable f = Flowable .unsafeCreate(so) .timeout(80, TimeUnit.MILLISECONDS) .retry(retry5); - FlowableRetryTest.AsyncObserver async = new FlowableRetryTest.AsyncObserver(observer); + FlowableRetryTest.AsyncSubscriber async = new FlowableRetryTest.AsyncSubscriber(subscriber); - o.subscribe(async); + f.subscribe(async); async.await(); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); // Should fail once - inOrder.verify(observer, times(1)).onError(any(Throwable.class)); - inOrder.verify(observer, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onComplete(); assertEquals("Start 6 threads, retry 5 then fail on 6", 6, so.efforts.get()); } @@ -418,30 +415,34 @@ public void dontRetry() { @Test public void retryDisposeRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishProcessor pp = PublishProcessor.create(); - - final TestSubscriber ts = pp.retry(Functions.alwaysTrue()).test(); + final TestException ex = new TestException(); + RxJavaPlugins.setErrorHandler(Functions.emptyConsumer()); + try { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishProcessor pp = PublishProcessor.create(); - final TestException ex = new TestException(); + final TestSubscriber ts = pp.retry(Functions.alwaysTrue()).test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onError(ex); - } - }; + Runnable r1 = new Runnable() { + @Override + public void run() { + pp.onError(ex); + } + }; - Runnable r2 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; + Runnable r2 = new Runnable() { + @Override + public void run() { + ts.cancel(); + } + }; - TestHelper.race(r1, r2); + TestHelper.race(r1, r2); - ts.assertEmpty(); + ts.assertEmpty(); + } + } finally { + RxJavaPlugins.reset(); } } @@ -466,35 +467,40 @@ public boolean test(Integer n, Throwable e) throws Exception { @Test public void retryBiPredicateDisposeRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishProcessor pp = PublishProcessor.create(); + RxJavaPlugins.setErrorHandler(Functions.emptyConsumer()); + try { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishProcessor pp = PublishProcessor.create(); - final TestSubscriber ts = pp.retry(new BiPredicate() { - @Override - public boolean test(Object t1, Object t2) throws Exception { - return true; - } - }).test(); + final TestSubscriber ts = pp.retry(new BiPredicate() { + @Override + public boolean test(Object t1, Object t2) throws Exception { + return true; + } + }).test(); - final TestException ex = new TestException(); + final TestException ex = new TestException(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onError(ex); - } - }; + Runnable r1 = new Runnable() { + @Override + public void run() { + pp.onError(ex); + } + }; - Runnable r2 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; + Runnable r2 = new Runnable() { + @Override + public void run() { + ts.cancel(); + } + }; - TestHelper.race(r1, r2); + TestHelper.race(r1, r2); - ts.assertEmpty(); + ts.assertEmpty(); + } + } finally { + RxJavaPlugins.reset(); } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java index f168dc1891..12e354cda2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java @@ -33,78 +33,78 @@ public class FlowableSampleTest { private TestScheduler scheduler; private Scheduler.Worker innerScheduler; - private Subscriber observer; - private Subscriber observer2; + private Subscriber subscriber; + private Subscriber subscriber2; @Before // due to mocking public void before() { scheduler = new TestScheduler(); innerScheduler = scheduler.createWorker(); - observer = TestHelper.mockSubscriber(); - observer2 = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); + subscriber2 = TestHelper.mockSubscriber(); } @Test public void testSample() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer1) { - observer1.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber1) { + subscriber1.onSubscribe(new BooleanSubscription()); innerScheduler.schedule(new Runnable() { @Override public void run() { - observer1.onNext(1L); + subscriber1.onNext(1L); } }, 1, TimeUnit.SECONDS); innerScheduler.schedule(new Runnable() { @Override public void run() { - observer1.onNext(2L); + subscriber1.onNext(2L); } }, 2, TimeUnit.SECONDS); innerScheduler.schedule(new Runnable() { @Override public void run() { - observer1.onComplete(); + subscriber1.onComplete(); } }, 3, TimeUnit.SECONDS); } }); Flowable sampled = source.sample(400L, TimeUnit.MILLISECONDS, scheduler); - sampled.subscribe(observer); + sampled.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(800L, TimeUnit.MILLISECONDS); - verify(observer, never()).onNext(any(Long.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any(Long.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(1200L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext(1L); - verify(observer, never()).onNext(2L); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext(1L); + verify(subscriber, never()).onNext(2L); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(1600L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(1L); - verify(observer, never()).onNext(2L); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(1L); + verify(subscriber, never()).onNext(2L); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(2000L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(1L); - inOrder.verify(observer, times(1)).onNext(2L); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(1L); + inOrder.verify(subscriber, times(1)).onNext(2L); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(3000L, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(1L); - inOrder.verify(observer, never()).onNext(2L); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(1L); + inOrder.verify(subscriber, never()).onNext(2L); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -113,7 +113,7 @@ public void sampleWithSamplerNormal() { PublishProcessor sampler = PublishProcessor.create(); Flowable m = source.sample(sampler); - m.subscribe(observer2); + m.subscribe(subscriber2); source.onNext(1); source.onNext(2); @@ -124,13 +124,13 @@ public void sampleWithSamplerNormal() { source.onComplete(); sampler.onNext(3); - InOrder inOrder = inOrder(observer2); - inOrder.verify(observer2, never()).onNext(1); - inOrder.verify(observer2, times(1)).onNext(2); - inOrder.verify(observer2, never()).onNext(3); - inOrder.verify(observer2, times(1)).onNext(4); - inOrder.verify(observer2, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber2); + inOrder.verify(subscriber2, never()).onNext(1); + inOrder.verify(subscriber2, times(1)).onNext(2); + inOrder.verify(subscriber2, never()).onNext(3); + inOrder.verify(subscriber2, times(1)).onNext(4); + inOrder.verify(subscriber2, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -139,7 +139,7 @@ public void sampleWithSamplerNoDuplicates() { PublishProcessor sampler = PublishProcessor.create(); Flowable m = source.sample(sampler); - m.subscribe(observer2); + m.subscribe(subscriber2); source.onNext(1); source.onNext(2); @@ -154,13 +154,13 @@ public void sampleWithSamplerNoDuplicates() { source.onComplete(); sampler.onNext(3); - InOrder inOrder = inOrder(observer2); - inOrder.verify(observer2, never()).onNext(1); - inOrder.verify(observer2, times(1)).onNext(2); - inOrder.verify(observer2, never()).onNext(3); - inOrder.verify(observer2, times(1)).onNext(4); - inOrder.verify(observer2, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber2); + inOrder.verify(subscriber2, never()).onNext(1); + inOrder.verify(subscriber2, times(1)).onNext(2); + inOrder.verify(subscriber2, never()).onNext(3); + inOrder.verify(subscriber2, times(1)).onNext(4); + inOrder.verify(subscriber2, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -169,7 +169,7 @@ public void sampleWithSamplerTerminatingEarly() { PublishProcessor sampler = PublishProcessor.create(); Flowable m = source.sample(sampler); - m.subscribe(observer2); + m.subscribe(subscriber2); source.onNext(1); source.onNext(2); @@ -179,12 +179,12 @@ public void sampleWithSamplerTerminatingEarly() { source.onNext(3); source.onNext(4); - InOrder inOrder = inOrder(observer2); - inOrder.verify(observer2, never()).onNext(1); - inOrder.verify(observer2, times(1)).onNext(2); - inOrder.verify(observer2, times(1)).onComplete(); - inOrder.verify(observer2, never()).onNext(any()); - verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber2); + inOrder.verify(subscriber2, never()).onNext(1); + inOrder.verify(subscriber2, times(1)).onNext(2); + inOrder.verify(subscriber2, times(1)).onComplete(); + inOrder.verify(subscriber2, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -193,7 +193,7 @@ public void sampleWithSamplerEmitAndTerminate() { PublishProcessor sampler = PublishProcessor.create(); Flowable m = source.sample(sampler); - m.subscribe(observer2); + m.subscribe(subscriber2); source.onNext(1); source.onNext(2); @@ -203,13 +203,13 @@ public void sampleWithSamplerEmitAndTerminate() { sampler.onNext(2); sampler.onComplete(); - InOrder inOrder = inOrder(observer2); - inOrder.verify(observer2, never()).onNext(1); - inOrder.verify(observer2, times(1)).onNext(2); - inOrder.verify(observer2, never()).onNext(3); - inOrder.verify(observer2, times(1)).onComplete(); - inOrder.verify(observer2, never()).onNext(any()); - verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber2); + inOrder.verify(subscriber2, never()).onNext(1); + inOrder.verify(subscriber2, times(1)).onNext(2); + inOrder.verify(subscriber2, never()).onNext(3); + inOrder.verify(subscriber2, times(1)).onComplete(); + inOrder.verify(subscriber2, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -218,15 +218,15 @@ public void sampleWithSamplerEmptySource() { PublishProcessor sampler = PublishProcessor.create(); Flowable m = source.sample(sampler); - m.subscribe(observer2); + m.subscribe(subscriber2); source.onComplete(); sampler.onNext(1); - InOrder inOrder = inOrder(observer2); - inOrder.verify(observer2, times(1)).onComplete(); - verify(observer2, never()).onNext(any()); - verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber2); + inOrder.verify(subscriber2, times(1)).onComplete(); + verify(subscriber2, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -235,16 +235,16 @@ public void sampleWithSamplerSourceThrows() { PublishProcessor sampler = PublishProcessor.create(); Flowable m = source.sample(sampler); - m.subscribe(observer2); + m.subscribe(subscriber2); source.onNext(1); source.onError(new RuntimeException("Forced failure!")); sampler.onNext(1); - InOrder inOrder = inOrder(observer2); - inOrder.verify(observer2, times(1)).onError(any(Throwable.class)); - verify(observer2, never()).onNext(any()); - verify(observer, never()).onComplete(); + InOrder inOrder = inOrder(subscriber2); + inOrder.verify(subscriber2, times(1)).onError(any(Throwable.class)); + verify(subscriber2, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -253,22 +253,22 @@ public void sampleWithSamplerThrows() { PublishProcessor sampler = PublishProcessor.create(); Flowable m = source.sample(sampler); - m.subscribe(observer2); + m.subscribe(subscriber2); source.onNext(1); sampler.onNext(1); sampler.onError(new RuntimeException("Forced failure!")); - InOrder inOrder = inOrder(observer2); - inOrder.verify(observer2, times(1)).onNext(1); - inOrder.verify(observer2, times(1)).onError(any(RuntimeException.class)); - verify(observer, never()).onComplete(); + InOrder inOrder = inOrder(subscriber2); + inOrder.verify(subscriber2, times(1)).onNext(1); + inOrder.verify(subscriber2, times(1)).onError(any(RuntimeException.class)); + verify(subscriber, never()).onComplete(); } @Test public void testSampleUnsubscribe() { final Subscription s = mock(Subscription.class); - Flowable o = Flowable.unsafeCreate( + Flowable f = Flowable.unsafeCreate( new Publisher() { @Override public void subscribe(Subscriber subscriber) { @@ -276,7 +276,7 @@ public void subscribe(Subscriber subscriber) { } } ); - o.throttleLast(1, TimeUnit.MILLISECONDS).subscribe().dispose(); + f.throttleLast(1, TimeUnit.MILLISECONDS).subscribe().dispose(); verify(s).cancel(); } @@ -450,9 +450,9 @@ public void run() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) + public Flowable apply(Flowable f) throws Exception { - return o.sample(1, TimeUnit.SECONDS); + return f.sample(1, TimeUnit.SECONDS); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java index a01495295e..d12476cf4e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java @@ -37,11 +37,11 @@ public class FlowableScanTest { @Test public void testScanIntegersWithInitialValue() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable observable = Flowable.just(1, 2, 3); + Flowable flowable = Flowable.just(1, 2, 3); - Flowable m = observable.scan("", new BiFunction() { + Flowable m = flowable.scan("", new BiFunction() { @Override public String apply(String s, Integer n) { @@ -49,25 +49,25 @@ public String apply(String s, Integer n) { } }); - m.subscribe(observer); + m.subscribe(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onNext(""); - verify(observer, times(1)).onNext("1"); - verify(observer, times(1)).onNext("12"); - verify(observer, times(1)).onNext("123"); - verify(observer, times(4)).onNext(anyString()); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext(""); + verify(subscriber, times(1)).onNext("1"); + verify(subscriber, times(1)).onNext("12"); + verify(subscriber, times(1)).onNext("123"); + verify(subscriber, times(4)).onNext(anyString()); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testScanIntegersWithoutInitialValue() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable observable = Flowable.just(1, 2, 3); + Flowable flowable = Flowable.just(1, 2, 3); - Flowable m = observable.scan(new BiFunction() { + Flowable m = flowable.scan(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -75,25 +75,25 @@ public Integer apply(Integer t1, Integer t2) { } }); - m.subscribe(observer); + m.subscribe(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onNext(0); - verify(observer, times(1)).onNext(1); - verify(observer, times(1)).onNext(3); - verify(observer, times(1)).onNext(6); - verify(observer, times(3)).onNext(anyInt()); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(0); + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onNext(3); + verify(subscriber, times(1)).onNext(6); + verify(subscriber, times(3)).onNext(anyInt()); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testScanIntegersWithoutInitialValueAndOnlyOneValue() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable observable = Flowable.just(1); + Flowable flowable = Flowable.just(1); - Flowable m = observable.scan(new BiFunction() { + Flowable m = flowable.scan(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -101,14 +101,14 @@ public Integer apply(Integer t1, Integer t2) { } }); - m.subscribe(observer); + m.subscribe(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onNext(0); - verify(observer, times(1)).onNext(1); - verify(observer, times(1)).onNext(anyInt()); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(0); + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onNext(anyInt()); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -283,7 +283,7 @@ public void accept(List list, Integer t2) { */ @Test public void testSeedFactoryFlowable() { - Flowable> o = Flowable.range(1, 10) + Flowable> f = Flowable.range(1, 10) .collect(new Callable>() { @Override @@ -300,13 +300,13 @@ public void accept(List list, Integer t2) { }).toFlowable().takeLast(1); - assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), o.blockingSingle()); - assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), o.blockingSingle()); + assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), f.blockingSingle()); + assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), f.blockingSingle()); } @Test public void testScanWithRequestOne() { - Flowable o = Flowable.just(1, 2).scan(0, new BiFunction() { + Flowable f = Flowable.just(1, 2).scan(0, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -315,7 +315,7 @@ public Integer apply(Integer t1, Integer t2) { }).take(1); TestSubscriber subscriber = new TestSubscriber(); - o.subscribe(subscriber); + f.subscribe(subscriber); subscriber.assertValue(0); subscriber.assertTerminated(); subscriber.assertNoErrors(); @@ -324,7 +324,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testScanShouldNotRequestZero() { final AtomicReference producer = new AtomicReference(); - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override public void subscribe(final Subscriber subscriber) { Subscription p = spy(new Subscription() { @@ -356,7 +356,7 @@ public Integer apply(Integer t1, Integer t2) { }); - o.subscribe(new TestSubscriber(1L) { + f.subscribe(new TestSubscriber(1L) { @Override public void onNext(Integer integer) { @@ -427,8 +427,8 @@ public Integer apply(Integer a, Integer b) throws Exception { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.scan(new BiFunction() { + public Flowable apply(Flowable f) throws Exception { + return f.scan(new BiFunction() { @Override public Object apply(Object a, Object b) throws Exception { return a; @@ -439,8 +439,8 @@ public Object apply(Object a, Object b) throws Exception { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.scan(0, new BiFunction() { + public Flowable apply(Flowable f) throws Exception { + return f.scan(0, new BiFunction() { @Override public Object apply(Object a, Object b) throws Exception { return a; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java index a71e68f696..4ee2fad368 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java @@ -37,98 +37,98 @@ public class FlowableSequenceEqualTest { @Test public void test1Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable.just("one", "two", "three")).toFlowable(); - verifyResult(observable, true); + verifyResult(flowable, true); } @Test public void test2Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable.just("one", "two", "three", "four")).toFlowable(); - verifyResult(observable, false); + verifyResult(flowable, false); } @Test public void test3Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.just("one", "two", "three", "four"), Flowable.just("one", "two", "three")).toFlowable(); - verifyResult(observable, false); + verifyResult(flowable, false); } @Test public void testWithError1Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.concat(Flowable.just("one"), Flowable. error(new TestException())), Flowable.just("one", "two", "three")).toFlowable(); - verifyError(observable); + verifyError(flowable); } @Test public void testWithError2Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable.concat(Flowable.just("one"), Flowable. error(new TestException()))).toFlowable(); - verifyError(observable); + verifyError(flowable); } @Test public void testWithError3Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.concat(Flowable.just("one"), Flowable. error(new TestException())), Flowable.concat(Flowable.just("one"), Flowable. error(new TestException()))).toFlowable(); - verifyError(observable); + verifyError(flowable); } @Test public void testWithEmpty1Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable. empty(), Flowable.just("one", "two", "three")).toFlowable(); - verifyResult(observable, false); + verifyResult(flowable, false); } @Test public void testWithEmpty2Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable. empty()).toFlowable(); - verifyResult(observable, false); + verifyResult(flowable, false); } @Test public void testWithEmpty3Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable. empty(), Flowable. empty()).toFlowable(); - verifyResult(observable, true); + verifyResult(flowable, true); } @Test @Ignore("Null values not allowed") public void testWithNull1Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.just((String) null), Flowable.just("one")).toFlowable(); - verifyResult(observable, false); + verifyResult(flowable, false); } @Test @Ignore("Null values not allowed") public void testWithNull2Flowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.just((String) null), Flowable.just((String) null)).toFlowable(); - verifyResult(observable, true); + verifyResult(flowable, true); } @Test public void testWithEqualityErrorFlowable() { - Flowable observable = Flowable.sequenceEqual( + Flowable flowable = Flowable.sequenceEqual( Flowable.just("one"), Flowable.just("one"), new BiPredicate() { @Override @@ -136,103 +136,103 @@ public boolean test(String t1, String t2) { throw new TestException(); } }).toFlowable(); - verifyError(observable); + verifyError(flowable); } @Test public void test1() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable.just("one", "two", "three")); - verifyResult(observable, true); + verifyResult(single, true); } @Test public void test2() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable.just("one", "two", "three", "four")); - verifyResult(observable, false); + verifyResult(single, false); } @Test public void test3() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.just("one", "two", "three", "four"), Flowable.just("one", "two", "three")); - verifyResult(observable, false); + verifyResult(single, false); } @Test public void testWithError1() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.concat(Flowable.just("one"), Flowable. error(new TestException())), Flowable.just("one", "two", "three")); - verifyError(observable); + verifyError(single); } @Test public void testWithError2() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable.concat(Flowable.just("one"), Flowable. error(new TestException()))); - verifyError(observable); + verifyError(single); } @Test public void testWithError3() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.concat(Flowable.just("one"), Flowable. error(new TestException())), Flowable.concat(Flowable.just("one"), Flowable. error(new TestException()))); - verifyError(observable); + verifyError(single); } @Test public void testWithEmpty1() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable. empty(), Flowable.just("one", "two", "three")); - verifyResult(observable, false); + verifyResult(single, false); } @Test public void testWithEmpty2() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable. empty()); - verifyResult(observable, false); + verifyResult(single, false); } @Test public void testWithEmpty3() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable. empty(), Flowable. empty()); - verifyResult(observable, true); + verifyResult(single, true); } @Test @Ignore("Null values not allowed") public void testWithNull1() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.just((String) null), Flowable.just("one")); - verifyResult(observable, false); + verifyResult(single, false); } @Test @Ignore("Null values not allowed") public void testWithNull2() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.just((String) null), Flowable.just((String) null)); - verifyResult(observable, true); + verifyResult(single, true); } @Test public void testWithEqualityError() { - Single observable = Flowable.sequenceEqual( + Single single = Flowable.sequenceEqual( Flowable.just("one"), Flowable.just("one"), new BiPredicate() { @Override @@ -240,42 +240,42 @@ public boolean test(String t1, String t2) { throw new TestException(); } }); - verifyError(observable); + verifyError(single); } - private void verifyResult(Flowable observable, boolean result) { - Subscriber observer = TestHelper.mockSubscriber(); + private void verifyResult(Flowable flowable, boolean result) { + Subscriber subscriber = TestHelper.mockSubscriber(); - observable.subscribe(observer); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(result); - inOrder.verify(observer).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(result); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); } - private void verifyResult(Single observable, boolean result) { + private void verifyResult(Single single, boolean result) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(result); inOrder.verifyNoMoreInteractions(); } - private void verifyError(Flowable observable) { - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + private void verifyError(Flowable flowable) { + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError(isA(TestException.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onError(isA(TestException.class)); inOrder.verifyNoMoreInteractions(); } - private void verifyError(Single observable) { + private void verifyError(Single single) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError(isA(TestException.class)); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSerializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSerializeTest.java index 8fe8431271..6094955e83 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSerializeTest.java @@ -28,11 +28,11 @@ public class FlowableSerializeTest { - Subscriber observer; + Subscriber subscriber; @Before public void before() { - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); } @Test @@ -40,14 +40,14 @@ public void testSingleThreadedBasic() { TestSingleThreadedObservable onSubscribe = new TestSingleThreadedObservable("one", "two", "three"); Flowable w = Flowable.unsafeCreate(onSubscribe); - w.serialize().subscribe(observer); + w.serialize().subscribe(subscriber); onSubscribe.waitToFinish(); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); // non-deterministic because unsubscribe happens after 'waitToFinish' releases // so commenting out for now as this is not a critical thing to test here // verify(s, times(1)).unsubscribe(); @@ -144,18 +144,18 @@ public void testMultiThreadedWithNPEinMiddle() { */ static class OnNextThread implements Runnable { - private final DefaultSubscriber observer; + private final DefaultSubscriber subscriber; private final int numStringsToSend; - OnNextThread(DefaultSubscriber observer, int numStringsToSend) { - this.observer = observer; + OnNextThread(DefaultSubscriber subscriber, int numStringsToSend) { + this.subscriber = subscriber; this.numStringsToSend = numStringsToSend; } @Override public void run() { for (int i = 0; i < numStringsToSend; i++) { - observer.onNext("aString"); + subscriber.onNext("aString"); } } } @@ -165,12 +165,12 @@ public void run() { */ static class CompletionThread implements Runnable { - private final DefaultSubscriber observer; + private final DefaultSubscriber subscriber; private final TestConcurrencyobserverEvent event; private final Future[] waitOnThese; - CompletionThread(DefaultSubscriber observer, TestConcurrencyobserverEvent event, Future... waitOnThese) { - this.observer = observer; + CompletionThread(DefaultSubscriber subscriber, TestConcurrencyobserverEvent event, Future... waitOnThese) { + this.subscriber = subscriber; this.event = event; this.waitOnThese = waitOnThese; } @@ -190,9 +190,9 @@ public void run() { /* send the event */ if (event == TestConcurrencyobserverEvent.onError) { - observer.onError(new RuntimeException("mocked exception")); + subscriber.onError(new RuntimeException("mocked exception")); } else if (event == TestConcurrencyobserverEvent.onComplete) { - observer.onComplete(); + subscriber.onComplete(); } else { throw new IllegalArgumentException("Expecting either onError or onComplete"); @@ -218,8 +218,8 @@ private static class TestSingleThreadedObservable implements Publisher { } @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); System.out.println("TestSingleThreadedObservable subscribed to ..."); t = new Thread(new Runnable() { @@ -229,9 +229,9 @@ public void run() { System.out.println("running TestSingleThreadedObservable thread"); for (String s : values) { System.out.println("TestSingleThreadedObservable onNext: " + s); - observer.onNext(s); + subscriber.onNext(s); } - observer.onComplete(); + subscriber.onComplete(); } catch (Throwable e) { throw new RuntimeException(e); } @@ -269,8 +269,8 @@ private static class TestMultiThreadedObservable implements Publisher { } @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); System.out.println("TestMultiThreadedObservable subscribed to ..."); final NullPointerException npe = new NullPointerException(); t = new Thread(new Runnable() { @@ -299,7 +299,7 @@ public void run() { } System.out.println("TestMultiThreadedObservable onNext: " + s); } - observer.onNext(s); + subscriber.onNext(s); // capture 'maxThreads' int concurrentThreads = threadsRunning.get(); int maxThreads = maxConcurrentThreads.get(); @@ -307,7 +307,7 @@ public void run() { maxConcurrentThreads.compareAndSet(maxThreads, concurrentThreads); } } catch (Throwable e) { - observer.onError(e); + subscriber.onError(e); } finally { threadsRunning.decrementAndGet(); } @@ -327,7 +327,7 @@ public void run() { } catch (InterruptedException e) { throw new RuntimeException(e); } - observer.onComplete(); + subscriber.onComplete(); } }); System.out.println("starting TestMultiThreadedObservable thread"); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java index 8be75e36e1..88cb84d40d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java @@ -34,40 +34,40 @@ public class FlowableSingleTest { @Test public void testSingleFlowable() { - Flowable observable = Flowable.just(1).singleElement().toFlowable(); + Flowable flowable = Flowable.just(1).singleElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleWithTooManyElementsFlowable() { - Flowable observable = Flowable.just(1, 2).singleElement().toFlowable(); + Flowable flowable = Flowable.just(1, 2).singleElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError( + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onError( isA(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleWithEmptyFlowable() { - Flowable observable = Flowable. empty().singleElement().toFlowable(); + Flowable flowable = Flowable. empty().singleElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onComplete(); - inOrder.verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onComplete(); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); inOrder.verifyNoMoreInteractions(); } @@ -195,7 +195,7 @@ public void onNext(Integer t) { @Test public void testSingleWithPredicateFlowable() { - Flowable observable = Flowable.just(1, 2) + Flowable flowable = Flowable.just(1, 2) .filter( new Predicate() { @@ -206,18 +206,18 @@ public boolean test(Integer t1) { }) .singleElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleWithPredicateAndTooManyElementsFlowable() { - Flowable observable = Flowable.just(1, 2, 3, 4) + Flowable flowable = Flowable.just(1, 2, 3, 4) .filter( new Predicate() { @@ -228,18 +228,18 @@ public boolean test(Integer t1) { }) .singleElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError( + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onError( isA(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleWithPredicateAndEmptyFlowable() { - Flowable observable = Flowable.just(1) + Flowable flowable = Flowable.just(1) .filter( new Predicate() { @@ -249,58 +249,58 @@ public boolean test(Integer t1) { } }) .singleElement().toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onComplete(); - inOrder.verify(observer, never()).onError(any(Throwable.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onComplete(); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleOrDefaultFlowable() { - Flowable observable = Flowable.just(1).single(2).toFlowable(); + Flowable flowable = Flowable.just(1).single(2).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleOrDefaultWithTooManyElementsFlowable() { - Flowable observable = Flowable.just(1, 2).single(3).toFlowable(); + Flowable flowable = Flowable.just(1, 2).single(3).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError( + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onError( isA(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleOrDefaultWithEmptyFlowable() { - Flowable observable = Flowable. empty() + Flowable flowable = Flowable. empty() .single(1).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(1); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(1); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleOrDefaultWithPredicateFlowable() { - Flowable observable = Flowable.just(1, 2) + Flowable flowable = Flowable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -309,18 +309,18 @@ public boolean test(Integer t1) { }) .single(4).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleOrDefaultWithPredicateAndTooManyElementsFlowable() { - Flowable observable = Flowable.just(1, 2, 3, 4) + Flowable flowable = Flowable.just(1, 2, 3, 4) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -329,18 +329,18 @@ public boolean test(Integer t1) { }) .single(6).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError( + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onError( isA(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleOrDefaultWithPredicateAndEmptyFlowable() { - Flowable observable = Flowable.just(1) + Flowable flowable = Flowable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -349,18 +349,18 @@ public boolean test(Integer t1) { }) .single(2).toFlowable(); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testSingleWithBackpressureFlowable() { - Flowable observable = Flowable.just(1, 2).singleElement().toFlowable(); + Flowable flowable = Flowable.just(1, 2).singleElement().toFlowable(); Subscriber subscriber = spy(new DefaultSubscriber() { @@ -384,7 +384,7 @@ public void onNext(Integer integer) { request(1); } }); - observable.subscribe(subscriber); + flowable.subscribe(subscriber); InOrder inOrder = inOrder(subscriber); inOrder.verify(subscriber, times(1)).onError(isA(IllegalArgumentException.class)); @@ -393,10 +393,10 @@ public void onNext(Integer integer) { @Test public void testSingle() { - Maybe observable = Flowable.just(1).singleElement(); + Maybe maybe = Flowable.just(1).singleElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); @@ -405,10 +405,10 @@ public void testSingle() { @Test public void testSingleWithTooManyElements() { - Maybe observable = Flowable.just(1, 2).singleElement(); + Maybe maybe = Flowable.just(1, 2).singleElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -418,10 +418,10 @@ public void testSingleWithTooManyElements() { @Test public void testSingleWithEmpty() { - Maybe observable = Flowable. empty().singleElement(); + Maybe maybe = Flowable. empty().singleElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer).onComplete(); @@ -476,7 +476,7 @@ public void accept(long n) { @Test public void testSingleWithPredicate() { - Maybe observable = Flowable.just(1, 2) + Maybe maybe = Flowable.just(1, 2) .filter( new Predicate() { @@ -488,7 +488,7 @@ public boolean test(Integer t1) { .singleElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(2); @@ -497,7 +497,7 @@ public boolean test(Integer t1) { @Test public void testSingleWithPredicateAndTooManyElements() { - Maybe observable = Flowable.just(1, 2, 3, 4) + Maybe maybe = Flowable.just(1, 2, 3, 4) .filter( new Predicate() { @@ -509,7 +509,7 @@ public boolean test(Integer t1) { .singleElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -519,7 +519,7 @@ public boolean test(Integer t1) { @Test public void testSingleWithPredicateAndEmpty() { - Maybe observable = Flowable.just(1) + Maybe maybe = Flowable.just(1) .filter( new Predicate() { @@ -531,7 +531,7 @@ public boolean test(Integer t1) { .singleElement(); MaybeObserver observer = TestHelper.mockMaybeObserver(); - observable.subscribe(observer); + maybe.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer).onComplete(); @@ -541,10 +541,10 @@ public boolean test(Integer t1) { @Test public void testSingleOrDefault() { - Single observable = Flowable.just(1).single(2); + Single single = Flowable.just(1).single(2); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); @@ -553,10 +553,10 @@ public void testSingleOrDefault() { @Test public void testSingleOrDefaultWithTooManyElements() { - Single observable = Flowable.just(1, 2).single(3); + Single single = Flowable.just(1, 2).single(3); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -566,11 +566,11 @@ public void testSingleOrDefaultWithTooManyElements() { @Test public void testSingleOrDefaultWithEmpty() { - Single observable = Flowable. empty() + Single single = Flowable. empty() .single(1); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); @@ -579,7 +579,7 @@ public void testSingleOrDefaultWithEmpty() { @Test public void testSingleOrDefaultWithPredicate() { - Single observable = Flowable.just(1, 2) + Single single = Flowable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -589,7 +589,7 @@ public boolean test(Integer t1) { .single(4); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(2); @@ -598,7 +598,7 @@ public boolean test(Integer t1) { @Test public void testSingleOrDefaultWithPredicateAndTooManyElements() { - Single observable = Flowable.just(1, 2, 3, 4) + Single single = Flowable.just(1, 2, 3, 4) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -608,7 +608,7 @@ public boolean test(Integer t1) { .single(6); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -618,7 +618,7 @@ public boolean test(Integer t1) { @Test public void testSingleOrDefaultWithPredicateAndEmpty() { - Single observable = Flowable.just(1) + Single single = Flowable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -628,7 +628,7 @@ public boolean test(Integer t1) { .single(2); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(2); @@ -715,9 +715,9 @@ public void singleElementOperatorDoNotSwallowExceptionWhenDone() { }); Flowable.unsafeCreate(new Publisher() { - @Override public void subscribe(final Subscriber observer) { - observer.onComplete(); - observer.onError(exception); + @Override public void subscribe(final Subscriber subscriber) { + subscriber.onComplete(); + subscriber.onError(exception); } }).singleElement().test().assertComplete(); @@ -731,22 +731,22 @@ public void singleElementOperatorDoNotSwallowExceptionWhenDone() { public void badSource() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.singleOrError(); + public Object apply(Flowable f) throws Exception { + return f.singleOrError(); } }, false, 1, 1, 1); TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.singleElement(); + public Object apply(Flowable f) throws Exception { + return f.singleElement(); } }, false, 1, 1, 1); TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.singleOrError().toFlowable(); + public Object apply(Flowable f) throws Exception { + return f.singleOrError().toFlowable(); } }, false, 1, 1, 1); } @@ -755,29 +755,29 @@ public Object apply(Flowable o) throws Exception { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function, SingleSource>() { @Override - public SingleSource apply(Flowable o) throws Exception { - return o.singleOrError(); + public SingleSource apply(Flowable f) throws Exception { + return f.singleOrError(); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.singleOrError().toFlowable(); + public Flowable apply(Flowable f) throws Exception { + return f.singleOrError().toFlowable(); } }); TestHelper.checkDoubleOnSubscribeFlowableToMaybe(new Function, MaybeSource>() { @Override - public MaybeSource apply(Flowable o) throws Exception { - return o.singleElement(); + public MaybeSource apply(Flowable f) throws Exception { + return f.singleElement(); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.singleElement().toFlowable(); + public Flowable apply(Flowable f) throws Exception { + return f.singleElement().toFlowable(); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTest.java index 9918af965d..11680a0927 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTest.java @@ -32,72 +32,77 @@ public class FlowableSkipLastTest { @Test public void testSkipLastEmpty() { - Flowable observable = Flowable. empty().skipLast(2); + Flowable flowable = Flowable. empty().skipLast(2); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); - verify(observer, never()).onNext(any(String.class)); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); + + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testSkipLast1() { - Flowable observable = Flowable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2); - - Subscriber observer = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer); - observable.subscribe(observer); - inOrder.verify(observer, never()).onNext("two"); - inOrder.verify(observer, never()).onNext("three"); - verify(observer, times(1)).onNext("one"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Flowable flowable = Flowable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2); + + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); + flowable.subscribe(subscriber); + + inOrder.verify(subscriber, never()).onNext("two"); + inOrder.verify(subscriber, never()).onNext("three"); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testSkipLast2() { - Flowable observable = Flowable.fromIterable(Arrays.asList("one", "two")).skipLast(2); + Flowable flowable = Flowable.fromIterable(Arrays.asList("one", "two")).skipLast(2); + + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); - verify(observer, never()).onNext(any(String.class)); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testSkipLastWithZeroCount() { Flowable w = Flowable.just("one", "two"); - Flowable observable = w.skipLast(0); - - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Flowable flowable = w.skipLast(0); + + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); + + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @Ignore("Null values not allowed") public void testSkipLastWithNull() { - Flowable observable = Flowable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1); - - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext(null); - verify(observer, never()).onNext("two"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Flowable flowable = Flowable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1); + + Subscriber subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); + + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext(null); + verify(subscriber, never()).onNext("two"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testSkipLastWithBackpressure() { - Flowable o = Flowable.range(0, Flowable.bufferSize() * 2).skipLast(Flowable.bufferSize() + 10); + Flowable f = Flowable.range(0, Flowable.bufferSize() * 2).skipLast(Flowable.bufferSize() + 10); TestSubscriber ts = new TestSubscriber(); - o.observeOn(Schedulers.computation()).subscribe(ts); + f.observeOn(Schedulers.computation()).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); assertEquals((Flowable.bufferSize()) - 10, ts.valueCount()); @@ -126,9 +131,9 @@ public void error() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) + public Flowable apply(Flowable f) throws Exception { - return o.skipLast(1); + return f.skipLast(1); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java index f82e172f23..d24a84b4b6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java @@ -40,9 +40,9 @@ public void testSkipLastTimed() { // FIXME the timeunit now matters due to rounding Flowable result = source.skipLast(1000, TimeUnit.MILLISECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -57,17 +57,17 @@ public void testSkipLastTimed() { scheduler.advanceTimeBy(950, TimeUnit.MILLISECONDS); source.onComplete(); - InOrder inOrder = inOrder(o); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onNext(3); - inOrder.verify(o, never()).onNext(4); - inOrder.verify(o, never()).onNext(5); - inOrder.verify(o, never()).onNext(6); - inOrder.verify(o).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber, never()).onNext(4); + inOrder.verify(subscriber, never()).onNext(5); + inOrder.verify(subscriber, never()).onNext(6); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -78,9 +78,9 @@ public void testSkipLastTimedErrorBeforeTime() { Flowable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -89,10 +89,10 @@ public void testSkipLastTimedErrorBeforeTime() { scheduler.advanceTimeBy(1050, TimeUnit.MILLISECONDS); - verify(o).onError(any(TestException.class)); + verify(subscriber).onError(any(TestException.class)); - verify(o, never()).onComplete(); - verify(o, never()).onNext(any()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any()); } @Test @@ -103,9 +103,9 @@ public void testSkipLastTimedCompleteBeforeTime() { Flowable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -115,12 +115,12 @@ public void testSkipLastTimedCompleteBeforeTime() { source.onComplete(); - InOrder inOrder = inOrder(o); - inOrder.verify(o).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(any()); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -131,9 +131,9 @@ public void testSkipLastTimedWhenAllElementsAreValid() { Flowable result = source.skipLast(1, TimeUnit.MILLISECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -143,11 +143,11 @@ public void testSkipLastTimedWhenAllElementsAreValid() { source.onComplete(); - InOrder inOrder = inOrder(o); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onNext(3); - inOrder.verify(o).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -187,8 +187,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.skipLast(1, TimeUnit.DAYS); + public Flowable apply(Flowable f) throws Exception { + return f.skipLast(1, TimeUnit.DAYS); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java index 7597e23f69..25d902310b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java @@ -34,13 +34,13 @@ public void testSkipNegativeElements() { Flowable skip = Flowable.just("one", "two", "three").skip(-99); - Subscriber observer = TestHelper.mockSubscriber(); - skip.subscribe(observer); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + skip.subscribe(subscriber); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -48,13 +48,13 @@ public void testSkipZeroElements() { Flowable skip = Flowable.just("one", "two", "three").skip(0); - Subscriber observer = TestHelper.mockSubscriber(); - skip.subscribe(observer); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + skip.subscribe(subscriber); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -62,13 +62,13 @@ public void testSkipOneElement() { Flowable skip = Flowable.just("one", "two", "three").skip(1); - Subscriber observer = TestHelper.mockSubscriber(); - skip.subscribe(observer); - verify(observer, never()).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + skip.subscribe(subscriber); + verify(subscriber, never()).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -76,13 +76,13 @@ public void testSkipTwoElements() { Flowable skip = Flowable.just("one", "two", "three").skip(2); - Subscriber observer = TestHelper.mockSubscriber(); - skip.subscribe(observer); - verify(observer, never()).onNext("one"); - verify(observer, never()).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + skip.subscribe(subscriber); + verify(subscriber, never()).onNext("one"); + verify(subscriber, never()).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -91,11 +91,11 @@ public void testSkipEmptyStream() { Flowable w = Flowable.empty(); Flowable skip = w.skip(1); - Subscriber observer = TestHelper.mockSubscriber(); - skip.subscribe(observer); - verify(observer, never()).onNext(any(String.class)); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + skip.subscribe(subscriber); + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -104,19 +104,19 @@ public void testSkipMultipleObservers() { Flowable skip = Flowable.just("one", "two", "three") .skip(2); - Subscriber observer1 = TestHelper.mockSubscriber(); - skip.subscribe(observer1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + skip.subscribe(subscriber1); - Subscriber observer2 = TestHelper.mockSubscriber(); - skip.subscribe(observer2); + Subscriber subscriber2 = TestHelper.mockSubscriber(); + skip.subscribe(subscriber2); - verify(observer1, times(1)).onNext(any(String.class)); - verify(observer1, never()).onError(any(Throwable.class)); - verify(observer1, times(1)).onComplete(); + verify(subscriber1, times(1)).onNext(any(String.class)); + verify(subscriber1, never()).onError(any(Throwable.class)); + verify(subscriber1, times(1)).onComplete(); - verify(observer2, times(1)).onNext(any(String.class)); - verify(observer2, never()).onError(any(Throwable.class)); - verify(observer2, times(1)).onComplete(); + verify(subscriber2, times(1)).onNext(any(String.class)); + verify(subscriber2, never()).onError(any(Throwable.class)); + verify(subscriber2, times(1)).onComplete(); } @Test @@ -129,12 +129,12 @@ public void testSkipError() { Flowable skip = Flowable.concat(ok, error).skip(100); - Subscriber observer = TestHelper.mockSubscriber(); - skip.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + skip.subscribe(subscriber); - verify(observer, never()).onNext(any(String.class)); - verify(observer, times(1)).onError(e); - verify(observer, never()).onComplete(); + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, times(1)).onError(e); + verify(subscriber, never()).onComplete(); } @@ -179,9 +179,9 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) + public Flowable apply(Flowable f) throws Exception { - return o.skip(1); + return f.skip(1); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTimedTest.java index 1869d74e66..0033cb4559 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTimedTest.java @@ -36,9 +36,9 @@ public void testSkipTimed() { Flowable result = source.skip(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -52,17 +52,17 @@ public void testSkipTimed() { source.onComplete(); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(o, never()).onNext(1); - inOrder.verify(o, never()).onNext(2); - inOrder.verify(o, never()).onNext(3); - inOrder.verify(o).onNext(4); - inOrder.verify(o).onNext(5); - inOrder.verify(o).onNext(6); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber, never()).onNext(1); + inOrder.verify(subscriber, never()).onNext(2); + inOrder.verify(subscriber, never()).onNext(3); + inOrder.verify(subscriber).onNext(4); + inOrder.verify(subscriber).onNext(5); + inOrder.verify(subscriber).onNext(6); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -73,9 +73,9 @@ public void testSkipTimedFinishBeforeTime() { Flowable result = source.skip(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -84,12 +84,12 @@ public void testSkipTimedFinishBeforeTime() { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(any()); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -100,9 +100,9 @@ public void testSkipTimedErrorBeforeTime() { Flowable result = source.skip(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -111,12 +111,12 @@ public void testSkipTimedErrorBeforeTime() { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(o).onError(any(TestException.class)); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -127,9 +127,9 @@ public void testSkipTimedErrorAfterTime() { Flowable result = source.skip(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -143,17 +143,17 @@ public void testSkipTimedErrorAfterTime() { source.onError(new TestException()); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(o, never()).onNext(1); - inOrder.verify(o, never()).onNext(2); - inOrder.verify(o, never()).onNext(3); - inOrder.verify(o).onNext(4); - inOrder.verify(o).onNext(5); - inOrder.verify(o).onNext(6); - inOrder.verify(o).onError(any(TestException.class)); + inOrder.verify(subscriber, never()).onNext(1); + inOrder.verify(subscriber, never()).onNext(2); + inOrder.verify(subscriber, never()).onNext(3); + inOrder.verify(subscriber).onNext(4); + inOrder.verify(subscriber).onNext(5); + inOrder.verify(subscriber).onNext(6); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onComplete(); + verify(subscriber, never()).onComplete(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipUntilTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipUntilTest.java index 00386c8a7f..a770b8520b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipUntilTest.java @@ -23,11 +23,11 @@ import io.reactivex.processors.PublishProcessor; public class FlowableSkipUntilTest { - Subscriber observer; + Subscriber subscriber; @Before public void before() { - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); } @Test @@ -36,7 +36,7 @@ public void normal1() { PublishProcessor other = PublishProcessor.create(); Flowable m = source.skipUntil(other); - m.subscribe(observer); + m.subscribe(subscriber); source.onNext(0); source.onNext(1); @@ -48,11 +48,11 @@ public void normal1() { source.onNext(4); source.onComplete(); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onNext(2); - verify(observer, times(1)).onNext(3); - verify(observer, times(1)).onNext(4); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, times(1)).onNext(3); + verify(subscriber, times(1)).onNext(4); + verify(subscriber, times(1)).onComplete(); } @Test @@ -61,7 +61,7 @@ public void otherNeverFires() { Flowable m = source.skipUntil(Flowable.never()); - m.subscribe(observer); + m.subscribe(subscriber); source.onNext(0); source.onNext(1); @@ -70,9 +70,9 @@ public void otherNeverFires() { source.onNext(4); source.onComplete(); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onNext(any()); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, times(1)).onComplete(); } @Test @@ -81,11 +81,11 @@ public void otherEmpty() { Flowable m = source.skipUntil(Flowable.empty()); - m.subscribe(observer); + m.subscribe(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onNext(any()); - verify(observer, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -94,7 +94,7 @@ public void otherFiresAndCompletes() { PublishProcessor other = PublishProcessor.create(); Flowable m = source.skipUntil(other); - m.subscribe(observer); + m.subscribe(subscriber); source.onNext(0); source.onNext(1); @@ -107,11 +107,11 @@ public void otherFiresAndCompletes() { source.onNext(4); source.onComplete(); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onNext(2); - verify(observer, times(1)).onNext(3); - verify(observer, times(1)).onNext(4); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, times(1)).onNext(3); + verify(subscriber, times(1)).onNext(4); + verify(subscriber, times(1)).onComplete(); } @Test @@ -120,7 +120,7 @@ public void sourceThrows() { PublishProcessor other = PublishProcessor.create(); Flowable m = source.skipUntil(other); - m.subscribe(observer); + m.subscribe(subscriber); source.onNext(0); source.onNext(1); @@ -131,9 +131,9 @@ public void sourceThrows() { source.onNext(2); source.onError(new RuntimeException("Forced failure")); - verify(observer, times(1)).onNext(2); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); } @Test @@ -142,16 +142,16 @@ public void otherThrowsImmediately() { PublishProcessor other = PublishProcessor.create(); Flowable m = source.skipUntil(other); - m.subscribe(observer); + m.subscribe(subscriber); source.onNext(0); source.onNext(1); other.onError(new RuntimeException("Forced failure")); - verify(observer, never()).onNext(any()); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); } @Test @@ -163,15 +163,15 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.skipUntil(Flowable.never()); + public Flowable apply(Flowable f) throws Exception { + return f.skipUntil(Flowable.never()); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return Flowable.never().skipUntil(o); + public Flowable apply(Flowable f) throws Exception { + return Flowable.never().skipUntil(f); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java index d098675349..b9574cd8ef 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java @@ -121,16 +121,16 @@ public void testSkipManySubscribers() { Flowable src = Flowable.range(1, 10).skipWhile(LESS_THAN_FIVE); int n = 5; for (int i = 0; i < n; i++) { - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - src.subscribe(o); + src.subscribe(subscriber); for (int j = 5; j < 10; j++) { - inOrder.verify(o).onNext(j); + inOrder.verify(subscriber).onNext(j); } - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } } @@ -143,8 +143,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.skipWhile(Functions.alwaysFalse()); + public Flowable apply(Flowable f) throws Exception { + return f.skipWhile(Functions.alwaysFalse()); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOnTest.java index 0214825887..6b1b24b78e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOnTest.java @@ -40,7 +40,7 @@ public void testIssue813() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch doneLatch = new CountDownLatch(1); - TestSubscriber observer = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber(); Flowable .unsafeCreate(new Publisher() { @@ -64,16 +64,16 @@ public void subscribe( doneLatch.countDown(); } } - }).subscribeOn(Schedulers.computation()).subscribe(observer); + }).subscribeOn(Schedulers.computation()).subscribe(ts); // wait for scheduling scheduled.await(); // trigger unsubscribe - observer.dispose(); + ts.dispose(); latch.countDown(); doneLatch.await(); - observer.assertNoErrors(); - observer.assertComplete(); + ts.assertNoErrors(); + ts.assertComplete(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java index 1607a4b524..6c7cc67603 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java @@ -35,7 +35,7 @@ public class FlowableSwitchIfEmptyTest { @Test public void testSwitchWhenNotEmpty() throws Exception { final AtomicBoolean subscribed = new AtomicBoolean(false); - final Flowable observable = Flowable.just(4) + final Flowable flowable = Flowable.just(4) .switchIfEmpty(Flowable.just(2) .doOnSubscribe(new Consumer() { @Override @@ -44,16 +44,16 @@ public void accept(Subscription s) { } })); - assertEquals(4, observable.blockingSingle().intValue()); + assertEquals(4, flowable.blockingSingle().intValue()); assertFalse(subscribed.get()); } @Test public void testSwitchWhenEmpty() throws Exception { - final Flowable observable = Flowable.empty() + final Flowable flowable = Flowable.empty() .switchIfEmpty(Flowable.fromIterable(Arrays.asList(42))); - assertEquals(42, observable.blockingSingle().intValue()); + assertEquals(42, flowable.blockingSingle().intValue()); } @Test @@ -80,8 +80,8 @@ public void cancel() { } }); - final Flowable observable = Flowable.empty().switchIfEmpty(withProducer); - assertEquals(42, observable.blockingSingle().intValue()); + final Flowable flowable = Flowable.empty().switchIfEmpty(withProducer); + assertEquals(42, flowable.blockingSingle().intValue()); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java index 28f599e487..1878d133a4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java @@ -40,290 +40,290 @@ public class FlowableSwitchTest { private TestScheduler scheduler; private Scheduler.Worker innerScheduler; - private Subscriber observer; + private Subscriber subscriber; @Before public void before() { scheduler = new TestScheduler(); innerScheduler = scheduler.createWorker(); - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); } @Test public void testSwitchWhenOuterCompleteBeforeInner() { Flowable> source = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, Flowable.unsafeCreate(new Publisher() { + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 70, "one"); - publishNext(observer, 100, "two"); - publishCompleted(observer, 200); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 70, "one"); + publishNext(subscriber, 100, "two"); + publishCompleted(subscriber, 200); } })); - publishCompleted(observer, 60); + publishCompleted(subscriber, 60); } }); Flowable sampled = Flowable.switchOnNext(source); - sampled.subscribe(observer); + sampled.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(2)).onNext(anyString()); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(2)).onNext(anyString()); + inOrder.verify(subscriber, times(1)).onComplete(); } @Test public void testSwitchWhenInnerCompleteBeforeOuter() { Flowable> source = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 10, Flowable.unsafeCreate(new Publisher() { + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 10, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 0, "one"); - publishNext(observer, 10, "two"); - publishCompleted(observer, 20); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 0, "one"); + publishNext(subscriber, 10, "two"); + publishCompleted(subscriber, 20); } })); - publishNext(observer, 100, Flowable.unsafeCreate(new Publisher() { + publishNext(subscriber, 100, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 0, "three"); - publishNext(observer, 10, "four"); - publishCompleted(observer, 20); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 0, "three"); + publishNext(subscriber, 10, "four"); + publishCompleted(subscriber, 20); } })); - publishCompleted(observer, 200); + publishCompleted(subscriber, 200); } }); Flowable sampled = Flowable.switchOnNext(source); - sampled.subscribe(observer); + sampled.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(150, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onComplete(); - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, times(1)).onNext("four"); + inOrder.verify(subscriber, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, times(1)).onNext("four"); scheduler.advanceTimeTo(250, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyString()); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, never()).onNext(anyString()); + inOrder.verify(subscriber, times(1)).onComplete(); } @Test public void testSwitchWithComplete() { Flowable> source = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, Flowable.unsafeCreate(new Publisher() { + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 60, "one"); - publishNext(observer, 100, "two"); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 60, "one"); + publishNext(subscriber, 100, "two"); } })); - publishNext(observer, 200, Flowable.unsafeCreate(new Publisher() { + publishNext(subscriber, 200, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 0, "three"); - publishNext(observer, 100, "four"); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 0, "three"); + publishNext(subscriber, 100, "four"); } })); - publishCompleted(observer, 250); + publishCompleted(subscriber, 250); } }); Flowable sampled = Flowable.switchOnNext(source); - sampled.subscribe(observer); + sampled.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyString()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(anyString()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("one"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(175, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("two"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("two"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(225, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("three"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("four"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("four"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testSwitchWithError() { Flowable> source = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, Flowable.unsafeCreate(new Publisher() { + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, "one"); - publishNext(observer, 100, "two"); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, "one"); + publishNext(subscriber, 100, "two"); } })); - publishNext(observer, 200, Flowable.unsafeCreate(new Publisher() { + publishNext(subscriber, 200, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 0, "three"); - publishNext(observer, 100, "four"); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 0, "three"); + publishNext(subscriber, 100, "four"); } })); - publishError(observer, 250, new TestException()); + publishError(subscriber, 250, new TestException()); } }); Flowable sampled = Flowable.switchOnNext(source); - sampled.subscribe(observer); + sampled.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyString()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(anyString()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("one"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(175, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("two"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("two"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(225, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("three"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyString()); - verify(observer, never()).onComplete(); - verify(observer, times(1)).onError(any(TestException.class)); + inOrder.verify(subscriber, never()).onNext(anyString()); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onError(any(TestException.class)); } @Test public void testSwitchWithSubsequenceComplete() { Flowable> source = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, Flowable.unsafeCreate(new Publisher() { + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, "one"); - publishNext(observer, 100, "two"); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, "one"); + publishNext(subscriber, 100, "two"); } })); - publishNext(observer, 130, Flowable.unsafeCreate(new Publisher() { + publishNext(subscriber, 130, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishCompleted(observer, 0); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishCompleted(subscriber, 0); } })); - publishNext(observer, 150, Flowable.unsafeCreate(new Publisher() { + publishNext(subscriber, 150, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, "three"); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, "three"); } })); } }); Flowable sampled = Flowable.switchOnNext(source); - sampled.subscribe(observer); + sampled.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyString()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(anyString()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("one"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(250, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("three"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testSwitchWithSubsequenceError() { Flowable> source = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, Flowable.unsafeCreate(new Publisher() { + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, "one"); - publishNext(observer, 100, "two"); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, "one"); + publishNext(subscriber, 100, "two"); } })); - publishNext(observer, 130, Flowable.unsafeCreate(new Publisher() { + publishNext(subscriber, 130, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishError(observer, 0, new TestException()); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishError(subscriber, 0, new TestException()); } })); - publishNext(observer, 150, Flowable.unsafeCreate(new Publisher() { + publishNext(subscriber, 150, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 50, "three"); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, "three"); } })); @@ -331,49 +331,49 @@ public void subscribe(Subscriber observer) { }); Flowable sampled = Flowable.switchOnNext(source); - sampled.subscribe(observer); + sampled.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext(anyString()); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onNext(anyString()); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("one"); - verify(observer, never()).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); scheduler.advanceTimeTo(250, TimeUnit.MILLISECONDS); - inOrder.verify(observer, never()).onNext("three"); - verify(observer, never()).onComplete(); - verify(observer, times(1)).onError(any(TestException.class)); + inOrder.verify(subscriber, never()).onNext("three"); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onError(any(TestException.class)); } - private void publishCompleted(final Subscriber observer, long delay) { + private void publishCompleted(final Subscriber subscriber, long delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onComplete(); + subscriber.onComplete(); } }, delay, TimeUnit.MILLISECONDS); } - private void publishError(final Subscriber observer, long delay, final Throwable error) { + private void publishError(final Subscriber subscriber, long delay, final Throwable error) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onError(error); + subscriber.onError(error); } }, delay, TimeUnit.MILLISECONDS); } - private void publishNext(final Subscriber observer, long delay, final T value) { + private void publishNext(final Subscriber subscriber, long delay, final T value) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onNext(value); + subscriber.onNext(value); } }, delay, TimeUnit.MILLISECONDS); } @@ -383,45 +383,45 @@ public void testSwitchIssue737() { // https://github.com/ReactiveX/RxJava/issues/737 Flowable> source = Flowable.unsafeCreate(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 0, Flowable.unsafeCreate(new Publisher() { + public void subscribe(Subscriber> subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 0, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 10, "1-one"); - publishNext(observer, 20, "1-two"); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 10, "1-one"); + publishNext(subscriber, 20, "1-two"); // The following events will be ignored - publishNext(observer, 30, "1-three"); - publishCompleted(observer, 40); + publishNext(subscriber, 30, "1-three"); + publishCompleted(subscriber, 40); } })); - publishNext(observer, 25, Flowable.unsafeCreate(new Publisher() { + publishNext(subscriber, 25, Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 10, "2-one"); - publishNext(observer, 20, "2-two"); - publishNext(observer, 30, "2-three"); - publishCompleted(observer, 40); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 10, "2-one"); + publishNext(subscriber, 20, "2-two"); + publishNext(subscriber, 30, "2-three"); + publishCompleted(subscriber, 40); } })); - publishCompleted(observer, 30); + publishCompleted(subscriber, 30); } }); Flowable sampled = Flowable.switchOnNext(source); - sampled.subscribe(observer); + sampled.subscribe(subscriber); scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("1-one"); - inOrder.verify(observer, times(1)).onNext("1-two"); - inOrder.verify(observer, times(1)).onNext("2-one"); - inOrder.verify(observer, times(1)).onNext("2-two"); - inOrder.verify(observer, times(1)).onNext("2-three"); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("1-one"); + inOrder.verify(subscriber, times(1)).onNext("1-two"); + inOrder.verify(subscriber, times(1)).onNext("2-one"); + inOrder.verify(subscriber, times(1)).onNext("2-two"); + inOrder.verify(subscriber, times(1)).onNext("2-three"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -965,11 +965,11 @@ public void badMainSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onComplete(); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .switchMap(Functions.justFunction(Flowable.never())) @@ -1005,12 +1005,12 @@ public void badInnerSource() { Flowable.just(1).hide() .switchMap(Functions.justFunction(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException()); - observer.onComplete(); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException()); + subscriber.onComplete(); + subscriber.onError(new TestException()); + subscriber.onComplete(); } })) .test() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java index 2d31e46223..5da9f37c50 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java @@ -118,7 +118,9 @@ public void requestMore(long n) { @Override public void onStart() { - request(initialRequest); + if (initialRequest > 0) { + request(initialRequest); + } } @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java index 9ae4bfd380..3277d5f831 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java @@ -37,11 +37,12 @@ public void testTakeLastEmpty() { Flowable w = Flowable.empty(); Flowable take = w.takeLast(2); - Subscriber observer = TestHelper.mockSubscriber(); - take.subscribe(observer); - verify(observer, never()).onNext(any(String.class)); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + take.subscribe(subscriber); + + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -49,14 +50,15 @@ public void testTakeLast1() { Flowable w = Flowable.just("one", "two", "three"); Flowable take = w.takeLast(2); - Subscriber observer = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(observer); - take.subscribe(observer); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - verify(observer, never()).onNext("one"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); + take.subscribe(subscriber); + + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onNext("one"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -64,11 +66,12 @@ public void testTakeLast2() { Flowable w = Flowable.just("one"); Flowable take = w.takeLast(10); - Subscriber observer = TestHelper.mockSubscriber(); - take.subscribe(observer); - verify(observer, times(1)).onNext("one"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + take.subscribe(subscriber); + + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -76,11 +79,12 @@ public void testTakeLastWithZeroCount() { Flowable w = Flowable.just("one"); Flowable take = w.takeLast(0); - Subscriber observer = TestHelper.mockSubscriber(); - take.subscribe(observer); - verify(observer, never()).onNext("one"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + take.subscribe(subscriber); + + verify(subscriber, never()).onNext("one"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -89,13 +93,14 @@ public void testTakeLastWithNull() { Flowable w = Flowable.just("one", null, "three"); Flowable take = w.takeLast(2); - Subscriber observer = TestHelper.mockSubscriber(); - take.subscribe(observer); - verify(observer, never()).onNext("one"); - verify(observer, times(1)).onNext(null); - verify(observer, times(1)).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + take.subscribe(subscriber); + + verify(subscriber, never()).onNext("one"); + verify(subscriber, times(1)).onNext(null); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test(expected = IndexOutOfBoundsException.class) @@ -328,8 +333,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.takeLast(5); + public Flowable apply(Flowable f) throws Exception { + return f.takeLast(5); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java index a0bce236de..4864cac7f6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java @@ -44,11 +44,11 @@ public void takeLastTimed() { // FIXME time unit now matters! Flowable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); @@ -62,13 +62,13 @@ public void takeLastTimed() { scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); source.onComplete(); // T: 1250ms - inOrder.verify(o, times(1)).onNext(2); - inOrder.verify(o, times(1)).onNext(3); - inOrder.verify(o, times(1)).onNext(4); - inOrder.verify(o, times(1)).onNext(5); - inOrder.verify(o, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onNext(3); + inOrder.verify(subscriber, times(1)).onNext(4); + inOrder.verify(subscriber, times(1)).onNext(5); + inOrder.verify(subscriber, times(1)).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -80,11 +80,11 @@ public void takeLastTimedDelayCompletion() { // FIXME time unit now matters Flowable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); @@ -98,10 +98,10 @@ public void takeLastTimedDelayCompletion() { scheduler.advanceTimeBy(1250, TimeUnit.MILLISECONDS); source.onComplete(); // T: 2250ms - inOrder.verify(o, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); - verify(o, never()).onNext(any()); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -113,11 +113,11 @@ public void takeLastTimedWithCapacity() { // FIXME time unit now matters! Flowable result = source.takeLast(2, 1000, TimeUnit.MILLISECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); @@ -131,11 +131,11 @@ public void takeLastTimedWithCapacity() { scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); source.onComplete(); // T: 1250ms - inOrder.verify(o, times(1)).onNext(4); - inOrder.verify(o, times(1)).onNext(5); - inOrder.verify(o, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext(4); + inOrder.verify(subscriber, times(1)).onNext(5); + inOrder.verify(subscriber, times(1)).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -146,11 +146,11 @@ public void takeLastTimedThrowingSource() { Flowable result = source.takeLast(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); @@ -164,10 +164,10 @@ public void takeLastTimedThrowingSource() { scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); source.onError(new TestException()); // T: 1250ms - inOrder.verify(o, times(1)).onError(any(TestException.class)); + inOrder.verify(subscriber, times(1)).onError(any(TestException.class)); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @Test @@ -178,11 +178,11 @@ public void takeLastTimedWithZeroCapacity() { Flowable result = source.takeLast(0, 1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + InOrder inOrder = inOrder(subscriber); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); @@ -196,10 +196,10 @@ public void takeLastTimedWithZeroCapacity() { scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); source.onComplete(); // T: 1250ms - inOrder.verify(o, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); - verify(o, never()).onNext(any()); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java index 345282bfbd..5510b534ea 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java @@ -41,13 +41,14 @@ public void testTake1() { Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); Flowable take = w.take(2); - Subscriber observer = TestHelper.mockSubscriber(); - take.subscribe(observer); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, never()).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + take.subscribe(subscriber); + + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, never()).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -55,13 +56,14 @@ public void testTake2() { Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); Flowable take = w.take(1); - Subscriber observer = TestHelper.mockSubscriber(); - take.subscribe(observer); - verify(observer, times(1)).onNext("one"); - verify(observer, never()).onNext("two"); - verify(observer, never()).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + take.subscribe(subscriber); + + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onNext("two"); + verify(subscriber, never()).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test(expected = IllegalArgumentException.class) @@ -85,10 +87,11 @@ public Integer apply(Integer t1) { } }); - Subscriber observer = TestHelper.mockSubscriber(); - w.subscribe(observer); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError(any(IllegalArgumentException.class)); + Subscriber subscriber = TestHelper.mockSubscriber(); + w.subscribe(subscriber); + + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onError(any(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); } @@ -101,34 +104,42 @@ public Integer apply(Integer t1) { } }); - Subscriber observer = TestHelper.mockSubscriber(); - w.subscribe(observer); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError(any(IllegalArgumentException.class)); + Subscriber subscriber = TestHelper.mockSubscriber(); + w.subscribe(subscriber); + + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onError(any(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); } @Test public void testTakeDoesntLeakErrors() { - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext("one"); - observer.onError(new Throwable("test failed")); - } - }); + List errors = TestHelper.trackPluginErrors(); + try { + Flowable source = Flowable.unsafeCreate(new Publisher() { + @Override + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("one"); + subscriber.onError(new Throwable("test failed")); + } + }); + + Subscriber subscriber = TestHelper.mockSubscriber(); - Subscriber observer = TestHelper.mockSubscriber(); + source.take(1).subscribe(subscriber); - source.take(1).subscribe(observer); + verify(subscriber).onSubscribe((Subscription)notNull()); + verify(subscriber, times(1)).onNext("one"); + // even though onError is called we take(1) so shouldn't see it + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verifyNoMoreInteractions(subscriber); - verify(observer).onSubscribe((Subscription)notNull()); - verify(observer, times(1)).onNext("one"); - // even though onError is called we take(1) so shouldn't see it - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verifyNoMoreInteractions(observer); + TestHelper.assertUndeliverable(errors, 0, Throwable.class, "test failed"); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -138,24 +149,25 @@ public void testTakeZeroDoesntLeakError() { final BooleanSubscription bs = new BooleanSubscription(); Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { + public void subscribe(Subscriber subscriber) { subscribed.set(true); - observer.onSubscribe(bs); - observer.onError(new Throwable("test failed")); + subscriber.onSubscribe(bs); + subscriber.onError(new Throwable("test failed")); } }); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); + + source.take(0).subscribe(subscriber); - source.take(0).subscribe(observer); assertTrue("source subscribed", subscribed.get()); assertTrue("source unsubscribed", bs.isCancelled()); - verify(observer, never()).onNext(anyString()); + verify(subscriber, never()).onNext(anyString()); // even though onError is called we take(0) so shouldn't see it - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verifyNoMoreInteractions(observer); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verifyNoMoreInteractions(subscriber); } @Test @@ -163,10 +175,10 @@ public void testUnsubscribeAfterTake() { TestFlowableFunc f = new TestFlowableFunc("one", "two", "three"); Flowable w = Flowable.unsafeCreate(f); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable take = w.take(1); - take.subscribe(observer); + take.subscribe(subscriber); // wait for the Flowable to complete try { @@ -177,14 +189,14 @@ public void testUnsubscribeAfterTake() { } System.out.println("TestFlowable thread finished"); - verify(observer).onSubscribe((Subscription)notNull()); - verify(observer, times(1)).onNext("one"); - verify(observer, never()).onNext("two"); - verify(observer, never()).onNext("three"); - verify(observer, times(1)).onComplete(); + verify(subscriber).onSubscribe((Subscription)notNull()); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onNext("two"); + verify(subscriber, never()).onNext("three"); + verify(subscriber, times(1)).onComplete(); // FIXME no longer assertable // verify(s, times(1)).unsubscribe(); - verifyNoMoreInteractions(observer); + verifyNoMoreInteractions(subscriber); } @Test(timeout = 2000) @@ -240,8 +252,8 @@ static class TestFlowableFunc implements Publisher { } @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); System.out.println("TestFlowable subscribed to ..."); t = new Thread(new Runnable() { @@ -251,9 +263,9 @@ public void run() { System.out.println("running TestFlowable thread"); for (String s : values) { System.out.println("TestFlowable onNext: " + s); - observer.onNext(s); + subscriber.onNext(s); } - observer.onComplete(); + subscriber.onComplete(); } catch (Throwable e) { throw new RuntimeException(e); } @@ -283,18 +295,18 @@ public void subscribe(Subscriber op) { @Test(timeout = 2000) public void testTakeObserveOn() { - Subscriber o = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); INFINITE_OBSERVABLE.onBackpressureDrop() .observeOn(Schedulers.newThread()).take(1).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - verify(o).onNext(1L); - verify(o, never()).onNext(2L); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1L); + verify(subscriber, never()).onNext(2L); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -467,8 +479,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.take(2); + public Flowable apply(Flowable f) throws Exception { + return f.take(2); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTimedTest.java index cc04d04b6b..db1132e86c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTimedTest.java @@ -36,9 +36,9 @@ public void testTakeTimed() { Flowable result = source.take(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -48,15 +48,15 @@ public void testTakeTimed() { source.onNext(4); - InOrder inOrder = inOrder(o); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onNext(3); - inOrder.verify(o).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(4); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(4); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -67,9 +67,9 @@ public void testTakeTimedErrorBeforeTime() { Flowable result = source.take(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -80,15 +80,15 @@ public void testTakeTimedErrorBeforeTime() { source.onNext(4); - InOrder inOrder = inOrder(o); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onNext(3); - inOrder.verify(o).onError(any(TestException.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onComplete(); - verify(o, never()).onNext(4); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(4); } @Test @@ -99,9 +99,9 @@ public void testTakeTimedErrorAfterTime() { Flowable result = source.take(1, TimeUnit.SECONDS, scheduler); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -112,15 +112,15 @@ public void testTakeTimedErrorAfterTime() { source.onNext(4); source.onError(new TestException()); - InOrder inOrder = inOrder(o); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onNext(3); - inOrder.verify(o).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(4); - verify(o, never()).onError(any(TestException.class)); + verify(subscriber, never()).onNext(4); + verify(subscriber, never()).onError(any(TestException.class)); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java index 4060487c64..22e96421f0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java @@ -34,54 +34,54 @@ public class FlowableTakeUntilPredicateTest { @Test public void takeEmpty() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable.empty().takeUntil(new Predicate() { @Override public boolean test(Object v) { return true; } - }).subscribe(o); + }).subscribe(subscriber); - verify(o, never()).onNext(any()); - verify(o, never()).onError(any(Throwable.class)); - verify(o).onComplete(); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); } @Test public void takeAll() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable.just(1, 2).takeUntil(new Predicate() { @Override public boolean test(Integer v) { return false; } - }).subscribe(o); + }).subscribe(subscriber); - verify(o).onNext(1); - verify(o).onNext(2); - verify(o, never()).onError(any(Throwable.class)); - verify(o).onComplete(); + verify(subscriber).onNext(1); + verify(subscriber).onNext(2); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); } @Test public void takeFirst() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable.just(1, 2).takeUntil(new Predicate() { @Override public boolean test(Integer v) { return true; } - }).subscribe(o); + }).subscribe(subscriber); - verify(o).onNext(1); - verify(o, never()).onNext(2); - verify(o, never()).onError(any(Throwable.class)); - verify(o).onComplete(); + verify(subscriber).onNext(1); + verify(subscriber, never()).onNext(2); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); } @Test public void takeSome() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable.just(1, 2, 3).takeUntil(new Predicate() { @Override @@ -89,17 +89,17 @@ public boolean test(Integer t1) { return t1 == 2; } }) - .subscribe(o); + .subscribe(subscriber); - verify(o).onNext(1); - verify(o).onNext(2); - verify(o, never()).onNext(3); - verify(o, never()).onError(any(Throwable.class)); - verify(o).onComplete(); + verify(subscriber).onNext(1); + verify(subscriber).onNext(2); + verify(subscriber, never()).onNext(3); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); } @Test public void functionThrows() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Predicate predicate = new Predicate() { @Override @@ -107,17 +107,17 @@ public boolean test(Integer t1) { throw new TestException("Forced failure"); } }; - Flowable.just(1, 2, 3).takeUntil(predicate).subscribe(o); + Flowable.just(1, 2, 3).takeUntil(predicate).subscribe(subscriber); - verify(o).onNext(1); - verify(o, never()).onNext(2); - verify(o, never()).onNext(3); - verify(o).onError(any(TestException.class)); - verify(o, never()).onComplete(); + verify(subscriber).onNext(1); + verify(subscriber, never()).onNext(2); + verify(subscriber, never()).onNext(3); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); } @Test public void sourceThrows() { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable.just(1) .concatWith(Flowable.error(new TestException())) @@ -127,12 +127,12 @@ public void sourceThrows() { public boolean test(Integer v) { return false; } - }).subscribe(o); + }).subscribe(subscriber); - verify(o).onNext(1); - verify(o, never()).onNext(2); - verify(o).onError(any(TestException.class)); - verify(o, never()).onComplete(); + verify(subscriber).onNext(1); + verify(subscriber, never()).onNext(2); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); } @Test public void backpressure() { @@ -178,8 +178,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.takeUntil(Functions.alwaysFalse()); + public Flowable apply(Flowable f) throws Exception { + return f.takeUntil(Functions.alwaysFalse()); } }); } @@ -190,12 +190,12 @@ public void badSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onComplete(); - observer.onNext(1); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); + subscriber.onNext(1); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .takeUntil(Functions.alwaysFalse()) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java index be7bc1621b..428eefa467 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java @@ -155,7 +155,7 @@ public void testTakeUntilOtherCompleted() { private static class TestObservable implements Publisher { - Subscriber observer; + Subscriber subscriber; Subscription s; TestObservable(Subscription s) { @@ -164,23 +164,23 @@ private static class TestObservable implements Publisher { /* used to simulate subscription */ public void sendOnCompleted() { - observer.onComplete(); + subscriber.onComplete(); } /* used to simulate subscription */ public void sendOnNext(String value) { - observer.onNext(value); + subscriber.onNext(value); } /* used to simulate subscription */ public void sendOnError(Throwable e) { - observer.onError(e); + subscriber.onError(e); } @Override - public void subscribe(Subscriber observer) { - this.observer = observer; - observer.onSubscribe(s); + public void subscribe(Subscriber subscriber) { + this.subscriber = subscriber; + subscriber.onSubscribe(s); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java index 4ad532f94f..f05b8e9fae 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java @@ -17,6 +17,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.List; + import org.junit.*; import org.reactivestreams.*; @@ -25,6 +27,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; import io.reactivex.subscribers.TestSubscriber; @@ -40,13 +43,14 @@ public boolean test(Integer input) { } }); - Subscriber observer = TestHelper.mockSubscriber(); - take.subscribe(observer); - verify(observer, times(1)).onNext(1); - verify(observer, times(1)).onNext(2); - verify(observer, never()).onNext(3); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + take.subscribe(subscriber); + + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, never()).onNext(3); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -59,8 +63,8 @@ public boolean test(Integer input) { } }); - Subscriber observer = TestHelper.mockSubscriber(); - take.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + take.subscribe(subscriber); s.onNext(1); s.onNext(2); @@ -69,13 +73,13 @@ public boolean test(Integer input) { s.onNext(5); s.onComplete(); - verify(observer, times(1)).onNext(1); - verify(observer, times(1)).onNext(2); - verify(observer, never()).onNext(3); - verify(observer, never()).onNext(4); - verify(observer, never()).onNext(5); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, never()).onNext(3); + verify(subscriber, never()).onNext(4); + verify(subscriber, never()).onNext(5); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -90,32 +94,40 @@ public boolean test(String input) { } }); - Subscriber observer = TestHelper.mockSubscriber(); - take.subscribe(observer); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, never()).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber subscriber = TestHelper.mockSubscriber(); + take.subscribe(subscriber); + + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, never()).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testTakeWhileDoesntLeakErrors() { - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext("one"); - observer.onError(new Throwable("test failed")); - } - }); + List errors = TestHelper.trackPluginErrors(); + try { + Flowable source = Flowable.unsafeCreate(new Publisher() { + @Override + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("one"); + subscriber.onError(new TestException("test failed")); + } + }); - source.takeWhile(new Predicate() { - @Override - public boolean test(String s) { - return false; - } - }).blockingLast(""); + source.takeWhile(new Predicate() { + @Override + public boolean test(String s) { + return false; + } + }).blockingLast(""); + + TestHelper.assertUndeliverable(errors, 0, TestException.class, "test failed"); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -123,7 +135,7 @@ public void testTakeWhileProtectsPredicateCall() { TestFlowable source = new TestFlowable(mock(Subscription.class), "one"); final RuntimeException testException = new RuntimeException("test exception"); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable take = Flowable.unsafeCreate(source) .takeWhile(new Predicate() { @Override @@ -131,7 +143,7 @@ public boolean test(String s) { throw testException; } }); - take.subscribe(observer); + take.subscribe(subscriber); // wait for the Flowable to complete try { @@ -141,8 +153,8 @@ public boolean test(String s) { fail(e.getMessage()); } - verify(observer, never()).onNext(any(String.class)); - verify(observer, times(1)).onError(testException); + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, times(1)).onError(testException); } @Test @@ -150,7 +162,7 @@ public void testUnsubscribeAfterTake() { Subscription s = mock(Subscription.class); TestFlowable w = new TestFlowable(s, "one", "two", "three"); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable take = Flowable.unsafeCreate(w) .takeWhile(new Predicate() { int index; @@ -160,7 +172,7 @@ public boolean test(String s) { return index++ < 1; } }); - take.subscribe(observer); + take.subscribe(subscriber); // wait for the Flowable to complete try { @@ -171,9 +183,9 @@ public boolean test(String s) { } System.out.println("TestFlowable thread finished"); - verify(observer, times(1)).onNext("one"); - verify(observer, never()).onNext("two"); - verify(observer, never()).onNext("three"); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, never()).onNext("two"); + verify(subscriber, never()).onNext("three"); verify(s, times(1)).cancel(); } @@ -189,9 +201,9 @@ private static class TestFlowable implements Publisher { } @Override - public void subscribe(final Subscriber observer) { + public void subscribe(final Subscriber subscriber) { System.out.println("TestFlowable subscribed to ..."); - observer.onSubscribe(s); + subscriber.onSubscribe(s); t = new Thread(new Runnable() { @Override @@ -200,9 +212,9 @@ public void run() { System.out.println("running TestFlowable thread"); for (String s : values) { System.out.println("TestFlowable onNext: " + s); - observer.onNext(s); + subscriber.onNext(s); } - observer.onComplete(); + subscriber.onComplete(); } catch (Throwable e) { throw new RuntimeException(e); } @@ -280,8 +292,8 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.takeWhile(Functions.alwaysTrue()); + public Flowable apply(Flowable f) throws Exception { + return f.takeWhile(Functions.alwaysTrue()); } }); } @@ -290,10 +302,10 @@ public Flowable apply(Flowable o) throws Exception { public void badSource() { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onComplete(); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); + subscriber.onComplete(); } } .takeWhile(Functions.alwaysTrue()) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java index 278b98a53a..f9dc9c01f1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java @@ -34,40 +34,40 @@ public class FlowableThrottleFirstTest { private TestScheduler scheduler; private Scheduler.Worker innerScheduler; - private Subscriber observer; + private Subscriber subscriber; @Before public void before() { scheduler = new TestScheduler(); innerScheduler = scheduler.createWorker(); - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); } @Test public void testThrottlingWithCompleted() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - publishNext(observer, 100, "one"); // publish as it's first - publishNext(observer, 300, "two"); // skip as it's last within the first 400 - publishNext(observer, 900, "three"); // publish - publishNext(observer, 905, "four"); // skip - publishCompleted(observer, 1000); // Should be published as soon as the timeout expires. + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 100, "one"); // publish as it's first + publishNext(subscriber, 300, "two"); // skip as it's last within the first 400 + publishNext(subscriber, 900, "three"); // publish + publishNext(subscriber, 905, "four"); // skip + publishCompleted(subscriber, 1000); // Should be published as soon as the timeout expires. } }); Flowable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); - sampled.subscribe(observer); + sampled.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS); - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(0)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, times(0)).onNext("four"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(0)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, times(0)).onNext("four"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -75,59 +75,59 @@ public void subscribe(Subscriber observer) { public void testThrottlingWithError() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); Exception error = new TestException(); - publishNext(observer, 100, "one"); // Should be published since it is first - publishNext(observer, 200, "two"); // Should be skipped since onError will arrive before the timeout expires - publishError(observer, 300, error); // Should be published as soon as the timeout expires. + publishNext(subscriber, 100, "one"); // Should be published since it is first + publishNext(subscriber, 200, "two"); // Should be skipped since onError will arrive before the timeout expires + publishError(subscriber, 300, error); // Should be published as soon as the timeout expires. } }); Flowable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); - sampled.subscribe(observer); + sampled.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); scheduler.advanceTimeTo(400, TimeUnit.MILLISECONDS); - inOrder.verify(observer).onNext("one"); - inOrder.verify(observer).onError(any(TestException.class)); + inOrder.verify(subscriber).onNext("one"); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); } - private void publishCompleted(final Subscriber observer, long delay) { + private void publishCompleted(final Subscriber subscriber, long delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onComplete(); + subscriber.onComplete(); } }, delay, TimeUnit.MILLISECONDS); } - private void publishError(final Subscriber observer, long delay, final Exception error) { + private void publishError(final Subscriber subscriber, long delay, final Exception error) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onError(error); + subscriber.onError(error); } }, delay, TimeUnit.MILLISECONDS); } - private void publishNext(final Subscriber observer, long delay, final T value) { + private void publishNext(final Subscriber subscriber, long delay, final T value) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onNext(value); + subscriber.onNext(value); } }, delay, TimeUnit.MILLISECONDS); } @Test public void testThrottle() { - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); TestScheduler s = new TestScheduler(); PublishProcessor o = PublishProcessor.create(); - o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(observer); + o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(subscriber); // send events with simulated time increments s.advanceTimeTo(0, TimeUnit.MILLISECONDS); @@ -145,11 +145,11 @@ public void testThrottle() { s.advanceTimeTo(1501, TimeUnit.MILLISECONDS); o.onComplete(); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onNext(1); - inOrder.verify(observer).onNext(3); - inOrder.verify(observer).onNext(7); - inOrder.verify(observer).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber).onNext(7); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -173,14 +173,14 @@ public void badSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onNext(2); - observer.onComplete(); - observer.onNext(3); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(1); + subscriber.onNext(2); + subscriber.onComplete(); + subscriber.onNext(3); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .throttleFirst(1, TimeUnit.DAYS) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeIntervalTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeIntervalTest.java index bf96ef9e45..1dc6369aba 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeIntervalTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeIntervalTest.java @@ -32,40 +32,40 @@ public class FlowableTimeIntervalTest { private static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS; - private Subscriber> observer; + private Subscriber> subscriber; private TestScheduler testScheduler; - private PublishProcessor subject; - private Flowable> observable; + private PublishProcessor processor; + private Flowable> flowable; @Before public void setUp() { - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); testScheduler = new TestScheduler(); - subject = PublishProcessor.create(); - observable = subject.timeInterval(testScheduler); + processor = PublishProcessor.create(); + flowable = processor.timeInterval(testScheduler); } @Test public void testTimeInterval() { - InOrder inOrder = inOrder(observer); - observable.subscribe(observer); + InOrder inOrder = inOrder(subscriber); + flowable.subscribe(subscriber); testScheduler.advanceTimeBy(1000, TIME_UNIT); - subject.onNext(1); + processor.onNext(1); testScheduler.advanceTimeBy(2000, TIME_UNIT); - subject.onNext(2); + processor.onNext(2); testScheduler.advanceTimeBy(3000, TIME_UNIT); - subject.onNext(3); - subject.onComplete(); + processor.onNext(3); + processor.onComplete(); - inOrder.verify(observer, times(1)).onNext( + inOrder.verify(subscriber, times(1)).onNext( new Timed(1, 1000, TIME_UNIT)); - inOrder.verify(observer, times(1)).onNext( + inOrder.verify(subscriber, times(1)).onNext( new Timed(2, 2000, TIME_UNIT)); - inOrder.verify(observer, times(1)).onNext( + inOrder.verify(subscriber, times(1)).onNext( new Timed(3, 3000, TIME_UNIT)); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java index b119bd00e4..ded3661e95 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java @@ -50,23 +50,23 @@ public void setUp() { @Test public void shouldNotTimeoutIfOnNextWithinTimeout() { - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); withTimeout.subscribe(ts); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); - verify(observer).onNext("One"); + verify(subscriber).onNext("One"); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); ts.cancel(); } @Test public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); withTimeout.subscribe(ts); @@ -74,59 +74,59 @@ public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { underlyingSubject.onNext("One"); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("Two"); - verify(observer).onNext("Two"); + verify(subscriber).onNext("Two"); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); ts.dispose(); } @Test public void shouldTimeoutIfOnNextNotWithinTimeout() { - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); withTimeout.subscribe(ts); testScheduler.advanceTimeBy(TIMEOUT + 1, TimeUnit.SECONDS); - verify(observer).onError(any(TimeoutException.class)); + verify(subscriber).onError(any(TimeoutException.class)); ts.dispose(); } @Test public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); - withTimeout.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); + withTimeout.subscribe(subscriber); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); - verify(observer).onNext("One"); + verify(subscriber).onNext("One"); testScheduler.advanceTimeBy(TIMEOUT + 1, TimeUnit.SECONDS); - verify(observer).onError(any(TimeoutException.class)); + verify(subscriber).onError(any(TimeoutException.class)); ts.dispose(); } @Test public void shouldCompleteIfUnderlyingComletes() { - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); - withTimeout.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); + withTimeout.subscribe(subscriber); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onComplete(); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); - verify(observer).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); ts.dispose(); } @Test public void shouldErrorIfUnderlyingErrors() { - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); - withTimeout.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); + withTimeout.subscribe(subscriber); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onError(new UnsupportedOperationException()); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); - verify(observer).onError(any(UnsupportedOperationException.class)); + verify(subscriber).onError(any(UnsupportedOperationException.class)); ts.dispose(); } @@ -135,20 +135,20 @@ public void shouldSwitchToOtherIfOnNextNotWithinTimeout() { Flowable other = Flowable.just("a", "b", "c"); Flowable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); source.subscribe(ts); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); testScheduler.advanceTimeBy(4, TimeUnit.SECONDS); underlyingSubject.onNext("Two"); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("One"); - inOrder.verify(observer, times(1)).onNext("a"); - inOrder.verify(observer, times(1)).onNext("b"); - inOrder.verify(observer, times(1)).onNext("c"); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("One"); + inOrder.verify(subscriber, times(1)).onNext("a"); + inOrder.verify(subscriber, times(1)).onNext("b"); + inOrder.verify(subscriber, times(1)).onNext("c"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); ts.dispose(); } @@ -158,20 +158,20 @@ public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() { Flowable other = Flowable.just("a", "b", "c"); Flowable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); source.subscribe(ts); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); testScheduler.advanceTimeBy(4, TimeUnit.SECONDS); underlyingSubject.onError(new UnsupportedOperationException()); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("One"); - inOrder.verify(observer, times(1)).onNext("a"); - inOrder.verify(observer, times(1)).onNext("b"); - inOrder.verify(observer, times(1)).onNext("c"); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("One"); + inOrder.verify(subscriber, times(1)).onNext("a"); + inOrder.verify(subscriber, times(1)).onNext("b"); + inOrder.verify(subscriber, times(1)).onNext("c"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); ts.dispose(); } @@ -181,20 +181,20 @@ public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() { Flowable other = Flowable.just("a", "b", "c"); Flowable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); source.subscribe(ts); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); testScheduler.advanceTimeBy(4, TimeUnit.SECONDS); underlyingSubject.onComplete(); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("One"); - inOrder.verify(observer, times(1)).onNext("a"); - inOrder.verify(observer, times(1)).onNext("b"); - inOrder.verify(observer, times(1)).onNext("c"); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("One"); + inOrder.verify(subscriber, times(1)).onNext("a"); + inOrder.verify(subscriber, times(1)).onNext("b"); + inOrder.verify(subscriber, times(1)).onNext("c"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); ts.dispose(); } @@ -204,8 +204,8 @@ public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() { PublishProcessor other = PublishProcessor.create(); Flowable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); source.subscribe(ts); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -222,10 +222,10 @@ public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() { other.onNext("d"); other.onComplete(); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("One"); - inOrder.verify(observer, times(1)).onNext("a"); - inOrder.verify(observer, times(1)).onNext("b"); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("One"); + inOrder.verify(subscriber, times(1)).onNext("a"); + inOrder.verify(subscriber, times(1)).onNext("b"); inOrder.verifyNoMoreInteractions(); } @@ -235,8 +235,8 @@ public void shouldTimeoutIfSynchronizedFlowableEmitFirstOnNextNotWithinTimeout() final CountDownLatch exit = new CountDownLatch(1); final CountDownLatch timeoutSetuped = new CountDownLatch(1); - final Subscriber observer = TestHelper.mockSubscriber(); - final TestSubscriber ts = new TestSubscriber(observer); + final Subscriber subscriber = TestHelper.mockSubscriber(); + final TestSubscriber ts = new TestSubscriber(subscriber); new Thread(new Runnable() { @@ -265,8 +265,8 @@ public void subscribe(Subscriber subscriber) { timeoutSetuped.await(); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError(isA(TimeoutException.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onError(isA(TimeoutException.class)); inOrder.verifyNoMoreInteractions(); exit.countDown(); // exit the thread @@ -287,14 +287,14 @@ public void subscribe(Subscriber subscriber) { TestScheduler testScheduler = new TestScheduler(); Flowable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); observableWithTimeout.subscribe(ts); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onError(isA(TimeoutException.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onError(isA(TimeoutException.class)); inOrder.verifyNoMoreInteractions(); verify(s, times(1)).cancel(); @@ -318,14 +318,14 @@ public void subscribe(Subscriber subscriber) { Flowable observableWithTimeout = immediatelyComplete.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); observableWithTimeout.subscribe(ts); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); verify(s, times(1)).cancel(); @@ -349,14 +349,14 @@ public void subscribe(Subscriber subscriber) { Flowable observableWithTimeout = immediatelyError.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); observableWithTimeout.subscribe(ts); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onError(isA(IOException.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onError(isA(IOException.class)); inOrder.verifyNoMoreInteractions(); verify(s, times(1)).cancel(); @@ -364,18 +364,18 @@ public void subscribe(Subscriber subscriber) { @Test public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() { - final PublishProcessor subject = PublishProcessor.create(); + final PublishProcessor processor = PublishProcessor.create(); final TestScheduler scheduler = new TestScheduler(); - final TestSubscriber observer = subject + final TestSubscriber subscriber = processor .timeout(100, TimeUnit.MILLISECONDS, scheduler) .test(); - assertTrue(subject.hasSubscribers()); + assertTrue(processor.hasSubscribers()); - observer.dispose(); + subscriber.dispose(); - assertFalse(subject.hasSubscribers()); + assertFalse(processor.hasSubscribers()); } @Test @@ -431,14 +431,14 @@ public void badSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - - observer.onNext(1); - observer.onComplete(); - observer.onNext(2); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + + subscriber.onNext(1); + subscriber.onComplete(); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .timeout(1, TimeUnit.DAYS) @@ -457,14 +457,14 @@ public void badSourceOther() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - - observer.onNext(1); - observer.onComplete(); - observer.onNext(2); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + + subscriber.onNext(1); + subscriber.onComplete(); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .timeout(1, TimeUnit.DAYS, Flowable.just(3)) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java index b1667e1e56..178e015413 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java @@ -53,22 +53,22 @@ public Flowable apply(Integer t1) { Flowable other = Flowable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.timeout(timeout, timeoutFunc, other).subscribe(o); + source.timeout(timeout, timeoutFunc, other).subscribe(subscriber); source.onNext(1); source.onNext(2); source.onNext(3); timeout.onNext(1); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o).onNext(3); - inOrder.verify(o).onNext(100); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onNext(3); + inOrder.verify(subscriber).onNext(100); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @@ -86,16 +86,16 @@ public Flowable apply(Integer t1) { Flowable other = Flowable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.timeout(timeout, timeoutFunc, other).subscribe(o); + source.timeout(timeout, timeoutFunc, other).subscribe(subscriber); timeout.onNext(1); - inOrder.verify(o).onNext(100); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(100); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @@ -120,13 +120,13 @@ public Flowable call() { Flowable other = Flowable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.timeout(Flowable.defer(firstTimeoutFunc), timeoutFunc, other).subscribe(o); + source.timeout(Flowable.defer(firstTimeoutFunc), timeoutFunc, other).subscribe(subscriber); - verify(o).onError(any(TestException.class)); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @@ -144,16 +144,16 @@ public Flowable apply(Integer t1) { Flowable other = Flowable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.timeout(timeout, timeoutFunc, other).subscribe(o); + source.timeout(timeout, timeoutFunc, other).subscribe(subscriber); source.onNext(1); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onError(any(TestException.class)); - verify(o, never()).onComplete(); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); } @@ -171,13 +171,13 @@ public Flowable apply(Integer t1) { Flowable other = Flowable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.timeout(Flowable. error(new TestException()), timeoutFunc, other).subscribe(o); + source.timeout(Flowable. error(new TestException()), timeoutFunc, other).subscribe(subscriber); - verify(o).onError(any(TestException.class)); - verify(o, never()).onNext(any()); - verify(o, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onNext(any()); + verify(subscriber, never()).onComplete(); } @@ -195,16 +195,16 @@ public Flowable apply(Integer t1) { Flowable other = Flowable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.timeout(timeout, timeoutFunc, other).subscribe(o); + source.timeout(timeout, timeoutFunc, other).subscribe(subscriber); source.onNext(1); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onError(any(TestException.class)); - verify(o, never()).onComplete(); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); } @@ -220,13 +220,13 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); - source.timeout(timeout, timeoutFunc).subscribe(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + source.timeout(timeout, timeoutFunc).subscribe(subscriber); timeout.onNext(1); - InOrder inOrder = inOrder(o); - inOrder.verify(o).onError(isA(TimeoutException.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onError(isA(TimeoutException.class)); inOrder.verifyNoMoreInteractions(); } @@ -242,15 +242,15 @@ public Flowable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); - source.timeout(PublishProcessor.create(), timeoutFunc).subscribe(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + source.timeout(PublishProcessor.create(), timeoutFunc).subscribe(subscriber); source.onNext(1); timeout.onNext(1); - InOrder inOrder = inOrder(o); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onError(isA(TimeoutException.class)); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onError(isA(TimeoutException.class)); inOrder.verifyNoMoreInteractions(); } @@ -308,7 +308,7 @@ public void subscribe(Subscriber subscriber) { } }; - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); doAnswer(new Answer() { @Override @@ -317,7 +317,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable { return null; } - }).when(o).onNext(2); + }).when(subscriber).onNext(2); doAnswer(new Answer() { @Override @@ -326,9 +326,9 @@ public Void answer(InvocationOnMock invocation) throws Throwable { return null; } - }).when(o).onComplete(); + }).when(subscriber).onComplete(); - final TestSubscriber ts = new TestSubscriber(o); + final TestSubscriber ts = new TestSubscriber(subscriber); new Thread(new Runnable() { @@ -363,12 +363,12 @@ public void run() { assertFalse("CoundDownLatch timeout", latchTimeout.get()); - InOrder inOrder = inOrder(o); - inOrder.verify(o).onSubscribe((Subscription)notNull()); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onNext(2); - inOrder.verify(o, never()).onNext(3); - inOrder.verify(o).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber).onSubscribe((Subscription)notNull()); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber, never()).onNext(3); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -383,15 +383,15 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.timeout(Functions.justFunction(Flowable.never())); + public Flowable apply(Flowable f) throws Exception { + return f.timeout(Functions.justFunction(Flowable.never())); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.timeout(Functions.justFunction(Flowable.never()), Flowable.never()); + public Flowable apply(Flowable f) throws Exception { + return f.timeout(Functions.justFunction(Flowable.never()), Flowable.never()); } }); } @@ -434,12 +434,12 @@ public void badInnerSource() { TestSubscriber ts = pp .timeout(Functions.justFunction(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException("First")); - observer.onNext(2); - observer.onError(new TestException("Second")); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException("First")); + subscriber.onNext(2); + subscriber.onError(new TestException("Second")); + subscriber.onComplete(); } })) .test(); @@ -463,12 +463,12 @@ public void badInnerSourceOther() { TestSubscriber ts = pp .timeout(Functions.justFunction(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException("First")); - observer.onNext(2); - observer.onError(new TestException("Second")); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException("First")); + subscriber.onNext(2); + subscriber.onError(new TestException("Second")); + subscriber.onComplete(); } }), Flowable.just(2)) .test(); @@ -493,22 +493,30 @@ public void withOtherMainError() { @Test public void badSourceTimeout() { - new Flowable() { - @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onNext(2); - observer.onError(new TestException("First")); - observer.onNext(3); - observer.onComplete(); - observer.onError(new TestException("Second")); + List errors = TestHelper.trackPluginErrors(); + try { + new Flowable() { + @Override + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(1); + subscriber.onNext(2); + subscriber.onError(new TestException("First")); + subscriber.onNext(3); + subscriber.onComplete(); + subscriber.onError(new TestException("Second")); + } } + .timeout(Functions.justFunction(Flowable.never()), Flowable.never()) + .take(1) + .test() + .assertResult(1); + + TestHelper.assertUndeliverable(errors, 0, TestException.class, "First"); + TestHelper.assertUndeliverable(errors, 1, TestException.class, "Second"); + } finally { + RxJavaPlugins.reset(); } - .timeout(Functions.justFunction(Flowable.never()), Flowable.never()) - .take(1) - .test() - .assertResult(1); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java index ec18215c00..21009d0da7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java @@ -35,29 +35,29 @@ public class FlowableTimerTest { @Mock - Subscriber observer; + Subscriber subscriber; @Mock - Subscriber observer2; + Subscriber subscriber2; TestScheduler scheduler; @Before public void before() { - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); - observer2 = TestHelper.mockSubscriber(); + subscriber2 = TestHelper.mockSubscriber(); scheduler = new TestScheduler(); } @Test public void testTimerOnce() { - Flowable.timer(100, TimeUnit.MILLISECONDS, scheduler).subscribe(observer); + Flowable.timer(100, TimeUnit.MILLISECONDS, scheduler).subscribe(subscriber); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); - verify(observer, times(1)).onNext(0L); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext(0L); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -239,26 +239,26 @@ public void onNext(Long t) { @Override public void onError(Throwable e) { - observer.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - observer.onComplete(); + subscriber.onComplete(); } }); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - verify(observer).onError(any(TestException.class)); - verify(observer, never()).onNext(anyLong()); - verify(observer, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); + verify(subscriber, never()).onNext(anyLong()); + verify(subscriber, never()).onComplete(); } @Test public void testPeriodicObserverThrows() { Flowable source = Flowable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); source.safeSubscribe(new DefaultSubscriber() { @@ -267,26 +267,26 @@ public void onNext(Long t) { if (t > 0) { throw new TestException(); } - observer.onNext(t); + subscriber.onNext(t); } @Override public void onError(Throwable e) { - observer.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - observer.onComplete(); + subscriber.onComplete(); } }); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - inOrder.verify(observer).onNext(0L); - inOrder.verify(observer).onError(any(TestException.class)); + inOrder.verify(subscriber).onNext(0L); + inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(observer, never()).onComplete(); + verify(subscriber, never()).onComplete(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimestampTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimestampTest.java index 1172245f9c..295f4d3a2b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimestampTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimestampTest.java @@ -28,11 +28,11 @@ import io.reactivex.schedulers.*; public class FlowableTimestampTest { - Subscriber observer; + Subscriber subscriber; @Before public void before() { - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); } @Test @@ -41,7 +41,7 @@ public void timestampWithScheduler() { PublishProcessor source = PublishProcessor.create(); Flowable> m = source.timestamp(scheduler); - m.subscribe(observer); + m.subscribe(subscriber); source.onNext(1); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); @@ -49,14 +49,14 @@ public void timestampWithScheduler() { scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); source.onNext(3); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(observer, times(1)).onNext(new Timed(1, 0, TimeUnit.MILLISECONDS)); - inOrder.verify(observer, times(1)).onNext(new Timed(2, 100, TimeUnit.MILLISECONDS)); - inOrder.verify(observer, times(1)).onNext(new Timed(3, 200, TimeUnit.MILLISECONDS)); + inOrder.verify(subscriber, times(1)).onNext(new Timed(1, 0, TimeUnit.MILLISECONDS)); + inOrder.verify(subscriber, times(1)).onNext(new Timed(2, 100, TimeUnit.MILLISECONDS)); + inOrder.verify(subscriber, times(1)).onNext(new Timed(3, 200, TimeUnit.MILLISECONDS)); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); } @Test @@ -65,7 +65,7 @@ public void timestampWithScheduler2() { PublishProcessor source = PublishProcessor.create(); Flowable> m = source.timestamp(scheduler); - m.subscribe(observer); + m.subscribe(subscriber); source.onNext(1); source.onNext(2); @@ -73,14 +73,14 @@ public void timestampWithScheduler2() { scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); source.onNext(3); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(observer, times(1)).onNext(new Timed(1, 0, TimeUnit.MILLISECONDS)); - inOrder.verify(observer, times(1)).onNext(new Timed(2, 0, TimeUnit.MILLISECONDS)); - inOrder.verify(observer, times(1)).onNext(new Timed(3, 200, TimeUnit.MILLISECONDS)); + inOrder.verify(subscriber, times(1)).onNext(new Timed(1, 0, TimeUnit.MILLISECONDS)); + inOrder.verify(subscriber, times(1)).onNext(new Timed(2, 0, TimeUnit.MILLISECONDS)); + inOrder.verify(subscriber, times(1)).onNext(new Timed(3, 200, TimeUnit.MILLISECONDS)); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToFutureTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToFutureTest.java index afe111c919..2fb5920d57 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToFutureTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToFutureTest.java @@ -34,17 +34,17 @@ public void testSuccess() throws Exception { Object value = new Object(); when(future.get()).thenReturn(value); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(o); + TestSubscriber ts = new TestSubscriber(subscriber); Flowable.fromFuture(future).subscribe(ts); ts.dispose(); - verify(o, times(1)).onNext(value); - verify(o, times(1)).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onNext(value); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); verify(future, never()).cancel(anyBoolean()); } @@ -55,18 +55,18 @@ public void testSuccessOperatesOnSuppliedScheduler() throws Exception { Object value = new Object(); when(future.get()).thenReturn(value); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); TestScheduler scheduler = new TestScheduler(); - TestSubscriber ts = new TestSubscriber(o); + TestSubscriber ts = new TestSubscriber(subscriber); Flowable.fromFuture(future, scheduler).subscribe(ts); - verify(o, never()).onNext(value); + verify(subscriber, never()).onNext(value); scheduler.triggerActions(); - verify(o, times(1)).onNext(value); + verify(subscriber, times(1)).onNext(value); } @Test @@ -76,17 +76,17 @@ public void testFailure() throws Exception { RuntimeException e = new RuntimeException(); when(future.get()).thenThrow(e); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(o); + TestSubscriber ts = new TestSubscriber(subscriber); Flowable.fromFuture(future).subscribe(ts); ts.dispose(); - verify(o, never()).onNext(null); - verify(o, never()).onComplete(); - verify(o, times(1)).onError(e); + verify(subscriber, never()).onNext(null); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onError(e); verify(future, never()).cancel(anyBoolean()); } @@ -97,9 +97,9 @@ public void testCancelledBeforeSubscribe() throws Exception { CancellationException e = new CancellationException("unit test synthetic cancellation"); when(future.get()).thenThrow(e); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(o); + TestSubscriber ts = new TestSubscriber(subscriber); ts.dispose(); Flowable.fromFuture(future).subscribe(ts); @@ -143,9 +143,9 @@ public Object get(long timeout, TimeUnit unit) throws InterruptedException, Exec } }; - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(o); + TestSubscriber ts = new TestSubscriber(subscriber); Flowable futureObservable = Flowable.fromFuture(future); futureObservable.subscribeOn(Schedulers.computation()).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java index 4c18a1ce29..20a0534285 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java @@ -36,66 +36,69 @@ public class FlowableToListTest { @Test public void testListFlowable() { Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); - Flowable> observable = w.toList().toFlowable(); + Flowable> flowable = w.toList().toFlowable(); - Subscriber> observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); - verify(observer, times(1)).onNext(Arrays.asList("one", "two", "three")); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber> subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); + + verify(subscriber, times(1)).onNext(Arrays.asList("one", "two", "three")); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testListViaFlowableFlowable() { Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); - Flowable> observable = w.toList().toFlowable(); + Flowable> flowable = w.toList().toFlowable(); - Subscriber> observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); - verify(observer, times(1)).onNext(Arrays.asList("one", "two", "three")); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber> subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); + + verify(subscriber, times(1)).onNext(Arrays.asList("one", "two", "three")); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testListMultipleSubscribersFlowable() { Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); - Flowable> observable = w.toList().toFlowable(); + Flowable> flowable = w.toList().toFlowable(); - Subscriber> o1 = TestHelper.mockSubscriber(); - observable.subscribe(o1); + Subscriber> subscriber1 = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber1); - Subscriber> o2 = TestHelper.mockSubscriber(); - observable.subscribe(o2); + Subscriber> subscriber2 = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber2); List expected = Arrays.asList("one", "two", "three"); - verify(o1, times(1)).onNext(expected); - verify(o1, Mockito.never()).onError(any(Throwable.class)); - verify(o1, times(1)).onComplete(); + verify(subscriber1, times(1)).onNext(expected); + verify(subscriber1, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber1, times(1)).onComplete(); - verify(o2, times(1)).onNext(expected); - verify(o2, Mockito.never()).onError(any(Throwable.class)); - verify(o2, times(1)).onComplete(); + verify(subscriber2, times(1)).onNext(expected); + verify(subscriber2, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber2, times(1)).onComplete(); } @Test @Ignore("Null values are not allowed") public void testListWithNullValueFlowable() { Flowable w = Flowable.fromIterable(Arrays.asList("one", null, "three")); - Flowable> observable = w.toList().toFlowable(); + Flowable> flowable = w.toList().toFlowable(); - Subscriber> observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); - verify(observer, times(1)).onNext(Arrays.asList("one", null, "three")); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber> subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); + + verify(subscriber, times(1)).onNext(Arrays.asList("one", null, "three")); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testListWithBlockingFirstFlowable() { - Flowable o = Flowable.fromIterable(Arrays.asList("one", "two", "three")); - List actual = o.toList().toFlowable().blockingFirst(); + Flowable f = Flowable.fromIterable(Arrays.asList("one", "two", "three")); + List actual = f.toList().toFlowable().blockingFirst(); Assert.assertEquals(Arrays.asList("one", "two", "three"), actual); } @Test @@ -170,10 +173,10 @@ public void capacityHintFlowable() { @Test public void testList() { Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); - Single> observable = w.toList(); + Single> single = w.toList(); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", "two", "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); } @@ -181,10 +184,10 @@ public void testList() { @Test public void testListViaFlowable() { Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); - Single> observable = w.toList(); + Single> single = w.toList(); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", "two", "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); } @@ -192,13 +195,13 @@ public void testListViaFlowable() { @Test public void testListMultipleSubscribers() { Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); - Single> observable = w.toList(); + Single> single = w.toList(); SingleObserver> o1 = TestHelper.mockSingleObserver(); - observable.subscribe(o1); + single.subscribe(o1); SingleObserver> o2 = TestHelper.mockSingleObserver(); - observable.subscribe(o2); + single.subscribe(o2); List expected = Arrays.asList("one", "two", "three"); @@ -213,18 +216,18 @@ public void testListMultipleSubscribers() { @Ignore("Null values are not allowed") public void testListWithNullValue() { Flowable w = Flowable.fromIterable(Arrays.asList("one", null, "three")); - Single> observable = w.toList(); + Single> single = w.toList(); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", null, "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); } @Test public void testListWithBlockingFirst() { - Flowable o = Flowable.fromIterable(Arrays.asList("one", "two", "three")); - List actual = o.toList().blockingGet(); + Flowable f = Flowable.fromIterable(Arrays.asList("one", "two", "three")); + List actual = f.toList().blockingGet(); Assert.assertEquals(Arrays.asList("one", "two", "three"), actual); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java index 8723a291bc..f8914e7182 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java @@ -25,12 +25,12 @@ import io.reactivex.functions.Function; public class FlowableToMapTest { - Subscriber objectObserver; + Subscriber objectSubscriber; SingleObserver singleObserver; @Before public void before() { - objectObserver = TestHelper.mockSubscriber(); + objectSubscriber = TestHelper.mockSubscriber(); singleObserver = TestHelper.mockSingleObserver(); } @@ -59,11 +59,11 @@ public void testToMapFlowable() { expected.put(3, "ccc"); expected.put(4, "dddd"); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onError(any(Throwable.class)); - verify(objectObserver, times(1)).onNext(expected); - verify(objectObserver, times(1)).onComplete(); + verify(objectSubscriber, never()).onError(any(Throwable.class)); + verify(objectSubscriber, times(1)).onNext(expected); + verify(objectSubscriber, times(1)).onComplete(); } @Test @@ -78,11 +78,11 @@ public void testToMapWithValueSelectorFlowable() { expected.put(3, "cccccc"); expected.put(4, "dddddddd"); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onError(any(Throwable.class)); - verify(objectObserver, times(1)).onNext(expected); - verify(objectObserver, times(1)).onComplete(); + verify(objectSubscriber, never()).onError(any(Throwable.class)); + verify(objectSubscriber, times(1)).onNext(expected); + verify(objectSubscriber, times(1)).onComplete(); } @Test @@ -106,11 +106,11 @@ public Integer apply(String t1) { expected.put(3, "ccc"); expected.put(4, "dddd"); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onNext(expected); - verify(objectObserver, never()).onComplete(); - verify(objectObserver, times(1)).onError(any(Throwable.class)); + verify(objectSubscriber, never()).onNext(expected); + verify(objectSubscriber, never()).onComplete(); + verify(objectSubscriber, times(1)).onError(any(Throwable.class)); } @@ -136,11 +136,11 @@ public String apply(String t1) { expected.put(3, "cccccc"); expected.put(4, "dddddddd"); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onNext(expected); - verify(objectObserver, never()).onComplete(); - verify(objectObserver, times(1)).onError(any(Throwable.class)); + verify(objectSubscriber, never()).onNext(expected); + verify(objectSubscriber, never()).onComplete(); + verify(objectSubscriber, times(1)).onError(any(Throwable.class)); } @@ -181,11 +181,11 @@ public String apply(String v) { expected.put(3, "ccc"); expected.put(4, "dddd"); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onError(any(Throwable.class)); - verify(objectObserver, times(1)).onNext(expected); - verify(objectObserver, times(1)).onComplete(); + verify(objectSubscriber, never()).onError(any(Throwable.class)); + verify(objectSubscriber, times(1)).onNext(expected); + verify(objectSubscriber, times(1)).onComplete(); } @Test @@ -217,11 +217,11 @@ public String apply(String v) { expected.put(3, "ccc"); expected.put(4, "dddd"); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onNext(expected); - verify(objectObserver, never()).onComplete(); - verify(objectObserver, times(1)).onError(any(Throwable.class)); + verify(objectSubscriber, never()).onNext(expected); + verify(objectSubscriber, never()).onComplete(); + verify(objectSubscriber, times(1)).onError(any(Throwable.class)); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java index af642121fb..1546815355 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java @@ -25,13 +25,13 @@ import io.reactivex.functions.Function; public class FlowableToMultimapTest { - Subscriber objectObserver; + Subscriber objectSubscriber; SingleObserver singleObserver; @Before public void before() { - objectObserver = TestHelper.mockSubscriber(); + objectSubscriber = TestHelper.mockSubscriber(); singleObserver = TestHelper.mockSingleObserver(); } @@ -58,11 +58,11 @@ public void testToMultimapFlowable() { expected.put(1, Arrays.asList("a", "b")); expected.put(2, Arrays.asList("cc", "dd")); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onError(any(Throwable.class)); - verify(objectObserver, times(1)).onNext(expected); - verify(objectObserver, times(1)).onComplete(); + verify(objectSubscriber, never()).onError(any(Throwable.class)); + verify(objectSubscriber, times(1)).onNext(expected); + verify(objectSubscriber, times(1)).onComplete(); } @Test @@ -75,11 +75,11 @@ public void testToMultimapWithValueSelectorFlowable() { expected.put(1, Arrays.asList("aa", "bb")); expected.put(2, Arrays.asList("cccc", "dddd")); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onError(any(Throwable.class)); - verify(objectObserver, times(1)).onNext(expected); - verify(objectObserver, times(1)).onComplete(); + verify(objectSubscriber, never()).onError(any(Throwable.class)); + verify(objectSubscriber, times(1)).onNext(expected); + verify(objectSubscriber, times(1)).onComplete(); } @Test @@ -121,11 +121,11 @@ public Collection apply(Integer e) { expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, Arrays.asList("eee", "fff")); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onError(any(Throwable.class)); - verify(objectObserver, times(1)).onNext(expected); - verify(objectObserver, times(1)).onComplete(); + verify(objectSubscriber, never()).onError(any(Throwable.class)); + verify(objectSubscriber, times(1)).onNext(expected); + verify(objectSubscriber, times(1)).onComplete(); } @Test @@ -163,11 +163,11 @@ public Map> call() { expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, new HashSet(Arrays.asList("eee"))); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, never()).onError(any(Throwable.class)); - verify(objectObserver, times(1)).onNext(expected); - verify(objectObserver, times(1)).onComplete(); + verify(objectSubscriber, never()).onError(any(Throwable.class)); + verify(objectSubscriber, times(1)).onNext(expected); + verify(objectSubscriber, times(1)).onComplete(); } @Test @@ -190,11 +190,11 @@ public Integer apply(String t1) { expected.put(1, Arrays.asList("a", "b")); expected.put(2, Arrays.asList("cc", "dd")); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, times(1)).onError(any(Throwable.class)); - verify(objectObserver, never()).onNext(expected); - verify(objectObserver, never()).onComplete(); + verify(objectSubscriber, times(1)).onError(any(Throwable.class)); + verify(objectSubscriber, never()).onNext(expected); + verify(objectSubscriber, never()).onComplete(); } @Test @@ -217,11 +217,11 @@ public String apply(String t1) { expected.put(1, Arrays.asList("aa", "bb")); expected.put(2, Arrays.asList("cccc", "dddd")); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, times(1)).onError(any(Throwable.class)); - verify(objectObserver, never()).onNext(expected); - verify(objectObserver, never()).onComplete(); + verify(objectSubscriber, times(1)).onError(any(Throwable.class)); + verify(objectSubscriber, never()).onNext(expected); + verify(objectSubscriber, never()).onComplete(); } @Test @@ -247,11 +247,11 @@ public String apply(String v) { expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, Arrays.asList("eee", "fff")); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, times(1)).onError(any(Throwable.class)); - verify(objectObserver, never()).onNext(expected); - verify(objectObserver, never()).onComplete(); + verify(objectSubscriber, times(1)).onError(any(Throwable.class)); + verify(objectSubscriber, never()).onNext(expected); + verify(objectSubscriber, never()).onComplete(); } @Test @@ -289,11 +289,11 @@ public Map> call() { expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, Collections.singleton("eee")); - mapped.subscribe(objectObserver); + mapped.subscribe(objectSubscriber); - verify(objectObserver, times(1)).onError(any(Throwable.class)); - verify(objectObserver, never()).onNext(expected); - verify(objectObserver, never()).onComplete(); + verify(objectSubscriber, times(1)).onError(any(Throwable.class)); + verify(objectSubscriber, never()).onNext(expected); + verify(objectSubscriber, never()).onComplete(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java index db118e2ab1..bea7ef749a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java @@ -34,19 +34,20 @@ public class FlowableToSortedListTest { @Test public void testSortedListFlowable() { Flowable w = Flowable.just(1, 3, 2, 5, 4); - Flowable> observable = w.toSortedList().toFlowable(); + Flowable> flowable = w.toSortedList().toFlowable(); - Subscriber> observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); - verify(observer, times(1)).onNext(Arrays.asList(1, 2, 3, 4, 5)); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber> subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); + + verify(subscriber, times(1)).onNext(Arrays.asList(1, 2, 3, 4, 5)); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testSortedListWithCustomFunctionFlowable() { Flowable w = Flowable.just(1, 3, 2, 5, 4); - Flowable> observable = w.toSortedList(new Comparator() { + Flowable> flowable = w.toSortedList(new Comparator() { @Override public int compare(Integer t1, Integer t2) { @@ -55,17 +56,18 @@ public int compare(Integer t1, Integer t2) { }).toFlowable(); - Subscriber> observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); - verify(observer, times(1)).onNext(Arrays.asList(5, 4, 3, 2, 1)); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + Subscriber> subscriber = TestHelper.mockSubscriber(); + flowable.subscribe(subscriber); + + verify(subscriber, times(1)).onNext(Arrays.asList(5, 4, 3, 2, 1)); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testWithFollowingFirstFlowable() { - Flowable o = Flowable.just(1, 3, 2, 5, 4); - assertEquals(Arrays.asList(1, 2, 3, 4, 5), o.toSortedList().toFlowable().blockingFirst()); + Flowable f = Flowable.just(1, 3, 2, 5, 4); + assertEquals(Arrays.asList(1, 2, 3, 4, 5), f.toSortedList().toFlowable().blockingFirst()); } @Test public void testBackpressureHonoredFlowable() { @@ -169,10 +171,10 @@ public int compare(Integer a, Integer b) { @Test public void testSortedList() { Flowable w = Flowable.just(1, 3, 2, 5, 4); - Single> observable = w.toSortedList(); + Single> single = w.toSortedList(); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList(1, 2, 3, 4, 5)); verify(observer, Mockito.never()).onError(any(Throwable.class)); } @@ -180,7 +182,7 @@ public void testSortedList() { @Test public void testSortedListWithCustomFunction() { Flowable w = Flowable.just(1, 3, 2, 5, 4); - Single> observable = w.toSortedList(new Comparator() { + Single> single = w.toSortedList(new Comparator() { @Override public int compare(Integer t1, Integer t2) { @@ -190,15 +192,15 @@ public int compare(Integer t1, Integer t2) { }); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList(5, 4, 3, 2, 1)); verify(observer, Mockito.never()).onError(any(Throwable.class)); } @Test public void testWithFollowingFirst() { - Flowable o = Flowable.just(1, 3, 2, 5, 4); - assertEquals(Arrays.asList(1, 2, 3, 4, 5), o.toSortedList().blockingGet()); + Flowable f = Flowable.just(1, 3, 2, 5, 4); + assertEquals(Arrays.asList(1, 2, 3, 4, 5), f.toSortedList().blockingGet()); } @Test @Ignore("Single doesn't do backpressure") diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java index d678bf11bf..3ed444424f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java @@ -97,13 +97,13 @@ public void subscribe(Subscriber t1) { } }); - TestSubscriber observer = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber(); w.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.computation()) .unsubscribeOn(uiEventLoop) .take(2) - .subscribe(observer); + .subscribe(ts); - observer.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitTerminalEvent(1, TimeUnit.SECONDS); Thread unsubscribeThread = subscription.getThread(); @@ -119,8 +119,8 @@ public void subscribe(Subscriber t1) { System.out.println("subscribeThread.get(): " + subscribeThread.get()); assertSame(unsubscribeThread, uiEventLoop.getThread()); - observer.assertValues(1, 2); - observer.assertTerminated(); + ts.assertValues(1, 2); + ts.assertTerminated(); } finally { uiEventLoop.shutdown(); } @@ -250,12 +250,12 @@ public void signalAfterDispose() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onNext(2); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(1); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .unsubscribeOn(Schedulers.single()) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java index e836796924..ad3869f4ac 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java @@ -87,16 +87,16 @@ public Flowable apply(Resource res) { } }; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable observable = Flowable.using(resourceFactory, observableFactory, + Flowable flowable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), disposeEagerly); - observable.subscribe(observer); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext("Hello"); - inOrder.verify(observer, times(1)).onNext("world!"); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext("Hello"); + inOrder.verify(subscriber, times(1)).onNext("world!"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); // The resouce should be closed @@ -147,22 +147,22 @@ public Flowable apply(Resource res) { } }; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable observable = Flowable.using(resourceFactory, observableFactory, + Flowable flowable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), disposeEagerly); - observable.subscribe(observer); - observable.subscribe(observer); + flowable.subscribe(subscriber); + flowable.subscribe(subscriber); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(observer, times(1)).onNext("Hello"); - inOrder.verify(observer, times(1)).onNext("world!"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("Hello"); + inOrder.verify(subscriber, times(1)).onNext("world!"); + inOrder.verify(subscriber, times(1)).onComplete(); - inOrder.verify(observer, times(1)).onNext("Hello"); - inOrder.verify(observer, times(1)).onNext("world!"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("Hello"); + inOrder.verify(subscriber, times(1)).onNext("world!"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -291,14 +291,14 @@ public Flowable apply(Resource resource) { } }; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable observable = Flowable.using(resourceFactory, observableFactory, + Flowable flowable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), true) .doOnCancel(unsub) .doOnComplete(completion); - observable.safeSubscribe(observer); + flowable.safeSubscribe(subscriber); assertEquals(Arrays.asList("disposed", "completed"), events); @@ -318,14 +318,14 @@ public Flowable apply(Resource resource) { } }; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable observable = Flowable.using(resourceFactory, observableFactory, + Flowable flowable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), false) .doOnCancel(unsub) .doOnComplete(completion); - observable.safeSubscribe(observer); + flowable.safeSubscribe(subscriber); assertEquals(Arrays.asList("completed", "disposed"), events); @@ -348,14 +348,14 @@ public Flowable apply(Resource resource) { } }; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable observable = Flowable.using(resourceFactory, observableFactory, + Flowable flowable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), true) .doOnCancel(unsub) .doOnError(onError); - observable.safeSubscribe(observer); + flowable.safeSubscribe(subscriber); assertEquals(Arrays.asList("disposed", "error"), events); @@ -376,14 +376,14 @@ public Flowable apply(Resource resource) { } }; - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable observable = Flowable.using(resourceFactory, observableFactory, + Flowable flowable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), false) .doOnCancel(unsub) .doOnError(onError); - observable.safeSubscribe(observer); + flowable.safeSubscribe(subscriber); assertEquals(Arrays.asList("error", "disposed"), events); } @@ -643,9 +643,9 @@ public void sourceSupplierReturnsNull() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) + public Flowable apply(Flowable f) throws Exception { - return Flowable.using(Functions.justCallable(1), Functions.justFunction(o), Functions.emptyConsumer()); + return Flowable.using(Functions.justCallable(1), Functions.justFunction(f), Functions.emptyConsumer()); } }); } @@ -656,10 +656,10 @@ public void eagerDisposedOnComplete() { Flowable.using(Functions.justCallable(1), Functions.justFunction(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); ts.cancel(); - observer.onComplete(); + subscriber.onComplete(); } }), Functions.emptyConsumer(), true) .subscribe(ts); @@ -671,10 +671,10 @@ public void eagerDisposedOnError() { Flowable.using(Functions.justCallable(1), Functions.justFunction(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); ts.cancel(); - observer.onError(new TestException()); + subscriber.onError(new TestException()); } }), Functions.emptyConsumer(), true) .subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java index 1bdb7a95e6..a6469281c4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java @@ -40,7 +40,7 @@ public void testWindowViaFlowableNormal1() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); final List> values = new ArrayList>(); @@ -55,12 +55,12 @@ public void onNext(Flowable args) { @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }; @@ -76,7 +76,7 @@ public void onComplete() { source.onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); assertEquals(n / 3, values.size()); @@ -90,7 +90,7 @@ public void onComplete() { j += 3; } - verify(o).onComplete(); + verify(subscriber).onComplete(); } @Test @@ -98,7 +98,7 @@ public void testWindowViaFlowableBoundaryCompletes() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); final List> values = new ArrayList>(); @@ -113,12 +113,12 @@ public void onNext(Flowable args) { @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }; @@ -145,8 +145,8 @@ public void onComplete() { j += 3; } - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -154,7 +154,7 @@ public void testWindowViaFlowableBoundaryThrows() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); final List> values = new ArrayList>(); @@ -169,12 +169,12 @@ public void onNext(Flowable args) { @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }; @@ -195,8 +195,8 @@ public void onComplete() { verify(mo).onNext(2); verify(mo).onError(any(TestException.class)); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } @Test @@ -204,7 +204,7 @@ public void testWindowViaFlowableThrows() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); final List> values = new ArrayList>(); @@ -219,12 +219,12 @@ public void onNext(Flowable args) { @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }; @@ -245,8 +245,8 @@ public void onComplete() { verify(mo).onNext(2); verify(mo).onError(any(TestException.class)); - verify(o, never()).onComplete(); - verify(o).onError(any(TestException.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber).onError(any(TestException.class)); } @Test @@ -497,8 +497,8 @@ public void mainError() { public void innerBadSource() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return Flowable.just(1).window(o).flatMap(new Function, Flowable>() { + public Object apply(Flowable f) throws Exception { + return Flowable.just(1).window(f).flatMap(new Function, Flowable>() { @Override public Flowable apply(Flowable v) throws Exception { return v; @@ -509,7 +509,7 @@ public Flowable apply(Flowable v) throws Exception { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(final Flowable o) throws Exception { + public Object apply(final Flowable f) throws Exception { return Flowable.just(1).window(new Callable>() { int count; @Override @@ -517,7 +517,7 @@ public Publisher call() throws Exception { if (++count > 1) { return Flowable.never(); } - return o; + return f; } }) .flatMap(new Function, Flowable>() { @@ -606,8 +606,8 @@ public Flowable apply(Flowable v) throws Exception { public void badSource() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.window(Flowable.never()).flatMap(new Function, Flowable>() { + public Object apply(Flowable f) throws Exception { + return f.window(Flowable.never()).flatMap(new Function, Flowable>() { @Override public Flowable apply(Flowable v) throws Exception { return v; @@ -621,8 +621,8 @@ public Flowable apply(Flowable v) throws Exception { public void badSourceCallable() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.window(Functions.justCallable(Flowable.never())).flatMap(new Function, Flowable>() { + public Object apply(Flowable f) throws Exception { + return f.window(Functions.justCallable(Flowable.never())).flatMap(new Function, Flowable>() { @Override public Flowable apply(Flowable v) throws Exception { return v; @@ -698,19 +698,33 @@ public void oneWindow() { @SuppressWarnings("unchecked") @Test public void boundaryDirectMissingBackpressure() { - BehaviorProcessor.create() - .window(Flowable.error(new TestException())) - .test(0) - .assertFailure(MissingBackpressureException.class); + List errors = TestHelper.trackPluginErrors(); + try { + BehaviorProcessor.create() + .window(Flowable.error(new TestException())) + .test(0) + .assertFailure(MissingBackpressureException.class); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @SuppressWarnings("unchecked") @Test public void boundaryDirectMissingBackpressureNoNullPointerException() { - BehaviorProcessor.createDefault(1) - .window(Flowable.error(new TestException())) - .test(0) - .assertFailure(MissingBackpressureException.class); + List errors = TestHelper.trackPluginErrors(); + try { + BehaviorProcessor.createDefault(1) + .window(Flowable.error(new TestException())) + .test(0) + .assertFailure(MissingBackpressureException.class); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -767,9 +781,9 @@ public void mainAndBoundaryBothError() { TestSubscriber> ts = Flowable.error(new TestException("main")) .window(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - ref.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + ref.set(subscriber); } }) .test(); @@ -800,16 +814,16 @@ public void mainCompleteBoundaryErrorRace() { TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - ref.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + ref.set(subscriber); } }) .test(); @@ -850,16 +864,16 @@ public void mainNextBoundaryNextRace() { TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - ref.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + ref.set(subscriber); } }) .test(); @@ -893,16 +907,16 @@ public void takeOneAnotherBoundary() { TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - ref.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + ref.set(subscriber); } }) .test(); @@ -925,16 +939,16 @@ public void disposeMainBoundaryCompleteRace() { final TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { final AtomicInteger counter = new AtomicInteger(); - observer.onSubscribe(new Subscription() { + subscriber.onSubscribe(new Subscription() { @Override public void cancel() { @@ -948,7 +962,7 @@ public void cancel() { public void request(long n) { } }); - ref.set(observer); + ref.set(subscriber); } }) .test(); @@ -962,9 +976,9 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - Subscriber o = ref.get(); - o.onNext(1); - o.onComplete(); + Subscriber subscriber = ref.get(); + subscriber.onNext(1); + subscriber.onComplete(); } }; @@ -982,16 +996,16 @@ public void disposeMainBoundaryErrorRace() { final TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { final AtomicInteger counter = new AtomicInteger(); - observer.onSubscribe(new Subscription() { + subscriber.onSubscribe(new Subscription() { @Override public void cancel() { @@ -1005,7 +1019,7 @@ public void cancel() { public void request(long n) { } }); - ref.set(observer); + ref.set(subscriber); } }) .test(); @@ -1019,9 +1033,9 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - Subscriber o = ref.get(); - o.onNext(1); - o.onError(ex); + Subscriber subscriber = ref.get(); + subscriber.onNext(1); + subscriber.onError(ex); } }; @@ -1073,9 +1087,9 @@ public void supplierMainAndBoundaryBothError() { TestSubscriber> ts = Flowable.error(new TestException("main")) .window(Functions.justCallable(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - ref.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + ref.set(subscriber); } })) .test(); @@ -1106,16 +1120,16 @@ public void supplierMainCompleteBoundaryErrorRace() { TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(Functions.justCallable(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - ref.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + ref.set(subscriber); } })) .test(); @@ -1156,16 +1170,16 @@ public void supplierMainNextBoundaryNextRace() { TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(Functions.justCallable(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - ref.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + ref.set(subscriber); } })) .test(); @@ -1199,16 +1213,16 @@ public void supplierTakeOneAnotherBoundary() { TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(Functions.justCallable(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - ref.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + ref.set(subscriber); } })) .test(); @@ -1231,16 +1245,16 @@ public void supplierDisposeMainBoundaryCompleteRace() { final TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(Functions.justCallable(new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { final AtomicInteger counter = new AtomicInteger(); - observer.onSubscribe(new Subscription() { + subscriber.onSubscribe(new Subscription() { @Override public void cancel() { @@ -1254,7 +1268,7 @@ public void cancel() { public void request(long n) { } }); - ref.set(observer); + ref.set(subscriber); } })) .test(); @@ -1268,9 +1282,9 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - Subscriber o = ref.get(); - o.onNext(1); - o.onComplete(); + Subscriber subscriber = ref.get(); + subscriber.onNext(1); + subscriber.onComplete(); } }; @@ -1290,9 +1304,9 @@ public void supplierDisposeMainBoundaryErrorRace() { final TestSubscriber> ts = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - refMain.set(observer); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + refMain.set(subscriber); } } .window(new Callable>() { @@ -1304,9 +1318,9 @@ public Flowable call() throws Exception { } return (new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { + protected void subscribeActual(Subscriber subscriber) { final AtomicInteger counter = new AtomicInteger(); - observer.onSubscribe(new Subscription() { + subscriber.onSubscribe(new Subscription() { @Override public void cancel() { @@ -1320,7 +1334,7 @@ public void cancel() { public void request(long n) { } }); - ref.set(observer); + ref.set(subscriber); } }); } @@ -1336,9 +1350,9 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - Subscriber o = ref.get(); - o.onNext(1); - o.onError(ex); + Subscriber subscriber = ref.get(); + subscriber.onNext(1); + subscriber.onError(ex); } }; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java index 32f6443233..aeb5381da7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java @@ -204,7 +204,7 @@ public void testBackpressureOuter() { final List list = new ArrayList(); - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); source.subscribe(new DefaultSubscriber>() { @Override @@ -220,28 +220,28 @@ public void onNext(Integer t) { } @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }); } @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }); assertEquals(Arrays.asList(1, 2, 3), list); - verify(o, never()).onError(any(Throwable.class)); - verify(o, times(1)).onComplete(); // 1 inner + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); // 1 inner } public static Flowable hotStream() { @@ -343,22 +343,22 @@ public void dispose() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>>() { @Override - public Flowable> apply(Flowable o) throws Exception { - return o.window(1); + public Flowable> apply(Flowable f) throws Exception { + return f.window(1); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>>() { @Override - public Flowable> apply(Flowable o) throws Exception { - return o.window(2, 1); + public Flowable> apply(Flowable f) throws Exception { + return f.window(2, 1); } }); TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>>() { @Override - public Flowable> apply(Flowable o) throws Exception { - return o.window(1, 2); + public Flowable> apply(Flowable f) throws Exception { + return f.window(1, 2); } }); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java index 561deaf7bb..c1d825afed 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java @@ -49,24 +49,24 @@ public void testFlowableBasedOpenerAndCloser() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, "one", 10); - push(observer, "two", 60); - push(observer, "three", 110); - push(observer, "four", 160); - push(observer, "five", 210); - complete(observer, 500); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 10); + push(subscriber, "two", 60); + push(subscriber, "three", 110); + push(subscriber, "four", 160); + push(subscriber, "five", 210); + complete(subscriber, 500); } }); Flowable openings = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, new Object(), 50); - push(observer, new Object(), 200); - complete(observer, 250); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, new Object(), 50); + push(subscriber, new Object(), 200); + complete(subscriber, 250); } }); @@ -75,10 +75,10 @@ public void subscribe(Subscriber observer) { public Flowable apply(Object opening) { return Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, new Object(), 100); - complete(observer, 101); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, new Object(), 100); + complete(subscriber, 101); } }); } @@ -100,14 +100,14 @@ public void testFlowableBasedCloser() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, "one", 10); - push(observer, "two", 60); - push(observer, "three", 110); - push(observer, "four", 160); - push(observer, "five", 210); - complete(observer, 250); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 10); + push(subscriber, "two", 60); + push(subscriber, "three", 110); + push(subscriber, "four", 160); + push(subscriber, "five", 210); + complete(subscriber, 250); } }); @@ -117,16 +117,16 @@ public void subscribe(Subscriber observer) { public Flowable call() { return Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); int c = calls++; if (c == 0) { - push(observer, new Object(), 100); + push(subscriber, new Object(), 100); } else if (c == 1) { - push(observer, new Object(), 100); + push(subscriber, new Object(), 100); } else { - complete(observer, 101); + complete(subscriber, 101); } } }); @@ -151,20 +151,20 @@ private List list(String... args) { return list; } - private void push(final Subscriber observer, final T value, int delay) { + private void push(final Subscriber subscriber, final T value, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onNext(value); + subscriber.onNext(value); } }, delay, TimeUnit.MILLISECONDS); } - private void complete(final Subscriber observer, int delay) { + private void complete(final Subscriber subscriber, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onComplete(); + subscriber.onComplete(); } }, delay, TimeUnit.MILLISECONDS); } @@ -300,8 +300,8 @@ public Flowable apply(Flowable v) throws Exception { public void badSourceCallable() { TestHelper.checkBadSourceFlowable(new Function, Object>() { @Override - public Object apply(Flowable o) throws Exception { - return o.window(Flowable.just(1), Functions.justFunction(Flowable.never())); + public Object apply(Flowable f) throws Exception { + return f.window(Flowable.just(1), Functions.justFunction(Flowable.never())); } }, false, 1, 1, (Object[])null); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java index 019c2d101f..296c973963 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java @@ -27,6 +27,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; @@ -50,14 +51,14 @@ public void testTimedAndCount() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, "one", 10); - push(observer, "two", 90); - push(observer, "three", 110); - push(observer, "four", 190); - push(observer, "five", 210); - complete(observer, 250); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 10); + push(subscriber, "two", 90); + push(subscriber, "three", 110); + push(subscriber, "four", 190); + push(subscriber, "five", 210); + complete(subscriber, 250); } }); @@ -84,14 +85,14 @@ public void testTimed() { Flowable source = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - push(observer, "one", 98); - push(observer, "two", 99); - push(observer, "three", 99); // FIXME happens after the window is open - push(observer, "four", 101); - push(observer, "five", 102); - complete(observer, 150); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 98); + push(subscriber, "two", 99); + push(subscriber, "three", 99); // FIXME happens after the window is open + push(subscriber, "four", 101); + push(subscriber, "five", 102); + complete(subscriber, 150); } }); @@ -115,20 +116,20 @@ private List list(String... args) { return list; } - private void push(final Subscriber observer, final T value, int delay) { + private void push(final Subscriber subscriber, final T value, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onNext(value); + subscriber.onNext(value); } }, delay, TimeUnit.MILLISECONDS); } - private void complete(final Subscriber observer, int delay) { + private void complete(final Subscriber subscriber, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { - observer.onComplete(); + subscriber.onComplete(); } }, delay, TimeUnit.MILLISECONDS); } @@ -366,47 +367,68 @@ public void timeskipOverlapping() { @Test public void exactOnError() { - TestScheduler scheduler = new TestScheduler(); + List errors = TestHelper.trackPluginErrors(); + try { + TestScheduler scheduler = new TestScheduler(); - PublishProcessor pp = PublishProcessor.create(); + PublishProcessor pp = PublishProcessor.create(); - TestSubscriber ts = pp.window(1, 1, TimeUnit.SECONDS, scheduler) - .flatMap(Functions.>identity()) - .test(); + TestSubscriber ts = pp.window(1, 1, TimeUnit.SECONDS, scheduler) + .flatMap(Functions.>identity()) + .test(); + + pp.onError(new TestException()); - pp.onError(new TestException()); + ts.assertFailure(TestException.class); - ts.assertFailure(TestException.class); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void overlappingOnError() { - TestScheduler scheduler = new TestScheduler(); + List errors = TestHelper.trackPluginErrors(); + try { + TestScheduler scheduler = new TestScheduler(); - PublishProcessor pp = PublishProcessor.create(); + PublishProcessor pp = PublishProcessor.create(); - TestSubscriber ts = pp.window(2, 1, TimeUnit.SECONDS, scheduler) - .flatMap(Functions.>identity()) - .test(); + TestSubscriber ts = pp.window(2, 1, TimeUnit.SECONDS, scheduler) + .flatMap(Functions.>identity()) + .test(); + + pp.onError(new TestException()); - pp.onError(new TestException()); + ts.assertFailure(TestException.class); - ts.assertFailure(TestException.class); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void skipOnError() { - TestScheduler scheduler = new TestScheduler(); + List errors = TestHelper.trackPluginErrors(); + try { + TestScheduler scheduler = new TestScheduler(); - PublishProcessor pp = PublishProcessor.create(); + PublishProcessor pp = PublishProcessor.create(); - TestSubscriber ts = pp.window(1, 2, TimeUnit.SECONDS, scheduler) - .flatMap(Functions.>identity()) - .test(); + TestSubscriber ts = pp.window(1, 2, TimeUnit.SECONDS, scheduler) + .flatMap(Functions.>identity()) + .test(); + + pp.onError(new TestException()); - pp.onError(new TestException()); + ts.assertFailure(TestException.class); - ts.assertFailure(TestException.class); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -484,16 +506,23 @@ public void skipBackpressure2() { @Test public void overlapBackpressure2() { - TestScheduler scheduler = new TestScheduler(); + List errors = TestHelper.trackPluginErrors(); + try { + TestScheduler scheduler = new TestScheduler(); - PublishProcessor pp = PublishProcessor.create(); + PublishProcessor pp = PublishProcessor.create(); - TestSubscriber> ts = pp.window(2, 1, TimeUnit.SECONDS, scheduler) - .test(1L); + TestSubscriber> ts = pp.window(2, 1, TimeUnit.SECONDS, scheduler) + .test(1L); - scheduler.advanceTimeBy(2, TimeUnit.SECONDS); + scheduler.advanceTimeBy(2, TimeUnit.SECONDS); - ts.assertError(MissingBackpressureException.class); + ts.assertError(MissingBackpressureException.class); + + TestHelper.assertError(errors, 0, MissingBackpressureException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java index 360aa9c3bc..e87ff9fe50 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java @@ -51,35 +51,35 @@ public void testSimple() { PublishProcessor source = PublishProcessor.create(); PublishProcessor other = PublishProcessor.create(); - Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); Flowable result = source.withLatestFrom(other, COMBINER); - result.subscribe(o); + result.subscribe(subscriber); source.onNext(1); - inOrder.verify(o, never()).onNext(anyInt()); + inOrder.verify(subscriber, never()).onNext(anyInt()); other.onNext(1); - inOrder.verify(o, never()).onNext(anyInt()); + inOrder.verify(subscriber, never()).onNext(anyInt()); source.onNext(2); - inOrder.verify(o).onNext((2 << 8) + 1); + inOrder.verify(subscriber).onNext((2 << 8) + 1); other.onNext(2); - inOrder.verify(o, never()).onNext(anyInt()); + inOrder.verify(subscriber, never()).onNext(anyInt()); other.onComplete(); - inOrder.verify(o, never()).onComplete(); + inOrder.verify(subscriber, never()).onComplete(); source.onNext(3); - inOrder.verify(o).onNext((3 << 8) + 2); + inOrder.verify(subscriber).onNext((3 << 8) + 2); source.onComplete(); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -641,12 +641,12 @@ public void manyErrors() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onError(new TestException("First")); - observer.onNext(1); - observer.onError(new TestException("Second")); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onError(new TestException("First")); + subscriber.onNext(1); + subscriber.onError(new TestException("Second")); + subscriber.onComplete(); } }.withLatestFrom(Flowable.just(2), Flowable.just(3), new Function3() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipCompletionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipCompletionTest.java index 546fdfe62b..6c46093017 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipCompletionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipCompletionTest.java @@ -35,7 +35,7 @@ public class FlowableZipCompletionTest { PublishProcessor s2; Flowable zipped; - Subscriber observer; + Subscriber subscriber; InOrder inOrder; @Before @@ -51,10 +51,10 @@ public String apply(String t1, String t2) { s2 = PublishProcessor.create(); zipped = Flowable.zip(s1, s2, concat2Strings); - observer = TestHelper.mockSubscriber(); - inOrder = inOrder(observer); + subscriber = TestHelper.mockSubscriber(); + inOrder = inOrder(subscriber); - zipped.subscribe(observer); + zipped.subscribe(subscriber); } @Test @@ -63,10 +63,10 @@ public void testFirstCompletesThenSecondInfinite() { s1.onNext("b"); s1.onComplete(); s2.onNext("1"); - inOrder.verify(observer, times(1)).onNext("a-1"); + inOrder.verify(subscriber, times(1)).onNext("a-1"); s2.onNext("2"); - inOrder.verify(observer, times(1)).onNext("b-2"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("b-2"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -75,11 +75,11 @@ public void testSecondInfiniteThenFirstCompletes() { s2.onNext("1"); s2.onNext("2"); s1.onNext("a"); - inOrder.verify(observer, times(1)).onNext("a-1"); + inOrder.verify(subscriber, times(1)).onNext("a-1"); s1.onNext("b"); - inOrder.verify(observer, times(1)).onNext("b-2"); + inOrder.verify(subscriber, times(1)).onNext("b-2"); s1.onComplete(); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -89,10 +89,10 @@ public void testSecondCompletesThenFirstInfinite() { s2.onNext("2"); s2.onComplete(); s1.onNext("a"); - inOrder.verify(observer, times(1)).onNext("a-1"); + inOrder.verify(subscriber, times(1)).onNext("a-1"); s1.onNext("b"); - inOrder.verify(observer, times(1)).onNext("b-2"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("b-2"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -101,11 +101,11 @@ public void testFirstInfiniteThenSecondCompletes() { s1.onNext("a"); s1.onNext("b"); s2.onNext("1"); - inOrder.verify(observer, times(1)).onNext("a-1"); + inOrder.verify(subscriber, times(1)).onNext("a-1"); s2.onNext("2"); - inOrder.verify(observer, times(1)).onNext("b-2"); + inOrder.verify(subscriber, times(1)).onNext("b-2"); s2.onComplete(); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java index c273d8be14..a86de18f52 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java @@ -38,7 +38,7 @@ public class FlowableZipIterableTest { PublishProcessor s2; Flowable zipped; - Subscriber observer; + Subscriber subscriber; InOrder inOrder; @Before @@ -54,10 +54,10 @@ public String apply(String t1, String t2) { s2 = PublishProcessor.create(); zipped = Flowable.zip(s1, s2, concat2Strings); - observer = TestHelper.mockSubscriber(); - inOrder = inOrder(observer); + subscriber = TestHelper.mockSubscriber(); + inOrder = inOrder(subscriber); - zipped.subscribe(observer); + zipped.subscribe(subscriber); } BiFunction zipr2 = new BiFunction() { @@ -81,24 +81,24 @@ public String apply(Object t1, Object t2, Object t3) { public void testZipIterableSameSize() { PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber o = TestHelper.mockSubscriber(); - InOrder io = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder io = inOrder(subscriber); Iterable r2 = Arrays.asList("1", "2", "3"); - r1.zipWith(r2, zipr2).subscribe(o); + r1.zipWith(r2, zipr2).subscribe(subscriber); r1.onNext("one-"); r1.onNext("two-"); r1.onNext("three-"); r1.onComplete(); - io.verify(o).onNext("one-1"); - io.verify(o).onNext("two-2"); - io.verify(o).onNext("three-3"); - io.verify(o).onComplete(); + io.verify(subscriber).onNext("one-1"); + io.verify(subscriber).onNext("two-2"); + io.verify(subscriber).onNext("three-3"); + io.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @@ -106,19 +106,19 @@ public void testZipIterableSameSize() { public void testZipIterableEmptyFirstSize() { PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber o = TestHelper.mockSubscriber(); - InOrder io = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder io = inOrder(subscriber); Iterable r2 = Arrays.asList("1", "2", "3"); - r1.zipWith(r2, zipr2).subscribe(o); + r1.zipWith(r2, zipr2).subscribe(subscriber); r1.onComplete(); - io.verify(o).onComplete(); + io.verify(subscriber).onComplete(); - verify(o, never()).onNext(any(String.class)); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @@ -126,44 +126,44 @@ public void testZipIterableEmptyFirstSize() { public void testZipIterableEmptySecond() { PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber o = TestHelper.mockSubscriber(); - InOrder io = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder io = inOrder(subscriber); Iterable r2 = Arrays.asList(); - r1.zipWith(r2, zipr2).subscribe(o); + r1.zipWith(r2, zipr2).subscribe(subscriber); r1.onNext("one-"); r1.onNext("two-"); r1.onNext("three-"); r1.onComplete(); - io.verify(o).onComplete(); + io.verify(subscriber).onComplete(); - verify(o, never()).onNext(any(String.class)); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testZipIterableFirstShorter() { PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber o = TestHelper.mockSubscriber(); - InOrder io = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder io = inOrder(subscriber); Iterable r2 = Arrays.asList("1", "2", "3"); - r1.zipWith(r2, zipr2).subscribe(o); + r1.zipWith(r2, zipr2).subscribe(subscriber); r1.onNext("one-"); r1.onNext("two-"); r1.onComplete(); - io.verify(o).onNext("one-1"); - io.verify(o).onNext("two-2"); - io.verify(o).onComplete(); + io.verify(subscriber).onNext("one-1"); + io.verify(subscriber).onNext("two-2"); + io.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @@ -171,23 +171,23 @@ public void testZipIterableFirstShorter() { public void testZipIterableSecondShorter() { PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber o = TestHelper.mockSubscriber(); - InOrder io = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder io = inOrder(subscriber); Iterable r2 = Arrays.asList("1", "2"); - r1.zipWith(r2, zipr2).subscribe(o); + r1.zipWith(r2, zipr2).subscribe(subscriber); r1.onNext("one-"); r1.onNext("two-"); r1.onNext("three-"); r1.onComplete(); - io.verify(o).onNext("one-1"); - io.verify(o).onNext("two-2"); - io.verify(o).onComplete(); + io.verify(subscriber).onNext("one-1"); + io.verify(subscriber).onNext("two-2"); + io.verify(subscriber).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @@ -195,22 +195,22 @@ public void testZipIterableSecondShorter() { public void testZipIterableFirstThrows() { PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber o = TestHelper.mockSubscriber(); - InOrder io = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder io = inOrder(subscriber); Iterable r2 = Arrays.asList("1", "2", "3"); - r1.zipWith(r2, zipr2).subscribe(o); + r1.zipWith(r2, zipr2).subscribe(subscriber); r1.onNext("one-"); r1.onNext("two-"); r1.onError(new TestException()); - io.verify(o).onNext("one-1"); - io.verify(o).onNext("two-2"); - io.verify(o).onError(any(TestException.class)); + io.verify(subscriber).onNext("one-1"); + io.verify(subscriber).onNext("two-2"); + io.verify(subscriber).onError(any(TestException.class)); - verify(o, never()).onComplete(); + verify(subscriber, never()).onComplete(); } @@ -218,8 +218,8 @@ public void testZipIterableFirstThrows() { public void testZipIterableIteratorThrows() { PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber o = TestHelper.mockSubscriber(); - InOrder io = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder io = inOrder(subscriber); Iterable r2 = new Iterable() { @Override @@ -228,16 +228,16 @@ public Iterator iterator() { } }; - r1.zipWith(r2, zipr2).subscribe(o); + r1.zipWith(r2, zipr2).subscribe(subscriber); r1.onNext("one-"); r1.onNext("two-"); r1.onError(new TestException()); - io.verify(o).onError(any(TestException.class)); + io.verify(subscriber).onError(any(TestException.class)); - verify(o, never()).onComplete(); - verify(o, never()).onNext(any(String.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any(String.class)); } @@ -245,8 +245,8 @@ public Iterator iterator() { public void testZipIterableHasNextThrows() { PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber o = TestHelper.mockSubscriber(); - InOrder io = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder io = inOrder(subscriber); Iterable r2 = new Iterable() { @@ -279,15 +279,15 @@ public void remove() { }; - r1.zipWith(r2, zipr2).subscribe(o); + r1.zipWith(r2, zipr2).subscribe(subscriber); r1.onNext("one-"); r1.onError(new TestException()); - io.verify(o).onNext("one-1"); - io.verify(o).onError(any(TestException.class)); + io.verify(subscriber).onNext("one-1"); + io.verify(subscriber).onError(any(TestException.class)); - verify(o, never()).onComplete(); + verify(subscriber, never()).onComplete(); } @@ -295,8 +295,8 @@ public void remove() { public void testZipIterableNextThrows() { PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber o = TestHelper.mockSubscriber(); - InOrder io = inOrder(o); + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder io = inOrder(subscriber); Iterable r2 = new Iterable() { @@ -323,14 +323,14 @@ public void remove() { }; - r1.zipWith(r2, zipr2).subscribe(o); + r1.zipWith(r2, zipr2).subscribe(subscriber); r1.onError(new TestException()); - io.verify(o).onError(any(TestException.class)); + io.verify(subscriber).onError(any(TestException.class)); - verify(o, never()).onNext(any(String.class)); - verify(o, never()).onComplete(); + verify(subscriber, never()).onNext(any(String.class)); + verify(subscriber, never()).onComplete(); } @@ -353,12 +353,12 @@ public String apply(Integer t1) { @Test public void testTake2() { - Flowable o = Flowable.just(1, 2, 3, 4, 5); + Flowable f = Flowable.just(1, 2, 3, 4, 5); Iterable it = Arrays.asList("a", "b", "c", "d", "e"); SquareStr squareStr = new SquareStr(); - o.map(squareStr).zipWith(it, concat2Strings).take(2).subscribe(printer); + f.map(squareStr).zipWith(it, concat2Strings).take(2).subscribe(printer); assertEquals(2, squareStr.counter.get()); } @@ -377,8 +377,8 @@ public Object apply(Integer a, Integer b) throws Exception { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.zipWith(Arrays.asList(1), new BiFunction() { + public Flowable apply(Flowable f) throws Exception { + return f.zipWith(Arrays.asList(1), new BiFunction() { @Override public Object apply(Integer a, Integer b) throws Exception { return a + b; @@ -406,13 +406,13 @@ public void badSource() { try { new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onComplete(); - observer.onNext(2); - observer.onError(new TestException()); - observer.onComplete(); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(1); + subscriber.onComplete(); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); } } .zipWith(Arrays.asList(1), new BiFunction() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java index d7304d26ff..b02fa664fe 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java @@ -43,7 +43,7 @@ public class FlowableZipTest { PublishProcessor s2; Flowable zipped; - Subscriber observer; + Subscriber subscriber; InOrder inOrder; @Before @@ -59,10 +59,10 @@ public String apply(String t1, String t2) { s2 = PublishProcessor.create(); zipped = Flowable.zip(s1, s2, concat2Strings); - observer = TestHelper.mockSubscriber(); - inOrder = inOrder(observer); + subscriber = TestHelper.mockSubscriber(); + inOrder = inOrder(subscriber); - zipped.subscribe(observer); + zipped.subscribe(subscriber); } @SuppressWarnings("unchecked") @@ -72,16 +72,16 @@ public void testCollectionSizeDifferentThanFunction() { //Function3 /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); @SuppressWarnings("rawtypes") Collection ws = java.util.Collections.singleton(Flowable.just("one", "two")); Flowable w = Flowable.zip(ws, zipr); - w.subscribe(observer); + w.subscribe(subscriber); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, never()).onNext(any(String.class)); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, never()).onNext(any(String.class)); } @Test @@ -99,18 +99,18 @@ public void testStartpingDifferentLengthFlowableSequences1() { /* simulate sending data */ // once for w1 - w1.observer.onNext("1a"); - w1.observer.onComplete(); + w1.subscriber.onNext("1a"); + w1.subscriber.onComplete(); // twice for w2 - w2.observer.onNext("2a"); - w2.observer.onNext("2b"); - w2.observer.onComplete(); + w2.subscriber.onNext("2a"); + w2.subscriber.onNext("2b"); + w2.subscriber.onComplete(); // 4 times for w3 - w3.observer.onNext("3a"); - w3.observer.onNext("3b"); - w3.observer.onNext("3c"); - w3.observer.onNext("3d"); - w3.observer.onComplete(); + w3.subscriber.onNext("3a"); + w3.subscriber.onNext("3b"); + w3.subscriber.onNext("3c"); + w3.subscriber.onNext("3d"); + w3.subscriber.onComplete(); /* we should have been called 1 time on the Subscriber */ InOrder io = inOrder(w); @@ -132,18 +132,18 @@ public void testStartpingDifferentLengthFlowableSequences2() { /* simulate sending data */ // 4 times for w1 - w1.observer.onNext("1a"); - w1.observer.onNext("1b"); - w1.observer.onNext("1c"); - w1.observer.onNext("1d"); - w1.observer.onComplete(); + w1.subscriber.onNext("1a"); + w1.subscriber.onNext("1b"); + w1.subscriber.onNext("1c"); + w1.subscriber.onNext("1d"); + w1.subscriber.onComplete(); // twice for w2 - w2.observer.onNext("2a"); - w2.observer.onNext("2b"); - w2.observer.onComplete(); + w2.subscriber.onNext("2a"); + w2.subscriber.onNext("2b"); + w2.subscriber.onComplete(); // 1 times for w3 - w3.observer.onNext("3a"); - w3.observer.onComplete(); + w3.subscriber.onNext("3a"); + w3.subscriber.onComplete(); /* we should have been called 1 time on the Subscriber */ InOrder io = inOrder(w); @@ -178,32 +178,32 @@ public void testAggregatorSimple() { PublishProcessor r1 = PublishProcessor.create(); PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(subscriber); /* simulate the Flowables pushing data into the aggregator */ r1.onNext("hello"); r2.onNext("world"); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - inOrder.verify(observer, times(1)).onNext("helloworld"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("helloworld"); r1.onNext("hello "); r2.onNext("again"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - inOrder.verify(observer, times(1)).onNext("hello again"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("hello again"); r1.onComplete(); r2.onComplete(); - inOrder.verify(observer, never()).onNext(anyString()); - verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, never()).onNext(anyString()); + verify(subscriber, times(1)).onComplete(); } @Test @@ -213,26 +213,26 @@ public void testAggregatorDifferentSizedResultsWithOnComplete() { PublishProcessor r1 = PublishProcessor.create(); PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); - Flowable.zip(r1, r2, zipr2).subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + Flowable.zip(r1, r2, zipr2).subscribe(subscriber); /* simulate the Flowables pushing data into the aggregator */ r1.onNext("hello"); r2.onNext("world"); r2.onComplete(); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(observer, never()).onError(any(Throwable.class)); - inOrder.verify(observer, times(1)).onNext("helloworld"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("helloworld"); + inOrder.verify(subscriber, times(1)).onComplete(); r1.onNext("hi"); r1.onComplete(); - inOrder.verify(observer, never()).onError(any(Throwable.class)); - inOrder.verify(observer, never()).onComplete(); - inOrder.verify(observer, never()).onNext(anyString()); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext(anyString()); } @Test @@ -240,27 +240,27 @@ public void testAggregateMultipleTypes() { PublishProcessor r1 = PublishProcessor.create(); PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(subscriber); /* simulate the Flowables pushing data into the aggregator */ r1.onNext("hello"); r2.onNext(1); r2.onComplete(); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(observer, never()).onError(any(Throwable.class)); - inOrder.verify(observer, times(1)).onNext("hello1"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onNext("hello1"); + inOrder.verify(subscriber, times(1)).onComplete(); r1.onNext("hi"); r1.onComplete(); - inOrder.verify(observer, never()).onError(any(Throwable.class)); - inOrder.verify(observer, never()).onComplete(); - inOrder.verify(observer, never()).onNext(anyString()); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext(anyString()); } @Test @@ -269,18 +269,18 @@ public void testAggregate3Types() { PublishProcessor r2 = PublishProcessor.create(); PublishProcessor> r3 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.zip(r1, r2, r3, zipr3).subscribe(observer); + Flowable.zip(r1, r2, r3, zipr3).subscribe(subscriber); /* simulate the Flowables pushing data into the aggregator */ r1.onNext("hello"); r2.onNext(2); r3.onNext(Arrays.asList(5, 6, 7)); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, times(1)).onNext("hello2[5, 6, 7]"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onNext("hello2[5, 6, 7]"); } @Test @@ -288,9 +288,9 @@ public void testAggregatorsWithDifferentSizesAndTiming() { PublishProcessor r1 = PublishProcessor.create(); PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(subscriber); /* simulate the Flowables pushing data into the aggregator */ r1.onNext("one"); @@ -298,24 +298,24 @@ public void testAggregatorsWithDifferentSizesAndTiming() { r1.onNext("three"); r2.onNext("A"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, times(1)).onNext("oneA"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onNext("oneA"); r1.onNext("four"); r1.onComplete(); r2.onNext("B"); - verify(observer, times(1)).onNext("twoB"); + verify(subscriber, times(1)).onNext("twoB"); r2.onNext("C"); - verify(observer, times(1)).onNext("threeC"); + verify(subscriber, times(1)).onNext("threeC"); r2.onNext("D"); - verify(observer, times(1)).onNext("fourD"); + verify(subscriber, times(1)).onNext("fourD"); r2.onNext("E"); - verify(observer, never()).onNext("E"); + verify(subscriber, never()).onNext("E"); r2.onComplete(); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -323,26 +323,26 @@ public void testAggregatorError() { PublishProcessor r1 = PublishProcessor.create(); PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(subscriber); /* simulate the Flowables pushing data into the aggregator */ r1.onNext("hello"); r2.onNext("world"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, times(1)).onNext("helloworld"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onNext("helloworld"); r1.onError(new RuntimeException("")); r1.onNext("hello"); r2.onNext("again"); - verify(observer, times(1)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); + verify(subscriber, times(1)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); // we don't want to be called again after an error - verify(observer, times(0)).onNext("helloagain"); + verify(subscriber, times(0)).onNext("helloagain"); } @Test @@ -350,8 +350,8 @@ public void testAggregatorUnsubscribe() { PublishProcessor r1 = PublishProcessor.create(); PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); Flowable.zip(r1, r2, zipr2).subscribe(ts); @@ -359,18 +359,18 @@ public void testAggregatorUnsubscribe() { r1.onNext("hello"); r2.onNext("world"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); - verify(observer, times(1)).onNext("helloworld"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); + verify(subscriber, times(1)).onNext("helloworld"); ts.dispose(); r1.onNext("hello"); r2.onNext("again"); - verify(observer, times(0)).onError(any(Throwable.class)); - verify(observer, never()).onComplete(); + verify(subscriber, times(0)).onError(any(Throwable.class)); + verify(subscriber, never()).onComplete(); // we don't want to be called again after an error - verify(observer, times(0)).onNext("helloagain"); + verify(subscriber, times(0)).onNext("helloagain"); } @Test @@ -378,9 +378,9 @@ public void testAggregatorEarlyCompletion() { PublishProcessor r1 = PublishProcessor.create(); PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - Flowable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(subscriber); /* simulate the Flowables pushing data into the aggregator */ r1.onNext("one"); @@ -388,17 +388,17 @@ public void testAggregatorEarlyCompletion() { r1.onComplete(); r2.onNext("A"); - InOrder inOrder = inOrder(observer); + InOrder inOrder = inOrder(subscriber); - inOrder.verify(observer, never()).onError(any(Throwable.class)); - inOrder.verify(observer, never()).onComplete(); - inOrder.verify(observer, times(1)).onNext("oneA"); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, never()).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("oneA"); r2.onComplete(); - inOrder.verify(observer, never()).onError(any(Throwable.class)); - inOrder.verify(observer, times(1)).onComplete(); - inOrder.verify(observer, never()).onNext(anyString()); + inOrder.verify(subscriber, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onComplete(); + inOrder.verify(subscriber, never()).onNext(anyString()); } @Test @@ -406,16 +406,16 @@ public void testStart2Types() { BiFunction zipr = getConcatStringIntegerZipr(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable w = Flowable.zip(Flowable.just("one", "two"), Flowable.just(2, 3, 4), zipr); - w.subscribe(observer); + w.subscribe(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("one2"); - verify(observer, times(1)).onNext("two3"); - verify(observer, never()).onNext("4"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one2"); + verify(subscriber, times(1)).onNext("two3"); + verify(subscriber, never()).onNext("4"); } @Test @@ -423,27 +423,27 @@ public void testStart3Types() { Function3 zipr = getConcatStringIntegerIntArrayZipr(); /* define a Subscriber to receive aggregated events */ - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable w = Flowable.zip(Flowable.just("one", "two"), Flowable.just(2), Flowable.just(new int[] { 4, 5, 6 }), zipr); - w.subscribe(observer); + w.subscribe(subscriber); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); - verify(observer, times(1)).onNext("one2[4, 5, 6]"); - verify(observer, never()).onNext("two"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one2[4, 5, 6]"); + verify(subscriber, never()).onNext("two"); } @Test public void testOnNextExceptionInvokesOnError() { BiFunction zipr = getDivideZipr(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable w = Flowable.zip(Flowable.just(10, 20, 30), Flowable.just(0, 1, 2), zipr); - w.subscribe(observer); + w.subscribe(subscriber); - verify(observer, times(1)).onError(any(Throwable.class)); + verify(subscriber, times(1)).onError(any(Throwable.class)); } @Test @@ -453,8 +453,8 @@ public void testOnFirstCompletion() { Subscriber obs = TestHelper.mockSubscriber(); - Flowable o = Flowable.zip(oA, oB, getConcat2Strings()); - o.subscribe(obs); + Flowable f = Flowable.zip(oA, oB, getConcat2Strings()); + f.subscribe(obs); InOrder io = inOrder(obs); @@ -503,8 +503,8 @@ public void testOnErrorTermination() { Subscriber obs = TestHelper.mockSubscriber(); - Flowable o = Flowable.zip(oA, oB, getConcat2Strings()); - o.subscribe(obs); + Flowable f = Flowable.zip(oA, oB, getConcat2Strings()); + f.subscribe(obs); InOrder io = inOrder(obs); @@ -619,13 +619,13 @@ private static String getStringValue(Object o) { private static class TestFlowable implements Publisher { - Subscriber observer; + Subscriber subscriber; @Override - public void subscribe(Subscriber observer) { + public void subscribe(Subscriber subscriber) { // just store the variable where it can be accessed so we can manually trigger it - this.observer = observer; - observer.onSubscribe(new BooleanSubscription()); + this.subscriber = subscriber; + subscriber.onSubscribe(new BooleanSubscription()); } } @@ -636,10 +636,10 @@ public void testFirstCompletesThenSecondInfinite() { s1.onNext("b"); s1.onComplete(); s2.onNext("1"); - inOrder.verify(observer, times(1)).onNext("a-1"); + inOrder.verify(subscriber, times(1)).onNext("a-1"); s2.onNext("2"); - inOrder.verify(observer, times(1)).onNext("b-2"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("b-2"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -648,11 +648,11 @@ public void testSecondInfiniteThenFirstCompletes() { s2.onNext("1"); s2.onNext("2"); s1.onNext("a"); - inOrder.verify(observer, times(1)).onNext("a-1"); + inOrder.verify(subscriber, times(1)).onNext("a-1"); s1.onNext("b"); - inOrder.verify(observer, times(1)).onNext("b-2"); + inOrder.verify(subscriber, times(1)).onNext("b-2"); s1.onComplete(); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -662,10 +662,10 @@ public void testSecondCompletesThenFirstInfinite() { s2.onNext("2"); s2.onComplete(); s1.onNext("a"); - inOrder.verify(observer, times(1)).onNext("a-1"); + inOrder.verify(subscriber, times(1)).onNext("a-1"); s1.onNext("b"); - inOrder.verify(observer, times(1)).onNext("b-2"); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("b-2"); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -674,11 +674,11 @@ public void testFirstInfiniteThenSecondCompletes() { s1.onNext("a"); s1.onNext("b"); s2.onNext("1"); - inOrder.verify(observer, times(1)).onNext("a-1"); + inOrder.verify(subscriber, times(1)).onNext("a-1"); s2.onNext("2"); - inOrder.verify(observer, times(1)).onNext("b-2"); + inOrder.verify(subscriber, times(1)).onNext("b-2"); s2.onComplete(); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -687,14 +687,14 @@ public void testFirstFails() { s2.onNext("a"); s1.onError(new RuntimeException("Forced failure")); - inOrder.verify(observer, times(1)).onError(any(RuntimeException.class)); + inOrder.verify(subscriber, times(1)).onError(any(RuntimeException.class)); s2.onNext("b"); s1.onNext("1"); s1.onNext("2"); - inOrder.verify(observer, never()).onComplete(); - inOrder.verify(observer, never()).onNext(any(String.class)); + inOrder.verify(subscriber, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext(any(String.class)); inOrder.verifyNoMoreInteractions(); } @@ -704,13 +704,13 @@ public void testSecondFails() { s1.onNext("b"); s2.onError(new RuntimeException("Forced failure")); - inOrder.verify(observer, times(1)).onError(any(RuntimeException.class)); + inOrder.verify(subscriber, times(1)).onError(any(RuntimeException.class)); s2.onNext("1"); s2.onNext("2"); - inOrder.verify(observer, never()).onComplete(); - inOrder.verify(observer, never()).onNext(any(String.class)); + inOrder.verify(subscriber, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext(any(String.class)); inOrder.verifyNoMoreInteractions(); } @@ -718,14 +718,14 @@ public void testSecondFails() { public void testStartWithOnCompletedTwice() { // issue: https://groups.google.com/forum/#!topic/rxjava/79cWTv3TFp0 // The problem is the original "zip" implementation does not wrap - // an internal observer with a SafeSubscriber. However, in the "zip", + // an internal subscriber with a SafeSubscriber. However, in the "zip", // it may calls "onComplete" twice. That breaks the Rx contract. // This test tries to emulate this case. // As "TestHelper.mockSubscriber()" will create an instance in the package "rx", - // we need to wrap "TestHelper.mockSubscriber()" with an observer instance + // we need to wrap "TestHelper.mockSubscriber()" with an subscriber instance // which is in the package "rx.operators". - final Subscriber observer = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); Flowable.zip(Flowable.just(1), Flowable.just(1), new BiFunction() { @@ -737,24 +737,24 @@ public Integer apply(Integer a, Integer b) { @Override public void onComplete() { - observer.onComplete(); + subscriber.onComplete(); } @Override public void onError(Throwable e) { - observer.onError(e); + subscriber.onError(e); } @Override public void onNext(Integer args) { - observer.onNext(args); + subscriber.onNext(args); } }); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(2); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, times(1)).onNext(2); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -858,7 +858,7 @@ public void onNext(String s) { public void testEmitNull() { Flowable oi = Flowable.just(1, null, 3); Flowable os = Flowable.just("a", "b", null); - Flowable o = Flowable.zip(oi, os, new BiFunction() { + Flowable f = Flowable.zip(oi, os, new BiFunction() { @Override public String apply(Integer t1, String t2) { @@ -868,7 +868,7 @@ public String apply(Integer t1, String t2) { }); final ArrayList list = new ArrayList(); - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String s) { @@ -906,7 +906,7 @@ static String value(Notification notification) { public void testEmitMaterializedNotifications() { Flowable> oi = Flowable.just(1, 2, 3).materialize(); Flowable> os = Flowable.just("a", "b", "c").materialize(); - Flowable o = Flowable.zip(oi, os, new BiFunction, Notification, String>() { + Flowable f = Flowable.zip(oi, os, new BiFunction, Notification, String>() { @Override public String apply(Notification t1, Notification t2) { @@ -916,7 +916,7 @@ public String apply(Notification t1, Notification t2) { }); final ArrayList list = new ArrayList(); - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String s) { @@ -935,7 +935,7 @@ public void accept(String s) { @Test public void testStartEmptyFlowables() { - Flowable o = Flowable.zip(Flowable. empty(), Flowable. empty(), new BiFunction() { + Flowable f = Flowable.zip(Flowable. empty(), Flowable. empty(), new BiFunction() { @Override public String apply(Integer t1, String t2) { @@ -945,7 +945,7 @@ public String apply(Integer t1, String t2) { }); final ArrayList list = new ArrayList(); - o.subscribe(new Consumer() { + f.subscribe(new Consumer() { @Override public void accept(String s) { @@ -963,7 +963,7 @@ public void testStartEmptyList() { final Object invoked = new Object(); Collection> observables = Collections.emptyList(); - Flowable o = Flowable.zip(observables, new Function() { + Flowable f = Flowable.zip(observables, new Function() { @Override public Object apply(final Object[] args) { assertEquals("No argument should have been passed", 0, args.length); @@ -972,7 +972,7 @@ public Object apply(final Object[] args) { }); TestSubscriber ts = new TestSubscriber(); - o.subscribe(ts); + f.subscribe(ts); ts.awaitTerminalEvent(200, TimeUnit.MILLISECONDS); ts.assertNoValues(); } @@ -987,7 +987,7 @@ public void testStartEmptyListBlocking() { final Object invoked = new Object(); Collection> observables = Collections.emptyList(); - Flowable o = Flowable.zip(observables, new Function() { + Flowable f = Flowable.zip(observables, new Function() { @Override public Object apply(final Object[] args) { assertEquals("No argument should have been passed", 0, args.length); @@ -995,18 +995,18 @@ public Object apply(final Object[] args) { } }); - o.blockingLast(); + f.blockingLast(); } @Test public void testBackpressureSync() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Flowable o1 = createInfiniteFlowable(generatedA); - Flowable o2 = createInfiniteFlowable(generatedB); + Flowable f1 = createInfiniteFlowable(generatedA); + Flowable f2 = createInfiniteFlowable(generatedB); TestSubscriber ts = new TestSubscriber(); - Flowable.zip(o1, o2, new BiFunction() { + Flowable.zip(f1, f2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { @@ -1026,11 +1026,11 @@ public String apply(Integer t1, Integer t2) { public void testBackpressureAsync() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Flowable o1 = createInfiniteFlowable(generatedA).subscribeOn(Schedulers.computation()); - Flowable o2 = createInfiniteFlowable(generatedB).subscribeOn(Schedulers.computation()); + Flowable f1 = createInfiniteFlowable(generatedA).subscribeOn(Schedulers.computation()); + Flowable f2 = createInfiniteFlowable(generatedB).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber(); - Flowable.zip(o1, o2, new BiFunction() { + Flowable.zip(f1, f2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { @@ -1050,11 +1050,11 @@ public String apply(Integer t1, Integer t2) { public void testDownstreamBackpressureRequestsWithFiniteSyncFlowables() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Flowable o1 = createInfiniteFlowable(generatedA).take(Flowable.bufferSize() * 2); - Flowable o2 = createInfiniteFlowable(generatedB).take(Flowable.bufferSize() * 2); + Flowable f1 = createInfiniteFlowable(generatedA).take(Flowable.bufferSize() * 2); + Flowable f2 = createInfiniteFlowable(generatedB).take(Flowable.bufferSize() * 2); TestSubscriber ts = new TestSubscriber(); - Flowable.zip(o1, o2, new BiFunction() { + Flowable.zip(f1, f2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { @@ -1075,11 +1075,11 @@ public String apply(Integer t1, Integer t2) { public void testDownstreamBackpressureRequestsWithInfiniteAsyncFlowables() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Flowable o1 = createInfiniteFlowable(generatedA).subscribeOn(Schedulers.computation()); - Flowable o2 = createInfiniteFlowable(generatedB).subscribeOn(Schedulers.computation()); + Flowable f1 = createInfiniteFlowable(generatedA).subscribeOn(Schedulers.computation()); + Flowable f2 = createInfiniteFlowable(generatedB).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber(); - Flowable.zip(o1, o2, new BiFunction() { + Flowable.zip(f1, f2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { @@ -1100,11 +1100,11 @@ public String apply(Integer t1, Integer t2) { public void testDownstreamBackpressureRequestsWithInfiniteSyncFlowables() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Flowable o1 = createInfiniteFlowable(generatedA); - Flowable o2 = createInfiniteFlowable(generatedB); + Flowable f1 = createInfiniteFlowable(generatedA); + Flowable f2 = createInfiniteFlowable(generatedB); TestSubscriber ts = new TestSubscriber(); - Flowable.zip(o1, o2, new BiFunction() { + Flowable.zip(f1, f2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { @@ -1122,7 +1122,7 @@ public String apply(Integer t1, Integer t2) { } private Flowable createInfiniteFlowable(final AtomicInteger generated) { - Flowable observable = Flowable.fromIterable(new Iterable() { + Flowable flowable = Flowable.fromIterable(new Iterable() { @Override public Iterator iterator() { return new Iterator() { @@ -1143,7 +1143,7 @@ public boolean hasNext() { }; } }); - return observable; + return flowable; } Flowable OBSERVABLE_OF_5_INTEGERS = OBSERVABLE_OF_5_INTEGERS(new AtomicInteger()); @@ -1152,18 +1152,18 @@ Flowable OBSERVABLE_OF_5_INTEGERS(final AtomicInteger numEmitted) { return Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber o) { + public void subscribe(final Subscriber subscriber) { BooleanSubscription bs = new BooleanSubscription(); - o.onSubscribe(bs); + subscriber.onSubscribe(bs); for (int i = 1; i <= 5; i++) { if (bs.isCancelled()) { break; } numEmitted.incrementAndGet(); - o.onNext(i); + subscriber.onNext(i); Thread.yield(); } - o.onComplete(); + subscriber.onComplete(); } }); @@ -1173,9 +1173,9 @@ Flowable ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(final CountDownLatch lat return Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber o) { + public void subscribe(final Subscriber subscriber) { final BooleanSubscription bs = new BooleanSubscription(); - o.onSubscribe(bs); + subscriber.onSubscribe(bs); Thread t = new Thread(new Runnable() { @Override @@ -1184,10 +1184,10 @@ public void run() { System.out.println("Starting thread: " + Thread.currentThread()); int i = 1; while (!bs.isCancelled()) { - o.onNext(i++); + subscriber.onNext(i++); Thread.yield(); } - o.onComplete(); + subscriber.onComplete(); latch.countDown(); System.out.println("Ending thread: " + Thread.currentThread()); } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionTest.java index 0b082b5899..e1f7886cb3 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionTest.java @@ -122,12 +122,12 @@ public void withPublisherCallAfterTerminalEvent() { try { Flowable f = new Flowable() { @Override - protected void subscribeActual(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext(1); - observer.onError(new TestException()); - observer.onComplete(); - observer.onNext(2); + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(1); + subscriber.onError(new TestException()); + subscriber.onComplete(); + subscriber.onNext(2); } }; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java index 6df94cbd82..81930eb12c 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java @@ -61,11 +61,11 @@ public void onSubscribeCrash() { new Maybe() { @Override - protected void subscribeActual(MaybeObserver s) { - s.onSubscribe(bs); - s.onError(new TestException("Second")); - s.onComplete(); - s.onSuccess(1); + protected void subscribeActual(MaybeObserver observer) { + observer.onSubscribe(bs); + observer.onError(new TestException("Second")); + observer.onComplete(); + observer.onSuccess(1); } } .doOnSubscribe(new Consumer() { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java index 28fabf6080..c78a7cf5d7 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java @@ -410,14 +410,14 @@ public Object call() throws Exception { public MaybeSource apply(Object v) throws Exception { return Maybe.wrap(new MaybeSource() { @Override - public void subscribe(MaybeObserver s) { + public void subscribe(MaybeObserver observer) { Disposable d1 = Disposables.empty(); - s.onSubscribe(d1); + observer.onSubscribe(d1); Disposable d2 = Disposables.empty(); - s.onSubscribe(d2); + observer.onSubscribe(d2); assertFalse(d1.isDisposed()); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java index fb732ff878..b02992e9fc 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java @@ -240,10 +240,10 @@ public void mainErrorAfterInnerError() { try { new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onError(new TestException("outer")); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onError(new TestException("outer")); } } .concatMapMaybe( diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java index b5743dd5d7..cdd5326368 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java @@ -155,10 +155,10 @@ public void mainErrorAfterInnerError() { try { new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onError(new TestException("outer")); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onError(new TestException("outer")); } } .concatMapSingle( diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletableTest.java index 72d4af0d52..c8b1bd3bc4 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletableTest.java @@ -312,10 +312,10 @@ public void innerErrorThenMainError() { try { new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onError(new TestException("main")); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onError(new TestException("main")); } } .switchMapCompletable(Functions.justFunction(Completable.error(new TestException("inner")))) diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java index 363f8c0614..3faa98caa5 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java @@ -353,10 +353,10 @@ public void mainErrorAfterTermination() { try { new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onError(new TestException("outer")); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onError(new TestException("outer")); } } .switchMapMaybe(new Function>() { @@ -384,10 +384,10 @@ public void innerErrorAfterTermination() { TestObserver to = new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onError(new TestException("outer")); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onError(new TestException("outer")); } } .switchMapMaybe(new Function>() { diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java index 92ec3c5523..03c38e54de 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java @@ -322,10 +322,10 @@ public void mainErrorAfterTermination() { try { new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onError(new TestException("outer")); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onError(new TestException("outer")); } } .switchMapSingle(new Function>() { @@ -353,10 +353,10 @@ public void innerErrorAfterTermination() { TestObserver to = new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onError(new TestException("outer")); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onError(new TestException("outer")); } } .switchMapSingle(new Function>() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java index 5ada2a774e..150a13580f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java @@ -267,7 +267,7 @@ public boolean test(String v) { @Test public void testAnyWithTwoItems() { Observable w = Observable.just(1, 2); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -276,7 +276,7 @@ public boolean test(Integer v) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(false); verify(observer, times(1)).onSuccess(true); @@ -286,11 +286,11 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithTwoItems() { Observable w = Observable.just(1, 2); - Single observable = w.isEmpty(); + Single single = w.isEmpty(); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(true); verify(observer, times(1)).onSuccess(false); @@ -300,7 +300,7 @@ public void testIsEmptyWithTwoItems() { @Test public void testAnyWithOneItem() { Observable w = Observable.just(1); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -309,7 +309,7 @@ public boolean test(Integer v) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(false); verify(observer, times(1)).onSuccess(true); @@ -319,11 +319,11 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithOneItem() { Observable w = Observable.just(1); - Single observable = w.isEmpty(); + Single single = w.isEmpty(); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(true); verify(observer, times(1)).onSuccess(false); @@ -333,7 +333,7 @@ public void testIsEmptyWithOneItem() { @Test public void testAnyWithEmpty() { Observable w = Observable.empty(); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -342,7 +342,7 @@ public boolean test(Integer v) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onSuccess(true); @@ -352,11 +352,11 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithEmpty() { Observable w = Observable.empty(); - Single observable = w.isEmpty(); + Single single = w.isEmpty(); SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(true); verify(observer, never()).onSuccess(false); @@ -366,7 +366,7 @@ public void testIsEmptyWithEmpty() { @Test public void testAnyWithPredicate1() { Observable w = Observable.just(1, 2, 3); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; @@ -375,7 +375,7 @@ public boolean test(Integer t1) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(false); verify(observer, times(1)).onSuccess(true); @@ -385,7 +385,7 @@ public boolean test(Integer t1) { @Test public void testExists1() { Observable w = Observable.just(1, 2, 3); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; @@ -394,7 +394,7 @@ public boolean test(Integer t1) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, never()).onSuccess(false); verify(observer, times(1)).onSuccess(true); @@ -404,7 +404,7 @@ public boolean test(Integer t1) { @Test public void testAnyWithPredicate2() { Observable w = Observable.just(1, 2, 3); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 1; @@ -413,7 +413,7 @@ public boolean test(Integer t1) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onSuccess(true); @@ -424,7 +424,7 @@ public boolean test(Integer t1) { public void testAnyWithEmptyAndPredicate() { // If the source is empty, always output false. Observable w = Observable.empty(); - Single observable = w.any(new Predicate() { + Single single = w.any(new Predicate() { @Override public boolean test(Integer t) { return true; @@ -433,7 +433,7 @@ public boolean test(Integer t) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onSuccess(true); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java index 3a02b31423..9ce8103e77 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java @@ -771,7 +771,7 @@ public void testBufferWithTimeDoesntUnsubscribeDownstream() throws InterruptedEx final Observer o = TestHelper.mockObserver(); final CountDownLatch cdl = new CountDownLatch(1); - DisposableObserver s = new DisposableObserver() { + DisposableObserver observer = new DisposableObserver() { @Override public void onNext(Object t) { o.onNext(t); @@ -788,7 +788,7 @@ public void onComplete() { } }; - Observable.range(1, 1).delay(1, TimeUnit.SECONDS).buffer(2, TimeUnit.SECONDS).subscribe(s); + Observable.range(1, 1).delay(1, TimeUnit.SECONDS).buffer(2, TimeUnit.SECONDS).subscribe(observer); cdl.await(); @@ -796,7 +796,7 @@ public void onComplete() { verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); - assertFalse(s.isDisposed()); + assertFalse(observer.isDisposed()); } @SuppressWarnings("unchecked") @@ -1599,24 +1599,24 @@ public void openClosebadSource() { try { new Observable() { @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { Disposable bs1 = Disposables.empty(); Disposable bs2 = Disposables.empty(); - s.onSubscribe(bs1); + observer.onSubscribe(bs1); assertFalse(bs1.isDisposed()); assertFalse(bs2.isDisposed()); - s.onSubscribe(bs2); + observer.onSubscribe(bs2); assertFalse(bs1.isDisposed()); assertTrue(bs2.isDisposed()); - s.onError(new IOException()); - s.onComplete(); - s.onNext(1); - s.onError(new TestException()); + observer.onError(new IOException()); + observer.onComplete(); + observer.onNext(1); + observer.onError(new TestException()); } } .buffer(Observable.never(), Functions.justFunction(Observable.never())) @@ -1720,30 +1720,30 @@ public void openCloseBadOpen() { Observable.never() .buffer(new Observable() { @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { - assertFalse(((Disposable)s).isDisposed()); + assertFalse(((Disposable)observer).isDisposed()); Disposable bs1 = Disposables.empty(); Disposable bs2 = Disposables.empty(); - s.onSubscribe(bs1); + observer.onSubscribe(bs1); assertFalse(bs1.isDisposed()); assertFalse(bs2.isDisposed()); - s.onSubscribe(bs2); + observer.onSubscribe(bs2); assertFalse(bs1.isDisposed()); assertTrue(bs2.isDisposed()); - s.onError(new IOException()); + observer.onError(new IOException()); - assertTrue(((Disposable)s).isDisposed()); + assertTrue(((Disposable)observer).isDisposed()); - s.onComplete(); - s.onNext(1); - s.onError(new TestException()); + observer.onComplete(); + observer.onNext(1); + observer.onError(new TestException()); } }, Functions.justFunction(Observable.never())) .test() @@ -1765,30 +1765,30 @@ public void openCloseBadClose() { .buffer(Observable.just(1).concatWith(Observable.never()), Functions.justFunction(new Observable() { @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { - assertFalse(((Disposable)s).isDisposed()); + assertFalse(((Disposable)observer).isDisposed()); Disposable bs1 = Disposables.empty(); Disposable bs2 = Disposables.empty(); - s.onSubscribe(bs1); + observer.onSubscribe(bs1); assertFalse(bs1.isDisposed()); assertFalse(bs2.isDisposed()); - s.onSubscribe(bs2); + observer.onSubscribe(bs2); assertFalse(bs1.isDisposed()); assertTrue(bs2.isDisposed()); - s.onError(new IOException()); + observer.onError(new IOException()); - assertTrue(((Disposable)s).isDisposed()); + assertTrue(((Disposable)observer).isDisposed()); - s.onComplete(); - s.onNext(1); - s.onError(new TestException()); + observer.onComplete(); + observer.onNext(1); + observer.onError(new TestException()); } })) .test() @@ -1872,10 +1872,10 @@ public void bufferBoundaryErrorTwice() { BehaviorSubject.createDefault(1) .buffer(Functions.justCallable(new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onError(new TestException("first")); - s.onError(new TestException("second")); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onError(new TestException("first")); + observer.onError(new TestException("second")); } })) .test() diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java index cee12d300e..55256bccd8 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java @@ -483,7 +483,7 @@ public List apply(Object[] args) { final CountDownLatch cdl = new CountDownLatch(1); - Observer> s = new DefaultObserver>() { + Observer> observer = new DefaultObserver>() { @Override public void onNext(List t) { @@ -503,7 +503,7 @@ public void onComplete() { } }; - result.subscribe(s); + result.subscribe(observer); cdl.await(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java index f1f95d2f68..f074441875 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java @@ -663,11 +663,11 @@ public void testConcatWithNonCompliantSourceDoubleOnComplete() { Observable o = Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext("hello"); - s.onComplete(); - s.onComplete(); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext("hello"); + observer.onComplete(); + observer.onComplete(); } }); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletableTest.java index e6a17f1d5a..458d0320c0 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletableTest.java @@ -105,17 +105,17 @@ public void cancelOther() { public void badSource() { new Observable() { @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { Disposable bs1 = Disposables.empty(); - s.onSubscribe(bs1); + observer.onSubscribe(bs1); Disposable bs2 = Disposables.empty(); - s.onSubscribe(bs2); + observer.onSubscribe(bs2); assertFalse(bs1.isDisposed()); assertTrue(bs2.isDisposed()); - s.onComplete(); + observer.onComplete(); } }.concatWith(Completable.complete()) .test() diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java index 3d323a979a..cbbed97785 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java @@ -138,17 +138,17 @@ protected void subscribeActual(Observer observer) { public void badSource() { new Observable() { @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { Disposable bs1 = Disposables.empty(); - s.onSubscribe(bs1); + observer.onSubscribe(bs1); Disposable bs2 = Disposables.empty(); - s.onSubscribe(bs2); + observer.onSubscribe(bs2); assertFalse(bs1.isDisposed()); assertTrue(bs2.isDisposed()); - s.onComplete(); + observer.onComplete(); } }.concatWith(Maybe.empty()) .test() @@ -159,17 +159,17 @@ protected void subscribeActual(Observer s) { public void badSource2() { Flowable.empty().concatWith(new Maybe() { @Override - protected void subscribeActual(MaybeObserver s) { + protected void subscribeActual(MaybeObserver observer) { Disposable bs1 = Disposables.empty(); - s.onSubscribe(bs1); + observer.onSubscribe(bs1); Disposable bs2 = Disposables.empty(); - s.onSubscribe(bs2); + observer.onSubscribe(bs2); assertFalse(bs1.isDisposed()); assertTrue(bs2.isDisposed()); - s.onComplete(); + observer.onComplete(); } }) .test() diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingleTest.java index 3de6edfd0f..824c6ac59e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingleTest.java @@ -110,17 +110,17 @@ protected void subscribeActual(Observer observer) { public void badSource() { new Observable() { @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { Disposable bs1 = Disposables.empty(); - s.onSubscribe(bs1); + observer.onSubscribe(bs1); Disposable bs2 = Disposables.empty(); - s.onSubscribe(bs2); + observer.onSubscribe(bs2); assertFalse(bs1.isDisposed()); assertTrue(bs2.isDisposed()); - s.onComplete(); + observer.onComplete(); } }.concatWith(Single.just(100)) .test() @@ -131,17 +131,17 @@ protected void subscribeActual(Observer s) { public void badSource2() { Flowable.empty().concatWith(new Single() { @Override - protected void subscribeActual(SingleObserver s) { + protected void subscribeActual(SingleObserver observer) { Disposable bs1 = Disposables.empty(); - s.onSubscribe(bs1); + observer.onSubscribe(bs1); Disposable bs2 = Disposables.empty(); - s.onSubscribe(bs2); + observer.onSubscribe(bs2); assertFalse(bs1.isDisposed()); assertTrue(bs2.isDisposed()); - s.onSuccess(100); + observer.onSuccess(100); } }) .test() diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java index 26ce6caa9c..9edae7bdc9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java @@ -471,11 +471,11 @@ public void timedDisposedIgnoredBySource() { new Observable() { @Override protected void subscribeActual( - Observer s) { - s.onSubscribe(Disposables.empty()); + Observer observer) { + observer.onSubscribe(Disposables.empty()); to.cancel(); - s.onNext(1); - s.onComplete(); + observer.onNext(1); + observer.onComplete(); } } .debounce(1, TimeUnit.SECONDS) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDeferTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDeferTest.java index 6e83ad1956..47ca034628 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDeferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDeferTest.java @@ -21,7 +21,6 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; -import io.reactivex.observers.DefaultObserver; @SuppressWarnings("unchecked") public class ObservableDeferTest { @@ -69,7 +68,7 @@ public void testDeferFunctionThrows() throws Exception { Observable result = Observable.defer(factory); - DefaultObserver o = mock(DefaultObserver.class); + Observer o = TestHelper.mockObserver(); result.subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java index 74bc2dfbfd..83ba70675b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java @@ -225,13 +225,13 @@ public void ignoreCancel() { try { Observable.wrap(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onNext(2); - s.onNext(3); - s.onError(new IOException()); - s.onComplete(); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onNext(2); + observer.onNext(3); + observer.onError(new IOException()); + observer.onComplete(); } }) .distinctUntilChanged(new BiPredicate() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java index 20538da8ca..161ae3db9e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java @@ -230,12 +230,12 @@ public void ignoreCancel() { try { Observable.wrap(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onNext(2); - s.onError(new IOException()); - s.onComplete(); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onNext(2); + observer.onError(new IOException()); + observer.onComplete(); } }) .doOnNext(new Consumer() { @@ -260,9 +260,9 @@ public void onErrorAfterCrash() { try { Observable.wrap(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onError(new TestException()); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onError(new TestException()); } }) .doAfterTerminate(new Action() { @@ -287,9 +287,9 @@ public void onCompleteAfterCrash() { try { Observable.wrap(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onComplete(); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); } }) .doAfterTerminate(new Action() { @@ -311,9 +311,9 @@ public void run() throws Exception { public void onCompleteCrash() { Observable.wrap(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onComplete(); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); } }) .doOnComplete(new Action() { @@ -333,12 +333,12 @@ public void ignoreCancelConditional() { try { Observable.wrap(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onNext(2); - s.onError(new IOException()); - s.onComplete(); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onNext(2); + observer.onError(new IOException()); + observer.onComplete(); } }) .doOnNext(new Consumer() { @@ -364,9 +364,9 @@ public void onErrorAfterCrashConditional() { try { Observable.wrap(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onError(new TestException()); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onError(new TestException()); } }) .doAfterTerminate(new Action() { @@ -408,9 +408,9 @@ public void onCompleteAfterCrashConditional() { try { Observable.wrap(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onComplete(); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); } }) .doAfterTerminate(new Action() { @@ -433,9 +433,9 @@ public void run() throws Exception { public void onCompleteCrashConditional() { Observable.wrap(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onComplete(); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); } }) .doOnComplete(new Action() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java index dbd4ca88eb..93143efe77 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java @@ -72,10 +72,10 @@ public void testDoOnUnSubscribeWorksWithRefCount() throws Exception { Observable o = Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); onSubscribed.incrementAndGet(); - sref.set(s); + sref.set(observer); } }).doOnSubscribe(new Consumer() { @@ -114,10 +114,10 @@ public void onSubscribeCrash() { new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(bs); - s.onError(new TestException("Second")); - s.onComplete(); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(bs); + observer.onError(new TestException("Second")); + observer.onComplete(); } } .doOnSubscribe(new Consumer() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java index 33ba15307e..84ff5fa5ec 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java @@ -372,14 +372,14 @@ public void innerObserver() { public CompletableSource apply(Integer v) throws Exception { return new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); - assertFalse(((Disposable)s).isDisposed()); + assertFalse(((Disposable)observer).isDisposed()); - ((Disposable)s).dispose(); + ((Disposable)observer).dispose(); - assertTrue(((Disposable)s).isDisposed()); + assertTrue(((Disposable)observer).isDisposed()); } }; } @@ -447,14 +447,14 @@ public void innerObserverObservable() { public CompletableSource apply(Integer v) throws Exception { return new Completable() { @Override - protected void subscribeActual(CompletableObserver s) { - s.onSubscribe(Disposables.empty()); + protected void subscribeActual(CompletableObserver observer) { + observer.onSubscribe(Disposables.empty()); - assertFalse(((Disposable)s).isDisposed()); + assertFalse(((Disposable)observer).isDisposed()); - ((Disposable)s).dispose(); + ((Disposable)observer).dispose(); - assertTrue(((Disposable)s).isDisposed()); + assertTrue(((Disposable)observer).isDisposed()); } }; } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java index ae00fc2403..95c892da87 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java @@ -993,10 +993,8 @@ public void testGroupByOnAsynchronousSourceAcceptsMultipleSubscriptions() throws Observable> stream = source.groupBy(IS_EVEN); // create two observers - @SuppressWarnings("unchecked") - DefaultObserver> o1 = mock(DefaultObserver.class); - @SuppressWarnings("unchecked") - DefaultObserver> o2 = mock(DefaultObserver.class); + Observer> o1 = TestHelper.mockObserver(); + Observer> o2 = TestHelper.mockObserver(); // subscribe with the observers stream.subscribe(o1); @@ -1222,8 +1220,7 @@ public void accept(GroupedObservable t1) { inner.get().subscribe(); - @SuppressWarnings("unchecked") - DefaultObserver o2 = mock(DefaultObserver.class); + Observer o2 = TestHelper.mockObserver(); inner.get().subscribe(o2); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java index 1b808a9234..bd6d291d33 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java @@ -343,7 +343,7 @@ public void testThrownErrorHandling() { Observable o1 = Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { + public void subscribe(Observer observer) { throw new RuntimeException("fail"); } @@ -559,13 +559,13 @@ public void testConcurrencyWithSleeping() { Observable o = Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(final Observer s) { + public void subscribe(final Observer observer) { Worker inner = Schedulers.newThread().createWorker(); final CompositeDisposable as = new CompositeDisposable(); as.add(Disposables.empty()); as.add(inner); - s.onSubscribe(as); + observer.onSubscribe(as); inner.schedule(new Runnable() { @@ -573,7 +573,7 @@ public void subscribe(final Observer s) { public void run() { try { for (int i = 0; i < 100; i++) { - s.onNext(1); + observer.onNext(1); try { Thread.sleep(1); } catch (InterruptedException e) { @@ -581,10 +581,10 @@ public void run() { } } } catch (Exception e) { - s.onError(e); + observer.onError(e); } as.dispose(); - s.onComplete(); + observer.onComplete(); } }); @@ -609,13 +609,13 @@ public void testConcurrencyWithBrokenOnCompleteContract() { Observable o = Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(final Observer s) { + public void subscribe(final Observer observer) { Worker inner = Schedulers.newThread().createWorker(); final CompositeDisposable as = new CompositeDisposable(); as.add(Disposables.empty()); as.add(inner); - s.onSubscribe(as); + observer.onSubscribe(as); inner.schedule(new Runnable() { @@ -623,15 +623,15 @@ public void subscribe(final Observer s) { public void run() { try { for (int i = 0; i < 10000; i++) { - s.onNext(i); + observer.onNext(i); } } catch (Exception e) { - s.onError(e); + observer.onError(e); } as.dispose(); - s.onComplete(); - s.onComplete(); - s.onComplete(); + observer.onComplete(); + observer.onComplete(); + observer.onComplete(); } }); @@ -840,8 +840,8 @@ public void mergeWithTerminalEventAfterUnsubscribe() { Observable bad = Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onNext("two"); + public void subscribe(Observer observer) { + observer.onNext("two"); // FIXME can't cancel downstream // s.unsubscribe(); // s.onComplete(); @@ -1023,8 +1023,8 @@ public Observable apply(final Integer i) { return Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); if (i < 500) { try { Thread.sleep(1); @@ -1032,8 +1032,8 @@ public void subscribe(Observer s) { e.printStackTrace(); } } - s.onNext(i); - s.onComplete(); + observer.onNext(i); + observer.onComplete(); } }).subscribeOn(Schedulers.computation()).cache(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java index a7d1edf098..a70e4c2fa8 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java @@ -177,18 +177,18 @@ public void onNext(Integer t) { public void onErrorMainOverflow() { List errors = TestHelper.trackPluginErrors(); try { - final AtomicReference> subscriber = new AtomicReference>(); + final AtomicReference> observerRef = new AtomicReference>(); TestObserver to = new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - subscriber.set(s); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observerRef.set(observer); } } .mergeWith(Maybe.error(new IOException())) .test(); - subscriber.get().onError(new TestException()); + observerRef.get().onError(new TestException()); to.assertFailure(IOException.class) ; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java index 5821461787..25ce78d486 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java @@ -169,18 +169,18 @@ public void onNext(Integer t) { public void onErrorMainOverflow() { List errors = TestHelper.trackPluginErrors(); try { - final AtomicReference> subscriber = new AtomicReference>(); + final AtomicReference> observerRef = new AtomicReference>(); TestObserver to = new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - subscriber.set(s); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observerRef.set(observer); } } .mergeWith(Single.error(new IOException())) .test(); - subscriber.get().onError(new TestException()); + observerRef.get().onError(new TestException()); to.assertFailure(IOException.class) ; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java index 0062e220ee..3330d8cd85 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java @@ -145,10 +145,8 @@ public void observeOnTheSameSchedulerTwice() { Observable o = Observable.just(1, 2, 3); Observable o2 = o.observeOn(scheduler); - @SuppressWarnings("unchecked") - DefaultObserver observer1 = mock(DefaultObserver.class); - @SuppressWarnings("unchecked") - DefaultObserver observer2 = mock(DefaultObserver.class); + Observer observer1 = TestHelper.mockObserver(); + Observer observer2 = TestHelper.mockObserver(); InOrder inOrder1 = inOrder(observer1); InOrder inOrder2 = inOrder(observer2); @@ -368,8 +366,7 @@ public void testDelayedErrorDeliveryWhenSafeSubscriberUnsubscribes() { Observable source = Observable.concat(Observable. error(new TestException()), Observable.just(1)); - @SuppressWarnings("unchecked") - DefaultObserver o = mock(DefaultObserver.class); + Observer o = TestHelper.mockObserver(); InOrder inOrder = inOrder(o); source.observeOn(testScheduler).subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java index ffb1e5c37b..9ba3738ce6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java @@ -126,8 +126,7 @@ public Observable apply(Throwable t1) { }; Observable o = Observable.unsafeCreate(w).onErrorResumeNext(resume); - @SuppressWarnings("unchecked") - DefaultObserver observer = mock(DefaultObserver.class); + Observer observer = TestHelper.mockObserver(); o.subscribe(observer); try { @@ -259,8 +258,7 @@ public Observable apply(Throwable t1) { }); - @SuppressWarnings("unchecked") - DefaultObserver observer = mock(DefaultObserver.class); + Observer observer = TestHelper.mockObserver(); TestObserver to = new TestObserver(observer); o.subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java index c0c8edc358..71f9a809fe 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java @@ -133,8 +133,7 @@ public void subscribe(Observer t1) { Observable resume = Observable.just("resume"); Observable observable = testObservable.subscribeOn(Schedulers.io()).onErrorResumeNext(resume); - @SuppressWarnings("unchecked") - DefaultObserver observer = mock(DefaultObserver.class); + Observer observer = TestHelper.mockObserver(); TestObserver to = new TestObserver(observer); observable.subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturnTest.java index 18d43e90d4..142d4a7f9f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturnTest.java @@ -46,8 +46,7 @@ public String apply(Throwable e) { }); - @SuppressWarnings("unchecked") - DefaultObserver observer = mock(DefaultObserver.class); + Observer observer = TestHelper.mockObserver(); observable.subscribe(observer); try { @@ -82,8 +81,7 @@ public String apply(Throwable e) { }); - @SuppressWarnings("unchecked") - DefaultObserver observer = mock(DefaultObserver.class); + Observer observer = TestHelper.mockObserver(); observable.subscribe(observer); try { @@ -128,8 +126,7 @@ public String apply(Throwable t1) { }); - @SuppressWarnings("unchecked") - DefaultObserver observer = mock(DefaultObserver.class); + Observer observer = TestHelper.mockObserver(); TestObserver to = new TestObserver(observer); observable.subscribe(to); to.awaitTerminalEvent(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java index e280f5cf9d..86194a7bf7 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java @@ -706,8 +706,8 @@ public void delayedUpstreamOnSubscribe() { new Observable() { @Override - protected void subscribeActual(Observer s) { - sub[0] = s; + protected void subscribeActual(Observer observer) { + sub[0] = observer; } } .publish() diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index d46ae8b204..381b2b964b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -232,22 +232,22 @@ public void run() { } }); - TestObserver s = new TestObserver(); - o.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(s); + TestObserver observer = new TestObserver(); + o.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(observer); System.out.println("send unsubscribe"); // wait until connected subscribeLatch.await(); // now unsubscribe - s.dispose(); + observer.dispose(); System.out.println("DONE sending unsubscribe ... now waiting"); if (!unsubscribeLatch.await(3000, TimeUnit.MILLISECONDS)) { - System.out.println("Errors: " + s.errors()); - if (s.errors().size() > 0) { - s.errors().get(0).printStackTrace(); + System.out.println("Errors: " + observer.errors()); + if (observer.errors().size() > 0) { + observer.errors().get(0).printStackTrace(); } fail("timed out waiting for unsubscribe"); } - s.assertNoErrors(); + observer.assertNoErrors(); } @Test @@ -277,12 +277,12 @@ public void accept(Disposable s) { } }); - TestObserver s = new TestObserver(); + TestObserver observer = new TestObserver(); - o.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(s); + o.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(observer); System.out.println("send unsubscribe"); // now immediately unsubscribe while subscribeOn is racing to subscribe - s.dispose(); + observer.dispose(); // this generally will mean it won't even subscribe as it is already unsubscribed by the time connect() gets scheduled // give time to the counter to update @@ -297,11 +297,11 @@ public void accept(Disposable s) { assertEquals(0, subUnsubCount.get()); System.out.println("DONE sending unsubscribe ... now waiting"); - System.out.println("Errors: " + s.errors()); - if (s.errors().size() > 0) { - s.errors().get(0).printStackTrace(); + System.out.println("Errors: " + observer.errors()); + if (observer.errors().size() > 0) { + observer.errors().get(0).printStackTrace(); } - s.assertNoErrors(); + observer.assertNoErrors(); } private Observable synchronousInterval() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java index 8c483fc40d..0c62893a77 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java @@ -1497,8 +1497,8 @@ public void delayedUpstreamOnSubscribe() { new Observable() { @Override - protected void subscribeActual(Observer s) { - sub[0] = s; + protected void subscribeActual(Observer observer) { + sub[0] = observer; } } .replay() diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java index a776cc97a7..9ebb3fd450 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java @@ -426,9 +426,9 @@ public void testRetryAllowsSubscriptionAfterAllSubscriptionsUnsubscribed() throw final AtomicInteger subsCount = new AtomicInteger(0); ObservableSource onSubscribe = new ObservableSource() { @Override - public void subscribe(Observer s) { + public void subscribe(Observer observer) { subsCount.incrementAndGet(); - s.onSubscribe(Disposables.fromRunnable(new Runnable() { + observer.onSubscribe(Disposables.fromRunnable(new Runnable() { @Override public void run() { subsCount.decrementAndGet(); @@ -455,13 +455,13 @@ public void testSourceObservableCallsUnsubscribe() throws InterruptedException { ObservableSource onSubscribe = new ObservableSource() { @Override - public void subscribe(Observer s) { + public void subscribe(Observer observer) { BooleanSubscription bs = new BooleanSubscription(); // if isUnsubscribed is true that means we have a bug such as // https://github.com/ReactiveX/RxJava/issues/1024 if (!bs.isCancelled()) { subsCount.incrementAndGet(); - s.onError(new RuntimeException("failed")); + observer.onError(new RuntimeException("failed")); // it unsubscribes the child directly // this simulates various error/completion scenarios that could occur // or just a source that proactively triggers cleanup @@ -469,7 +469,7 @@ public void subscribe(Observer s) { // s.unsubscribe(); bs.cancel(); } else { - s.onError(new RuntimeException()); + observer.onError(new RuntimeException()); } } }; @@ -486,10 +486,10 @@ public void testSourceObservableRetry1() throws InterruptedException { ObservableSource onSubscribe = new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); subsCount.incrementAndGet(); - s.onError(new RuntimeException("failed")); + observer.onError(new RuntimeException("failed")); } }; @@ -505,10 +505,10 @@ public void testSourceObservableRetry0() throws InterruptedException { ObservableSource onSubscribe = new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); subsCount.incrementAndGet(); - s.onError(new RuntimeException("failed")); + observer.onError(new RuntimeException("failed")); } }; @@ -634,8 +634,7 @@ public void testUnsubscribeAfterError() { @Test(timeout = 10000) public void testTimeoutWithRetry() { - @SuppressWarnings("unchecked") - DefaultObserver observer = mock(DefaultObserver.class); + Observer observer = TestHelper.mockObserver(); // Observable that sends every 100ms (timeout fails instead) SlowObservable so = new SlowObservable(100, 10); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java index db87844952..79ca287629 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java @@ -89,8 +89,7 @@ public void subscribe(Observer t1) { } }); - @SuppressWarnings("unchecked") - DefaultObserver o = mock(DefaultObserver.class); + Observer o = TestHelper.mockObserver(); InOrder inOrder = inOrder(o); source.retry(retryTwice).subscribe(o); @@ -117,8 +116,7 @@ public void subscribe(Observer t1) { } }); - @SuppressWarnings("unchecked") - DefaultObserver o = mock(DefaultObserver.class); + Observer o = TestHelper.mockObserver(); InOrder inOrder = inOrder(o); source.retry(retryTwice).subscribe(o); @@ -153,8 +151,7 @@ public void subscribe(Observer t1) { } }); - @SuppressWarnings("unchecked") - DefaultObserver o = mock(DefaultObserver.class); + Observer o = TestHelper.mockObserver(); InOrder inOrder = inOrder(o); source.retry(retryOnTestException).subscribe(o); @@ -190,8 +187,7 @@ public void subscribe(Observer t1) { } }); - @SuppressWarnings("unchecked") - DefaultObserver o = mock(DefaultObserver.class); + Observer o = TestHelper.mockObserver(); InOrder inOrder = inOrder(o); source.retry(retryOnTestException).subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableScalarXMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableScalarXMapTest.java index cb4661943c..0ab9e8e914 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableScalarXMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableScalarXMapTest.java @@ -35,8 +35,8 @@ public void utilityClass() { static final class CallablePublisher implements ObservableSource, Callable { @Override - public void subscribe(Observer s) { - EmptyDisposable.error(new TestException(), s); + public void subscribe(Observer observer) { + EmptyDisposable.error(new TestException(), observer); } @Override @@ -47,8 +47,8 @@ public Integer call() throws Exception { static final class EmptyCallablePublisher implements ObservableSource, Callable { @Override - public void subscribe(Observer s) { - EmptyDisposable.complete(s); + public void subscribe(Observer observer) { + EmptyDisposable.complete(observer); } @Override @@ -59,9 +59,9 @@ public Integer call() throws Exception { static final class OneCallablePublisher implements ObservableSource, Callable { @Override - public void subscribe(Observer s) { - ScalarDisposable sd = new ScalarDisposable(s, 1); - s.onSubscribe(sd); + public void subscribe(Observer observer) { + ScalarDisposable sd = new ScalarDisposable(observer, 1); + observer.onSubscribe(sd); sd.run(); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java index 5a5adb36d1..4a7a33ddd6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java @@ -150,9 +150,9 @@ private void verifyError(Observable observable) { inOrder.verifyNoMoreInteractions(); } - private void verifyError(Single observable) { + private void verifyError(Single single) { SingleObserver observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError(isA(TestException.class)); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSubscribeOnTest.java index 03e5472bde..c80b81e2cd 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSubscribeOnTest.java @@ -78,7 +78,7 @@ public void testThrownErrorHandling() { Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { + public void subscribe(Observer observer) { throw new RuntimeException("fail"); } @@ -93,9 +93,9 @@ public void testOnError() { Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onError(new RuntimeException("fail")); + public void subscribe(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onError(new RuntimeException("fail")); } }).subscribeOn(Schedulers.computation()).subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java index beae5a788c..ab68bd6790 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java @@ -664,9 +664,9 @@ public void switchMapSingleFunctionDoesntReturnSingle() { public SingleSource apply(Object v) throws Exception { return new SingleSource() { @Override - public void subscribe(SingleObserver s) { - s.onSubscribe(Disposables.empty()); - s.onSuccess(1); + public void subscribe(SingleObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onSuccess(1); } }; } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java index a738d40462..859e311a2d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java @@ -28,33 +28,33 @@ public class ObservableTakeLastOneTest { @Test public void testLastOfManyReturnsLast() { - TestObserver s = new TestObserver(); - Observable.range(1, 10).takeLast(1).subscribe(s); - s.assertValue(10); - s.assertNoErrors(); - s.assertTerminated(); + TestObserver to = new TestObserver(); + Observable.range(1, 10).takeLast(1).subscribe(to); + to.assertValue(10); + to.assertNoErrors(); + to.assertTerminated(); // NO longer assertable // s.assertUnsubscribed(); } @Test public void testLastOfEmptyReturnsEmpty() { - TestObserver s = new TestObserver(); - Observable.empty().takeLast(1).subscribe(s); - s.assertNoValues(); - s.assertNoErrors(); - s.assertTerminated(); + TestObserver to = new TestObserver(); + Observable.empty().takeLast(1).subscribe(to); + to.assertNoValues(); + to.assertNoErrors(); + to.assertTerminated(); // NO longer assertable // s.assertUnsubscribed(); } @Test public void testLastOfOneReturnsLast() { - TestObserver s = new TestObserver(); - Observable.just(1).takeLast(1).subscribe(s); - s.assertValue(1); - s.assertNoErrors(); - s.assertTerminated(); + TestObserver to = new TestObserver(); + Observable.just(1).takeLast(1).subscribe(to); + to.assertValue(1); + to.assertNoErrors(); + to.assertTerminated(); // NO longer assertable // s.assertUnsubscribed(); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java index f1f5851fd3..a9b9ae35d9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java @@ -208,13 +208,13 @@ public void testMultiTake() { Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { + public void subscribe(Observer observer) { Disposable bs = Disposables.empty(); - s.onSubscribe(bs); + observer.onSubscribe(bs); for (int i = 0; !bs.isDisposed(); i++) { System.out.println("Emit: " + i); count.incrementAndGet(); - s.onNext(i); + observer.onNext(i); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java index 921cd50383..4d38f049e7 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java @@ -562,9 +562,9 @@ public void lateOnTimeoutError() { @Override protected void subscribeActual( - Observer s) { - s.onSubscribe(Disposables.empty()); - sub[count++] = s; + Observer observer) { + observer.onSubscribe(Disposables.empty()); + sub[count++] = observer; } }; @@ -616,10 +616,10 @@ public void lateOnTimeoutFallbackRace() { @Override protected void subscribeActual( - Observer s) { - assertFalse(((Disposable)s).isDisposed()); - s.onSubscribe(Disposables.empty()); - sub[count++] = s; + Observer observer) { + assertFalse(((Disposable)observer).isDisposed()); + observer.onSubscribe(Disposables.empty()); + sub[count++] = observer; } }; @@ -671,10 +671,10 @@ public void onErrorOnTimeoutRace() { @Override protected void subscribeActual( - Observer s) { - assertFalse(((Disposable)s).isDisposed()); - s.onSubscribe(Disposables.empty()); - sub[count++] = s; + Observer observer) { + assertFalse(((Disposable)observer).isDisposed()); + observer.onSubscribe(Disposables.empty()); + sub[count++] = observer; } }; @@ -726,10 +726,10 @@ public void onCompleteOnTimeoutRace() { @Override protected void subscribeActual( - Observer s) { - assertFalse(((Disposable)s).isDisposed()); - s.onSubscribe(Disposables.empty()); - sub[count++] = s; + Observer observer) { + assertFalse(((Disposable)observer).isDisposed()); + observer.onSubscribe(Disposables.empty()); + sub[count++] = observer; } }; @@ -779,10 +779,10 @@ public void onCompleteOnTimeoutRaceFallback() { @Override protected void subscribeActual( - Observer s) { - assertFalse(((Disposable)s).isDisposed()); - s.onSubscribe(Disposables.empty()); - sub[count++] = s; + Observer observer) { + assertFalse(((Disposable)observer).isDisposed()); + observer.onSubscribe(Disposables.empty()); + sub[count++] = observer; } }; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java index fa838ad5f1..18447143aa 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java @@ -109,10 +109,10 @@ public void capacityHintObservable() { @Test public void testList() { Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); - Single> observable = w.toList(); + Single> single = w.toList(); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", "two", "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); } @@ -120,10 +120,10 @@ public void testList() { @Test public void testListViaObservable() { Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); - Single> observable = w.toList(); + Single> single = w.toList(); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", "two", "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); } @@ -131,13 +131,13 @@ public void testListViaObservable() { @Test public void testListMultipleSubscribers() { Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); - Single> observable = w.toList(); + Single> single = w.toList(); SingleObserver> o1 = TestHelper.mockSingleObserver(); - observable.subscribe(o1); + single.subscribe(o1); SingleObserver> o2 = TestHelper.mockSingleObserver(); - observable.subscribe(o2); + single.subscribe(o2); List expected = Arrays.asList("one", "two", "three"); @@ -152,10 +152,10 @@ public void testListMultipleSubscribers() { @Ignore("Null values are not allowed") public void testListWithNullValue() { Observable w = Observable.fromIterable(Arrays.asList("one", null, "three")); - Single> observable = w.toList(); + Single> single = w.toList(); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", null, "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java index b00cfbb483..f715b6b08c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java @@ -119,10 +119,10 @@ public int compare(Integer a, Integer b) { @Test public void testSortedList() { Observable w = Observable.just(1, 3, 2, 5, 4); - Single> observable = w.toSortedList(); + Single> single = w.toSortedList(); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList(1, 2, 3, 4, 5)); verify(observer, Mockito.never()).onError(any(Throwable.class)); } @@ -130,7 +130,7 @@ public void testSortedList() { @Test public void testSortedListWithCustomFunction() { Observable w = Observable.just(1, 3, 2, 5, 4); - Single> observable = w.toSortedList(new Comparator() { + Single> single = w.toSortedList(new Comparator() { @Override public int compare(Integer t1, Integer t2) { @@ -140,7 +140,7 @@ public int compare(Integer t1, Integer t2) { }); SingleObserver> observer = TestHelper.mockSingleObserver(); - observable.subscribe(observer); + single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList(5, 4, 3, 2, 1)); verify(observer, Mockito.never()).onError(any(Throwable.class)); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java index a3f2fedc41..8ef033d5f1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java @@ -208,13 +208,13 @@ private List list(String... args) { public static Observable hotStream() { return Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { + public void subscribe(Observer observer) { Disposable d = Disposables.empty(); - s.onSubscribe(d); + observer.onSubscribe(d); while (!d.isDisposed()) { // burst some number of items for (int i = 0; i < Math.random() * 20; i++) { - s.onNext(i); + observer.onNext(i); } try { // sleep for a random amount of time diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java index 41f3163f98..d1426a5a61 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java @@ -404,11 +404,11 @@ public Observable apply(Integer f) throws Exception { return new Observable() { @Override protected void subscribeActual( - Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onNext(2); - s.onError(new TestException()); + Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onNext(2); + observer.onError(new TestException()); } }; } diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDelayTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDelayTest.java index d0c2ea165b..8f0967d8b8 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDelayTest.java @@ -213,10 +213,10 @@ public void withObservableError2() { Single.just(1) .delaySubscription(new Observable() { @Override - protected void subscribeActual(Observer s) { - s.onSubscribe(Disposables.empty()); - s.onNext(1); - s.onError(new TestException()); + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onError(new TestException()); } }) .test() diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java index 853b21c320..8422a44c12 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java @@ -336,10 +336,10 @@ public void onSubscribeCrash() { new Single() { @Override - protected void subscribeActual(SingleObserver s) { - s.onSubscribe(bs); - s.onError(new TestException("Second")); - s.onSuccess(1); + protected void subscribeActual(SingleObserver observer) { + observer.onSubscribe(bs); + observer.onError(new TestException("Second")); + observer.onSuccess(1); } } .doOnSubscribe(new Consumer() { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleLiftTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleLiftTest.java index 1f09902b43..cf2345de35 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleLiftTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleLiftTest.java @@ -25,22 +25,22 @@ public void normal() { Single.just(1).lift(new SingleOperator() { @Override - public SingleObserver apply(final SingleObserver s) throws Exception { + public SingleObserver apply(final SingleObserver observer) throws Exception { return new SingleObserver() { @Override public void onSubscribe(Disposable d) { - s.onSubscribe(d); + observer.onSubscribe(d); } @Override public void onSuccess(Integer value) { - s.onSuccess(value + 1); + observer.onSuccess(value + 1); } @Override public void onError(Throwable e) { - s.onError(e); + observer.onError(e); } }; } diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java index 160579aab1..c811291851 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java @@ -55,9 +55,9 @@ public void wrap() { Single.wrap(new SingleSource() { @Override - public void subscribe(SingleObserver s) { - s.onSubscribe(Disposables.empty()); - s.onSuccess(1); + public void subscribe(SingleObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onSuccess(1); } }) .test() diff --git a/src/test/java/io/reactivex/internal/subscribers/BoundedSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/BoundedSubscriberTest.java index 0fed174be5..17e12986b4 100644 --- a/src/test/java/io/reactivex/internal/subscribers/BoundedSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/BoundedSubscriberTest.java @@ -42,7 +42,7 @@ public class BoundedSubscriberTest { public void onSubscribeThrows() { final List received = new ArrayList(); - BoundedSubscriber o = new BoundedSubscriber(new Consumer() { + BoundedSubscriber subscriber = new BoundedSubscriber(new Consumer() { @Override public void accept(Object o) throws Exception { received.add(o); @@ -64,21 +64,21 @@ public void accept(Subscription subscription) throws Exception { } }, 128); - assertFalse(o.isDisposed()); + assertFalse(subscriber.isDisposed()); - Flowable.just(1).subscribe(o); + Flowable.just(1).subscribe(subscriber); assertTrue(received.toString(), received.get(0) instanceof TestException); assertEquals(received.toString(), 1, received.size()); - assertTrue(o.isDisposed()); + assertTrue(subscriber.isDisposed()); } @Test public void onNextThrows() { final List received = new ArrayList(); - BoundedSubscriber o = new BoundedSubscriber(new Consumer() { + BoundedSubscriber subscriber = new BoundedSubscriber(new Consumer() { @Override public void accept(Object o) throws Exception { throw new TestException(); @@ -100,14 +100,14 @@ public void accept(Subscription subscription) throws Exception { } }, 128); - assertFalse(o.isDisposed()); + assertFalse(subscriber.isDisposed()); - Flowable.just(1).subscribe(o); + Flowable.just(1).subscribe(subscriber); assertTrue(received.toString(), received.get(0) instanceof TestException); assertEquals(received.toString(), 1, received.size()); - assertTrue(o.isDisposed()); + assertTrue(subscriber.isDisposed()); } @Test @@ -117,7 +117,7 @@ public void onErrorThrows() { try { final List received = new ArrayList(); - BoundedSubscriber o = new BoundedSubscriber(new Consumer() { + BoundedSubscriber subscriber = new BoundedSubscriber(new Consumer() { @Override public void accept(Object o) throws Exception { received.add(o); @@ -139,13 +139,13 @@ public void accept(Subscription subscription) throws Exception { } }, 128); - assertFalse(o.isDisposed()); + assertFalse(subscriber.isDisposed()); - Flowable.error(new TestException("Outer")).subscribe(o); + Flowable.error(new TestException("Outer")).subscribe(subscriber); assertTrue(received.toString(), received.isEmpty()); - assertTrue(o.isDisposed()); + assertTrue(subscriber.isDisposed()); TestHelper.assertError(errors, 0, CompositeException.class); List ce = TestHelper.compositeList(errors.get(0)); @@ -163,7 +163,7 @@ public void onCompleteThrows() { try { final List received = new ArrayList(); - BoundedSubscriber o = new BoundedSubscriber(new Consumer() { + BoundedSubscriber subscriber = new BoundedSubscriber(new Consumer() { @Override public void accept(Object o) throws Exception { received.add(o); @@ -185,13 +185,13 @@ public void accept(Subscription subscription) throws Exception { } }, 128); - assertFalse(o.isDisposed()); + assertFalse(subscriber.isDisposed()); - Flowable.empty().subscribe(o); + Flowable.empty().subscribe(subscriber); assertTrue(received.toString(), received.isEmpty()); - assertTrue(o.isDisposed()); + assertTrue(subscriber.isDisposed()); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { @@ -294,7 +294,7 @@ public void subscribe(Subscriber s) { final List received = new ArrayList(); - BoundedSubscriber o = new BoundedSubscriber(new Consumer() { + BoundedSubscriber subscriber = new BoundedSubscriber(new Consumer() { @Override public void accept(Object v) throws Exception { received.add(v); @@ -316,7 +316,7 @@ public void accept(Subscription s) throws Exception { } }, 128); - source.subscribe(o); + source.subscribe(subscriber); assertEquals(Arrays.asList(1, 100), received); } @@ -339,7 +339,7 @@ public void subscribe(Subscriber s) { final List received = new ArrayList(); - BoundedSubscriber o = new BoundedSubscriber(new Consumer() { + BoundedSubscriber subscriber = new BoundedSubscriber(new Consumer() { @Override public void accept(Object v) throws Exception { received.add(v); @@ -361,28 +361,28 @@ public void accept(Subscription s) throws Exception { } }, 128); - source.subscribe(o); + source.subscribe(subscriber); assertEquals(Arrays.asList(1, 100), received); } @Test public void onErrorMissingShouldReportNoCustomOnError() { - BoundedSubscriber o = new BoundedSubscriber(Functions.emptyConsumer(), + BoundedSubscriber subscriber = new BoundedSubscriber(Functions.emptyConsumer(), Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION, Functions.boundedConsumer(128), 128); - assertFalse(o.hasCustomOnError()); + assertFalse(subscriber.hasCustomOnError()); } @Test public void customOnErrorShouldReportCustomOnError() { - BoundedSubscriber o = new BoundedSubscriber(Functions.emptyConsumer(), + BoundedSubscriber subscriber = new BoundedSubscriber(Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.EMPTY_ACTION, Functions.boundedConsumer(128), 128); - assertTrue(o.hasCustomOnError()); + assertTrue(subscriber.hasCustomOnError()); } } diff --git a/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java index b6eef24c5e..7f16d6e0ee 100644 --- a/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java @@ -34,7 +34,7 @@ public class LambdaSubscriberTest { public void onSubscribeThrows() { final List received = new ArrayList(); - LambdaSubscriber o = new LambdaSubscriber(new Consumer() { + LambdaSubscriber subscriber = new LambdaSubscriber(new Consumer() { @Override public void accept(Object v) throws Exception { received.add(v); @@ -57,21 +57,21 @@ public void accept(Subscription s) throws Exception { } }); - assertFalse(o.isDisposed()); + assertFalse(subscriber.isDisposed()); - Flowable.just(1).subscribe(o); + Flowable.just(1).subscribe(subscriber); assertTrue(received.toString(), received.get(0) instanceof TestException); assertEquals(received.toString(), 1, received.size()); - assertTrue(o.isDisposed()); + assertTrue(subscriber.isDisposed()); } @Test public void onNextThrows() { final List received = new ArrayList(); - LambdaSubscriber o = new LambdaSubscriber(new Consumer() { + LambdaSubscriber subscriber = new LambdaSubscriber(new Consumer() { @Override public void accept(Object v) throws Exception { throw new TestException(); @@ -94,14 +94,14 @@ public void accept(Subscription s) throws Exception { } }); - assertFalse(o.isDisposed()); + assertFalse(subscriber.isDisposed()); - Flowable.just(1).subscribe(o); + Flowable.just(1).subscribe(subscriber); assertTrue(received.toString(), received.get(0) instanceof TestException); assertEquals(received.toString(), 1, received.size()); - assertTrue(o.isDisposed()); + assertTrue(subscriber.isDisposed()); } @Test @@ -111,7 +111,7 @@ public void onErrorThrows() { try { final List received = new ArrayList(); - LambdaSubscriber o = new LambdaSubscriber(new Consumer() { + LambdaSubscriber subscriber = new LambdaSubscriber(new Consumer() { @Override public void accept(Object v) throws Exception { received.add(v); @@ -134,13 +134,13 @@ public void accept(Subscription s) throws Exception { } }); - assertFalse(o.isDisposed()); + assertFalse(subscriber.isDisposed()); - Flowable.error(new TestException("Outer")).subscribe(o); + Flowable.error(new TestException("Outer")).subscribe(subscriber); assertTrue(received.toString(), received.isEmpty()); - assertTrue(o.isDisposed()); + assertTrue(subscriber.isDisposed()); TestHelper.assertError(errors, 0, CompositeException.class); List ce = TestHelper.compositeList(errors.get(0)); @@ -158,7 +158,7 @@ public void onCompleteThrows() { try { final List received = new ArrayList(); - LambdaSubscriber o = new LambdaSubscriber(new Consumer() { + LambdaSubscriber subscriber = new LambdaSubscriber(new Consumer() { @Override public void accept(Object v) throws Exception { received.add(v); @@ -181,13 +181,13 @@ public void accept(Subscription s) throws Exception { } }); - assertFalse(o.isDisposed()); + assertFalse(subscriber.isDisposed()); - Flowable.empty().subscribe(o); + Flowable.empty().subscribe(subscriber); assertTrue(received.toString(), received.isEmpty()); - assertTrue(o.isDisposed()); + assertTrue(subscriber.isDisposed()); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { @@ -215,7 +215,7 @@ public void subscribe(Subscriber s) { final List received = new ArrayList(); - LambdaSubscriber o = new LambdaSubscriber(new Consumer() { + LambdaSubscriber subscriber = new LambdaSubscriber(new Consumer() { @Override public void accept(Object v) throws Exception { received.add(v); @@ -238,7 +238,7 @@ public void accept(Subscription s) throws Exception { } }); - source.subscribe(o); + source.subscribe(subscriber); assertEquals(Arrays.asList(1, 100), received); } @@ -260,7 +260,7 @@ public void subscribe(Subscriber s) { final List received = new ArrayList(); - LambdaSubscriber o = new LambdaSubscriber(new Consumer() { + LambdaSubscriber subscriber = new LambdaSubscriber(new Consumer() { @Override public void accept(Object v) throws Exception { received.add(v); @@ -283,7 +283,7 @@ public void accept(Subscription s) throws Exception { } }); - source.subscribe(o); + source.subscribe(subscriber); assertEquals(Arrays.asList(1, 100), received); } @@ -351,21 +351,21 @@ public void accept(Subscription s) throws Exception { @Test public void onErrorMissingShouldReportNoCustomOnError() { - LambdaSubscriber o = new LambdaSubscriber(Functions.emptyConsumer(), + LambdaSubscriber subscriber = new LambdaSubscriber(Functions.emptyConsumer(), Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION, FlowableInternalHelper.RequestMax.INSTANCE); - assertFalse(o.hasCustomOnError()); + assertFalse(subscriber.hasCustomOnError()); } @Test public void customOnErrorShouldReportCustomOnError() { - LambdaSubscriber o = new LambdaSubscriber(Functions.emptyConsumer(), + LambdaSubscriber subscriber = new LambdaSubscriber(Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.EMPTY_ACTION, FlowableInternalHelper.RequestMax.INSTANCE); - assertTrue(o.hasCustomOnError()); + assertTrue(subscriber.hasCustomOnError()); } } diff --git a/src/test/java/io/reactivex/internal/subscribers/SubscriberResourceWrapperTest.java b/src/test/java/io/reactivex/internal/subscribers/SubscriberResourceWrapperTest.java index c519202ff8..6841d5bffd 100644 --- a/src/test/java/io/reactivex/internal/subscribers/SubscriberResourceWrapperTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/SubscriberResourceWrapperTest.java @@ -88,8 +88,8 @@ public void complete() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { @Override - public Flowable apply(Flowable o) throws Exception { - return o.lift(new FlowableOperator() { + public Flowable apply(Flowable f) throws Exception { + return f.lift(new FlowableOperator() { @Override public Subscriber apply( Subscriber s) throws Exception { diff --git a/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java b/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java index 38e099db23..b66f5d5671 100644 --- a/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java +++ b/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java @@ -36,7 +36,7 @@ public void reentrantOnNextOnNext() { final TestObserver ts = new TestObserver(); - Observer s = new Observer() { + Observer observer = new Observer() { @Override public void onSubscribe(Disposable s) { ts.onSubscribe(s); @@ -61,11 +61,11 @@ public void onComplete() { } }; - a[0] = s; + a[0] = observer; - s.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposables.empty()); - HalfSerializer.onNext(s, 1, wip, error); + HalfSerializer.onNext(observer, 1, wip, error); ts.assertValue(1).assertNoErrors().assertNotComplete(); } @@ -80,7 +80,7 @@ public void reentrantOnNextOnError() { final TestObserver ts = new TestObserver(); - Observer s = new Observer() { + Observer observer = new Observer() { @Override public void onSubscribe(Disposable s) { ts.onSubscribe(s); @@ -105,11 +105,11 @@ public void onComplete() { } }; - a[0] = s; + a[0] = observer; - s.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposables.empty()); - HalfSerializer.onNext(s, 1, wip, error); + HalfSerializer.onNext(observer, 1, wip, error); ts.assertFailure(TestException.class, 1); } @@ -124,7 +124,7 @@ public void reentrantOnNextOnComplete() { final TestObserver ts = new TestObserver(); - Observer s = new Observer() { + Observer observer = new Observer() { @Override public void onSubscribe(Disposable s) { ts.onSubscribe(s); @@ -149,11 +149,11 @@ public void onComplete() { } }; - a[0] = s; + a[0] = observer; - s.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposables.empty()); - HalfSerializer.onNext(s, 1, wip, error); + HalfSerializer.onNext(observer, 1, wip, error); ts.assertResult(1); } @@ -168,7 +168,7 @@ public void reentrantErrorOnError() { final TestObserver ts = new TestObserver(); - Observer s = new Observer() { + Observer observer = new Observer() { @Override public void onSubscribe(Disposable s) { ts.onSubscribe(s); @@ -191,11 +191,11 @@ public void onComplete() { } }; - a[0] = s; + a[0] = observer; - s.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposables.empty()); - HalfSerializer.onError(s, new TestException(), wip, error); + HalfSerializer.onError(observer, new TestException(), wip, error); ts.assertFailure(TestException.class); } diff --git a/src/test/java/io/reactivex/maybe/MaybeTest.java b/src/test/java/io/reactivex/maybe/MaybeTest.java index 18fe1fea4c..94c7c9eb8a 100644 --- a/src/test/java/io/reactivex/maybe/MaybeTest.java +++ b/src/test/java/io/reactivex/maybe/MaybeTest.java @@ -1002,7 +1002,7 @@ public void sourceThrowsNPE() { try { Maybe.unsafeCreate(new MaybeSource() { @Override - public void subscribe(MaybeObserver s) { + public void subscribe(MaybeObserver observer) { throw new NullPointerException("Forced failure"); } }).test(); @@ -1019,7 +1019,7 @@ public void sourceThrowsIAE() { try { Maybe.unsafeCreate(new MaybeSource() { @Override - public void subscribe(MaybeObserver s) { + public void subscribe(MaybeObserver observer) { throw new IllegalArgumentException("Forced failure"); } }).test(); diff --git a/src/test/java/io/reactivex/observable/ObservableNullTests.java b/src/test/java/io/reactivex/observable/ObservableNullTests.java index 105a429b1f..d04c324dfe 100644 --- a/src/test/java/io/reactivex/observable/ObservableNullTests.java +++ b/src/test/java/io/reactivex/observable/ObservableNullTests.java @@ -1662,7 +1662,7 @@ public void liftNull() { public void liftReturnsNull() { just1.lift(new ObservableOperator() { @Override - public Observer apply(Observer s) { + public Observer apply(Observer observer) { return null; } }).blockingSubscribe(); diff --git a/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java b/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java index 5e927ad46b..14af3cf2d0 100644 --- a/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java +++ b/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java @@ -215,7 +215,7 @@ public Observer apply(Observable a, Observer b) throws Exception { static final class BadObservable extends Observable { @Override - protected void subscribeActual(Observer s) { + protected void subscribeActual(Observer observer) { throw new IllegalArgumentException(); } } diff --git a/src/test/java/io/reactivex/observable/ObservableTest.java b/src/test/java/io/reactivex/observable/ObservableTest.java index 9b549670a8..64c5059bf8 100644 --- a/src/test/java/io/reactivex/observable/ObservableTest.java +++ b/src/test/java/io/reactivex/observable/ObservableTest.java @@ -346,7 +346,7 @@ public void testOnSubscribeFails() { final RuntimeException re = new RuntimeException("bad impl"); Observable o = Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { throw re; } + public void subscribe(Observer observer) { throw re; } }); o.subscribe(observer); @@ -1151,16 +1151,16 @@ public void testForEachWithNull() { @Test public void testExtend() { - final TestObserver subscriber = new TestObserver(); + final TestObserver to = new TestObserver(); final Object value = new Object(); Object returned = Observable.just(value).to(new Function, Object>() { @Override public Object apply(Observable onSubscribe) { - onSubscribe.subscribe(subscriber); - subscriber.assertNoErrors(); - subscriber.assertComplete(); - subscriber.assertValue(value); - return subscriber.values().get(0); + onSubscribe.subscribe(to); + to.assertNoErrors(); + to.assertComplete(); + to.assertValue(value); + return to.values().get(0); } }); assertSame(returned, value); @@ -1168,16 +1168,16 @@ public Object apply(Observable onSubscribe) { @Test public void testAsExtend() { - final TestObserver subscriber = new TestObserver(); + final TestObserver to = new TestObserver(); final Object value = new Object(); Object returned = Observable.just(value).as(new ObservableConverter() { @Override public Object apply(Observable onSubscribe) { - onSubscribe.subscribe(subscriber); - subscriber.assertNoErrors(); - subscriber.assertComplete(); - subscriber.assertValue(value); - return subscriber.values().get(0); + onSubscribe.subscribe(to); + to.assertNoErrors(); + to.assertComplete(); + to.assertValue(value); + return to.values().get(0); } }); assertSame(returned, value); diff --git a/src/test/java/io/reactivex/observers/SafeObserverTest.java b/src/test/java/io/reactivex/observers/SafeObserverTest.java index ee6eb83f43..54d1269138 100644 --- a/src/test/java/io/reactivex/observers/SafeObserverTest.java +++ b/src/test/java/io/reactivex/observers/SafeObserverTest.java @@ -447,7 +447,7 @@ static class SafeObserverTestException extends RuntimeException { @Ignore("Observers can't throw") public void testOnCompletedThrows() { final AtomicReference error = new AtomicReference(); - SafeObserver s = new SafeObserver(new DefaultObserver() { + SafeObserver observer = new SafeObserver(new DefaultObserver() { @Override public void onNext(Integer t) { @@ -463,7 +463,7 @@ public void onComplete() { }); try { - s.onComplete(); + observer.onComplete(); Assert.fail(); } catch (RuntimeException e) { assertNull(error.get()); @@ -483,9 +483,9 @@ public void onError(Throwable e) { public void onComplete() { } }; - SafeObserver s = new SafeObserver(actual); + SafeObserver observer = new SafeObserver(actual); - assertSame(actual, s.actual); + assertSame(actual, observer.actual); } @Test diff --git a/src/test/java/io/reactivex/observers/SerializedObserverTest.java b/src/test/java/io/reactivex/observers/SerializedObserverTest.java index 720964c1c0..726ca7aee4 100644 --- a/src/test/java/io/reactivex/observers/SerializedObserverTest.java +++ b/src/test/java/io/reactivex/observers/SerializedObserverTest.java @@ -435,11 +435,11 @@ private static Observable infinite(final AtomicInteger produced) { return Observable.unsafeCreate(new ObservableSource() { @Override - public void subscribe(Observer s) { + public void subscribe(Observer observer) { Disposable bs = Disposables.empty(); - s.onSubscribe(bs); + observer.onSubscribe(bs); while (!bs.isDisposed()) { - s.onNext("onNext"); + observer.onNext("onNext"); produced.incrementAndGet(); } } diff --git a/src/test/java/io/reactivex/observers/TestObserverTest.java b/src/test/java/io/reactivex/observers/TestObserverTest.java index c183451348..1b638ace38 100644 --- a/src/test/java/io/reactivex/observers/TestObserverTest.java +++ b/src/test/java/io/reactivex/observers/TestObserverTest.java @@ -48,68 +48,68 @@ public class TestObserverTest { @Test public void testAssert() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber subscriber = new TestSubscriber(); + oi.subscribe(subscriber); - o.assertValues(1, 2); - o.assertValueCount(2); - o.assertTerminated(); + subscriber.assertValues(1, 2); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); } @Test public void testAssertNotMatchCount() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber subscriber = new TestSubscriber(); + oi.subscribe(subscriber); thrown.expect(AssertionError.class); // FIXME different message format // thrown.expectMessage("Number of items does not match. Provided: 1 Actual: 2"); - o.assertValue(1); - o.assertValueCount(2); - o.assertTerminated(); + subscriber.assertValue(1); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); } @Test public void testAssertNotMatchValue() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber subscriber = new TestSubscriber(); + oi.subscribe(subscriber); thrown.expect(AssertionError.class); // FIXME different message format // thrown.expectMessage("Value at index: 1 expected to be [3] (Integer) but was: [2] (Integer)"); - o.assertValues(1, 3); - o.assertValueCount(2); - o.assertTerminated(); + subscriber.assertValues(1, 3); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); } @Test public void assertNeverAtNotMatchingValue() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber subscriber = new TestSubscriber(); + oi.subscribe(subscriber); - o.assertNever(3); - o.assertValueCount(2); - o.assertTerminated(); + subscriber.assertNever(3); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); } @Test public void assertNeverAtMatchingValue() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber subscriber = new TestSubscriber(); + oi.subscribe(subscriber); - o.assertValues(1, 2); + subscriber.assertValues(1, 2); thrown.expect(AssertionError.class); - o.assertNever(2); - o.assertValueCount(2); - o.assertTerminated(); + subscriber.assertNever(2); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); } @Test @@ -147,8 +147,8 @@ public boolean test(final Integer o) throws Exception { @Test public void testAssertTerminalEventNotReceived() { PublishProcessor p = PublishProcessor.create(); - TestSubscriber o = new TestSubscriber(); - p.subscribe(o); + TestSubscriber subscriber = new TestSubscriber(); + p.subscribe(subscriber); p.onNext(1); p.onNext(2); @@ -157,36 +157,36 @@ public void testAssertTerminalEventNotReceived() { // FIXME different message format // thrown.expectMessage("No terminal events received."); - o.assertValues(1, 2); - o.assertValueCount(2); - o.assertTerminated(); + subscriber.assertValues(1, 2); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); } @Test public void testWrappingMock() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - Subscriber mockObserver = TestHelper.mockSubscriber(); + Subscriber mockSubscriber = TestHelper.mockSubscriber(); - oi.subscribe(new TestSubscriber(mockObserver)); + oi.subscribe(new TestSubscriber(mockSubscriber)); - InOrder inOrder = inOrder(mockObserver); - inOrder.verify(mockObserver, times(1)).onNext(1); - inOrder.verify(mockObserver, times(1)).onNext(2); - inOrder.verify(mockObserver, times(1)).onComplete(); + InOrder inOrder = inOrder(mockSubscriber); + inOrder.verify(mockSubscriber, times(1)).onNext(1); + inOrder.verify(mockSubscriber, times(1)).onNext(2); + inOrder.verify(mockSubscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testWrappingMockWhenUnsubscribeInvolved() { 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)); + Subscriber mockSubscriber = TestHelper.mockSubscriber(); + oi.subscribe(new TestSubscriber(mockSubscriber)); - InOrder inOrder = inOrder(mockObserver); - inOrder.verify(mockObserver, times(1)).onNext(1); - inOrder.verify(mockObserver, times(1)).onNext(2); - inOrder.verify(mockObserver, times(1)).onComplete(); + InOrder inOrder = inOrder(mockSubscriber); + inOrder.verify(mockSubscriber, times(1)).onNext(1); + inOrder.verify(mockSubscriber, times(1)).onNext(2); + inOrder.verify(mockSubscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } diff --git a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java index b3cb2b142d..9fa9cc92d0 100644 --- a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java +++ b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java @@ -708,7 +708,7 @@ public void flowableStart() { try { RxJavaPlugins.setOnFlowableSubscribe(new BiFunction() { @Override - public Subscriber apply(Flowable o, final Subscriber t) { + public Subscriber apply(Flowable f, final Subscriber t) { return new Subscriber() { @Override diff --git a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java index 71251e7c9c..c97f3398e1 100644 --- a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java +++ b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java @@ -44,33 +44,33 @@ protected FlowableProcessor create() { public void testNeverCompleted() { AsyncProcessor processor = AsyncProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onNext("two"); processor.onNext("three"); - verify(observer, Mockito.never()).onNext(anyString()); - verify(observer, Mockito.never()).onError(testException); - verify(observer, Mockito.never()).onComplete(); + verify(subscriber, Mockito.never()).onNext(anyString()); + verify(subscriber, Mockito.never()).onError(testException); + verify(subscriber, Mockito.never()).onComplete(); } @Test public void testCompleted() { AsyncProcessor processor = AsyncProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onNext("two"); processor.onNext("three"); processor.onComplete(); - verify(observer, times(1)).onNext("three"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -78,40 +78,40 @@ public void testCompleted() { public void testNull() { AsyncProcessor processor = AsyncProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext(null); processor.onComplete(); - verify(observer, times(1)).onNext(null); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext(null); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testSubscribeAfterCompleted() { AsyncProcessor processor = AsyncProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); processor.onNext("one"); processor.onNext("two"); processor.onNext("three"); processor.onComplete(); - processor.subscribe(observer); + processor.subscribe(subscriber); - verify(observer, times(1)).onNext("three"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testSubscribeAfterError() { AsyncProcessor processor = AsyncProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); processor.onNext("one"); processor.onNext("two"); @@ -120,19 +120,19 @@ public void testSubscribeAfterError() { RuntimeException re = new RuntimeException("failed"); processor.onError(re); - processor.subscribe(observer); + processor.subscribe(subscriber); - verify(observer, times(1)).onError(re); - verify(observer, Mockito.never()).onNext(any(String.class)); - verify(observer, Mockito.never()).onComplete(); + verify(subscriber, times(1)).onError(re); + verify(subscriber, Mockito.never()).onNext(any(String.class)); + verify(subscriber, Mockito.never()).onComplete(); } @Test public void testError() { AsyncProcessor processor = AsyncProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onNext("two"); @@ -142,17 +142,17 @@ public void testError() { processor.onError(new Throwable()); processor.onComplete(); - verify(observer, Mockito.never()).onNext(anyString()); - verify(observer, times(1)).onError(testException); - verify(observer, Mockito.never()).onComplete(); + verify(subscriber, Mockito.never()).onNext(anyString()); + verify(subscriber, times(1)).onError(testException); + verify(subscriber, Mockito.never()).onComplete(); } @Test public void testUnsubscribeBeforeCompleted() { AsyncProcessor processor = AsyncProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); processor.subscribe(ts); processor.onNext("one"); @@ -160,31 +160,31 @@ public void testUnsubscribeBeforeCompleted() { ts.dispose(); - verify(observer, Mockito.never()).onNext(anyString()); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, Mockito.never()).onComplete(); + verify(subscriber, Mockito.never()).onNext(anyString()); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, Mockito.never()).onComplete(); processor.onNext("three"); processor.onComplete(); - verify(observer, Mockito.never()).onNext(anyString()); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, Mockito.never()).onComplete(); + verify(subscriber, Mockito.never()).onNext(anyString()); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, Mockito.never()).onComplete(); } @Test public void testEmptySubjectCompleted() { AsyncProcessor processor = AsyncProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onComplete(); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, never()).onNext(null); - inOrder.verify(observer, never()).onNext(any(String.class)); - inOrder.verify(observer, times(1)).onComplete(); + InOrder inOrder = inOrder(subscriber); + inOrder.verify(subscriber, never()).onNext(null); + inOrder.verify(subscriber, never()).onNext(any(String.class)); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } diff --git a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java index fd2677207f..59d8cbff02 100644 --- a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java +++ b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java @@ -47,19 +47,19 @@ protected FlowableProcessor create() { public void testThatSubscriberReceivesDefaultValueAndSubsequentEvents() { BehaviorProcessor processor = BehaviorProcessor.createDefault("default"); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onNext("two"); processor.onNext("three"); - verify(observer, times(1)).onNext("default"); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, Mockito.never()).onError(testException); - verify(observer, Mockito.never()).onComplete(); + verify(subscriber, times(1)).onNext("default"); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, Mockito.never()).onError(testException); + verify(subscriber, Mockito.never()).onComplete(); } @Test @@ -68,34 +68,34 @@ public void testThatSubscriberReceivesLatestAndThenSubsequentEvents() { processor.onNext("one"); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("two"); processor.onNext("three"); - verify(observer, Mockito.never()).onNext("default"); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, Mockito.never()).onError(testException); - verify(observer, Mockito.never()).onComplete(); + verify(subscriber, Mockito.never()).onNext("default"); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, Mockito.never()).onError(testException); + verify(subscriber, Mockito.never()).onComplete(); } @Test public void testSubscribeThenOnComplete() { BehaviorProcessor processor = BehaviorProcessor.createDefault("default"); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onComplete(); - verify(observer, times(1)).onNext("default"); - verify(observer, times(1)).onNext("one"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("default"); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -104,13 +104,13 @@ public void testSubscribeToCompletedOnlyEmitsOnComplete() { processor.onNext("one"); processor.onComplete(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); - verify(observer, never()).onNext("default"); - verify(observer, never()).onNext("one"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, never()).onNext("default"); + verify(subscriber, never()).onNext("one"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test @@ -120,13 +120,13 @@ public void testSubscribeToErrorOnlyEmitsOnError() { RuntimeException re = new RuntimeException("test error"); processor.onError(re); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); - verify(observer, never()).onNext("default"); - verify(observer, never()).onNext("one"); - verify(observer, times(1)).onError(re); - verify(observer, never()).onComplete(); + verify(subscriber, never()).onNext("default"); + verify(subscriber, never()).onNext("one"); + verify(subscriber, times(1)).onError(re); + verify(subscriber, never()).onComplete(); } @Test @@ -178,69 +178,69 @@ public void testCompletedStopsEmittingData() { public void testCompletedAfterErrorIsNotSent() { BehaviorProcessor processor = BehaviorProcessor.createDefault("default"); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onError(testException); processor.onNext("two"); processor.onComplete(); - verify(observer, times(1)).onNext("default"); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onError(testException); - verify(observer, never()).onNext("two"); - verify(observer, never()).onComplete(); + verify(subscriber, times(1)).onNext("default"); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onError(testException); + verify(subscriber, never()).onNext("two"); + verify(subscriber, never()).onComplete(); } @Test public void testCompletedAfterErrorIsNotSent2() { BehaviorProcessor processor = BehaviorProcessor.createDefault("default"); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onError(testException); processor.onNext("two"); processor.onComplete(); - verify(observer, times(1)).onNext("default"); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onError(testException); - verify(observer, never()).onNext("two"); - verify(observer, never()).onComplete(); + verify(subscriber, times(1)).onNext("default"); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onError(testException); + verify(subscriber, never()).onNext("two"); + verify(subscriber, never()).onComplete(); - Subscriber o2 = TestHelper.mockSubscriber(); - processor.subscribe(o2); - verify(o2, times(1)).onError(testException); - verify(o2, never()).onNext(any()); - verify(o2, never()).onComplete(); + Subscriber subscriber2 = TestHelper.mockSubscriber(); + processor.subscribe(subscriber2); + verify(subscriber2, times(1)).onError(testException); + verify(subscriber2, never()).onNext(any()); + verify(subscriber2, never()).onComplete(); } @Test public void testCompletedAfterErrorIsNotSent3() { BehaviorProcessor processor = BehaviorProcessor.createDefault("default"); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onComplete(); processor.onNext("two"); processor.onComplete(); - verify(observer, times(1)).onNext("default"); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onComplete(); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, never()).onNext("two"); + verify(subscriber, times(1)).onNext("default"); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext("two"); - Subscriber o2 = TestHelper.mockSubscriber(); - processor.subscribe(o2); - verify(o2, times(1)).onComplete(); - verify(o2, never()).onNext(any()); - verify(observer, never()).onError(any(Throwable.class)); + Subscriber subscriber2 = TestHelper.mockSubscriber(); + processor.subscribe(subscriber2); + verify(subscriber2, times(1)).onComplete(); + verify(subscriber2, never()).onNext(any()); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test(timeout = 1000) @@ -248,8 +248,8 @@ public void testUnsubscriptionCase() { 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(); - InOrder inOrder = inOrder(o); + final Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); String v = "" + i; src.onNext(v); System.out.printf("Turn: %d%n", i); @@ -264,34 +264,34 @@ public Flowable apply(String t1) { .subscribe(new DefaultSubscriber() { @Override public void onNext(String t) { - o.onNext(t); + subscriber.onNext(t); } @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }); - inOrder.verify(o).onNext(v + ", " + v); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(v + ", " + v); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } } @Test public void testStartEmpty() { BehaviorProcessor source = BehaviorProcessor.create(); - final Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + final Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); - source.subscribe(o); + source.subscribe(subscriber); - inOrder.verify(o, never()).onNext(any()); - inOrder.verify(o, never()).onComplete(); + inOrder.verify(subscriber, never()).onNext(any()); + inOrder.verify(subscriber, never()).onComplete(); source.onNext(1); @@ -299,10 +299,10 @@ public void testStartEmpty() { source.onNext(2); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); - inOrder.verify(o).onNext(1); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); @@ -310,52 +310,52 @@ public void testStartEmpty() { @Test public void testStartEmptyThenAddOne() { BehaviorProcessor source = BehaviorProcessor.create(); - final Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + final Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); source.onNext(1); - source.subscribe(o); + source.subscribe(subscriber); - inOrder.verify(o).onNext(1); + inOrder.verify(subscriber).onNext(1); source.onComplete(); source.onNext(2); - inOrder.verify(o).onComplete(); + inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test public void testStartEmptyCompleteWithOne() { BehaviorProcessor source = BehaviorProcessor.create(); - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); source.onNext(1); source.onComplete(); source.onNext(2); - source.subscribe(o); + source.subscribe(subscriber); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); - verify(o, never()).onNext(any()); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(any()); } @Test public void testTakeOneSubscriber() { BehaviorProcessor source = BehaviorProcessor.createDefault(1); - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); - source.take(1).subscribe(o); + source.take(1).subscribe(subscriber); - verify(o).onNext(1); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); assertEquals(0, source.subscriberCount()); assertFalse(source.hasSubscribers()); diff --git a/src/test/java/io/reactivex/processors/PublishProcessorTest.java b/src/test/java/io/reactivex/processors/PublishProcessorTest.java index 9989f6b392..8d9d4b7a88 100644 --- a/src/test/java/io/reactivex/processors/PublishProcessorTest.java +++ b/src/test/java/io/reactivex/processors/PublishProcessorTest.java @@ -42,8 +42,8 @@ protected FlowableProcessor create() { public void testCompleted() { PublishProcessor processor = PublishProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onNext("two"); @@ -57,7 +57,7 @@ public void testCompleted() { processor.onComplete(); processor.onError(new Throwable()); - assertCompletedSubscriber(observer); + assertCompletedSubscriber(subscriber); // todo bug? assertNeverSubscriber(anotherSubscriber); } @@ -103,20 +103,20 @@ public void testCompletedStopsEmittingData() { inOrderC.verifyNoMoreInteractions(); } - private void assertCompletedSubscriber(Subscriber observer) { - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + private void assertCompletedSubscriber(Subscriber subscriber) { + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testError() { PublishProcessor processor = PublishProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onNext("two"); @@ -130,29 +130,29 @@ public void testError() { processor.onError(new Throwable()); processor.onComplete(); - assertErrorSubscriber(observer); + assertErrorSubscriber(subscriber); // todo bug? assertNeverSubscriber(anotherSubscriber); } - private void assertErrorSubscriber(Subscriber observer) { - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, times(1)).onError(testException); - verify(observer, Mockito.never()).onComplete(); + private void assertErrorSubscriber(Subscriber subscriber) { + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, times(1)).onError(testException); + verify(subscriber, Mockito.never()).onComplete(); } @Test public void testSubscribeMidSequence() { PublishProcessor processor = PublishProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onNext("two"); - assertObservedUntilTwo(observer); + assertObservedUntilTwo(subscriber); Subscriber anotherSubscriber = TestHelper.mockSubscriber(); processor.subscribe(anotherSubscriber); @@ -160,31 +160,31 @@ public void testSubscribeMidSequence() { processor.onNext("three"); processor.onComplete(); - assertCompletedSubscriber(observer); + assertCompletedSubscriber(subscriber); assertCompletedStartingWithThreeSubscriber(anotherSubscriber); } - private void assertCompletedStartingWithThreeSubscriber(Subscriber observer) { - verify(observer, Mockito.never()).onNext("one"); - verify(observer, Mockito.never()).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + private void assertCompletedStartingWithThreeSubscriber(Subscriber subscriber) { + verify(subscriber, Mockito.never()).onNext("one"); + verify(subscriber, Mockito.never()).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); } @Test public void testUnsubscribeFirstSubscriber() { PublishProcessor processor = PublishProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); processor.subscribe(ts); processor.onNext("one"); processor.onNext("two"); ts.dispose(); - assertObservedUntilTwo(observer); + assertObservedUntilTwo(subscriber); Subscriber anotherSubscriber = TestHelper.mockSubscriber(); processor.subscribe(anotherSubscriber); @@ -192,16 +192,16 @@ public void testUnsubscribeFirstSubscriber() { processor.onNext("three"); processor.onComplete(); - assertObservedUntilTwo(observer); + assertObservedUntilTwo(subscriber); assertCompletedStartingWithThreeSubscriber(anotherSubscriber); } - private void assertObservedUntilTwo(Subscriber observer) { - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, Mockito.never()).onComplete(); + private void assertObservedUntilTwo(Subscriber subscriber) { + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, Mockito.never()).onComplete(); } @Test @@ -262,16 +262,16 @@ public void accept(String v) { public void testReSubscribe() { final PublishProcessor pp = PublishProcessor.create(); - Subscriber o1 = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(o1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber1); pp.subscribe(ts); // emit pp.onNext(1); // validate we got it - InOrder inOrder1 = inOrder(o1); - inOrder1.verify(o1, times(1)).onNext(1); + InOrder inOrder1 = inOrder(subscriber1); + inOrder1.verify(subscriber1, times(1)).onNext(1); inOrder1.verifyNoMoreInteractions(); // unsubscribe @@ -280,16 +280,16 @@ public void testReSubscribe() { // emit again but nothing will be there to receive it pp.onNext(2); - Subscriber o2 = TestHelper.mockSubscriber(); - TestSubscriber ts2 = new TestSubscriber(o2); + Subscriber subscriber2 = TestHelper.mockSubscriber(); + TestSubscriber ts2 = new TestSubscriber(subscriber2); pp.subscribe(ts2); // emit pp.onNext(3); // validate we got it - InOrder inOrder2 = inOrder(o2); - inOrder2.verify(o2, times(1)).onNext(3); + InOrder inOrder2 = inOrder(subscriber2); + inOrder2.verify(subscriber2, times(1)).onNext(3); inOrder2.verifyNoMoreInteractions(); ts2.dispose(); @@ -302,8 +302,8 @@ public void testUnsubscriptionCase() { PublishProcessor src = PublishProcessor.create(); for (int i = 0; i < 10; i++) { - final Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + final Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); String v = "" + i; System.out.printf("Turn: %d%n", i); src.firstElement().toFlowable() @@ -317,24 +317,24 @@ public Flowable apply(String t1) { .subscribe(new DefaultSubscriber() { @Override public void onNext(String t) { - o.onNext(t); + subscriber.onNext(t); } @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }); src.onNext(v); - inOrder.verify(o).onNext(v + ", " + v); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext(v + ", " + v); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } } diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java index 7edef31ecd..dd0f32821f 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java @@ -39,13 +39,13 @@ public void run() { Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber o) { + public void subscribe(Subscriber subscriber) { System.out.println("********* Start Source Data ***********"); for (long l = 1; l <= 10000; l++) { - o.onNext(l); + subscriber.onNext(l); } System.out.println("********* Finished Source Data ***********"); - o.onComplete(); + subscriber.onComplete(); } }).subscribe(replay); } @@ -148,13 +148,13 @@ public void run() { Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber o) { + public void subscribe(Subscriber subscriber) { System.out.println("********* Start Source Data ***********"); for (long l = 1; l <= 10000; l++) { - o.onNext(l); + subscriber.onNext(l); } System.out.println("********* Finished Source Data ***********"); - o.onComplete(); + subscriber.onComplete(); } }).subscribe(replay); } diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java index 62b0817678..e63f8f361f 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java @@ -39,13 +39,13 @@ public void run() { Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber o) { + public void subscribe(Subscriber subscriber) { System.out.println("********* Start Source Data ***********"); for (long l = 1; l <= 10000; l++) { - o.onNext(l); + subscriber.onNext(l); } System.out.println("********* Finished Source Data ***********"); - o.onComplete(); + subscriber.onComplete(); } }).subscribe(replay); } @@ -148,13 +148,13 @@ public void run() { Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber o) { + public void subscribe(Subscriber subscriber) { System.out.println("********* Start Source Data ***********"); for (long l = 1; l <= 10000; l++) { - o.onNext(l); + subscriber.onNext(l); } System.out.println("********* Finished Source Data ***********"); - o.onComplete(); + subscriber.onComplete(); } }).subscribe(replay); } diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java index 20e6b9a8df..75c013d996 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java @@ -47,8 +47,8 @@ protected FlowableProcessor create() { public void testCompleted() { ReplayProcessor processor = ReplayProcessor.create(); - Subscriber o1 = TestHelper.mockSubscriber(); - processor.subscribe(o1); + Subscriber subscriber1 = TestHelper.mockSubscriber(); + processor.subscribe(subscriber1); processor.onNext("one"); processor.onNext("two"); @@ -59,12 +59,12 @@ public void testCompleted() { processor.onComplete(); processor.onError(new Throwable()); - assertCompletedSubscriber(o1); + assertCompletedSubscriber(subscriber1); // assert that subscribing a 2nd time gets the same data - Subscriber o2 = TestHelper.mockSubscriber(); - processor.subscribe(o2); - assertCompletedSubscriber(o2); + Subscriber subscriber2 = TestHelper.mockSubscriber(); + processor.subscribe(subscriber2); + assertCompletedSubscriber(subscriber2); } @Test @@ -140,7 +140,7 @@ public void testCompletedStopsEmittingData() { public void testCompletedAfterError() { ReplayProcessor processor = ReplayProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); processor.onNext("one"); processor.onError(testException); @@ -148,21 +148,21 @@ public void testCompletedAfterError() { processor.onComplete(); processor.onError(new RuntimeException()); - processor.subscribe(observer); - verify(observer).onSubscribe((Subscription)notNull()); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onError(testException); - verifyNoMoreInteractions(observer); + processor.subscribe(subscriber); + verify(subscriber).onSubscribe((Subscription)notNull()); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onError(testException); + verifyNoMoreInteractions(subscriber); } - private void assertCompletedSubscriber(Subscriber observer) { - InOrder inOrder = inOrder(observer); + private void assertCompletedSubscriber(Subscriber subscriber) { + InOrder inOrder = inOrder(subscriber); - inOrder.verify(observer, times(1)).onNext("one"); - inOrder.verify(observer, times(1)).onNext("two"); - inOrder.verify(observer, times(1)).onNext("three"); - inOrder.verify(observer, Mockito.never()).onError(any(Throwable.class)); - inOrder.verify(observer, times(1)).onComplete(); + inOrder.verify(subscriber, times(1)).onNext("one"); + inOrder.verify(subscriber, times(1)).onNext("two"); + inOrder.verify(subscriber, times(1)).onNext("three"); + inOrder.verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @@ -170,8 +170,8 @@ private void assertCompletedSubscriber(Subscriber observer) { public void testError() { ReplayProcessor processor = ReplayProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onNext("two"); @@ -182,32 +182,32 @@ public void testError() { processor.onError(new Throwable()); processor.onComplete(); - assertErrorSubscriber(observer); + assertErrorSubscriber(subscriber); - observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); - assertErrorSubscriber(observer); + subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); + assertErrorSubscriber(subscriber); } - private void assertErrorSubscriber(Subscriber observer) { - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, times(1)).onError(testException); - verify(observer, Mockito.never()).onComplete(); + private void assertErrorSubscriber(Subscriber subscriber) { + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, times(1)).onError(testException); + verify(subscriber, Mockito.never()).onComplete(); } @Test public void testSubscribeMidSequence() { ReplayProcessor processor = ReplayProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - processor.subscribe(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + processor.subscribe(subscriber); processor.onNext("one"); processor.onNext("two"); - assertObservedUntilTwo(observer); + assertObservedUntilTwo(subscriber); Subscriber anotherSubscriber = TestHelper.mockSubscriber(); processor.subscribe(anotherSubscriber); @@ -216,7 +216,7 @@ public void testSubscribeMidSequence() { processor.onNext("three"); processor.onComplete(); - assertCompletedSubscriber(observer); + assertCompletedSubscriber(subscriber); assertCompletedSubscriber(anotherSubscriber); } @@ -224,15 +224,15 @@ public void testSubscribeMidSequence() { public void testUnsubscribeFirstSubscriber() { ReplayProcessor processor = ReplayProcessor.create(); - Subscriber observer = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(observer); + Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber ts = new TestSubscriber(subscriber); processor.subscribe(ts); processor.onNext("one"); processor.onNext("two"); ts.dispose(); - assertObservedUntilTwo(observer); + assertObservedUntilTwo(subscriber); Subscriber anotherSubscriber = TestHelper.mockSubscriber(); processor.subscribe(anotherSubscriber); @@ -241,23 +241,23 @@ public void testUnsubscribeFirstSubscriber() { processor.onNext("three"); processor.onComplete(); - assertObservedUntilTwo(observer); + assertObservedUntilTwo(subscriber); assertCompletedSubscriber(anotherSubscriber); } - private void assertObservedUntilTwo(Subscriber observer) { - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, Mockito.never()).onNext("three"); - verify(observer, Mockito.never()).onError(any(Throwable.class)); - verify(observer, Mockito.never()).onComplete(); + private void assertObservedUntilTwo(Subscriber subscriber) { + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, Mockito.never()).onNext("three"); + verify(subscriber, Mockito.never()).onError(any(Throwable.class)); + verify(subscriber, Mockito.never()).onComplete(); } @Test(timeout = 2000) public void testNewSubscriberDoesntBlockExisting() throws InterruptedException { final AtomicReference lastValueForSubscriber1 = new AtomicReference(); - Subscriber observer1 = new DefaultSubscriber() { + Subscriber subscriber1 = new DefaultSubscriber() { @Override public void onComplete() { @@ -281,7 +281,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 DefaultSubscriber() { + Subscriber subscriber2 = new DefaultSubscriber() { @Override public void onComplete() { @@ -311,14 +311,14 @@ public void onNext(String v) { }; ReplayProcessor processor = ReplayProcessor.create(); - processor.subscribe(observer1); + processor.subscribe(subscriber1); processor.onNext("one"); assertEquals("one", lastValueForSubscriber1.get()); processor.onNext("two"); assertEquals("two", lastValueForSubscriber1.get()); // use subscribeOn to make this async otherwise we deadlock as we are using CountDownLatches - processor.subscribeOn(Schedulers.newThread()).subscribe(observer2); + processor.subscribeOn(Schedulers.newThread()).subscribe(subscriber2); System.out.println("before waiting for one"); @@ -368,8 +368,8 @@ public void testUnsubscriptionCase() { ReplayProcessor src = ReplayProcessor.create(); for (int i = 0; i < 10; i++) { - final Subscriber o = TestHelper.mockSubscriber(); - InOrder inOrder = inOrder(o); + final Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); String v = "" + i; src.onNext(v); System.out.printf("Turn: %d%n", i); @@ -385,22 +385,22 @@ public Flowable apply(String t1) { @Override public void onNext(String t) { System.out.println(t); - o.onNext(t); + subscriber.onNext(t); } @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }); - inOrder.verify(o).onNext("0, 0"); - inOrder.verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + inOrder.verify(subscriber).onNext("0, 0"); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } } @Test @@ -410,30 +410,30 @@ public void testTerminateOnce() { source.onNext(2); source.onComplete(); - final Subscriber o = TestHelper.mockSubscriber(); + final Subscriber subscriber = TestHelper.mockSubscriber(); source.subscribe(new DefaultSubscriber() { @Override public void onNext(Integer t) { - o.onNext(t); + subscriber.onNext(t); } @Override public void onError(Throwable e) { - o.onError(e); + subscriber.onError(e); } @Override public void onComplete() { - o.onComplete(); + subscriber.onComplete(); } }); - verify(o).onNext(1); - verify(o).onNext(2); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber).onNext(1); + verify(subscriber).onNext(2); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -445,35 +445,35 @@ public void testReplay1AfterTermination() { source.onComplete(); for (int i = 0; i < 1; i++) { - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.subscribe(o); + source.subscribe(subscriber); - verify(o, never()).onNext(1); - verify(o).onNext(2); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(1); + verify(subscriber).onNext(2); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } } @Test public void testReplay1Directly() { ReplayProcessor source = ReplayProcessor.createWithSize(1); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); source.onNext(1); source.onNext(2); - source.subscribe(o); + source.subscribe(subscriber); source.onNext(3); source.onComplete(); - verify(o, never()).onNext(1); - verify(o).onNext(2); - verify(o).onNext(3); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(1); + verify(subscriber).onNext(2); + verify(subscriber).onNext(3); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -494,15 +494,15 @@ public void testReplayTimestampedAfterTermination() { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.subscribe(o); + source.subscribe(subscriber); - verify(o, never()).onNext(1); - verify(o, never()).onNext(2); - verify(o, never()).onNext(3); - verify(o).onComplete(); - verify(o, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(1); + verify(subscriber, never()).onNext(2); + verify(subscriber, never()).onNext(3); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); } @Test @@ -514,9 +514,9 @@ public void testReplayTimestampedDirectly() { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Subscriber o = TestHelper.mockSubscriber(); + Subscriber subscriber = TestHelper.mockSubscriber(); - source.subscribe(o); + source.subscribe(subscriber); source.onNext(2); @@ -530,11 +530,11 @@ public void testReplayTimestampedDirectly() { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - verify(o, never()).onError(any(Throwable.class)); - verify(o, never()).onNext(1); - verify(o).onNext(2); - verify(o).onNext(3); - verify(o).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, never()).onNext(1); + verify(subscriber).onNext(2); + verify(subscriber).onNext(3); + verify(subscriber).onComplete(); } // FIXME RS subscribers can't throw diff --git a/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java b/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java index f34ed7b604..120dee09d7 100644 --- a/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java +++ b/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java @@ -290,11 +290,11 @@ public void testRecursionAndOuterUnsubscribe() throws InterruptedException { try { Flowable obs = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { + public void subscribe(final Subscriber subscriber) { inner.schedule(new Runnable() { @Override public void run() { - observer.onNext(42); + subscriber.onNext(42); latch.countDown(); // this will recursively schedule this task for execution again @@ -302,12 +302,12 @@ public void run() { } }); - observer.onSubscribe(new Subscription() { + subscriber.onSubscribe(new Subscription() { @Override public void cancel() { inner.dispose(); - observer.onComplete(); + subscriber.onComplete(); completionLatch.countDown(); } @@ -368,9 +368,9 @@ public final void testSubscribeWithScheduler() throws InterruptedException { final AtomicInteger count = new AtomicInteger(); - Flowable o1 = Flowable. just(1, 2, 3, 4, 5); + Flowable f1 = Flowable. just(1, 2, 3, 4, 5); - o1.subscribe(new Consumer() { + f1.subscribe(new Consumer() { @Override public void accept(Integer t) { @@ -393,7 +393,7 @@ public void accept(Integer t) { final CountDownLatch latch = new CountDownLatch(5); final CountDownLatch first = new CountDownLatch(1); - o1.subscribeOn(scheduler).subscribe(new Consumer() { + f1.subscribeOn(scheduler).subscribe(new Consumer() { @Override public void accept(Integer t) { diff --git a/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java b/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java index 8d2b56b460..ed67bce571 100644 --- a/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java +++ b/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java @@ -329,11 +329,11 @@ public void run() { public final void testRecursiveSchedulerInObservable() { Flowable obs = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { + public void subscribe(final Subscriber subscriber) { final Scheduler.Worker inner = getScheduler().createWorker(); AsyncSubscription as = new AsyncSubscription(); - observer.onSubscribe(as); + subscriber.onSubscribe(as); as.setResource(inner); inner.schedule(new Runnable() { @@ -343,14 +343,14 @@ public void subscribe(final Subscriber observer) { public void run() { if (i > 42) { try { - observer.onComplete(); + subscriber.onComplete(); } finally { inner.dispose(); } return; } - observer.onNext(i++); + subscriber.onNext(i++); inner.schedule(this); } @@ -375,18 +375,18 @@ public void accept(Integer v) { public final void testConcurrentOnNextFailsValidation() throws InterruptedException { final int count = 10; final CountDownLatch latch = new CountDownLatch(count); - Flowable o = Flowable.unsafeCreate(new Publisher() { + Flowable f = Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); for (int i = 0; i < count; i++) { final int v = i; new Thread(new Runnable() { @Override public void run() { - observer.onNext("v: " + v); + subscriber.onNext("v: " + v); latch.countDown(); } @@ -397,7 +397,7 @@ public void run() { ConcurrentObserverValidator observer = new ConcurrentObserverValidator(); // this should call onNext concurrently - o.subscribe(observer); + f.subscribe(observer); if (!observer.completed.await(3000, TimeUnit.MILLISECONDS)) { fail("timed out"); @@ -412,11 +412,11 @@ public void run() { public final void testObserveOn() throws InterruptedException { final Scheduler scheduler = getScheduler(); - Flowable o = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); + Flowable f = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); ConcurrentObserverValidator observer = new ConcurrentObserverValidator(); - o.observeOn(scheduler).subscribe(observer); + f.observeOn(scheduler).subscribe(observer); if (!observer.completed.await(3000, TimeUnit.MILLISECONDS)) { fail("timed out"); @@ -432,7 +432,7 @@ public final void testObserveOn() throws InterruptedException { public final void testSubscribeOnNestedConcurrency() throws InterruptedException { final Scheduler scheduler = getScheduler(); - Flowable o = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") + Flowable f = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") .flatMap(new Function>() { @Override @@ -440,10 +440,10 @@ public Flowable apply(final String v) { return Flowable.unsafeCreate(new Publisher() { @Override - public void subscribe(Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); - observer.onNext("value_after_map-" + v); - observer.onComplete(); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("value_after_map-" + v); + subscriber.onComplete(); } }).subscribeOn(scheduler); } @@ -451,7 +451,7 @@ public void subscribe(Subscriber observer) { ConcurrentObserverValidator observer = new ConcurrentObserverValidator(); - o.subscribe(observer); + f.subscribe(observer); if (!observer.completed.await(3000, TimeUnit.MILLISECONDS)) { fail("timed out"); diff --git a/src/test/java/io/reactivex/schedulers/CachedThreadSchedulerTest.java b/src/test/java/io/reactivex/schedulers/CachedThreadSchedulerTest.java index 61b14fac21..df6ba44670 100644 --- a/src/test/java/io/reactivex/schedulers/CachedThreadSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/CachedThreadSchedulerTest.java @@ -38,9 +38,9 @@ protected Scheduler getScheduler() { @Test public final void testIOScheduler() { - 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() { + Flowable f1 = Flowable.just(1, 2, 3, 4, 5); + Flowable f2 = Flowable.just(6, 7, 8, 9, 10); + Flowable f = Flowable.merge(f1, f2).map(new Function() { @Override public String apply(Integer t) { @@ -49,7 +49,7 @@ public String apply(Integer t) { } }); - o.subscribeOn(Schedulers.io()).blockingForEach(new Consumer() { + f.subscribeOn(Schedulers.io()).blockingForEach(new Consumer() { @Override public void accept(String t) { diff --git a/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java b/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java index 67912db80d..9caa79e7b3 100644 --- a/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java +++ b/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java @@ -91,9 +91,9 @@ public void run() { @Test public final void testComputationThreadPool1() { - 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() { + Flowable f1 = Flowable. just(1, 2, 3, 4, 5); + Flowable f2 = Flowable. just(6, 7, 8, 9, 10); + Flowable f = Flowable. merge(f1, f2).map(new Function() { @Override public String apply(Integer t) { @@ -102,7 +102,7 @@ public String apply(Integer t) { } }); - o.subscribeOn(Schedulers.computation()).blockingForEach(new Consumer() { + f.subscribeOn(Schedulers.computation()).blockingForEach(new Consumer() { @Override public void accept(String t) { @@ -117,9 +117,9 @@ public final void testMergeWithExecutorScheduler() { final String currentThreadName = Thread.currentThread().getName(); - 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() { + Flowable f1 = Flowable. just(1, 2, 3, 4, 5); + Flowable f2 = Flowable. just(6, 7, 8, 9, 10); + Flowable f = Flowable. merge(f1, f2).subscribeOn(Schedulers.computation()).map(new Function() { @Override public String apply(Integer t) { @@ -129,7 +129,7 @@ public String apply(Integer t) { } }); - o.blockingForEach(new Consumer() { + f.blockingForEach(new Consumer() { @Override public void accept(String t) { diff --git a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java index df40ea63fd..2768a12b1a 100644 --- a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java @@ -45,9 +45,9 @@ public final void testMergeWithCurrentThreadScheduler1() { final String currentThreadName = Thread.currentThread().getName(); - 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() { + Flowable f1 = Flowable. just(1, 2, 3, 4, 5); + Flowable f2 = Flowable. just(6, 7, 8, 9, 10); + Flowable f = Flowable. merge(f1, f2).subscribeOn(Schedulers.trampoline()).map(new Function() { @Override public String apply(Integer t) { @@ -56,7 +56,7 @@ public String apply(Integer t) { } }); - o.blockingForEach(new Consumer() { + f.blockingForEach(new Consumer() { @Override public void accept(String t) { @@ -110,8 +110,8 @@ public void run() { @Test public void testTrampolineWorkerHandlesConcurrentScheduling() { final Worker trampolineWorker = Schedulers.trampoline().createWorker(); - final Subscriber observer = TestHelper.mockSubscriber(); - final TestSubscriber ts = new TestSubscriber(observer); + final Subscriber subscriber = TestHelper.mockSubscriber(); + final TestSubscriber ts = new TestSubscriber(subscriber); // Spam the trampoline with actions. Flowable.range(0, 50) diff --git a/src/test/java/io/reactivex/single/SingleNullTests.java b/src/test/java/io/reactivex/single/SingleNullTests.java index 374d7ee313..3efcbbcc6e 100644 --- a/src/test/java/io/reactivex/single/SingleNullTests.java +++ b/src/test/java/io/reactivex/single/SingleNullTests.java @@ -664,7 +664,7 @@ public void liftNull() { public void liftFunctionReturnsNull() { just1.lift(new SingleOperator() { @Override - public SingleObserver apply(SingleObserver s) { + public SingleObserver apply(SingleObserver observer) { return null; } }).blockingGet(); diff --git a/src/test/java/io/reactivex/single/SingleTest.java b/src/test/java/io/reactivex/single/SingleTest.java index ac9df2fafb..9e3d136c6d 100644 --- a/src/test/java/io/reactivex/single/SingleTest.java +++ b/src/test/java/io/reactivex/single/SingleTest.java @@ -131,9 +131,9 @@ public void testCreateSuccess() { Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(SingleObserver s) { - s.onSubscribe(Disposables.empty()); - s.onSuccess("Hello"); + public void subscribe(SingleObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onSuccess("Hello"); } }).toFlowable().subscribe(ts); @@ -145,9 +145,9 @@ public void testCreateError() { TestSubscriber ts = new TestSubscriber(); Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(SingleObserver s) { - s.onSubscribe(Disposables.empty()); - s.onError(new RuntimeException("fail")); + public void subscribe(SingleObserver observer) { + observer.onSubscribe(Disposables.empty()); + observer.onError(new RuntimeException("fail")); } }).toFlowable().subscribe(ts); @@ -202,14 +202,14 @@ public void testTimeout() { TestSubscriber ts = new TestSubscriber(); Single s1 = Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(SingleObserver s) { - s.onSubscribe(Disposables.empty()); + public void subscribe(SingleObserver observer) { + observer.onSubscribe(Disposables.empty()); try { Thread.sleep(5000); } catch (InterruptedException e) { // ignore as we expect this for the test } - s.onSuccess("success"); + observer.onSuccess("success"); } }).subscribeOn(Schedulers.io()); @@ -224,14 +224,14 @@ public void testTimeoutWithFallback() { TestSubscriber ts = new TestSubscriber(); Single s1 = Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(SingleObserver s) { - s.onSubscribe(Disposables.empty()); + public void subscribe(SingleObserver observer) { + observer.onSubscribe(Disposables.empty()); try { Thread.sleep(5000); } catch (InterruptedException e) { // ignore as we expect this for the test } - s.onSuccess("success"); + observer.onSuccess("success"); } }).subscribeOn(Schedulers.io()); @@ -251,16 +251,16 @@ public void testUnsubscribe() throws InterruptedException { Single s1 = Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(final SingleObserver s) { + public void subscribe(final SingleObserver observer) { SerialDisposable sd = new SerialDisposable(); - s.onSubscribe(sd); + observer.onSubscribe(sd); final Thread t = new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(5000); - s.onSuccess("success"); + observer.onSuccess("success"); } catch (InterruptedException e) { interrupted.set(true); latch.countDown(); @@ -325,16 +325,16 @@ public void onError(Throwable error) { Single s1 = Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(final SingleObserver s) { + public void subscribe(final SingleObserver observer) { SerialDisposable sd = new SerialDisposable(); - s.onSubscribe(sd); + observer.onSubscribe(sd); final Thread t = new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(5000); - s.onSuccess("success"); + observer.onSuccess("success"); } catch (InterruptedException e) { interrupted.set(true); latch.countDown(); @@ -381,16 +381,16 @@ public void testUnsubscribeViaReturnedSubscription() throws InterruptedException Single s1 = Single.unsafeCreate(new SingleSource() { @Override - public void subscribe(final SingleObserver s) { + public void subscribe(final SingleObserver observer) { SerialDisposable sd = new SerialDisposable(); - s.onSubscribe(sd); + observer.onSubscribe(sd); final Thread t = new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(5000); - s.onSuccess("success"); + observer.onSuccess("success"); } catch (InterruptedException e) { interrupted.set(true); latch.countDown(); diff --git a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java index a57aaf6a4a..2e1893d2f8 100644 --- a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java @@ -117,27 +117,27 @@ public void testOnErrorAfterOnCompleted() { */ private static class TestObservable implements Publisher { - Subscriber observer; + Subscriber subscriber; /* used to simulate subscription */ public void sendOnCompleted() { - observer.onComplete(); + subscriber.onComplete(); } /* used to simulate subscription */ public void sendOnNext(String value) { - observer.onNext(value); + subscriber.onNext(value); } /* used to simulate subscription */ public void sendOnError(Throwable e) { - observer.onError(e); + subscriber.onError(e); } @Override - public void subscribe(Subscriber observer) { - this.observer = observer; - observer.onSubscribe(new Subscription() { + public void subscribe(Subscriber subscriber) { + this.subscriber = subscriber; + subscriber.onSubscribe(new Subscription() { @Override public void cancel() { @@ -199,7 +199,7 @@ public void onCompleteFailure() { @Test public void onErrorFailure() { try { - OBSERVER_ONERROR_FAIL().onError(new SafeSubscriberTestException("error!")); + subscriberOnErrorFail().onError(new SafeSubscriberTestException("error!")); fail("expects exception to be thrown"); } catch (Exception e) { assertTrue(e instanceof SafeSubscriberTestException); @@ -211,7 +211,7 @@ public void onErrorFailure() { @Ignore("Observers can't throw") public void onErrorFailureSafe() { try { - new SafeSubscriber(OBSERVER_ONERROR_FAIL()).onError(new SafeSubscriberTestException("error!")); + new SafeSubscriber(subscriberOnErrorFail()).onError(new SafeSubscriberTestException("error!")); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -237,7 +237,7 @@ public void onErrorFailureSafe() { @Ignore("Observers can't throw") public void onErrorNotImplementedFailureSafe() { try { - new SafeSubscriber(OBSERVER_ONERROR_NOTIMPLEMENTED()).onError(new SafeSubscriberTestException("error!")); + new SafeSubscriber(subscriberOnErrorNotImplemented()).onError(new SafeSubscriberTestException("error!")); fail("expects exception to be thrown"); } catch (Exception e) { // assertTrue(e instanceof OnErrorNotImplementedException); @@ -301,10 +301,10 @@ public void request(long n) { @Test @Ignore("Observers can't throw") public void onCompleteSuccessWithUnsubscribeFailure() { - Subscriber o = OBSERVER_SUCCESS(); + Subscriber subscriber = subscriberSuccess(); try { - o.onSubscribe(THROWING_DISPOSABLE); - new SafeSubscriber(o).onComplete(); + subscriber.onSubscribe(THROWING_DISPOSABLE); + new SafeSubscriber(subscriber).onComplete(); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -322,10 +322,10 @@ public void onCompleteSuccessWithUnsubscribeFailure() { @Ignore("Observers can't throw") public void onErrorSuccessWithUnsubscribeFailure() { AtomicReference onError = new AtomicReference(); - Subscriber o = OBSERVER_SUCCESS(onError); + Subscriber subscriber = subscriberSuccess(onError); try { - o.onSubscribe(THROWING_DISPOSABLE); - new SafeSubscriber(o).onError(new SafeSubscriberTestException("failed")); + subscriber.onSubscribe(THROWING_DISPOSABLE); + new SafeSubscriber(subscriber).onError(new SafeSubscriberTestException("failed")); fail("we expect the unsubscribe failure to cause an exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -348,10 +348,10 @@ public void onErrorSuccessWithUnsubscribeFailure() { @Test @Ignore("Observers can't throw") public void onErrorFailureWithUnsubscribeFailure() { - Subscriber o = OBSERVER_ONERROR_FAIL(); + Subscriber subscriber = subscriberOnErrorFail(); try { - o.onSubscribe(THROWING_DISPOSABLE); - new SafeSubscriber(o).onError(new SafeSubscriberTestException("onError failure")); + subscriber.onSubscribe(THROWING_DISPOSABLE); + new SafeSubscriber(subscriber).onError(new SafeSubscriberTestException("onError failure")); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -385,10 +385,10 @@ public void onErrorFailureWithUnsubscribeFailure() { @Test @Ignore("Observers can't throw") public void onErrorNotImplementedFailureWithUnsubscribeFailure() { - Subscriber o = OBSERVER_ONERROR_NOTIMPLEMENTED(); + Subscriber subscriber = subscriberOnErrorNotImplemented(); try { - o.onSubscribe(THROWING_DISPOSABLE); - new SafeSubscriber(o).onError(new SafeSubscriberTestException("error!")); + subscriber.onSubscribe(THROWING_DISPOSABLE); + new SafeSubscriber(subscriber).onError(new SafeSubscriberTestException("error!")); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -415,7 +415,7 @@ public void onErrorNotImplementedFailureWithUnsubscribeFailure() { } } - private static Subscriber OBSERVER_SUCCESS() { + private static Subscriber subscriberSuccess() { return new DefaultSubscriber() { @Override @@ -436,7 +436,7 @@ public void onNext(String args) { } - private static Subscriber OBSERVER_SUCCESS(final AtomicReference onError) { + private static Subscriber subscriberSuccess(final AtomicReference onError) { return new DefaultSubscriber() { @Override @@ -499,7 +499,7 @@ public void onNext(String args) { }; } - private static Subscriber OBSERVER_ONERROR_FAIL() { + private static Subscriber subscriberOnErrorFail() { return new DefaultSubscriber() { @Override @@ -520,7 +520,7 @@ public void onNext(String args) { }; } - private static Subscriber OBSERVER_ONERROR_NOTIMPLEMENTED() { + private static Subscriber subscriberOnErrorNotImplemented() { return new DefaultSubscriber() { @Override diff --git a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java index 6f2e6fc7e6..44d2920699 100644 --- a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java @@ -32,15 +32,15 @@ public class SerializedSubscriberTest { - Subscriber observer; + Subscriber subscriber; @Before public void before() { - observer = TestHelper.mockSubscriber(); + subscriber = TestHelper.mockSubscriber(); } - private Subscriber serializedSubscriber(Subscriber o) { - return new SerializedSubscriber(o); + private Subscriber serializedSubscriber(Subscriber subscriber) { + return new SerializedSubscriber(subscriber); } @Test @@ -48,16 +48,16 @@ public void testSingleThreadedBasic() { TestSingleThreadedPublisher onSubscribe = new TestSingleThreadedPublisher("one", "two", "three"); Flowable w = Flowable.unsafeCreate(onSubscribe); - Subscriber aw = serializedSubscriber(observer); + Subscriber aw = serializedSubscriber(subscriber); w.subscribe(aw); onSubscribe.waitToFinish(); - verify(observer, times(1)).onNext("one"); - verify(observer, times(1)).onNext("two"); - verify(observer, times(1)).onNext("three"); - verify(observer, never()).onError(any(Throwable.class)); - verify(observer, times(1)).onComplete(); + verify(subscriber, times(1)).onNext("one"); + verify(subscriber, times(1)).onNext("two"); + verify(subscriber, times(1)).onNext("three"); + verify(subscriber, never()).onError(any(Throwable.class)); + verify(subscriber, times(1)).onComplete(); // non-deterministic because unsubscribe happens after 'waitToFinish' releases // so commenting out for now as this is not a critical thing to test here // verify(s, times(1)).unsubscribe(); @@ -290,10 +290,10 @@ public void onNext(String t) { } }); - Subscriber o = serializedSubscriber(ts); + Subscriber subscriber = serializedSubscriber(ts); - Future f1 = tp1.submit(new OnNextThread(o, 1, onNextCount, running)); - Future f2 = tp2.submit(new OnNextThread(o, 1, onNextCount, running)); + Future f1 = tp1.submit(new OnNextThread(subscriber, 1, onNextCount, running)); + Future f2 = tp2.submit(new OnNextThread(subscriber, 1, onNextCount, running)); running.await(); // let one of the OnNextThread actually run before proceeding @@ -315,7 +315,7 @@ public void onNext(String t) { assertSame(t1, t2); System.out.println(ts.values()); - o.onComplete(); + subscriber.onComplete(); System.out.println(ts.values()); } } finally { @@ -370,16 +370,16 @@ public void onNext(String t) { } }); - final Subscriber o = serializedSubscriber(ts); + final Subscriber subscriber = serializedSubscriber(ts); AtomicInteger p1 = new AtomicInteger(); AtomicInteger p2 = new AtomicInteger(); - o.onSubscribe(new BooleanSubscription()); + subscriber.onSubscribe(new BooleanSubscription()); ResourceSubscriber as1 = new ResourceSubscriber() { @Override public void onNext(String t) { - o.onNext(t); + subscriber.onNext(t); } @Override @@ -396,7 +396,7 @@ public void onComplete() { ResourceSubscriber as2 = new ResourceSubscriber() { @Override public void onNext(String t) { - o.onNext(t); + subscriber.onNext(t); } @Override @@ -455,29 +455,29 @@ public void subscribe(Subscriber s) { public static class OnNextThread implements Runnable { private final CountDownLatch latch; - private final Subscriber observer; + private final Subscriber subscriber; private final int numStringsToSend; final AtomicInteger produced; private final CountDownLatch running; - OnNextThread(Subscriber observer, int numStringsToSend, CountDownLatch latch, CountDownLatch running) { - this(observer, numStringsToSend, new AtomicInteger(), latch, running); + OnNextThread(Subscriber subscriber, int numStringsToSend, CountDownLatch latch, CountDownLatch running) { + this(subscriber, numStringsToSend, new AtomicInteger(), latch, running); } - OnNextThread(Subscriber observer, int numStringsToSend, AtomicInteger produced) { - this(observer, numStringsToSend, produced, null, null); + OnNextThread(Subscriber subscriber, int numStringsToSend, AtomicInteger produced) { + this(subscriber, numStringsToSend, produced, null, null); } - OnNextThread(Subscriber observer, int numStringsToSend, AtomicInteger produced, CountDownLatch latch, CountDownLatch running) { - this.observer = observer; + OnNextThread(Subscriber subscriber, int numStringsToSend, AtomicInteger produced, CountDownLatch latch, CountDownLatch running) { + this.subscriber = subscriber; this.numStringsToSend = numStringsToSend; this.produced = produced; this.latch = latch; this.running = running; } - OnNextThread(Subscriber observer, int numStringsToSend) { - this(observer, numStringsToSend, new AtomicInteger()); + OnNextThread(Subscriber subscriber, int numStringsToSend) { + this(subscriber, numStringsToSend, new AtomicInteger()); } @Override @@ -486,7 +486,7 @@ public void run() { running.countDown(); } for (int i = 0; i < numStringsToSend; i++) { - observer.onNext(Thread.currentThread().getId() + "-" + i); + subscriber.onNext(Thread.currentThread().getId() + "-" + i); if (latch != null) { latch.countDown(); } @@ -500,12 +500,12 @@ public void run() { */ public static class CompletionThread implements Runnable { - private final Subscriber observer; + private final Subscriber subscriber; private final TestConcurrencySubscriberEvent event; private final Future[] waitOnThese; CompletionThread(Subscriber Subscriber, TestConcurrencySubscriberEvent event, Future... waitOnThese) { - this.observer = Subscriber; + this.subscriber = Subscriber; this.event = event; this.waitOnThese = waitOnThese; } @@ -525,9 +525,9 @@ public void run() { /* send the event */ if (event == TestConcurrencySubscriberEvent.onError) { - observer.onError(new RuntimeException("mocked exception")); + subscriber.onError(new RuntimeException("mocked exception")); } else if (event == TestConcurrencySubscriberEvent.onComplete) { - observer.onComplete(); + subscriber.onComplete(); } else { throw new IllegalArgumentException("Expecting either onError or onComplete"); @@ -642,8 +642,8 @@ static class TestSingleThreadedPublisher implements Publisher { } @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); System.out.println("TestSingleThreadedObservable subscribed to ..."); t = new Thread(new Runnable() { @@ -653,9 +653,9 @@ public void run() { System.out.println("running TestSingleThreadedObservable thread"); for (String s : values) { System.out.println("TestSingleThreadedObservable onNext: " + s); - observer.onNext(s); + subscriber.onNext(s); } - observer.onComplete(); + subscriber.onComplete(); } catch (Throwable e) { throw new RuntimeException(e); } @@ -694,8 +694,8 @@ static class TestMultiThreadedObservable implements Publisher { } @Override - public void subscribe(final Subscriber observer) { - observer.onSubscribe(new BooleanSubscription()); + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); final NullPointerException npe = new NullPointerException(); System.out.println("TestMultiThreadedObservable subscribed to ..."); t = new Thread(new Runnable() { @@ -725,7 +725,7 @@ public void run() { Thread.sleep(sleep); } } - observer.onNext(s); + subscriber.onNext(s); // capture 'maxThreads' int concurrentThreads = threadsRunning.get(); int maxThreads = maxConcurrentThreads.get(); @@ -733,7 +733,7 @@ public void run() { maxConcurrentThreads.compareAndSet(maxThreads, concurrentThreads); } } catch (Throwable e) { - observer.onError(e); + subscriber.onError(e); } finally { threadsRunning.decrementAndGet(); } @@ -755,7 +755,7 @@ public void run() { } catch (InterruptedException e) { throw new RuntimeException(e); } - observer.onComplete(); + subscriber.onComplete(); } }); System.out.println("starting TestMultiThreadedObservable thread"); diff --git a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java index 98657d5883..a720be050c 100644 --- a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java @@ -46,69 +46,69 @@ public class TestSubscriberTest { @Test public void testAssert() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber ts = new TestSubscriber(); + oi.subscribe(ts); - o.assertValues(1, 2); - o.assertValueCount(2); - o.assertTerminated(); + ts.assertValues(1, 2); + ts.assertValueCount(2); + ts.assertTerminated(); } @Test public void testAssertNotMatchCount() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber ts = new TestSubscriber(); + oi.subscribe(ts); thrown.expect(AssertionError.class); // FIXME different message pattern // thrown.expectMessage("Number of items does not match. Provided: 1 Actual: 2"); - o.assertValues(1); - o.assertValueCount(2); - o.assertTerminated(); + ts.assertValues(1); + ts.assertValueCount(2); + ts.assertTerminated(); } @Test public void testAssertNotMatchValue() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber ts = new TestSubscriber(); + oi.subscribe(ts); thrown.expect(AssertionError.class); // FIXME different message pattern // thrown.expectMessage("Value at index: 1 expected to be [3] (Integer) but was: [2] (Integer)"); - o.assertValues(1, 3); - o.assertValueCount(2); - o.assertTerminated(); + ts.assertValues(1, 3); + ts.assertValueCount(2); + ts.assertTerminated(); } @Test public void assertNeverAtNotMatchingValue() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber ts = new TestSubscriber(); + oi.subscribe(ts); - o.assertNever(3); - o.assertValueCount(2); - o.assertTerminated(); + ts.assertNever(3); + ts.assertValueCount(2); + ts.assertTerminated(); } @Test public void assertNeverAtMatchingValue() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber o = new TestSubscriber(); - oi.subscribe(o); + TestSubscriber ts = new TestSubscriber(); + oi.subscribe(ts); - o.assertValues(1, 2); + ts.assertValues(1, 2); thrown.expect(AssertionError.class); - o.assertNever(2); - o.assertValueCount(2); - o.assertTerminated(); + ts.assertNever(2); + ts.assertValueCount(2); + ts.assertTerminated(); } @Test @@ -146,8 +146,8 @@ public boolean test(final Integer o) throws Exception { @Test public void testAssertTerminalEventNotReceived() { PublishProcessor p = PublishProcessor.create(); - TestSubscriber o = new TestSubscriber(); - p.subscribe(o); + TestSubscriber ts = new TestSubscriber(); + p.subscribe(ts); p.onNext(1); p.onNext(2); @@ -156,35 +156,35 @@ public void testAssertTerminalEventNotReceived() { // FIXME different message pattern // thrown.expectMessage("No terminal events received."); - o.assertValues(1, 2); - o.assertValueCount(2); - o.assertTerminated(); + ts.assertValues(1, 2); + ts.assertValueCount(2); + ts.assertTerminated(); } @Test public void testWrappingMock() { Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - Subscriber mockObserver = TestHelper.mockSubscriber(); + Subscriber mockSubscriber = TestHelper.mockSubscriber(); - oi.subscribe(new TestSubscriber(mockObserver)); + oi.subscribe(new TestSubscriber(mockSubscriber)); - InOrder inOrder = inOrder(mockObserver); - inOrder.verify(mockObserver, times(1)).onNext(1); - inOrder.verify(mockObserver, times(1)).onNext(2); - inOrder.verify(mockObserver, times(1)).onComplete(); + InOrder inOrder = inOrder(mockSubscriber); + inOrder.verify(mockSubscriber, times(1)).onNext(1); + inOrder.verify(mockSubscriber, times(1)).onNext(2); + inOrder.verify(mockSubscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } @Test public void testWrappingMockWhenUnsubscribeInvolved() { 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)); + Subscriber mockSubscriber = TestHelper.mockSubscriber(); + oi.subscribe(new TestSubscriber(mockSubscriber)); - InOrder inOrder = inOrder(mockObserver); - inOrder.verify(mockObserver, times(1)).onNext(1); - inOrder.verify(mockObserver, times(1)).onNext(2); - inOrder.verify(mockObserver, times(1)).onComplete(); + InOrder inOrder = inOrder(mockSubscriber); + inOrder.verify(mockSubscriber, times(1)).onNext(1); + inOrder.verify(mockSubscriber, times(1)).onNext(2); + inOrder.verify(mockSubscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } diff --git a/src/test/java/io/reactivex/tck/MulticastProcessorRefCountedTckTest.java b/src/test/java/io/reactivex/tck/MulticastProcessorRefCountedTckTest.java index 24a3b8d09f..0e61371f7e 100644 --- a/src/test/java/io/reactivex/tck/MulticastProcessorRefCountedTckTest.java +++ b/src/test/java/io/reactivex/tck/MulticastProcessorRefCountedTckTest.java @@ -26,7 +26,7 @@ public class MulticastProcessorRefCountedTckTest extends IdentityProcessorVerification { public MulticastProcessorRefCountedTckTest() { - super(new TestEnvironment(50)); + super(new TestEnvironment(200)); } @Override From 7ade77a94439639d65a8293d7908177d7bd10a7d Mon Sep 17 00:00:00 2001 From: ChanHoHo <41296887+ChanHoHo@users.noreply.github.com> Date: Thu, 2 Aug 2018 00:08:30 +0800 Subject: [PATCH 039/211] Fixed broken link under RxJS in docs/Additional-Reading.md (#6125) * Fixed broken link in docs/Additional-Reading.md * updated broken-link in docs/Additional-reading.md --- docs/Additional-Reading.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Additional-Reading.md b/docs/Additional-Reading.md index 8693b414c6..6f65b4f677 100644 --- a/docs/Additional-Reading.md +++ b/docs/Additional-Reading.md @@ -1,4 +1,4 @@ -(A more complete and up-to-date list of resources can be found at the reactivex.io site: [[http://reactivex.io/tutorials.html]]) +(A more complete and up-to-date list of resources can be found at the reactivex.io site: [[http://reactivex.io/tutorials.html]]) # Introducing Reactive Programming * [Introduction to Rx](http://www.introtorx.com/): a free, on-line book by Lee Campbell @@ -38,11 +38,11 @@ * [MSDN Rx forum](http://social.msdn.microsoft.com/Forums/en-US/home?forum=rx) # RxJS -* [the RxJS github site](http://reactive-extensions.github.io/RxJS/) +* [the RxJS github site](https://github.com/reactivex/rxjs) * An interactive tutorial: [Functional Programming in Javascript](http://jhusain.github.io/learnrx/) and [an accompanying lecture (video)](http://www.youtube.com/watch?v=LB4lhFJBBq0) by Jafar Husain * [Netflix JavaScript Talks - Async JavaScript with Reactive Extensions](https://www.youtube.com/watch?v=XRYN2xt11Ek) video of a talk by Jafar Husain about the Rx way of programming * [RxJS](https://xgrommx.github.io/rx-book/), an on-line book by @xgrommx -* [Journey from procedural to reactive Javascript with stops](http://bahmutov.calepin.co/journey-from-procedural-to-reactive-javascript-with-stops.html) by Gleb Bahmutov +* [Journey from procedural to reactive Javascript with stops](https://glebbahmutov.com/blog/journey-from-procedural-to-reactive-javascript-with-stops/) by Gleb Bahmutov # Miscellany * [RxJava Observables and Akka Actors](http://onoffswitch.net/rxjava-observables-akka-actors/) by Anton Kropp From a008e03484177f48ec7fef4c311705bb43fd8ec9 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 1 Aug 2018 22:20:36 +0200 Subject: [PATCH 040/211] 2.x: Improve Completable.onErrorResumeNext internals (#6123) * 2.x: Improve Completable.onErrorResumeNext internals * Use ObjectHelper --- .../completable/CompletableResumeNext.java | 76 +++++++++---------- .../completable/CompletableTest.java | 7 +- .../CompletableResumeNextTest.java | 61 +++++++++++++++ 3 files changed, 104 insertions(+), 40 deletions(-) create mode 100644 src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java index 16c46aeb24..940942c943 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java @@ -13,11 +13,14 @@ package io.reactivex.internal.operators.completable; +import java.util.concurrent.atomic.AtomicReference; + import io.reactivex.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.SequentialDisposable; +import io.reactivex.internal.disposables.DisposableHelper; +import io.reactivex.internal.functions.ObjectHelper; public final class CompletableResumeNext extends Completable { @@ -35,20 +38,32 @@ public CompletableResumeNext(CompletableSource source, @Override protected void subscribeActual(final CompletableObserver observer) { - - final SequentialDisposable sd = new SequentialDisposable(); - observer.onSubscribe(sd); - source.subscribe(new ResumeNext(observer, sd)); + ResumeNextObserver parent = new ResumeNextObserver(observer, errorMapper); + observer.onSubscribe(parent); + source.subscribe(parent); } - final class ResumeNext implements CompletableObserver { + static final class ResumeNextObserver + extends AtomicReference + implements CompletableObserver, Disposable { + + private static final long serialVersionUID = 5018523762564524046L; final CompletableObserver downstream; - final SequentialDisposable sd; - ResumeNext(CompletableObserver observer, SequentialDisposable sd) { + final Function errorMapper; + + boolean once; + + ResumeNextObserver(CompletableObserver observer, Function errorMapper) { this.downstream = observer; - this.sd = sd; + this.errorMapper = errorMapper; + } + + + @Override + public void onSubscribe(Disposable d) { + DisposableHelper.replace(this, d); } @Override @@ -58,48 +73,33 @@ public void onComplete() { @Override public void onError(Throwable e) { + if (once) { + downstream.onError(e); + return; + } + once = true; + CompletableSource c; try { - c = errorMapper.apply(e); + c = ObjectHelper.requireNonNull(errorMapper.apply(e), "The errorMapper returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - downstream.onError(new CompositeException(ex, e)); + downstream.onError(new CompositeException(e, ex)); return; } - if (c == null) { - NullPointerException npe = new NullPointerException("The CompletableConsumable returned is null"); - npe.initCause(e); - downstream.onError(npe); - return; - } - - c.subscribe(new OnErrorObserver()); + c.subscribe(this); } @Override - public void onSubscribe(Disposable d) { - sd.update(d); + public boolean isDisposed() { + return DisposableHelper.isDisposed(get()); } - final class OnErrorObserver implements CompletableObserver { - - @Override - public void onComplete() { - downstream.onComplete(); - } - - @Override - public void onError(Throwable e) { - downstream.onError(e); - } - - @Override - public void onSubscribe(Disposable d) { - sd.update(d); - } - + @Override + public void dispose() { + DisposableHelper.dispose(this); } } } diff --git a/src/test/java/io/reactivex/completable/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java index 5dcfa1b531..dd4bdfc9e3 100644 --- a/src/test/java/io/reactivex/completable/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -2170,8 +2170,11 @@ public Completable apply(Throwable e) { try { c.blockingAwait(); Assert.fail("Did not throw an exception"); - } catch (NullPointerException ex) { - Assert.assertTrue(ex.getCause() instanceof TestException); + } catch (CompositeException ex) { + List errors = ex.getExceptions(); + TestHelper.assertError(errors, 0, TestException.class); + TestHelper.assertError(errors, 1, NullPointerException.class); + assertEquals(2, errors.size()); } } diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java new file mode 100644 index 0000000000..c2a3af2769 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.completable; + +import org.junit.Test; + +import io.reactivex.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Function; +import io.reactivex.internal.functions.Functions; + +public class CompletableResumeNextTest { + + @Test + public void resumeWithError() { + Completable.error(new TestException()) + .onErrorResumeNext(Functions.justFunction(Completable.error(new TestException("second")))) + .test() + .assertFailureAndMessage(TestException.class, "second"); + } + + @Test + public void disposeInMain() { + TestHelper.checkDisposedCompletable(new Function() { + @Override + public CompletableSource apply(Completable c) throws Exception { + return c.onErrorResumeNext(Functions.justFunction(Completable.complete())); + } + }); + } + + + @Test + public void disposeInResume() { + TestHelper.checkDisposedCompletable(new Function() { + @Override + public CompletableSource apply(Completable c) throws Exception { + return Completable.error(new TestException()).onErrorResumeNext(Functions.justFunction(c)); + } + }); + } + + @Test + public void disposed() { + TestHelper.checkDisposed( + Completable.error(new TestException()) + .onErrorResumeNext(Functions.justFunction(Completable.never())) + ); + } +} From c0f17ce9d83d6fff506e17020e3881074ec41efd Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Thu, 2 Aug 2018 09:34:23 +0200 Subject: [PATCH 041/211] Add marbles for Single.timer, Single.defer and Single.toXXX operators (#6095) * Add marbles for Single.timer, Single.defer and Single.toXXX operators * Correct image height for marbles --- src/main/java/io/reactivex/Single.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 17d243f7a1..84f40621c4 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -493,6 +493,8 @@ public static Single create(SingleOnSubscribe source) { /** * Calls a {@link Callable} for each individual {@link SingleObserver} to return the actual {@link SingleSource} to * be subscribed to. + *

+ * *

*
Scheduler:
*
{@code defer} does not operate by default on a particular {@link Scheduler}.
@@ -1243,6 +1245,8 @@ public static Single never() { /** * Signals success with 0L value after the given delay for each SingleObserver. + *

+ * *

*
Scheduler:
*
{@code timer} operates by default on the {@code computation} {@link Scheduler}.
@@ -1260,6 +1264,8 @@ public static Single timer(long delay, TimeUnit unit) { /** * Signals success with 0L value after the given delay for each SingleObserver. + *

+ * *

*
Scheduler:
*
you specify the {@link Scheduler} to signal on.
@@ -3705,7 +3711,7 @@ public final Completable ignoreElement() { /** * Converts this Single into a {@link Flowable}. *

- * + * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
@@ -3729,7 +3735,7 @@ public final Flowable toFlowable() { /** * Returns a {@link Future} representing the single value emitted by this {@code Single}. *

- * + * *

*
Scheduler:
*
{@code toFuture} does not operate by default on a particular {@link Scheduler}.
@@ -3747,7 +3753,7 @@ public final Future toFuture() { /** * Converts this Single into a {@link Maybe}. *

- * + * *

*
Scheduler:
*
{@code toMaybe} does not operate by default on a particular {@link Scheduler}.
From 30afb3b9f82e53fa82a127cf745198b324631bf2 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 2 Aug 2018 10:02:06 +0200 Subject: [PATCH 042/211] 2.x: Flowable.onErrorResumeNext improvements (#6121) --- .../flowable/FlowableOnErrorNext.java | 31 +++++++++++-------- .../reactivex/flowable/FlowableNullTests.java | 22 ++++++++----- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java index dd1198d0a9..8a36aad3ce 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.exceptions.*; import io.reactivex.functions.Function; +import io.reactivex.internal.functions.ObjectHelper; import io.reactivex.internal.subscriptions.SubscriptionArbiter; import io.reactivex.plugins.RxJavaPlugins; @@ -35,30 +36,36 @@ public FlowableOnErrorNext(Flowable source, @Override protected void subscribeActual(Subscriber s) { OnErrorNextSubscriber parent = new OnErrorNextSubscriber(s, nextSupplier, allowFatal); - s.onSubscribe(parent.arbiter); + s.onSubscribe(parent); source.subscribe(parent); } - static final class OnErrorNextSubscriber implements FlowableSubscriber { + static final class OnErrorNextSubscriber + extends SubscriptionArbiter + implements FlowableSubscriber { + private static final long serialVersionUID = 4063763155303814625L; + final Subscriber actual; + final Function> nextSupplier; + final boolean allowFatal; - final SubscriptionArbiter arbiter; boolean once; boolean done; + long produced; + OnErrorNextSubscriber(Subscriber actual, Function> nextSupplier, boolean allowFatal) { this.actual = actual; this.nextSupplier = nextSupplier; this.allowFatal = allowFatal; - this.arbiter = new SubscriptionArbiter(); } @Override public void onSubscribe(Subscription s) { - arbiter.setSubscription(s); + setSubscription(s); } @Override @@ -66,10 +73,10 @@ public void onNext(T t) { if (done) { return; } - actual.onNext(t); if (!once) { - arbiter.produced(1L); + produced++; } + actual.onNext(t); } @Override @@ -92,18 +99,16 @@ public void onError(Throwable t) { Publisher p; try { - p = nextSupplier.apply(t); + p = ObjectHelper.requireNonNull(nextSupplier.apply(t), "The nextSupplier returned a null Publisher"); } catch (Throwable e) { Exceptions.throwIfFatal(e); actual.onError(new CompositeException(t, e)); return; } - if (p == null) { - NullPointerException npe = new NullPointerException("Publisher is null"); - npe.initCause(t); - actual.onError(npe); - return; + long mainProduced = produced; + if (mainProduced != 0L) { + produced(mainProduced); } p.subscribe(this); diff --git a/src/test/java/io/reactivex/flowable/FlowableNullTests.java b/src/test/java/io/reactivex/flowable/FlowableNullTests.java index 12c7a9b5c1..80f70a75ad 100644 --- a/src/test/java/io/reactivex/flowable/FlowableNullTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableNullTests.java @@ -1648,14 +1648,22 @@ public void onErrorResumeNextFunctionNull() { just1.onErrorResumeNext((Function>)null); } - @Test(expected = NullPointerException.class) + @Test public void onErrorResumeNextFunctionReturnsNull() { - Flowable.error(new TestException()).onErrorResumeNext(new Function>() { - @Override - public Publisher apply(Throwable e) { - return null; - } - }).blockingSubscribe(); + try { + Flowable.error(new TestException()).onErrorResumeNext(new Function>() { + @Override + public Publisher apply(Throwable e) { + return null; + } + }).blockingSubscribe(); + fail("Should have thrown"); + } catch (CompositeException ex) { + List errors = ex.getExceptions(); + TestHelper.assertError(errors, 0, TestException.class); + TestHelper.assertError(errors, 1, NullPointerException.class); + assertEquals(2, errors.size()); + } } @Test(expected = NullPointerException.class) From 2274c42ed4be3f66e999d83bb31a9d23db3a2663 Mon Sep 17 00:00:00 2001 From: JianxinLi Date: Thu, 2 Aug 2018 20:42:00 +0800 Subject: [PATCH 043/211] 2.x: Remove fromEmitter() in wiki (#6128) --- docs/Creating-Observables.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/Creating-Observables.md b/docs/Creating-Observables.md index 25b215f982..b8a6b90ca7 100644 --- a/docs/Creating-Observables.md +++ b/docs/Creating-Observables.md @@ -2,8 +2,7 @@ This page shows methods that create Observables. * [**`just( )`**](http://reactivex.io/documentation/operators/just.html) — convert an object or several objects into an Observable that emits that object or those objects * [**`from( )`**](http://reactivex.io/documentation/operators/from.html) — convert an Iterable, a Future, or an Array into an Observable -* [**`create( )`**](http://reactivex.io/documentation/operators/create.html) — **advanced use only!** create an Observable from scratch by means of a function, consider `fromEmitter` instead -* [**`fromEmitter()`**](http://reactivex.io/RxJava/javadoc/rx/Observable.html#fromEmitter(rx.functions.Action1,%20rx.AsyncEmitter.BackpressureMode)) — create safe, backpressure-enabled, unsubscription-supporting Observable via a function and push events. +* [**`create( )`**](http://reactivex.io/documentation/operators/create.html) — **advanced use only!** create an Observable from scratch by means of a function * [**`defer( )`**](http://reactivex.io/documentation/operators/defer.html) — do not create the Observable until a Subscriber subscribes; create a fresh Observable on each subscription * [**`range( )`**](http://reactivex.io/documentation/operators/range.html) — create an Observable that emits a range of sequential integers * [**`interval( )`**](http://reactivex.io/documentation/operators/interval.html) — create an Observable that emits a sequence of integers spaced by a given time interval From a58c491b9853e2135d3ae04e08095be79f495ba7 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 3 Aug 2018 22:37:05 +0200 Subject: [PATCH 044/211] 2.x: Update _Sidebar.md with new order of topics (#6133) --- docs/_Sidebar.md | 57 ++++++++++++++++++++++++--------------------- docs/_Sidebar.md.md | 56 +++++++++++++++++++++----------------------- 2 files changed, 57 insertions(+), 56 deletions(-) diff --git a/docs/_Sidebar.md b/docs/_Sidebar.md index d27b620b10..1fe0339407 100644 --- a/docs/_Sidebar.md +++ b/docs/_Sidebar.md @@ -1,26 +1,31 @@ -* [[Getting Started]] -* [[How To Use RxJava]] -* [[Additional Reading]] -* [[Observable]] - * [[Creating Observables]] - * [[Transforming Observables]] - * [[Filtering Observables]] - * [[Combining Observables]] - * [[Error Handling Operators]] - * [[Observable Utility Operators]] - * [[Conditional and Boolean Operators]] - * [[Mathematical and Aggregate Operators]] - * [[Async Operators]] - * [[Connectable Observable Operators]] - * [[Blocking Observable Operators]] - * [[String Observables]] - * [[Alphabetical List of Observable Operators]] - * [[Implementing Your Own Operators]] -* [[Subject]] -* [[Scheduler]] -* [[Plugins]] -* [[Backpressure]] -* [[Error Handling]] -* [[The RxJava Android Module]] -* [[How to Contribute]] -* [Javadoc](http://reactivex.io/RxJava/javadoc/rx/Observable.html) \ No newline at end of file +* [Introduction](https://github.com/ReactiveX/RxJava/wiki/Home) +* [Getting Started](https://github.com/ReactiveX/RxJava/wiki/Getting-Started) +* [How to Use RxJava](https://github.com/ReactiveX/RxJava/wiki/How-To-Use-RxJava) +* [Reactive Streams](https://github.com/ReactiveX/RxJava/wiki/Reactive-Streams) +* [The reactive types of RxJava](https://github.com/ReactiveX/RxJava/wiki/Observable) +* [Schedulers](https://github.com/ReactiveX/RxJava/wiki/Scheduler) +* [Subjects](https://github.com/ReactiveX/RxJava/wiki/Subject) +* [Error Handling](https://github.com/ReactiveX/RxJava/wiki/Error-Handling) +* [Operators (Alphabetical List)](https://github.com/ReactiveX/RxJava/wiki/Alphabetical-List-of-Observable-Operators) + * [Async](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) + * [Blocking](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) + * [Combining](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables) + * [Conditional & Boolean](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators) + * [Connectable](https://github.com/ReactiveX/RxJava/wiki/Connectable-Observable-Operators) + * [Creation](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables) + * [Error management](https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators) + * [Filtering](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) + * [Mathematical and Aggregate](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators) + * [Parallel flows](https://github.com/ReactiveX/RxJava/wiki/Parallel-flows) + * [String](https://github.com/ReactiveX/RxJava/wiki/String-Observables) + * [Transformation](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables) + * [Utility](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) + * [Notable 3rd party Operators (Alphabetical List)](https://github.com/ReactiveX/RxJava/wiki/Alphabetical-List-of-3rd-party-Operators) +* [Plugins](https://github.com/ReactiveX/RxJava/wiki/Plugins) +* [How to Contribute](https://github.com/ReactiveX/RxJava/wiki/How-to-Contribute) +* [Writing operators](https://github.com/ReactiveX/RxJava/wiki/Writing-operators-for-2.0) +* [Backpressure](https://github.com/ReactiveX/RxJava/wiki/Backpressure-(2.0)) + * [another explanation](https://github.com/ReactiveX/RxJava/wiki/Backpressure) +* [JavaDoc](http://reactivex.io/RxJava/2.x/javadoc) +* [Coming from RxJava 1](https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0) +* [Additional Reading](https://github.com/ReactiveX/RxJava/wiki/Additional-Reading) diff --git a/docs/_Sidebar.md.md b/docs/_Sidebar.md.md index a07aa3d93e..1fe0339407 100644 --- a/docs/_Sidebar.md.md +++ b/docs/_Sidebar.md.md @@ -1,35 +1,31 @@ * [Introduction](https://github.com/ReactiveX/RxJava/wiki/Home) * [Getting Started](https://github.com/ReactiveX/RxJava/wiki/Getting-Started) -* [JavaDoc](http://reactivex.io/RxJava/javadoc) - * [1.x](http://reactivex.io/RxJava/1.x/javadoc/rx/Observable.html) - * [2.x](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html) * [How to Use RxJava](https://github.com/ReactiveX/RxJava/wiki/How-To-Use-RxJava) -* [Additional Reading](https://github.com/ReactiveX/RxJava/wiki/Additional-Reading) -* [The Observable](https://github.com/ReactiveX/RxJava/wiki/Observable) -* Operators [(Alphabetical List)](http://reactivex.io/documentation/operators.html#alphabetical) - * [Async](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) - * [Blocking Observable](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) - * [Combining](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables) - * [Conditional & Boolean](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators) - * [Connectable Observable](https://github.com/ReactiveX/RxJava/wiki/Connectable-Observable-Operators) - * [Error Handling Operators](https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators) - * [Filtering](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) - * [Mathematical and Aggregate](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators) - * [Observable Creation](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables) - * [Parallel flows](https://github.com/ReactiveX/RxJava/wiki/Parallel-flows) - * [String](https://github.com/ReactiveX/RxJava/wiki/String-Observables) - * [Transformational](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables) - * [Utility Operators](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) - * [Implementing Custom Operators](https://github.com/ReactiveX/RxJava/wiki/Implementing-custom-operators-(draft)), [previous](https://github.com/ReactiveX/RxJava/wiki/Implementing-Your-Own-Operators) -* [Backpressure](https://github.com/ReactiveX/RxJava/wiki/Backpressure) -* [Error Handling](https://github.com/ReactiveX/RxJava/wiki/Error-Handling) -* [Plugins](https://github.com/ReactiveX/RxJava/wiki/Plugins) +* [Reactive Streams](https://github.com/ReactiveX/RxJava/wiki/Reactive-Streams) +* [The reactive types of RxJava](https://github.com/ReactiveX/RxJava/wiki/Observable) * [Schedulers](https://github.com/ReactiveX/RxJava/wiki/Scheduler) * [Subjects](https://github.com/ReactiveX/RxJava/wiki/Subject) -* [The RxJava Android Module](https://github.com/ReactiveX/RxAndroid/wiki) -* RxJava 2.0 - * [Reactive Streams](https://github.com/ReactiveX/RxJava/wiki/Reactive-Streams) - * [What's different](https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0) - * [Writing operators](https://github.com/ReactiveX/RxJava/wiki/Writing-operators-for-2.0) - * [Backpressure](https://github.com/ReactiveX/RxJava/wiki/Backpressure-(2.0)) -* [How to Contribute](https://github.com/ReactiveX/RxJava/wiki/How-to-Contribute) \ No newline at end of file +* [Error Handling](https://github.com/ReactiveX/RxJava/wiki/Error-Handling) +* [Operators (Alphabetical List)](https://github.com/ReactiveX/RxJava/wiki/Alphabetical-List-of-Observable-Operators) + * [Async](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) + * [Blocking](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) + * [Combining](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables) + * [Conditional & Boolean](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators) + * [Connectable](https://github.com/ReactiveX/RxJava/wiki/Connectable-Observable-Operators) + * [Creation](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables) + * [Error management](https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators) + * [Filtering](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) + * [Mathematical and Aggregate](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators) + * [Parallel flows](https://github.com/ReactiveX/RxJava/wiki/Parallel-flows) + * [String](https://github.com/ReactiveX/RxJava/wiki/String-Observables) + * [Transformation](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables) + * [Utility](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) + * [Notable 3rd party Operators (Alphabetical List)](https://github.com/ReactiveX/RxJava/wiki/Alphabetical-List-of-3rd-party-Operators) +* [Plugins](https://github.com/ReactiveX/RxJava/wiki/Plugins) +* [How to Contribute](https://github.com/ReactiveX/RxJava/wiki/How-to-Contribute) +* [Writing operators](https://github.com/ReactiveX/RxJava/wiki/Writing-operators-for-2.0) +* [Backpressure](https://github.com/ReactiveX/RxJava/wiki/Backpressure-(2.0)) + * [another explanation](https://github.com/ReactiveX/RxJava/wiki/Backpressure) +* [JavaDoc](http://reactivex.io/RxJava/2.x/javadoc) +* [Coming from RxJava 1](https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0) +* [Additional Reading](https://github.com/ReactiveX/RxJava/wiki/Additional-Reading) From 3c27426b764cfcc56df56d1ea2ae2a7f1f019ccc Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Sat, 4 Aug 2018 20:33:02 +0400 Subject: [PATCH 045/211] Initial clean up for Combining Observables docs (#6135) * Initial clean up for Combining Observables docs This patch updates the style of the combining observables documentation to be similar to that of #6131 and adds examples for most of the operators therein. Refs #6132. * Address comments --- docs/Combining-Observables.md | 168 ++++++++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 7 deletions(-) diff --git a/docs/Combining-Observables.md b/docs/Combining-Observables.md index 2a60e64bd2..0e3796da1f 100644 --- a/docs/Combining-Observables.md +++ b/docs/Combining-Observables.md @@ -1,12 +1,166 @@ This section explains operators you can use to combine multiple Observables. -* [**`startWith( )`**](http://reactivex.io/documentation/operators/startwith.html) — emit a specified sequence of items before beginning to emit the items from the Observable -* [**`merge( )`**](http://reactivex.io/documentation/operators/merge.html) — combine multiple Observables into one -* [**`mergeDelayError( )`**](http://reactivex.io/documentation/operators/merge.html) — combine multiple Observables into one, allowing error-free Observables to continue before propagating errors -* [**`zip( )`**](http://reactivex.io/documentation/operators/zip.html) — combine sets of items emitted by two or more Observables together via a specified function and emit items based on the results of this function -* (`rxjava-joins`) [**`and( )`, `then( )`, and `when( )`**](http://reactivex.io/documentation/operators/and-then-when.html) — combine sets of items emitted by two or more Observables by means of `Pattern` and `Plan` intermediaries -* [**`combineLatest( )`**](http://reactivex.io/documentation/operators/combinelatest.html) — when an item is emitted by either of two Observables, combine the latest item emitted by each Observable via a specified function and emit items based on the results of this function +# Outline + +- [`combineLatest`](#combineLatest) +- [`join` and `groupJoin`](#joins) +- [`merge`](#merge) +- [`mergeDelayError`](#mergeDelayError) +- [`rxjava-joins`](#rxjava-joins) +- [`startWith`](#startWith) +- [`switchOnNext`](#switchOnNext) +- [`zip`](#zip) + +## startWith + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/startwith.html](http://reactivex.io/documentation/operators/startwith.html) + +Emit a specified sequence of items before beginning to emit the items from the Observable. + +#### startWith Example + +```java +Observable names = Observable.just("Spock", "McCoy"); +names.startWith("Kirk").subscribe(item -> System.out.println(item)); + +// prints Kirk, Spock, McCoy +``` + +## merge + +Combines multiple Observables into one. + + +### merge + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/merge.html](http://reactivex.io/documentation/operators/merge.html) + +Combines multiple Observables into one. Any `onError` notifications passed from any of the source observables will immediately be passed through to through to the observers and will terminate the merged `Observable`. + +#### merge Example + +```java +Observable.just(1, 2, 3) + .mergeWith(Observable.just(4, 5, 6)) + .subscribe(item -> System.out.println(item)); + +// prints 1, 2, 3, 4, 5, 6 +``` + +### mergeDelayError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/merge.html](http://reactivex.io/documentation/operators/merge.html) + +Combines multiple Observables into one. Any `onError` notifications passed from any of the source observables will be withheld until all merged Observables complete, and only then will be passed along to the observers. + +#### mergeDelayError Example + +```java +Observable observable1 = Observable.error(new IllegalArgumentException("")); +Observable observable2 = Observable.just("Four", "Five", "Six"); +Observable.mergeDelayError(observable1, observable2) + .subscribe(item -> System.out.println(item)); + +// emits 4, 5, 6 and then the IllegalArgumentException (in this specific +// example, this throws an `OnErrorNotImplementedException`). +``` + +## zip + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/zip.html](http://reactivex.io/documentation/operators/zip.html) + +Combines sets of items emitted by two or more Observables together via a specified function and emit items based on the results of this function. + +#### zip Example + +```java +Observable firstNames = Observable.just("James", "Jean-Luc", "Benjamin"); +Observable lastNames = Observable.just("Kirk", "Picard", "Sisko"); +firstNames.zipWith(lastNames, (first, last) -> first + " " + last) + .subscribe(item -> System.out.println(item)); + +// prints James Kirk, Jean-Luc Picard, Benjamin Sisko +``` + +## combineLatest + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/combinelatest.html](http://reactivex.io/documentation/operators/combinelatest.html) + +When an item is emitted by either of two Observables, combine the latest item emitted by each Observable via a specified function and emit items based on the results of this function. + +#### combineLatest Example + +```java +Observable newsRefreshes = Observable.interval(100, TimeUnit.MILLISECONDS); +Observable weatherRefreshes = Observable.interval(50, TimeUnit.MILLISECONDS); +Observable.combineLatest(newsRefreshes, weatherRefreshes, + (newsRefreshTimes, weatherRefreshTimes) -> + "Refreshed news " + newsRefreshTimes + " times and weather " + weatherRefreshTimes) + .subscribe(item -> System.out.println(item)); + +// prints: +// Refreshed news 0 times and weather 0 +// Refreshed news 0 times and weather 1 +// Refreshed news 0 times and weather 2 +// Refreshed news 1 times and weather 2 +// Refreshed news 1 times and weather 3 +// Refreshed news 1 times and weather 4 +// Refreshed news 2 times and weather 4 +// Refreshed news 2 times and weather 5 +// ... +``` + +## switchOnNext + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/switch.html](http://reactivex.io/documentation/operators/switch.html) + +Convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently emitted of those Observables. + +#### switchOnNext Example + +```java +Observable> timeIntervals = + Observable.interval(1, TimeUnit.SECONDS) + .map(ticks -> Observable.interval(100, TimeUnit.MILLISECONDS) + .map(innerInterval -> "outer: " + ticks + " - inner: " + innerInterval)); +Observable.switchOnNext(timeIntervals) + .subscribe(item -> System.out.println(item)); + +// prints: +// outer: 0 - inner: 0 +// outer: 0 - inner: 1 +// outer: 0 - inner: 2 +// outer: 0 - inner: 3 +// outer: 0 - inner: 4 +// outer: 0 - inner: 5 +// outer: 0 - inner: 6 +// outer: 0 - inner: 7 +// outer: 0 - inner: 8 +// outer: 1 - inner: 0 +// outer: 1 - inner: 1 +// outer: 1 - inner: 2 +// outer: 1 - inner: 3 +// ... +``` + +## joins + * [**`join( )` and `groupJoin( )`**](http://reactivex.io/documentation/operators/join.html) — combine the items emitted by two Observables whenever one item from one Observable falls within a window of duration specified by an item emitted by the other Observable -* [**`switchOnNext( )`**](http://reactivex.io/documentation/operators/switch.html) — convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently emitted of those Observables + +## rxjava-joins + +* (`rxjava-joins`) [**`and( )`, `then( )`, and `when( )`**](http://reactivex.io/documentation/operators/and-then-when.html) — combine sets of items emitted by two or more Observables by means of `Pattern` and `Plan` intermediaries > (`rxjava-joins`) — indicates that this operator is currently part of the optional `rxjava-joins` package under `rxjava-contrib` and is not included with the standard RxJava set of operators From c7f3349fec5b230f55f415dc3feeef07b5ed2957 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sat, 4 Aug 2018 19:05:06 +0200 Subject: [PATCH 046/211] 2.x: Expand Creating-Observables.md wiki (#6131) --- docs/Creating-Observables.md | 416 ++++++++++++++++++++++++++++++++++- 1 file changed, 404 insertions(+), 12 deletions(-) diff --git a/docs/Creating-Observables.md b/docs/Creating-Observables.md index b8a6b90ca7..b167c4d866 100644 --- a/docs/Creating-Observables.md +++ b/docs/Creating-Observables.md @@ -1,12 +1,404 @@ -This page shows methods that create Observables. - -* [**`just( )`**](http://reactivex.io/documentation/operators/just.html) — convert an object or several objects into an Observable that emits that object or those objects -* [**`from( )`**](http://reactivex.io/documentation/operators/from.html) — convert an Iterable, a Future, or an Array into an Observable -* [**`create( )`**](http://reactivex.io/documentation/operators/create.html) — **advanced use only!** create an Observable from scratch by means of a function -* [**`defer( )`**](http://reactivex.io/documentation/operators/defer.html) — do not create the Observable until a Subscriber subscribes; create a fresh Observable on each subscription -* [**`range( )`**](http://reactivex.io/documentation/operators/range.html) — create an Observable that emits a range of sequential integers -* [**`interval( )`**](http://reactivex.io/documentation/operators/interval.html) — create an Observable that emits a sequence of integers spaced by a given time interval -* [**`timer( )`**](http://reactivex.io/documentation/operators/timer.html) — create an Observable that emits a single item after a given delay -* [**`empty( )`**](http://reactivex.io/documentation/operators/empty-never-throw.html) — create an Observable that emits nothing and then completes -* [**`error( )`**](http://reactivex.io/documentation/operators/empty-never-throw.html) — create an Observable that emits nothing and then signals an error -* [**`never( )`**](http://reactivex.io/documentation/operators/empty-never-throw.html) — create an Observable that emits nothing at all +This page shows methods that create reactive sources, such as `Observable`s. + +### Outline + +- [`create`](#create) +- [`defer`](#defer) +- [`empty`](#empty) +- [`error`](#error) +- [`from`](#from) +- [`interval`](#interval) +- [`just`](#just) +- [`never`](#never) +- [`range`](#range) +- [`timer`](#timer) + +## just + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/just.html](http://reactivex.io/documentation/operators/just.html) + +Constructs a reactive type by taking a pre-existing object and emitting that specific object to the downstream consumer upon subscription. + +#### just example: + +```java +String greeting = "Hello world!"; + +Observable observable = Observable.just(greeting); + +observable.subscribe(item -> System.out.println(item)); +``` + +There exist overloads with 2 to 9 arguments for convenience, which objects (with the same common type) will be emitted in the order they are specified. + +```java +Observable observable = Observable.just("1", "A", "3.2", "def"); + +observable.subscribe(item -> System.out.print(item), error -> error.printStackTrace, + () -> System.out.println()); +``` + +## From + +Constructs a sequence from a pre-existing source or generator type. + +*Note: These static methods use the postfix naming convention (i.e., the argument type is repeated in the method name) to avoid overload resolution ambiguities.* + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/from.html](http://reactivex.io/documentation/operators/from.html) + +### fromIterable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +Signals the items from a `java.lang.Iterable` source (such as `List`s, `Set`s or `Collection`s or custom `Iterable`s) and then completes the sequence. + +#### fromIterable example: + +```java +List list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8)); + +Observable observable = Observable.fromIterable(list); + +observable.subscribe(item -> System.out.println(item), error -> error.printStackTrace(), + () -> System.out.println("Done")); +``` + +### fromArray + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +Signals the elements of the given array and then completes the sequence. + +#### fromArray example: + +```java +Integer[] array = new Integer[10]; +for (int i = 0; i < array.length; i++) { + array[i] = i; +} + +Observable observable = Observable.fromIterable(array); + +observable.subscribe(item -> System.out.println(item), error -> error.printStackTrace(), + () -> System.out.println("Done")); +``` + +*Note: RxJava does not support primitive arrays, only (generic) reference arrays.* + +### fromCallable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +When a consumer subscribes, the given `java.util.concurrent.Callable` is invoked and its returned value (or thrown exception) is relayed to that consumer. + +#### fromCallable example: + +```java +Callable callable = () -> { + System.out.println("Hello World!"); + return "Hello World!"); +} + +Observable observable = Observable.fromCallable(callable); + +observable.subscribe(item -> System.out.println(item), error -> error.printStackTrace(), + () -> System.out.println("Done")); +``` + +*Remark: In `Completable`, the actual returned value is ignored and the `Completable` simply completes.* + +## fromAction + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +When a consumer subscribes, the given `io.reactivex.function.Action` is invoked and the consumer completes or receives the exception the `Action` threw. + +#### fromAction example: + +```java +Action action = () -> System.out.println("Hello World!"); + +Completable completable = Completable.fromAction(action); + +completable.subscribe(() -> System.out.println("Done"), error -> error.printStackTrace()); +``` + +*Note: the difference between `fromAction` and `fromRunnable` is that the `Action` interface allows throwing a checked exception while the `java.lang.Runnable` does not.* + +## fromRunnable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +When a consumer subscribes, the given `io.reactivex.function.Action` is invoked and the consumer completes or receives the exception the `Action` threw. + +#### fromRunnable example: + +```java +Runnable runnable = () -> System.out.println("Hello World!"); + +Completable completable = Completable.fromRunnable(runnable); + +completable.subscribe(() -> System.out.println("Done"), error -> error.printStackTrace()); +``` + +*Note: the difference between `fromAction` and `fromRunnable` is that the `Action` interface allows throwing a checked exception while the `java.lang.Runnable` does not.* + +### fromFuture + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +Given a pre-existing, already running or already completed `java.util.concurrent.Future`, wait for the `Future` to complete normally or with an exception in a blocking fashion and relay the produced value or exception to the consumers. + +#### fromFuture example: + +```java +ScheduledExecutorService executor = Executors.newSingleThreadedScheduledExecutor(); + +Future future = executor.schedule(() -> "Hello world!", 1, TimeUnit.SECONDS); + +Observable observable = Observable.fromFuture(future); + +observable.subscribe( + item -> System.out.println(item), + error -> error.printStackTrace(), + () -> System.out.println("Done")); + +executor.shutdown(); +``` + +### from{reactive type} + +Wraps or converts another reactive type to the target reactive type. + +The following combinations are available in the various reactive types with the following signature pattern: `targetType.from{sourceType}()` + +**Available in:** + +targetType \ sourceType | Publisher | Observable | Maybe | Single | Completable +----|---------------|-----------|---------|-----------|---------------- +Flowable | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) | | | | | +Observable | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) | | | | | +Maybe | | | | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) +Single | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) | | | +Completable | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) | ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) | + +*Note: not all possible conversion is implemented via the `from{reactive type}` method families. Check out the `to{reactive type}` method families for further conversion possibilities. + +#### from{reactive type} example: + +```java +Flux reactorFlux = Flux.fromCompletionStage(CompletableFuture.completedFuture(1)); + +Observable observable = Observable.fromPublisher(reactorFlux); + +observable.subscribe( + item -> System.out.println(item), + error -> error.printStackTrace(), + () -> System.out.println("Done")); +``` + +## create + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/create.html](http://reactivex.io/documentation/operators/create.html) + +Construct a **safe** reactive type instance which when subscribed to by a consumer, runs an user-provided function and provides a type-specific `Emitter` for this function to generate the signal(s) the designated business logic requires. This method allows bridging the non-reactive, usually listener/callback-style world, with the reactive world. + +#### create example: + +```java +ScheduledExecutorService executor = Executors.newSingleThreadedScheduledExecutor(); + +ObservableOnSubscribe handler = emitter -> { + + Future future = executor.schedule(() -> { + emitter.onNext("Hello"); + emitter.onNext("World"); + emitter.onComplete(); + return null; + }, 1, TimeUnit.SECONDS); + + emitter.setCancellable(() -> future.cancel(false)); +}; + +Observable observable = Observable.create(handler); + +observable.subscribe(item -> System.out.println(item), error -> error.printStackTrace(), + () -> System.out.println("Done")); + +Thread.sleep(2000); +executor.shutdown(); +``` + +*Note: `Flowable.create()` must also specify the backpressure behavior to be applied when the user-provided function generates more items than the downstream consumer has requested.* + +## defer + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/defer.html](http://reactivex.io/documentation/operators/defer.html) + +Calls an user-provided `java.util.concurrent.Callable` when a consumer subscribes to the reactive type so that the `Callable` can generate the actual reactive instance to relay signals from towards the consumer. `defer` allows: + +- associating a per-consumer state with such generated reactive instances, +- allows executing side-effects before an actual/generated reactive instance gets subscribed to, +- turn hot sources (i.e., `Subject`s and `Processor`s) into cold sources by basically making those hot sources not exist until a consumer subscribes. + +#### defer example: + +```java +Observable observable = Observable.defer(() -> { + long time = System.currentTimeMillis(); + return Observable.just(time); +}); + +observable.subscribe(time -> System.out.println(time)); + +Thread.sleep(1000); + +observable.subscribe(time -> System.out.println(time)); +``` + +## range + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/range.html](http://reactivex.io/documentation/operators/range.html) + +Generates a sequence of values to each individual consumer. The `range()` method generates `Integer`s, the `rangeLong()` generates `Long`s. + +#### range example: +```java +String greeting = "Hello World!"; + +Observable indexes = Observable.range(0, greeting.length()); + +Observable characters = indexes + .map(index -> greeting.charAt(index)); + +characters.subscribe(character -> System.out.print(character), erro -> error.printStackTrace(), + () -> System.out.println()); +``` + +## interval + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/interval.html](http://reactivex.io/documentation/operators/interval.html) + +Periodically generates an infinite, ever increasing numbers (of type `Long`). The `intervalRange` variant generates a limited amount of such numbers. + +#### interval example: + +```java +Observable clock = Observable.interval(1, TimeUnit.SECONDS); + +clock.subscribe(time -> { + if (time % 2 == 0) { + System.out.println("Tick"); + } else { + System.out.println("Tock"); + } +}); +``` + +## timer + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/timer.html](http://reactivex.io/documentation/operators/timer.html) + +After the specified time, this reactive source signals a single `0L` (then completes for `Flowable` and `Observable`). + +#### timer example: + +```java +Observable eggTimer = Observable.timer(5, TimeUnit.MINUTES); + +eggTimer.blockingSubscribe(v -> System.out.println("Egg is ready!")); +``` + +## empty + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/empty-never-throw.html](http://reactivex.io/documentation/operators/empty-never-throw.html) + +This type of source signals completion immediately upon subscription. + +#### empty example: + +```java +Observable empty = Observable.empty(); + +empty.subscribe( + v -> System.out.println("This should never be printed!"), + error -> System.out.println("Or this!"), + () -> System.out.println("Done will be printed.")); +``` + +## never + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/empty-never-throw.html](http://reactivex.io/documentation/operators/empty-never-throw.html) + +This type of source does not signal any `onNext`, `onSuccess`, `onError` or `onComplete`. This type of reactive source is useful in testing or "disabling" certain sources in combinator operators. + +#### never example: + +```java +Observable never = Observable.never(); + +never.subscribe( + v -> System.out.println("This should never be printed!"), + error -> System.out.println("Or this!"), + () -> System.out.println("This neither!")); +``` + +## error + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/empty-never-throw.html](http://reactivex.io/documentation/operators/empty-never-throw.html) + +Signal an error, either pre-existing or generated via a `java.util.concurrent.Callable`, to the consumer. + +#### error example: + +```java +Observable error = Observable.error(new IOException()); + +error.subscribe( + v -> System.out.println("This should never be printed!"), + error -> error.printStackTrace(), + () -> System.out.println("This neither!")); +``` + +A typical use case is to conditionally map or suppress an exception in a chain utilizing `onErrorResumeNext`: + +```java +Observable observable = Observable.fromCallable(() -> { + if (Math.random() < 0.5) { + throw new IOException(); + } + throw new IllegalArgumentException(); +}); + +Observable result = observable.onErrorResumeNext(error -> { + if (error instanceof IllegalArgumentException) { + return Observable.empty(); + } + return Observable.error(error); +}); + +for (int i = 0; i < 10; i++) { + result.subscribe( + v -> System.out.println("This should never be printed!"), + error -> error.printStackTrace(), + () -> System.out.println("Done")); +} +``` From c146374e210caf0b4982825034c0ec51d5505c00 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Sat, 4 Aug 2018 21:21:32 +0400 Subject: [PATCH 047/211] Update RxJava Android Module documentation (#6134) This patch updates the RxJava Android wiki page to point to the RxAndroid project and the RxAndroid wiki page. This refs #6132. --- docs/The-RxJava-Android-Module.md | 111 +----------------------------- 1 file changed, 2 insertions(+), 109 deletions(-) diff --git a/docs/The-RxJava-Android-Module.md b/docs/The-RxJava-Android-Module.md index 108febec04..ad9817c80a 100644 --- a/docs/The-RxJava-Android-Module.md +++ b/docs/The-RxJava-Android-Module.md @@ -1,110 +1,3 @@ -**Note:** This page is out-of-date. See [the RxAndroid wiki](https://github.com/ReactiveX/RxAndroid/wiki) for more up-to-date instructions. +## RxAndroid -*** - -The `rxjava-android` module contains Android-specific bindings for RxJava. It adds a number of classes to RxJava to assist in writing reactive components in Android applications. - -- It provides a `Scheduler` that schedules an `Observable` on a given Android `Handler` thread, particularly the main UI thread. -- It provides operators that make it easier to deal with `Fragment` and `Activity` life-cycle callbacks. -- It provides wrappers for various Android messaging and notification components so that they can be lifted into an Rx call chain -- It provides reusable, self-contained, reactive components for common Android use cases and UI concerns. _(coming soon)_ - -# Binaries - -You can find binaries and dependency information for Maven, Ivy, Gradle and others at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22rxandroid%22). - -Here is an example for [Maven](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22rxandroid%22): - -```xml - - io.reactivex - rxandroid - 0.23.0 - -``` - -…and for Ivy: - -```xml - -``` - -The currently supported `minSdkVersion` is `10` (Android 2.3/Gingerbread) - -# Examples - -## Observing on the UI thread - -You commonly deal with asynchronous tasks on Android by observing the task’s result or outcome on the main UI thread. Using vanilla Android, you would typically accomplish this with an `AsyncTask`. With RxJava you would instead declare your `Observable` to be observed on the main thread by using the `observeOn` operator: - -```java -public class ReactiveFragment extends Fragment { - -@Override -public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Observable.from("one", "two", "three", "four", "five") - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(/* an Observer */); -} -``` - -This executes the Observable on a new thread, which emits results through `onNext` on the main UI thread. - -## Observing on arbitrary threads -The previous example is a specialization of a more general concept: binding asynchronous communication to an Android message loop by using the `Handler` class. In order to observe an `Observable` on an arbitrary thread, create a `Handler` bound to that thread and use the `AndroidSchedulers.handlerThread` scheduler: - -```java -new Thread(new Runnable() { - @Override - public void run() { - final Handler handler = new Handler(); // bound to this thread - Observable.from("one", "two", "three", "four", "five") - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.handlerThread(handler)) - .subscribe(/* an Observer */) - - // perform work, ... - } -}, "custom-thread-1").start(); -``` - -This executes the Observable on a new thread and emits results through `onNext` on `custom-thread-1`. (This example is contrived since you could as well call `observeOn(Schedulers.currentThread())` but it illustrates the idea.) - -## Fragment and Activity life-cycle - -On Android it is tricky for asynchronous actions to access framework objects in their callbacks. That’s because Android may decide to destroy an `Activity`, for instance, while a background thread is still running. The thread will attempt to access views on the now dead `Activity`, which results in a crash. (This will also create a memory leak, since your background thread holds on to the `Activity` even though it’s not visible anymore.) - -This is still a concern when using RxJava on Android, but you can deal with the problem in a more elegant way by using `Subscription`s and a number of Observable operators. In general, when you run an `Observable` inside an `Activity` that subscribes to the result (either directly or through an inner class), you must unsubscribe from the sequence in `onDestroy`, as shown in the following example: - -```java -// MyActivity -private Subscription subscription; - -protected void onCreate(Bundle savedInstanceState) { - this.subscription = observable.subscribe(this); -} - -... - -protected void onDestroy() { - this.subscription.unsubscribe(); - super.onDestroy(); -} -``` - -This ensures that all references to the subscriber (the `Activity`) will be released as soon as possible, and no more notifications will arrive at the subscriber through `onNext`. - -One problem with this is that if the `Activity` is destroyed because of a change in screen orientation, the Observable will fire again in `onCreate`. You can prevent this by using the `cache` or `replay` Observable operators, while making sure the Observable somehow survives the `Activity` life-cycle (for instance, by storing it in a global cache, in a Fragment, etc.) You can use either operator to ensure that when the subscriber subscribes to an Observable that’s already “running,” items emitted by the Observable during the span when it was detached from the `Activity` will be “played back,” and any in-flight notifications from the Observable will be delivered as usual. - -# See also -* [How the New York Times is building its Android app with Groovy/RxJava](http://open.blogs.nytimes.com/2014/08/18/getting-groovy-with-reactive-android/?_php=true&_type=blogs&_php=true&_type=blogs&_r=1&) by Mohit Pandey -* [Functional Reactive Programming on Android With RxJava](http://mttkay.github.io/blog/2013/08/25/functional-reactive-programming-on-android-with-rxjava/) and [Conquering concurrency - bringing the Reactive Extensions to the Android platform](https://speakerdeck.com/mttkay/conquering-concurrency-bringing-the-reactive-extensions-to-the-android-platform) by Matthias Käppler -* [Learning RxJava for Android by example](https://github.com/kaushikgopal/Android-RxJava) by Kaushik Gopal -* [Top 7 Tips for RxJava on Android](http://blog.futurice.com/top-7-tips-for-rxjava-on-android) and [Rx Architectures in Android](http://www.slideshare.net/TimoTuominen1/rxjava-architectures-on-android-8-android-livecode-32531688) by Timo Tuominen -* [FRP on Android](http://slid.es/yaroslavheriatovych/frponandroid) by Yaroslav Heriatovych -* [Rx for .NET and RxJava for Android](http://blog.futurice.com/tech-pick-of-the-week-rx-for-net-and-rxjava-for-android) by Olli Salonen -* [RxJava in Xtend for Android](http://blog.futurice.com/android-development-has-its-own-swift) by Andre Medeiros -* [RxJava and Xtend](http://mnmlst-dvlpr.blogspot.de/2014/07/rxjava-and-xtend.html) by Stefan Oehme -* Grokking RxJava, [Part 1: The Basics](http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/), [Part 2: Operator, Operator](http://blog.danlew.net/2014/09/22/grokking-rxjava-part-2/), [Part 3: Reactive with Benefits](http://blog.danlew.net/2014/09/30/grokking-rxjava-part-3/), [Part 4: Reactive Android](http://blog.danlew.net/2014/10/08/grokking-rxjava-part-4/) - published in Sep/Oct 2014 by Daniel Lew \ No newline at end of file +See the [RxAndroid](https://github.com/ReactiveX/RxAndroid) project page and the [the RxAndroid wiki](https://github.com/ReactiveX/RxAndroid/wiki) for details. From 690258e1c0853664dfebc4ffe8dd99e499eb41c6 Mon Sep 17 00:00:00 2001 From: Ashish Krishnan Date: Sun, 5 Aug 2018 13:31:52 +0530 Subject: [PATCH 048/211] 2.x: Update Getting started docs (#6136) * Remove troubleshooting guide. * Getting Started, all artifacts point to RxJava2. * Fix JFrog links to point to 2.x --- docs/Getting-Started.md | 63 ++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/docs/Getting-Started.md b/docs/Getting-Started.md index 1a95121c4e..fb9baa47dd 100644 --- a/docs/Getting-Started.md +++ b/docs/Getting-Started.md @@ -1,20 +1,20 @@ ## Getting Binaries -You can find binaries and dependency information for Maven, Ivy, Gradle, SBT, and others at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.reactivex%22%20AND%20a%3A%22rxjava%22). +You can find binaries and dependency information for Maven, Ivy, Gradle, SBT, and others at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cg%3A"io.reactivex.rxjava2"%20AND%20"rxjava2"). Example for Maven: ```xml - io.reactivex + io.reactivex.rxjava2 rxjava - 1.3.4 + 2.2.0 ``` and for Ivy: ```xml - + ``` and for SBT: @@ -22,35 +22,35 @@ and for SBT: ```scala libraryDependencies += "io.reactivex" %% "rxscala" % "0.26.5" -libraryDependencies += "io.reactivex" % "rxjava" % "1.3.4" +libraryDependencies += "io.reactivex.rxjava2" % "rxjava" % "2.2.0" ``` and for Gradle: ```groovy -compile 'io.reactivex:rxjava:1.3.4' +compile 'io.reactivex.rxjava2:rxjava:2.2.0' ``` If you need to download the jars instead of using a build system, create a Maven `pom` file like this with the desired version: ```xml - - 4.0.0 - com.netflix.rxjava.download - rxjava-download - 1.0-SNAPSHOT - Simple POM to download rxjava and dependencies - http://github.com/ReactiveX/RxJava - - - io.reactivex - rxjava - 1.3.4 - - - + 4.0.0 + io.reactivex.rxjava2 + rxjava + 2.2.0 + RxJava + Reactive Extensions for Java + https://github.com/ReactiveX/RxJava + + + io.reactivex.rxjava2 + rxjava + 2.2.0 + + ``` @@ -66,7 +66,7 @@ You need Java 6 or later. ### Snapshots -Snapshots are available via [JFrog](https://oss.jfrog.org/webapp/search/artifact/?5&q=rxjava): +Snapshots are available via [JFrog](https://oss.jfrog.org/libs-snapshot/io/reactivex/rxjava2/rxjava/): ```groovy repositories { @@ -74,7 +74,7 @@ repositories { } dependencies { - compile 'io.reactivex:rxjava:1.3.y-SNAPSHOT' + compile 'io.reactivex.rxjava2:rxjava:2.2.0-SNAPSHOT' } ``` @@ -124,18 +124,3 @@ On a clean build you will see the unit tests run. They will look something like ``` > Building > :rxjava:test > 91 tests completed ``` - -#### Troubleshooting - -One developer reported getting the following error: - -> Could not resolve all dependencies for configuration ':language-adaptors:rxjava-scala:provided' - -He was able to resolve the problem by removing old versions of `scala-library` from `.gradle/caches` and `.m2/repository/org/scala-lang/` and then doing a clean build. (See this page for details.) - -You may get the following error during building RxJava: - -> Failed to apply plugin [id 'java'] -> Could not generate a proxy class for class nebula.core.NamedContainerProperOrder. - -It's a JVM issue, see [GROOVY-6951](https://jira.codehaus.org/browse/GROOVY-6951) for details. If so, you can run `export GRADLE_OPTS=-noverify` before building RxJava, or update your JDK. From bb939111a026a12880a1e9b75c5579c366177fe0 Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Sun, 5 Aug 2018 14:31:07 +0200 Subject: [PATCH 049/211] 2.x: Add marbles for Single.concat operator (#6137) * Add marbles for Single.concat operator * Update URL for Single.concat marble diagram * Update Single.concat marble's height --- src/main/java/io/reactivex/Single.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 84f40621c4..8ae6ac777c 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -166,6 +166,8 @@ public static Single ambArray(final SingleSource... sources) /** * Concatenate the single values, in a non-overlapping fashion, of the SingleSources provided by * an Iterable sequence. + *

+ * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
@@ -187,6 +189,8 @@ public static Flowable concat(Iterable + * *
*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
@@ -207,6 +211,8 @@ public static Observable concat(ObservableSource + * *
*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer @@ -229,6 +235,8 @@ public static Flowable concat(Publisher + * *
*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer @@ -255,7 +263,7 @@ public static Flowable concat(Publisher - * + * *
*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
@@ -286,7 +294,7 @@ public static Flowable concat( /** * Returns a Flowable that emits the items emitted by three Singles, one after the other. *

- * + * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
@@ -321,7 +329,7 @@ public static Flowable concat( /** * Returns a Flowable that emits the items emitted by four Singles, one after the other. *

- * + * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
@@ -359,6 +367,8 @@ public static Flowable concat( /** * Concatenate the single values, in a non-overlapping fashion, of the SingleSources provided in * an array. + *

+ * *

*
Backpressure:
*
The returned {@code Flowable} honors the backpressure of the downstream consumer.
From c8b0a0e82ea7e616325fe21e6d56391c80f99d42 Mon Sep 17 00:00:00 2001 From: lorenzpahl Date: Sun, 5 Aug 2018 20:28:02 +0200 Subject: [PATCH 050/211] 2.x: Update Mathematical and Aggregate Operators docs (#6140) * Update document structure; remove obsolete operators * Add examples * Change formatting * Include 'Flowable' in the introduction * Add additional notes to the mathematical operators * Rename section; add additional note * Create additional sections --- docs/Mathematical-and-Aggregate-Operators.md | 391 +++++++++++++++++-- 1 file changed, 366 insertions(+), 25 deletions(-) diff --git a/docs/Mathematical-and-Aggregate-Operators.md b/docs/Mathematical-and-Aggregate-Operators.md index f4a976f9d3..574111ad0e 100644 --- a/docs/Mathematical-and-Aggregate-Operators.md +++ b/docs/Mathematical-and-Aggregate-Operators.md @@ -1,25 +1,366 @@ -This page shows operators that perform mathematical or other operations over an entire sequence of items emitted by an Observable. Because these operations must wait for the source Observable to complete emitting items before they can construct their own emissions (and must usually buffer these items), these operators are dangerous to use on Observables that may have very long or infinite sequences. - -#### Operators in the `rxjava-math` module -* [**`averageInteger( )`**](http://reactivex.io/documentation/operators/average.html) — calculates the average of Integers emitted by an Observable and emits this average -* [**`averageLong( )`**](http://reactivex.io/documentation/operators/average.html) — calculates the average of Longs emitted by an Observable and emits this average -* [**`averageFloat( )`**](http://reactivex.io/documentation/operators/average.html) — calculates the average of Floats emitted by an Observable and emits this average -* [**`averageDouble( )`**](http://reactivex.io/documentation/operators/average.html) — calculates the average of Doubles emitted by an Observable and emits this average -* [**`max( )`**](http://reactivex.io/documentation/operators/max.html) — emits the maximum value emitted by a source Observable -* [**`maxBy( )`**](http://reactivex.io/documentation/operators/max.html) — emits the item emitted by the source Observable that has the maximum key value -* [**`min( )`**](http://reactivex.io/documentation/operators/min.html) — emits the minimum value emitted by a source Observable -* [**`minBy( )`**](http://reactivex.io/documentation/operators/min.html) — emits the item emitted by the source Observable that has the minimum key value -* [**`sumInteger( )`**](http://reactivex.io/documentation/operators/sum.html) — adds the Integers emitted by an Observable and emits this sum -* [**`sumLong( )`**](http://reactivex.io/documentation/operators/sum.html) — adds the Longs emitted by an Observable and emits this sum -* [**`sumFloat( )`**](http://reactivex.io/documentation/operators/sum.html) — adds the Floats emitted by an Observable and emits this sum -* [**`sumDouble( )`**](http://reactivex.io/documentation/operators/sum.html) — adds the Doubles emitted by an Observable and emits this sum - -#### Other Aggregate Operators -* [**`concat( )`**](http://reactivex.io/documentation/operators/concat.html) — concatenate two or more Observables sequentially -* [**`count( )` and `countLong( )`**](http://reactivex.io/documentation/operators/count.html) — counts the number of items emitted by an Observable and emits this count -* [**`reduce( )`**](http://reactivex.io/documentation/operators/reduce.html) — apply a function to each emitted item, sequentially, and emit only the final accumulated value -* [**`collect( )`**](http://reactivex.io/documentation/operators/reduce.html) — collect items emitted by the source Observable into a single mutable data structure and return an Observable that emits this structure -* [**`toList( )`**](http://reactivex.io/documentation/operators/to.html) — collect all items from an Observable and emit them as a single List -* [**`toSortedList( )`**](http://reactivex.io/documentation/operators/to.html) — collect all items from an Observable and emit them as a single, sorted List -* [**`toMap( )`**](http://reactivex.io/documentation/operators/to.html) — convert the sequence of items emitted by an Observable into a map keyed by a specified key function -* [**`toMultiMap( )`**](http://reactivex.io/documentation/operators/to.html) — convert the sequence of items emitted by an Observable into an ArrayList that is also a map keyed by a specified key function \ No newline at end of file +This page shows operators that perform mathematical or other operations over an entire sequence of items emitted by an `Observable` or `Flowable`. Because these operations must wait for the source `Observable`/`Flowable` to complete emitting items before they can construct their own emissions (and must usually buffer these items), these operators are dangerous to use on `Observable`s and `Flowable`s that may have very long or infinite sequences. + +# Outline + +- [Mathematical Operators](#mathematical-operators) + - [`averageDouble`](#averagedouble) + - [`averageFloat`](#averagefloat) + - [`max`](#max) + - [`min`](#min) + - [`sumDouble`](#sumdouble) + - [`sumFloat`](#sumfloat) + - [`sumInt`](#sumint) + - [`sumLong`](#sumlong) +- [Standard Aggregate Operators](#standard-aggregate-operators) + - [`count`](#count) + - [`reduce`](#reduce) + - [`reduceWith`](#reducewith) + - [`collect`](#collect) + - [`collectInto`](#collectinto) + - [`toList`](#tolist) + - [`toSortedList`](#tosortedlist) + - [`toMap`](#tomap) + - [`toMultimap`](#tomultimap) + +## Mathematical Operators + +> The operators in this section are part of the [`RxJava2Extensions`](https://github.com/akarnokd/RxJava2Extensions) project. You have to add the `rxjava2-extensions` module as a dependency to your project. It can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.akarnokd%22). + +> Note that unlike the standard RxJava aggregator operators, these mathematical operators return `Observable` and `Flowable` instead of the `Single` or `Maybe`. + +*The examples below assume that the `MathObservable` and `MathFlowable` classes are imported from the `rxjava2-extensions` module:* + +```java +import hu.akarnokd.rxjava2.math.MathObservable; +import hu.akarnokd.rxjava2.math.MathFlowable; +``` + +### averageDouble + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/average.html](http://reactivex.io/documentation/operators/average.html) + +Calculates the average of `Number`s emitted by an `Observable` and emits this average as a `Double`. + +#### averageDouble example + +```java +Observable numbers = Observable.just(1, 2, 3); +MathObservable.averageDouble(numbers).subscribe((Double avg) -> System.out.println(avg)); + +// prints 2.0 +``` + +### averageFloat + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/average.html](http://reactivex.io/documentation/operators/average.html) + +Calculates the average of `Number`s emitted by an `Observable` and emits this average as a `Float`. + +#### averageFloat example + +```java +Observable numbers = Observable.just(1, 2, 3); +MathObservable.averageFloat(numbers).subscribe((Float avg) -> System.out.println(avg)); + +// prints 2.0 +``` + +### max + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/max.html](http://reactivex.io/documentation/operators/max.html) + +Emits the maximum value emitted by a source `Observable`. A `Comparator` can be specified that will be used to compare the elements emitted by the `Observable`. + +#### max example + +```java +Observable numbers = Observable.just(4, 9, 5); +MathObservable.max(numbers).subscribe(System.out::println); + +// prints 9 +``` + +The following example specifies a `Comparator` to find the longest `String` in the source `Observable`: + +```java +final Observable names = Observable.just("Kirk", "Spock", "Chekov", "Sulu"); +MathObservable.max(names, Comparator.comparingInt(String::length)) + .subscribe(System.out::println); + +// prints Chekov +``` + +### min + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/min.html](http://reactivex.io/documentation/operators/min.html) + +Emits the minimum value emitted by a source `Observable`. A `Comparator` can be specified that will be used to compare the elements emitted by the `Observable`. + +#### min example + +```java +Observable numbers = Observable.just(4, 9, 5); +MathObservable.min(numbers).subscribe(System.out::println); + +// prints 4 +``` + +### sumDouble + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) + +Adds the `Double`s emitted by an `Observable` and emits this sum. + +#### sumDouble example + +```java +Observable numbers = Observable.just(1.0, 2.0, 3.0); +MathObservable.sumDouble(numbers).subscribe((Double sum) -> System.out.println(sum)); + +// prints 6.0 +``` + +### sumFloat + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) + +Adds the `Float`s emitted by an `Observable` and emits this sum. + +#### sumFloat example + +```java +Observable numbers = Observable.just(1.0F, 2.0F, 3.0F); +MathObservable.sumFloat(numbers).subscribe((Float sum) -> System.out.println(sum)); + +// prints 6.0 +``` + +### sumInt + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) + +Adds the `Integer`s emitted by an `Observable` and emits this sum. + +#### sumInt example + +```java +Observable numbers = Observable.range(1, 100); +MathObservable.sumInt(numbers).subscribe((Integer sum) -> System.out.println(sum)); + +// prints 5050 +``` + +### sumLong + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) + +Adds the `Long`s emitted by an `Observable` and emits this sum. + +#### sumLong example + +```java +Observable numbers = Observable.rangeLong(1L, 100L); +MathObservable.sumLong(numbers).subscribe((Long sum) -> System.out.println(sum)); + +// prints 5050 +``` + +## Standard Aggregate Operators + +> Note that these standard aggregate operators return a `Single` or `Maybe` because the number of output items is always know to be at most one. + +### count + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/count.html](http://reactivex.io/documentation/operators/count.html) + +Counts the number of items emitted by an `Observable` and emits this count as a `Long`. + +#### count example + +```java +Observable.just(1, 2, 3).count().subscribe(System.out::println); + +// prints 3 +``` + +### reduce + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) + +Apply a function to each emitted item, sequentially, and emit only the final accumulated value. + +#### reduce example + +```java +Observable.range(1, 5) + .reduce((product, x) -> product * x) + .subscribe(System.out::println); + +// prints 120 +``` + +### reduceWith + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) + +Apply a function to each emitted item, sequentially, and emit only the final accumulated value. + + +#### reduceWith example + +```java +Observable.just(1, 2, 2, 3, 4, 4, 4, 5) + .reduceWith(TreeSet::new, (set, x) -> { + set.add(x); + return set; + }) + .subscribe(System.out::println); + +// prints [1, 2, 3, 4, 5] +``` + +### collect + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) + +Collect items emitted by the source `Observable` into a single mutable data structure and return an `Observable` that emits this structure. + +#### collect example + +```java +Observable.just("Kirk", "Spock", "Chekov", "Sulu") + .collect(() -> new StringJoiner(" \uD83D\uDD96 "), StringJoiner::add) + .map(StringJoiner::toString) + .subscribe(System.out::println); + +// prints Kirk 🖖 Spock 🖖 Chekov 🖖 Sulu +``` + +### collectInto + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) + +Collect items emitted by the source `Observable` into a single mutable data structure and return an `Observable` that emits this structure. + +#### collectInto example + +*Note: the mutable value that will collect the items (here the `StringBuilder`) will be shared between multiple subscribers.* + +```java +Observable.just('R', 'x', 'J', 'a', 'v', 'a') + .collectInto(new StringBuilder(), StringBuilder::append) + .map(StringBuilder::toString) + .subscribe(System.out::println); + +// prints RxJava +``` + +### toList + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) + +Collect all items from an `Observable` and emit them as a single `List`. + +#### toList example + +```java +Observable.just(2, 1, 3) + .toList() + .subscribe(System.out::println); + +// prints [2, 1, 3] +``` + +### toSortedList + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) + +Collect all items from an `Observable` and emit them as a single, sorted `List`. + +#### toSortedList example + +```java +Observable.just(2, 1, 3) + .toSortedList(Comparator.reverseOrder()) + .subscribe(System.out::println); + +// prints [3, 2, 1] +``` + +### toMap + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) + +Convert the sequence of items emitted by an `Observable` into a `Map` keyed by a specified key function. + +#### toMap example + +```java +Observable.just(1, 2, 3, 4) + .toMap((x) -> { + // defines the key in the Map + return x; + }, (x) -> { + // defines the value that is mapped to the key + return (x % 2 == 0) ? "even" : "odd"; + }) + .subscribe(System.out::println); + +// prints {1=odd, 2=even, 3=odd, 4=even} +``` + +### toMultimap + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) + +Convert the sequence of items emitted by an `Observable` into a `Collection` that is also a `Map` keyed by a specified key function. + +#### toMultimap example + +```java +Observable.just(1, 2, 3, 4) + .toMultimap((x) -> { + // defines the key in the Map + return (x % 2 == 0) ? "even" : "odd"; + }, (x) -> { + // defines the value that is mapped to the key + return x; + }) + .subscribe(System.out::println); + +// prints {even=[2, 4], odd=[1, 3]} +``` From 579e90dc21937b900877a8baf3918cdca22d3a91 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sun, 5 Aug 2018 21:14:21 +0200 Subject: [PATCH 051/211] 2.x: Cleaunp - rename fields to upstream and downstream (#6129) * 2.x: Cleaunp - rename fields to upstream and downstream * Make links in MaybeEmitter.setDisposable --- src/jmh/java/io/reactivex/MemoryPerf.java | 10 +- src/main/java/io/reactivex/Completable.java | 6 +- .../java/io/reactivex/CompletableEmitter.java | 8 +- .../java/io/reactivex/CompletableSource.java | 6 +- src/main/java/io/reactivex/Flowable.java | 2 +- .../java/io/reactivex/FlowableEmitter.java | 12 +- src/main/java/io/reactivex/Maybe.java | 6 +- src/main/java/io/reactivex/MaybeEmitter.java | 12 +- src/main/java/io/reactivex/Observable.java | 6 +- .../java/io/reactivex/ObservableEmitter.java | 8 +- src/main/java/io/reactivex/Single.java | 6 +- src/main/java/io/reactivex/SingleEmitter.java | 10 +- .../observers/BasicFuseableObserver.java | 46 +++--- .../observers/BlockingBaseObserver.java | 6 +- .../observers/BlockingFirstObserver.java | 2 +- .../observers/BlockingMultiObserver.java | 6 +- .../internal/observers/BlockingObserver.java | 4 +- .../observers/DeferredScalarDisposable.java | 14 +- .../observers/DeferredScalarObserver.java | 18 +-- .../observers/DisposableLambdaObserver.java | 36 ++--- .../observers/ForEachWhileObserver.java | 4 +- .../internal/observers/FutureObserver.java | 24 +-- .../observers/FutureSingleObserver.java | 22 +-- .../observers/InnerQueuedObserver.java | 14 +- .../internal/observers/LambdaObserver.java | 6 +- .../observers/QueueDrainObserver.java | 8 +- .../observers/ResumeSingleObserver.java | 10 +- .../SubscriberCompletableObserver.java | 8 +- .../completable/CompletableCache.java | 10 +- .../completable/CompletableConcat.java | 28 ++-- .../completable/CompletableConcatArray.java | 8 +- .../CompletableConcatIterable.java | 12 +- .../completable/CompletableCreate.java | 10 +- .../completable/CompletableDetach.java | 34 ++-- .../completable/CompletableDisposeOn.java | 16 +- .../completable/CompletableDoFinally.java | 20 +-- .../completable/CompletableFromPublisher.java | 28 ++-- .../completable/CompletableHide.java | 24 +-- .../completable/CompletableMerge.java | 36 ++--- .../completable/CompletableMergeArray.java | 8 +- .../CompletableMergeDelayErrorArray.java | 8 +- .../completable/CompletableMergeIterable.java | 8 +- .../completable/CompletableObserveOn.java | 10 +- .../completable/CompletablePeek.java | 32 ++-- .../completable/CompletableSubscribeOn.java | 8 +- .../completable/CompletableTimer.java | 8 +- .../completable/CompletableUsing.java | 28 ++-- .../operators/flowable/FlowableAll.java | 16 +- .../operators/flowable/FlowableAllSingle.java | 36 ++--- .../operators/flowable/FlowableAmb.java | 26 ++-- .../operators/flowable/FlowableAny.java | 16 +- .../operators/flowable/FlowableAnySingle.java | 36 ++--- .../operators/flowable/FlowableBuffer.java | 76 ++++----- .../flowable/FlowableBufferBoundary.java | 6 +- .../FlowableBufferBoundarySupplier.java | 24 +-- .../flowable/FlowableBufferExactBoundary.java | 20 +-- .../flowable/FlowableBufferTimed.java | 58 +++---- .../operators/flowable/FlowableCollect.java | 14 +- .../flowable/FlowableCollectSingle.java | 28 ++-- .../flowable/FlowableCombineLatest.java | 8 +- .../flowable/FlowableConcatArray.java | 18 +-- .../operators/flowable/FlowableConcatMap.java | 88 +++++------ .../flowable/FlowableConcatMapEager.java | 24 +-- .../FlowableConcatWithCompletable.java | 12 +- .../flowable/FlowableConcatWithMaybe.java | 8 +- .../flowable/FlowableConcatWithSingle.java | 6 +- .../operators/flowable/FlowableCount.java | 16 +- .../flowable/FlowableCountSingle.java | 28 ++-- .../operators/flowable/FlowableCreate.java | 46 +++--- .../operators/flowable/FlowableDebounce.java | 24 +-- .../flowable/FlowableDebounceTimed.java | 22 +-- .../operators/flowable/FlowableDelay.java | 30 ++-- .../FlowableDelaySubscriptionOther.java | 7 +- .../flowable/FlowableDematerialize.java | 28 ++-- .../operators/flowable/FlowableDetach.java | 36 ++--- .../operators/flowable/FlowableDistinct.java | 12 +- .../FlowableDistinctUntilChanged.java | 16 +- .../flowable/FlowableDoAfterNext.java | 6 +- .../operators/flowable/FlowableDoFinally.java | 46 +++--- .../operators/flowable/FlowableDoOnEach.java | 22 +-- .../flowable/FlowableDoOnLifecycle.java | 30 ++-- .../operators/flowable/FlowableElementAt.java | 18 +-- .../flowable/FlowableElementAtMaybe.java | 32 ++-- .../flowable/FlowableElementAtSingle.java | 34 ++-- .../operators/flowable/FlowableFilter.java | 12 +- .../operators/flowable/FlowableFlatMap.java | 14 +- .../flowable/FlowableFlatMapCompletable.java | 28 ++-- ...FlowableFlatMapCompletableCompletable.java | 28 ++-- .../flowable/FlowableFlatMapMaybe.java | 40 ++--- .../flowable/FlowableFlatMapSingle.java | 32 ++-- .../flowable/FlowableFlattenIterable.java | 30 ++-- .../operators/flowable/FlowableFromArray.java | 16 +- .../flowable/FlowableFromIterable.java | 16 +- .../flowable/FlowableFromObservable.java | 22 +-- .../operators/flowable/FlowableGenerate.java | 10 +- .../operators/flowable/FlowableGroupBy.java | 30 ++-- .../operators/flowable/FlowableGroupJoin.java | 6 +- .../operators/flowable/FlowableHide.java | 24 +-- .../flowable/FlowableIgnoreElements.java | 20 +-- .../FlowableIgnoreElementsCompletable.java | 28 ++-- .../operators/flowable/FlowableInterval.java | 10 +- .../flowable/FlowableIntervalRange.java | 10 +- .../operators/flowable/FlowableJoin.java | 6 +- .../operators/flowable/FlowableLastMaybe.java | 30 ++-- .../flowable/FlowableLastSingle.java | 30 ++-- .../operators/flowable/FlowableLimit.java | 16 +- .../operators/flowable/FlowableMap.java | 10 +- .../flowable/FlowableMapNotification.java | 8 +- .../flowable/FlowableMaterialize.java | 6 +- .../FlowableMergeWithCompletable.java | 20 +-- .../flowable/FlowableMergeWithMaybe.java | 12 +- .../flowable/FlowableMergeWithSingle.java | 12 +- .../operators/flowable/FlowableObserveOn.java | 70 ++++----- .../FlowableOnBackpressureBuffer.java | 24 +-- .../FlowableOnBackpressureBufferStrategy.java | 20 +-- .../flowable/FlowableOnBackpressureDrop.java | 20 +-- .../flowable/FlowableOnBackpressureError.java | 22 +-- .../FlowableOnBackpressureLatest.java | 18 +-- .../flowable/FlowableOnErrorNext.java | 14 +- .../flowable/FlowableOnErrorReturn.java | 6 +- .../flowable/FlowablePublishMulticast.java | 48 +++--- .../operators/flowable/FlowableRange.java | 16 +- .../operators/flowable/FlowableRangeLong.java | 16 +- .../operators/flowable/FlowableReduce.java | 28 ++-- .../flowable/FlowableReduceMaybe.java | 22 +-- .../flowable/FlowableReduceSeedSingle.java | 28 ++-- .../operators/flowable/FlowableRefCount.java | 12 +- .../operators/flowable/FlowableRepeat.java | 10 +- .../flowable/FlowableRepeatUntil.java | 12 +- .../flowable/FlowableRepeatWhen.java | 25 ++- .../flowable/FlowableRetryBiPredicate.java | 12 +- .../flowable/FlowableRetryPredicate.java | 14 +- .../operators/flowable/FlowableRetryWhen.java | 2 +- .../flowable/FlowableSamplePublisher.java | 36 ++--- .../flowable/FlowableSampleTimed.java | 26 ++-- .../operators/flowable/FlowableScan.java | 24 +-- .../operators/flowable/FlowableScanSeed.java | 20 +-- .../flowable/FlowableSequenceEqual.java | 10 +- .../flowable/FlowableSequenceEqualSingle.java | 20 +-- .../operators/flowable/FlowableSingle.java | 20 +-- .../flowable/FlowableSingleMaybe.java | 36 ++--- .../flowable/FlowableSingleSingle.java | 34 ++-- .../operators/flowable/FlowableSkip.java | 22 +-- .../operators/flowable/FlowableSkipLast.java | 24 +-- .../flowable/FlowableSkipLastTimed.java | 16 +- .../operators/flowable/FlowableSkipUntil.java | 28 ++-- .../operators/flowable/FlowableSkipWhile.java | 30 ++-- .../flowable/FlowableSubscribeOn.java | 30 ++-- .../flowable/FlowableSwitchIfEmpty.java | 10 +- .../operators/flowable/FlowableSwitchMap.java | 22 +-- .../operators/flowable/FlowableTake.java | 38 +++-- .../operators/flowable/FlowableTakeLast.java | 18 +-- .../flowable/FlowableTakeLastOne.java | 18 +-- .../flowable/FlowableTakeLastTimed.java | 16 +- .../operators/flowable/FlowableTakeUntil.java | 30 ++-- .../flowable/FlowableTakeUntilPredicate.java | 28 ++-- .../operators/flowable/FlowableTakeWhile.java | 28 ++-- .../flowable/FlowableThrottleFirstTimed.java | 22 +-- .../flowable/FlowableTimeInterval.java | 22 +-- .../operators/flowable/FlowableTimeout.java | 32 ++-- .../flowable/FlowableTimeoutTimed.java | 34 ++-- .../operators/flowable/FlowableTimer.java | 12 +- .../operators/flowable/FlowableToList.java | 12 +- .../flowable/FlowableToListSingle.java | 26 ++-- .../flowable/FlowableUnsubscribeOn.java | 22 +-- .../operators/flowable/FlowableUsing.java | 38 ++--- .../operators/flowable/FlowableWindow.java | 66 ++++---- .../flowable/FlowableWindowBoundary.java | 4 +- .../FlowableWindowBoundarySelector.java | 18 +-- .../FlowableWindowBoundarySupplier.java | 8 +- .../flowable/FlowableWindowTimed.java | 76 ++++----- .../flowable/FlowableWithLatestFrom.java | 15 +- .../flowable/FlowableWithLatestFromMany.java | 32 ++-- .../operators/flowable/FlowableZip.java | 6 +- .../flowable/FlowableZipIterable.java | 30 ++-- .../internal/operators/maybe/MaybeAmb.java | 12 +- .../internal/operators/maybe/MaybeCache.java | 10 +- .../operators/maybe/MaybeConcatArray.java | 8 +- .../maybe/MaybeConcatArrayDelayError.java | 6 +- .../operators/maybe/MaybeConcatIterable.java | 8 +- .../operators/maybe/MaybeContains.java | 30 ++-- .../internal/operators/maybe/MaybeCount.java | 32 ++-- .../internal/operators/maybe/MaybeCreate.java | 14 +- .../internal/operators/maybe/MaybeDelay.java | 12 +- .../maybe/MaybeDelayOtherPublisher.java | 34 ++-- .../MaybeDelaySubscriptionOtherPublisher.java | 40 ++--- .../maybe/MaybeDelayWithCompletable.java | 22 +-- .../internal/operators/maybe/MaybeDetach.java | 40 ++--- .../operators/maybe/MaybeDoAfterSuccess.java | 22 +-- .../operators/maybe/MaybeDoFinally.java | 22 +-- .../operators/maybe/MaybeDoOnEvent.java | 34 ++-- .../operators/maybe/MaybeEqualSingle.java | 12 +- .../internal/operators/maybe/MaybeFilter.java | 28 ++-- .../operators/maybe/MaybeFilterSingle.java | 26 ++-- .../maybe/MaybeFlatMapBiSelector.java | 20 +-- .../maybe/MaybeFlatMapCompletable.java | 8 +- .../maybe/MaybeFlatMapIterableFlowable.java | 28 ++-- .../maybe/MaybeFlatMapIterableObservable.java | 24 +-- .../maybe/MaybeFlatMapNotification.java | 26 ++-- .../operators/maybe/MaybeFlatMapSingle.java | 26 ++-- .../maybe/MaybeFlatMapSingleElement.java | 26 ++-- .../operators/maybe/MaybeFlatten.java | 26 ++-- .../operators/maybe/MaybeFromCompletable.java | 28 ++-- .../operators/maybe/MaybeFromSingle.java | 28 ++-- .../internal/operators/maybe/MaybeHide.java | 26 ++-- .../operators/maybe/MaybeIgnoreElement.java | 32 ++-- .../maybe/MaybeIgnoreElementCompletable.java | 32 ++-- .../operators/maybe/MaybeIsEmpty.java | 24 +-- .../operators/maybe/MaybeIsEmptySingle.java | 32 ++-- .../internal/operators/maybe/MaybeMap.java | 26 ++-- .../operators/maybe/MaybeMergeArray.java | 8 +- .../operators/maybe/MaybeObserveOn.java | 12 +- .../operators/maybe/MaybeOnErrorComplete.java | 26 ++-- .../operators/maybe/MaybeOnErrorNext.java | 32 ++-- .../operators/maybe/MaybeOnErrorReturn.java | 24 +-- .../internal/operators/maybe/MaybePeek.java | 40 ++--- .../operators/maybe/MaybeSubscribeOn.java | 12 +- .../operators/maybe/MaybeSwitchIfEmpty.java | 22 +-- .../maybe/MaybeSwitchIfEmptySingle.java | 20 +-- .../operators/maybe/MaybeTakeUntilMaybe.java | 16 +- .../maybe/MaybeTakeUntilPublisher.java | 16 +- .../operators/maybe/MaybeTimeoutMaybe.java | 26 ++-- .../maybe/MaybeTimeoutPublisher.java | 26 ++-- .../internal/operators/maybe/MaybeTimer.java | 8 +- .../operators/maybe/MaybeToFlowable.java | 18 +-- .../operators/maybe/MaybeToObservable.java | 14 +- .../operators/maybe/MaybeToSingle.java | 32 ++-- .../operators/maybe/MaybeUnsubscribeOn.java | 12 +- .../internal/operators/maybe/MaybeUsing.java | 34 ++-- .../operators/maybe/MaybeZipArray.java | 12 +- .../mixed/ObservableConcatMapCompletable.java | 10 +- .../mixed/ObservableConcatMapMaybe.java | 6 +- .../mixed/ObservableConcatMapSingle.java | 6 +- .../mixed/ObservableSwitchMapCompletable.java | 6 +- .../mixed/ObservableSwitchMapMaybe.java | 6 +- .../mixed/ObservableSwitchMapSingle.java | 6 +- .../BlockingObservableIterable.java | 4 +- .../operators/observable/ObservableAll.java | 32 ++-- .../observable/ObservableAllSingle.java | 28 ++-- .../operators/observable/ObservableAmb.java | 30 ++-- .../operators/observable/ObservableAny.java | 32 ++-- .../observable/ObservableAnySingle.java | 28 ++-- .../observable/ObservableBuffer.java | 64 ++++---- .../observable/ObservableBufferBoundary.java | 24 +-- .../ObservableBufferBoundarySupplier.java | 28 ++-- .../ObservableBufferExactBoundary.java | 24 +-- .../observable/ObservableBufferTimed.java | 74 ++++----- .../operators/observable/ObservableCache.java | 4 +- .../observable/ObservableCollect.java | 26 ++-- .../observable/ObservableCollectSingle.java | 24 +-- .../observable/ObservableCombineLatest.java | 12 +- .../observable/ObservableConcatMap.java | 76 ++++----- .../observable/ObservableConcatMapEager.java | 22 +-- .../ObservableConcatWithCompletable.java | 12 +- .../observable/ObservableConcatWithMaybe.java | 16 +- .../ObservableConcatWithSingle.java | 14 +- .../operators/observable/ObservableCount.java | 26 ++-- .../observable/ObservableCountSingle.java | 28 ++-- .../observable/ObservableCreate.java | 4 +- .../observable/ObservableDebounce.java | 26 ++-- .../observable/ObservableDebounceTimed.java | 22 +-- .../operators/observable/ObservableDelay.java | 22 +-- .../observable/ObservableDematerialize.java | 30 ++-- .../observable/ObservableDetach.java | 40 ++--- .../observable/ObservableDistinct.java | 10 +- .../ObservableDistinctUntilChanged.java | 6 +- .../observable/ObservableDoAfterNext.java | 4 +- .../observable/ObservableDoFinally.java | 22 +-- .../observable/ObservableDoOnEach.java | 26 ++-- .../observable/ObservableElementAt.java | 32 ++-- .../observable/ObservableElementAtMaybe.java | 26 ++-- .../observable/ObservableElementAtSingle.java | 28 ++-- .../observable/ObservableFilter.java | 6 +- .../observable/ObservableFlatMap.java | 34 ++-- .../ObservableFlatMapCompletable.java | 26 ++-- ...servableFlatMapCompletableCompletable.java | 26 ++-- .../observable/ObservableFlatMapMaybe.java | 30 ++-- .../observable/ObservableFlatMapSingle.java | 26 ++-- .../observable/ObservableFlattenIterable.java | 40 ++--- .../observable/ObservableFromArray.java | 10 +- .../observable/ObservableFromIterable.java | 12 +- .../observable/ObservableFromPublisher.java | 24 +-- .../observable/ObservableGenerate.java | 10 +- .../observable/ObservableGroupBy.java | 28 ++-- .../observable/ObservableGroupJoin.java | 14 +- .../operators/observable/ObservableHide.java | 24 +-- .../observable/ObservableIgnoreElements.java | 20 +-- .../ObservableIgnoreElementsCompletable.java | 20 +-- .../observable/ObservableInterval.java | 8 +- .../observable/ObservableIntervalRange.java | 8 +- .../operators/observable/ObservableJoin.java | 6 +- .../observable/ObservableLastMaybe.java | 32 ++-- .../observable/ObservableLastSingle.java | 32 ++-- .../operators/observable/ObservableMap.java | 6 +- .../observable/ObservableMapNotification.java | 34 ++-- .../observable/ObservableMaterialize.java | 30 ++-- .../ObservableMergeWithCompletable.java | 16 +- .../observable/ObservableMergeWithMaybe.java | 12 +- .../observable/ObservableMergeWithSingle.java | 12 +- .../observable/ObservableObserveOn.java | 36 ++--- .../observable/ObservableOnErrorNext.java | 20 +-- .../observable/ObservableOnErrorReturn.java | 30 ++-- .../observable/ObservablePublish.java | 8 +- .../observable/ObservablePublishSelector.java | 24 +-- .../operators/observable/ObservableRange.java | 6 +- .../observable/ObservableRangeLong.java | 6 +- .../observable/ObservableReduceMaybe.java | 24 +-- .../ObservableReduceSeedSingle.java | 22 +-- .../observable/ObservableRefCount.java | 14 +- .../observable/ObservableRepeat.java | 14 +- .../observable/ObservableRepeatUntil.java | 20 +-- .../observable/ObservableRepeatWhen.java | 26 ++-- .../ObservableRetryBiPredicate.java | 22 +-- .../observable/ObservableRetryPredicate.java | 24 +-- .../observable/ObservableRetryWhen.java | 26 ++-- .../observable/ObservableSampleTimed.java | 32 ++-- .../ObservableSampleWithObservable.java | 40 ++--- .../operators/observable/ObservableScan.java | 26 ++-- .../observable/ObservableScanSeed.java | 28 ++-- .../observable/ObservableSequenceEqual.java | 30 ++-- .../ObservableSequenceEqualSingle.java | 24 +-- .../observable/ObservableSingleMaybe.java | 30 ++-- .../observable/ObservableSingleSingle.java | 28 ++-- .../operators/observable/ObservableSkip.java | 22 +-- .../observable/ObservableSkipLast.java | 24 +-- .../observable/ObservableSkipLastTimed.java | 18 +-- .../observable/ObservableSkipUntil.java | 40 ++--- .../observable/ObservableSkipWhile.java | 30 ++-- .../observable/ObservableSubscribeOn.java | 22 +-- .../observable/ObservableSwitchIfEmpty.java | 14 +- .../observable/ObservableSwitchMap.java | 32 ++-- .../operators/observable/ObservableTake.java | 32 ++-- .../observable/ObservableTakeLast.java | 20 +-- .../observable/ObservableTakeLastOne.java | 26 ++-- .../observable/ObservableTakeLastTimed.java | 16 +- .../ObservableTakeUntilPredicate.java | 32 ++-- .../observable/ObservableTakeWhile.java | 30 ++-- .../ObservableThrottleFirstTimed.java | 22 +-- .../observable/ObservableThrottleLatest.java | 6 +- .../observable/ObservableTimeInterval.java | 24 +-- .../observable/ObservableTimeout.java | 44 +++--- .../observable/ObservableTimeoutTimed.java | 46 +++--- .../operators/observable/ObservableTimer.java | 10 +- .../observable/ObservableToList.java | 27 ++-- .../observable/ObservableToListSingle.java | 22 +-- .../observable/ObservableUnsubscribeOn.java | 22 +-- .../operators/observable/ObservableUsing.java | 36 ++--- .../observable/ObservableWindow.java | 48 +++--- .../ObservableWindowBoundarySelector.java | 18 +-- .../observable/ObservableWindowTimed.java | 72 ++++----- .../observable/ObservableWithLatestFrom.java | 44 +++--- .../ObservableWithLatestFromMany.java | 30 ++-- .../operators/observable/ObservableZip.java | 16 +- .../observable/ObservableZipIterable.java | 32 ++-- .../observable/ObserverResourceWrapper.java | 24 +-- .../operators/parallel/ParallelCollect.java | 10 +- .../parallel/ParallelDoOnNextTry.java | 49 +++--- .../operators/parallel/ParallelFilter.java | 40 ++--- .../operators/parallel/ParallelFilterTry.java | 40 ++--- .../parallel/ParallelFromPublisher.java | 16 +- .../operators/parallel/ParallelJoin.java | 14 +- .../operators/parallel/ParallelMap.java | 46 +++--- .../operators/parallel/ParallelMapTry.java | 49 +++--- .../operators/parallel/ParallelPeek.java | 26 ++-- .../operators/parallel/ParallelReduce.java | 10 +- .../parallel/ParallelReduceFull.java | 4 +- .../operators/parallel/ParallelRunOn.java | 34 ++-- .../parallel/ParallelSortedJoin.java | 6 +- .../operators/single/SingleCache.java | 8 +- .../operators/single/SingleCreate.java | 17 +- .../single/SingleDelayWithCompletable.java | 10 +- .../single/SingleDelayWithObservable.java | 10 +- .../single/SingleDelayWithPublisher.java | 20 +-- .../single/SingleDelayWithSingle.java | 10 +- .../operators/single/SingleDetach.java | 34 ++-- .../single/SingleDoAfterSuccess.java | 20 +-- .../single/SingleDoAfterTerminate.java | 20 +-- .../operators/single/SingleDoFinally.java | 20 +-- .../operators/single/SingleDoOnDispose.java | 20 +-- .../operators/single/SingleDoOnSubscribe.java | 12 +- .../operators/single/SingleFlatMap.java | 26 ++-- .../single/SingleFlatMapCompletable.java | 8 +- .../single/SingleFlatMapIterableFlowable.java | 26 ++-- .../SingleFlatMapIterableObservable.java | 24 +-- .../operators/single/SingleFlatMapMaybe.java | 26 ++-- .../single/SingleFlatMapPublisher.java | 18 +-- .../operators/single/SingleFromPublisher.java | 26 ++-- .../internal/operators/single/SingleHide.java | 22 +-- .../operators/single/SingleObserveOn.java | 10 +- .../operators/single/SingleResumeNext.java | 12 +- .../operators/single/SingleSubscribeOn.java | 8 +- .../operators/single/SingleTakeUntil.java | 12 +- .../operators/single/SingleTimeout.java | 20 +-- .../operators/single/SingleTimer.java | 8 +- .../operators/single/SingleToFlowable.java | 16 +- .../operators/single/SingleToObservable.java | 14 +- .../operators/single/SingleUnsubscribeOn.java | 10 +- .../operators/single/SingleUsing.java | 28 ++-- .../operators/single/SingleZipArray.java | 10 +- .../internal/schedulers/DisposeOnCancel.java | 7 +- .../BasicFuseableConditionalSubscriber.java | 26 ++-- .../subscribers/BasicFuseableSubscriber.java | 26 ++-- .../subscribers/BlockingBaseSubscriber.java | 12 +- .../subscribers/BlockingFirstSubscriber.java | 2 +- .../subscribers/DeferredScalarSubscriber.java | 20 +-- .../subscribers/FutureSubscriber.java | 22 +-- .../subscribers/QueueDrainSubscriber.java | 10 +- .../SinglePostCompleteSubscriber.java | 26 ++-- .../subscribers/StrictSubscriber.java | 24 +-- .../SubscriberResourceWrapper.java | 24 +-- .../DeferredScalarSubscription.java | 14 +- .../internal/util/NotificationLite.java | 20 +-- .../reactivex/observers/DefaultObserver.java | 16 +- .../DisposableCompletableObserver.java | 11 +- .../observers/DisposableMaybeObserver.java | 10 +- .../observers/DisposableObserver.java | 10 +- .../observers/DisposableSingleObserver.java | 10 +- .../ResourceCompletableObserver.java | 10 +- .../observers/ResourceMaybeObserver.java | 10 +- .../reactivex/observers/ResourceObserver.java | 10 +- .../observers/ResourceSingleObserver.java | 10 +- .../io/reactivex/observers/SafeObserver.java | 52 +++---- .../observers/SerializedObserver.java | 34 ++-- .../io/reactivex/observers/TestObserver.java | 68 ++++---- .../reactivex/processors/AsyncProcessor.java | 4 +- .../processors/BehaviorProcessor.java | 12 +- .../processors/MulticastProcessor.java | 10 +- .../processors/PublishProcessor.java | 12 +- .../reactivex/processors/ReplayProcessor.java | 10 +- .../processors/UnicastProcessor.java | 28 ++-- .../io/reactivex/subjects/AsyncSubject.java | 8 +- .../reactivex/subjects/BehaviorSubject.java | 10 +- .../subjects/CompletableSubject.java | 8 +- .../io/reactivex/subjects/MaybeSubject.java | 10 +- .../io/reactivex/subjects/PublishSubject.java | 26 ++-- .../io/reactivex/subjects/ReplaySubject.java | 14 +- .../reactivex/subjects/SerializedSubject.java | 8 +- .../io/reactivex/subjects/SingleSubject.java | 8 +- .../io/reactivex/subjects/UnicastSubject.java | 32 ++-- .../subscribers/DefaultSubscriber.java | 14 +- .../reactivex/subscribers/SafeSubscriber.java | 50 +++--- .../subscribers/SerializedSubscriber.java | 32 ++-- .../reactivex/subscribers/TestSubscriber.java | 42 ++--- src/test/java/io/reactivex/TestHelper.java | 104 ++++++------- .../completable/CompletableTest.java | 42 ++--- .../disposables/CompositeDisposableTest.java | 114 +++++++------- .../flowable/FlowableBackpressureTests.java | 8 +- .../flowable/FlowableSubscriberTest.java | 6 +- .../io/reactivex/flowable/FlowableTests.java | 4 +- .../observers/DeferredScalarObserverTest.java | 16 +- .../observers/FutureObserverTest.java | 12 +- .../observers/LambdaObserverTest.java | 26 ++-- .../observers/QueueDrainObserverTest.java | 4 +- .../completable/CompletableDoOnTest.java | 2 +- .../flowable/FlowableBlockingTest.java | 8 +- .../flowable/FlowableCombineLatestTest.java | 4 +- .../flowable/FlowableCreateTest.java | 4 +- .../flowable/FlowableDistinctTest.java | 10 +- .../FlowableFlatMapCompletableTest.java | 10 +- .../flowable/FlowableFromIterableTest.java | 12 +- .../flowable/FlowableObserveOnTest.java | 10 +- ...wableOnErrorResumeNextViaFlowableTest.java | 6 +- .../flowable/FlowablePublishTest.java | 46 +++--- .../flowable/FlowableRefCountTest.java | 52 +++---- .../flowable/FlowableTakeUntilTest.java | 6 +- .../flowable/FlowableTakeWhileTest.java | 6 +- .../operators/flowable/FlowableUsingTest.java | 6 +- .../operators/maybe/MaybeDoOnEventTest.java | 2 +- .../MaybeFlatMapIterableFlowableTest.java | 16 +- .../operators/maybe/MaybeMergeArrayTest.java | 16 +- .../observable/ObservableAmbTest.java | 2 +- .../observable/ObservableConcatTest.java | 4 +- .../observable/ObservableDoFinallyTest.java | 40 ++--- .../ObservableDoOnSubscribeTest.java | 12 +- .../observable/ObservableFlatMapTest.java | 2 +- .../observable/ObservableGroupByTest.java | 6 +- .../observable/ObservableGroupJoinTest.java | 2 +- .../observable/ObservableMergeTest.java | 8 +- .../observable/ObservableObserveOnTest.java | 6 +- ...vableOnErrorResumeNextViaFunctionTest.java | 4 +- ...bleOnErrorResumeNextViaObservableTest.java | 12 +- .../observable/ObservablePublishTest.java | 34 ++-- .../observable/ObservableRefCountTest.java | 70 ++++----- .../observable/ObservableSampleTest.java | 6 +- .../ObservableSwitchIfEmptyTest.java | 2 +- .../observable/ObservableTakeUntilTest.java | 8 +- .../observable/ObservableTakeWhileTest.java | 14 +- .../observable/ObservableTimeoutTests.java | 18 +-- .../ObservableTimeoutWithSelectorTest.java | 4 +- .../observable/ObservableUsingTest.java | 6 +- .../operators/single/SingleDoOnTest.java | 10 +- .../SingleFlatMapIterableFlowableTest.java | 16 +- .../DeferredScalarSubscriberTest.java | 4 +- .../subscribers/StrictSubscriberTest.java | 16 +- .../internal/util/EndConsumerHelperTest.java | 6 +- .../util/HalfSerializerObserverTest.java | 56 +++---- .../observable/ObservableNullTests.java | 2 +- .../reactivex/observable/ObservableTest.java | 4 +- .../reactivex/observers/SafeObserverTest.java | 2 +- .../parallel/ParallelFromPublisherTest.java | 6 +- .../reactivex/plugins/RxJavaPluginsTest.java | 4 +- .../processors/ReplayProcessorTest.java | 4 +- .../schedulers/ExecutorSchedulerTest.java | 20 +-- .../schedulers/SchedulerLifecycleTest.java | 12 +- .../subjects/PublishSubjectTest.java | 6 +- .../reactivex/subjects/ReplaySubjectTest.java | 4 +- .../subscribers/DisposableSubscriberTest.java | 12 +- .../subscribers/ResourceSubscriberTest.java | 12 +- .../subscribers/SafeSubscriberTest.java | 20 +-- .../subscribers/SerializedSubscriberTest.java | 32 ++-- .../subscribers/TestSubscriberTest.java | 16 +- .../io/reactivex/tck/RefCountProcessor.java | 12 +- .../{ => validators}/BaseTypeAnnotations.java | 3 +- .../{ => validators}/BaseTypeParser.java | 2 +- .../CheckLocalVariablesInTests.java | 147 +++++++++++++++++- .../{ => validators}/FixLicenseHeaders.java | 2 +- .../{ => validators}/InternalWrongNaming.java | 2 +- .../JavadocFindUnescapedAngleBrackets.java | 2 +- .../JavadocForAnnotations.java | 4 +- .../{ => validators}/JavadocWording.java | 4 +- .../{ => validators}/MaybeNo2Dot0Since.java | 4 +- .../NoAnonymousInnerClassesTest.java | 2 +- .../{ => validators}/OperatorsAreFinal.java | 2 +- .../ParamValidationCheckerTest.java | 5 +- .../{ => validators}/PublicFinalMethods.java | 4 +- .../{ => validators}/TextualAorAn.java | 2 +- 526 files changed, 5499 insertions(+), 5325 deletions(-) rename src/test/java/io/reactivex/{ => validators}/BaseTypeAnnotations.java (99%) rename src/test/java/io/reactivex/{ => validators}/BaseTypeParser.java (99%) rename src/test/java/io/reactivex/{ => validators}/CheckLocalVariablesInTests.java (65%) rename src/test/java/io/reactivex/{ => validators}/FixLicenseHeaders.java (99%) rename src/test/java/io/reactivex/{ => validators}/InternalWrongNaming.java (99%) rename src/test/java/io/reactivex/{ => validators}/JavadocFindUnescapedAngleBrackets.java (99%) rename src/test/java/io/reactivex/{ => validators}/JavadocForAnnotations.java (99%) rename src/test/java/io/reactivex/{ => validators}/JavadocWording.java (99%) rename src/test/java/io/reactivex/{ => validators}/MaybeNo2Dot0Since.java (98%) rename src/test/java/io/reactivex/{ => validators}/NoAnonymousInnerClassesTest.java (98%) rename src/test/java/io/reactivex/{ => validators}/OperatorsAreFinal.java (98%) rename src/test/java/io/reactivex/{ => validators}/ParamValidationCheckerTest.java (99%) rename src/test/java/io/reactivex/{ => validators}/PublicFinalMethods.java (96%) rename src/test/java/io/reactivex/{ => validators}/TextualAorAn.java (99%) diff --git a/src/jmh/java/io/reactivex/MemoryPerf.java b/src/jmh/java/io/reactivex/MemoryPerf.java index ba92a89b78..2a625c2149 100644 --- a/src/jmh/java/io/reactivex/MemoryPerf.java +++ b/src/jmh/java/io/reactivex/MemoryPerf.java @@ -35,11 +35,11 @@ static long memoryUse() { static final class MyRx2Subscriber implements FlowableSubscriber { - org.reactivestreams.Subscription s; + org.reactivestreams.Subscription upstream; @Override public void onSubscribe(Subscription s) { - this.s = s; + this.upstream = s; } @Override @@ -61,11 +61,11 @@ public void onNext(Object t) { static final class MyRx2Observer implements io.reactivex.Observer, io.reactivex.SingleObserver, io.reactivex.MaybeObserver, io.reactivex.CompletableObserver { - Disposable s; + Disposable upstream; @Override - public void onSubscribe(Disposable s) { - this.s = s; + public void onSubscribe(Disposable d) { + this.upstream = d; } @Override diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 9a681d8bc5..b4f18a56c2 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -1622,11 +1622,11 @@ public final Completable doFinally(Action onFinally) { * // and subsequently this class has to send a Disposable to the downstream. * // Note that relaying the upstream's Disposable directly is not allowed in RxJava * @Override - * public void onSubscribe(Disposable s) { + * public void onSubscribe(Disposable d) { * if (upstream != null) { - * s.cancel(); + * d.dispose(); * } else { - * upstream = s; + * upstream = d; * downstream.onSubscribe(this); * } * } diff --git a/src/main/java/io/reactivex/CompletableEmitter.java b/src/main/java/io/reactivex/CompletableEmitter.java index b32e329c3b..ffbd9ba37b 100644 --- a/src/main/java/io/reactivex/CompletableEmitter.java +++ b/src/main/java/io/reactivex/CompletableEmitter.java @@ -59,15 +59,15 @@ public interface CompletableEmitter { void onError(@NonNull Throwable t); /** - * Sets a Disposable on this emitter; any previous Disposable - * or Cancellation will be disposed/cancelled. + * Sets a Disposable on this emitter; any previous {@link Disposable} + * or {@link Cancellable} will be disposed/cancelled. * @param d the disposable, null is allowed */ void setDisposable(@Nullable Disposable d); /** - * Sets a Cancellable on this emitter; any previous Disposable - * or Cancellation will be disposed/cancelled. + * Sets a Cancellable on this emitter; any previous {@link Disposable} + * or {@link Cancellable} will be disposed/cancelled. * @param c the cancellable resource, null is allowed */ void setCancellable(@Nullable Cancellable c); diff --git a/src/main/java/io/reactivex/CompletableSource.java b/src/main/java/io/reactivex/CompletableSource.java index 57019f3164..145b0404f7 100644 --- a/src/main/java/io/reactivex/CompletableSource.java +++ b/src/main/java/io/reactivex/CompletableSource.java @@ -24,8 +24,8 @@ public interface CompletableSource { /** * Subscribes the given CompletableObserver to this CompletableSource instance. - * @param cs the CompletableObserver, not null - * @throws NullPointerException if {@code cs} is null + * @param co the CompletableObserver, not null + * @throws NullPointerException if {@code co} is null */ - void subscribe(@NonNull CompletableObserver cs); + void subscribe(@NonNull CompletableObserver co); } diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 84d4e6bba5..1afe7b594f 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -10787,7 +10787,7 @@ public final Single lastOrError() { * * // In the subscription phase, the upstream sends a Subscription to this class * // and subsequently this class has to send a Subscription to the downstream. - * // Note that relaying the upstream's Subscription directly is not allowed in RxJava + * // Note that relaying the upstream's Subscription instance directly is not allowed in RxJava * @Override * public void onSubscribe(Subscription s) { * if (upstream != null) { diff --git a/src/main/java/io/reactivex/FlowableEmitter.java b/src/main/java/io/reactivex/FlowableEmitter.java index 06636449c4..1cd91e14b4 100644 --- a/src/main/java/io/reactivex/FlowableEmitter.java +++ b/src/main/java/io/reactivex/FlowableEmitter.java @@ -51,15 +51,15 @@ public interface FlowableEmitter extends Emitter { /** - * Sets a Disposable on this emitter; any previous Disposable - * or Cancellation will be disposed/cancelled. - * @param s the disposable, null is allowed + * Sets a Disposable on this emitter; any previous {@link Disposable} + * or {@link Cancellable} will be disposed/cancelled. + * @param d the disposable, null is allowed */ - void setDisposable(@Nullable Disposable s); + void setDisposable(@Nullable Disposable d); /** - * Sets a Cancellable on this emitter; any previous Disposable - * or Cancellation will be disposed/cancelled. + * Sets a Cancellable on this emitter; any previous {@link Disposable} + * or {@link Cancellable} will be disposed/cancelled. * @param c the cancellable resource, null is allowed */ void setCancellable(@Nullable Cancellable c); diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 9c50ef8518..519a64f6b9 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -3237,11 +3237,11 @@ public final Single isEmpty() { * // and subsequently this class has to send a Disposable to the downstream. * // Note that relaying the upstream's Disposable directly is not allowed in RxJava * @Override - * public void onSubscribe(Disposable s) { + * public void onSubscribe(Disposable d) { * if (upstream != null) { - * s.cancel(); + * d.dispose(); * } else { - * upstream = s; + * upstream = d; * downstream.onSubscribe(this); * } * } diff --git a/src/main/java/io/reactivex/MaybeEmitter.java b/src/main/java/io/reactivex/MaybeEmitter.java index f0e6ed6266..4819ce3c3e 100644 --- a/src/main/java/io/reactivex/MaybeEmitter.java +++ b/src/main/java/io/reactivex/MaybeEmitter.java @@ -67,15 +67,15 @@ public interface MaybeEmitter { void onComplete(); /** - * Sets a Disposable on this emitter; any previous Disposable - * or Cancellation will be unsubscribed/cancelled. - * @param s the disposable, null is allowed + * Sets a Disposable on this emitter; any previous {@link Disposable} + * or {@link Cancellable} will be disposed/cancelled. + * @param d the disposable, null is allowed */ - void setDisposable(@Nullable Disposable s); + void setDisposable(@Nullable Disposable d); /** - * Sets a Cancellable on this emitter; any previous Disposable - * or Cancellation will be unsubscribed/cancelled. + * Sets a Cancellable on this emitter; any previous {@link Disposable} + * or {@link Cancellable} will be disposed/cancelled. * @param c the cancellable resource, null is allowed */ void setCancellable(@Nullable Cancellable c); diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 4d672cea00..ab38ab2374 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -9409,11 +9409,11 @@ public final Single lastOrError() { * // and subsequently this class has to send a Disposable to the downstream. * // Note that relaying the upstream's Disposable directly is not allowed in RxJava * @Override - * public void onSubscribe(Disposable s) { + * public void onSubscribe(Disposable d) { * if (upstream != null) { - * s.dispose(); + * d.dispose(); * } else { - * upstream = s; + * upstream = d; * downstream.onSubscribe(this); * } * } diff --git a/src/main/java/io/reactivex/ObservableEmitter.java b/src/main/java/io/reactivex/ObservableEmitter.java index 0adbdb3a8d..9faccf528d 100644 --- a/src/main/java/io/reactivex/ObservableEmitter.java +++ b/src/main/java/io/reactivex/ObservableEmitter.java @@ -50,15 +50,15 @@ public interface ObservableEmitter extends Emitter { /** - * Sets a Disposable on this emitter; any previous Disposable - * or Cancellation will be unsubscribed/cancelled. + * Sets a Disposable on this emitter; any previous {@link Disposable} + * or {@link Cancellable} will be disposed/cancelled. * @param d the disposable, null is allowed */ void setDisposable(@Nullable Disposable d); /** - * Sets a Cancellable on this emitter; any previous Disposable - * or Cancellation will be unsubscribed/cancelled. + * Sets a Cancellable on this emitter; any previous {@link Disposable} + * or {@link Cancellable} will be disposed/cancelled. * @param c the cancellable resource, null is allowed */ void setCancellable(@Nullable Cancellable c); diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 8ae6ac777c..0a461709df 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -2708,11 +2708,11 @@ public final T blockingGet() { * // and subsequently this class has to send a Disposable to the downstream. * // Note that relaying the upstream's Disposable directly is not allowed in RxJava * @Override - * public void onSubscribe(Disposable s) { + * public void onSubscribe(Disposable d) { * if (upstream != null) { - * s.cancel(); + * d.dispose(); * } else { - * upstream = s; + * upstream = d; * downstream.onSubscribe(this); * } * } diff --git a/src/main/java/io/reactivex/SingleEmitter.java b/src/main/java/io/reactivex/SingleEmitter.java index 9e98f130e0..9c1ded1575 100644 --- a/src/main/java/io/reactivex/SingleEmitter.java +++ b/src/main/java/io/reactivex/SingleEmitter.java @@ -63,14 +63,14 @@ public interface SingleEmitter { /** * Sets a Disposable on this emitter; any previous Disposable - * or Cancellation will be unsubscribed/cancelled. - * @param s the disposable, null is allowed + * or Cancellable will be disposed/cancelled. + * @param d the disposable, null is allowed */ - void setDisposable(@Nullable Disposable s); + void setDisposable(@Nullable Disposable d); /** - * Sets a Cancellable on this emitter; any previous Disposable - * or Cancellation will be unsubscribed/cancelled. + * Sets a Cancellable on this emitter; any previous {@link Disposable} + * or {@link Cancellable} will be disposed/cancelled. * @param c the cancellable resource, null is allowed */ void setCancellable(@Nullable Cancellable c); diff --git a/src/main/java/io/reactivex/internal/observers/BasicFuseableObserver.java b/src/main/java/io/reactivex/internal/observers/BasicFuseableObserver.java index 64034616f0..56ec76bb61 100644 --- a/src/main/java/io/reactivex/internal/observers/BasicFuseableObserver.java +++ b/src/main/java/io/reactivex/internal/observers/BasicFuseableObserver.java @@ -28,13 +28,13 @@ public abstract class BasicFuseableObserver implements Observer, QueueDisposable { /** The downstream subscriber. */ - protected final Observer actual; + protected final Observer downstream; /** The upstream subscription. */ - protected Disposable s; + protected Disposable upstream; /** The upstream's QueueDisposable if not null. */ - protected QueueDisposable qs; + protected QueueDisposable qd; /** Flag indicating no further onXXX event should be accepted. */ protected boolean done; @@ -44,26 +44,26 @@ public abstract class BasicFuseableObserver implements Observer, QueueD /** * Construct a BasicFuseableObserver by wrapping the given subscriber. - * @param actual the subscriber, not null (not verified) + * @param downstream the subscriber, not null (not verified) */ - public BasicFuseableObserver(Observer actual) { - this.actual = actual; + public BasicFuseableObserver(Observer downstream) { + this.downstream = downstream; } // final: fixed protocol steps to support fuseable and non-fuseable upstream @SuppressWarnings("unchecked") @Override - public final void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { + public final void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { - this.s = s; - if (s instanceof QueueDisposable) { - this.qs = (QueueDisposable)s; + this.upstream = d; + if (d instanceof QueueDisposable) { + this.qd = (QueueDisposable)d; } if (beforeDownstream()) { - actual.onSubscribe(this); + downstream.onSubscribe(this); afterDownstream(); } @@ -97,7 +97,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } /** @@ -106,7 +106,7 @@ public void onError(Throwable t) { */ protected final void fail(Throwable t) { Exceptions.throwIfFatal(t); - s.dispose(); + upstream.dispose(); onError(t); } @@ -116,7 +116,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } /** @@ -124,16 +124,16 @@ public void onComplete() { * saves the established mode in {@link #sourceMode} if that mode doesn't * have the {@link QueueDisposable#BOUNDARY} flag set. *

- * If the upstream doesn't support fusion ({@link #qs} is null), the method + * If the upstream doesn't support fusion ({@link #qd} is null), the method * returns {@link QueueDisposable#NONE}. * @param mode the fusion mode requested * @return the established fusion mode */ protected final int transitiveBoundaryFusion(int mode) { - QueueDisposable qs = this.qs; - if (qs != null) { + QueueDisposable qd = this.qd; + if (qd != null) { if ((mode & BOUNDARY) == 0) { - int m = qs.requestFusion(mode); + int m = qd.requestFusion(mode); if (m != NONE) { sourceMode = m; } @@ -149,22 +149,22 @@ protected final int transitiveBoundaryFusion(int mode) { @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override public boolean isEmpty() { - return qs.isEmpty(); + return qd.isEmpty(); } @Override public void clear() { - qs.clear(); + qd.clear(); } // ----------------------------------------------------------- diff --git a/src/main/java/io/reactivex/internal/observers/BlockingBaseObserver.java b/src/main/java/io/reactivex/internal/observers/BlockingBaseObserver.java index 4efb537e08..63078f8e68 100644 --- a/src/main/java/io/reactivex/internal/observers/BlockingBaseObserver.java +++ b/src/main/java/io/reactivex/internal/observers/BlockingBaseObserver.java @@ -24,7 +24,7 @@ public abstract class BlockingBaseObserver extends CountDownLatch T value; Throwable error; - Disposable d; + Disposable upstream; volatile boolean cancelled; @@ -34,7 +34,7 @@ public BlockingBaseObserver() { @Override public final void onSubscribe(Disposable d) { - this.d = d; + this.upstream = d; if (cancelled) { d.dispose(); } @@ -48,7 +48,7 @@ public final void onComplete() { @Override public final void dispose() { cancelled = true; - Disposable d = this.d; + Disposable d = this.upstream; if (d != null) { d.dispose(); } diff --git a/src/main/java/io/reactivex/internal/observers/BlockingFirstObserver.java b/src/main/java/io/reactivex/internal/observers/BlockingFirstObserver.java index 2927679aff..212edb6bdb 100644 --- a/src/main/java/io/reactivex/internal/observers/BlockingFirstObserver.java +++ b/src/main/java/io/reactivex/internal/observers/BlockingFirstObserver.java @@ -24,7 +24,7 @@ public final class BlockingFirstObserver extends BlockingBaseObserver { public void onNext(T t) { if (value == null) { value = t; - d.dispose(); + upstream.dispose(); countDown(); } } diff --git a/src/main/java/io/reactivex/internal/observers/BlockingMultiObserver.java b/src/main/java/io/reactivex/internal/observers/BlockingMultiObserver.java index 934123e381..d96f3efa21 100644 --- a/src/main/java/io/reactivex/internal/observers/BlockingMultiObserver.java +++ b/src/main/java/io/reactivex/internal/observers/BlockingMultiObserver.java @@ -30,7 +30,7 @@ public final class BlockingMultiObserver T value; Throwable error; - Disposable d; + Disposable upstream; volatile boolean cancelled; @@ -40,7 +40,7 @@ public BlockingMultiObserver() { void dispose() { cancelled = true; - Disposable d = this.d; + Disposable d = this.upstream; if (d != null) { d.dispose(); } @@ -48,7 +48,7 @@ void dispose() { @Override public void onSubscribe(Disposable d) { - this.d = d; + this.upstream = d; if (cancelled) { d.dispose(); } diff --git a/src/main/java/io/reactivex/internal/observers/BlockingObserver.java b/src/main/java/io/reactivex/internal/observers/BlockingObserver.java index 3604ad0351..4731dc380d 100644 --- a/src/main/java/io/reactivex/internal/observers/BlockingObserver.java +++ b/src/main/java/io/reactivex/internal/observers/BlockingObserver.java @@ -34,8 +34,8 @@ public BlockingObserver(Queue queue) { } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override diff --git a/src/main/java/io/reactivex/internal/observers/DeferredScalarDisposable.java b/src/main/java/io/reactivex/internal/observers/DeferredScalarDisposable.java index a517ed04b2..a975f0aecc 100644 --- a/src/main/java/io/reactivex/internal/observers/DeferredScalarDisposable.java +++ b/src/main/java/io/reactivex/internal/observers/DeferredScalarDisposable.java @@ -27,7 +27,7 @@ public class DeferredScalarDisposable extends BasicIntQueueDisposable { private static final long serialVersionUID = -5502432239815349361L; /** The target of the events. */ - protected final Observer actual; + protected final Observer downstream; /** The value stored temporarily when in fusion mode. */ protected T value; @@ -47,10 +47,10 @@ public class DeferredScalarDisposable extends BasicIntQueueDisposable { /** * Constructs a DeferredScalarDisposable by wrapping the Observer. - * @param actual the Observer to wrap, not null (not verified) + * @param downstream the Observer to wrap, not null (not verified) */ - public DeferredScalarDisposable(Observer actual) { - this.actual = actual; + public DeferredScalarDisposable(Observer downstream) { + this.downstream = downstream; } @Override @@ -72,7 +72,7 @@ public final void complete(T value) { if ((state & (FUSED_READY | FUSED_CONSUMED | TERMINATED | DISPOSED)) != 0) { return; } - Observer a = actual; + Observer a = downstream; if (state == FUSED_EMPTY) { this.value = value; lazySet(FUSED_READY); @@ -97,7 +97,7 @@ public final void error(Throwable t) { return; } lazySet(TERMINATED); - actual.onError(t); + downstream.onError(t); } /** @@ -109,7 +109,7 @@ public final void complete() { return; } lazySet(TERMINATED); - actual.onComplete(); + downstream.onComplete(); } @Nullable diff --git a/src/main/java/io/reactivex/internal/observers/DeferredScalarObserver.java b/src/main/java/io/reactivex/internal/observers/DeferredScalarObserver.java index 4e5319abf4..91236b37c2 100644 --- a/src/main/java/io/reactivex/internal/observers/DeferredScalarObserver.java +++ b/src/main/java/io/reactivex/internal/observers/DeferredScalarObserver.java @@ -29,22 +29,22 @@ public abstract class DeferredScalarObserver private static final long serialVersionUID = -266195175408988651L; /** The upstream disposable. */ - protected Disposable s; + protected Disposable upstream; /** * Creates a DeferredScalarObserver instance and wraps a downstream Observer. - * @param actual the downstream subscriber, not null (not verified) + * @param downstream the downstream subscriber, not null (not verified) */ - public DeferredScalarObserver(Observer actual) { - super(actual); + public DeferredScalarObserver(Observer downstream) { + super(downstream); } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -68,6 +68,6 @@ public void onComplete() { @Override public void dispose() { super.dispose(); - s.dispose(); + upstream.dispose(); } } diff --git a/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java b/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java index 3ba9ebfa68..47d9990d4f 100644 --- a/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java +++ b/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java @@ -21,47 +21,47 @@ import io.reactivex.plugins.RxJavaPlugins; public final class DisposableLambdaObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Consumer onSubscribe; final Action onDispose; - Disposable s; + Disposable upstream; public DisposableLambdaObserver(Observer actual, Consumer onSubscribe, Action onDispose) { - this.actual = actual; + this.downstream = actual; this.onSubscribe = onSubscribe; this.onDispose = onDispose; } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { // this way, multiple calls to onSubscribe can show up in tests that use doOnSubscribe to validate behavior try { - onSubscribe.accept(s); + onSubscribe.accept(d); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); - this.s = DisposableHelper.DISPOSED; - EmptyDisposable.error(e, actual); + d.dispose(); + this.upstream = DisposableHelper.DISPOSED; + EmptyDisposable.error(e, downstream); return; } - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - if (s != DisposableHelper.DISPOSED) { - actual.onError(t); + if (upstream != DisposableHelper.DISPOSED) { + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -69,8 +69,8 @@ public void onError(Throwable t) { @Override public void onComplete() { - if (s != DisposableHelper.DISPOSED) { - actual.onComplete(); + if (upstream != DisposableHelper.DISPOSED) { + downstream.onComplete(); } } @@ -83,11 +83,11 @@ public void dispose() { Exceptions.throwIfFatal(e); RxJavaPlugins.onError(e); } - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } } diff --git a/src/main/java/io/reactivex/internal/observers/ForEachWhileObserver.java b/src/main/java/io/reactivex/internal/observers/ForEachWhileObserver.java index aaac865500..54b8fdbd5c 100644 --- a/src/main/java/io/reactivex/internal/observers/ForEachWhileObserver.java +++ b/src/main/java/io/reactivex/internal/observers/ForEachWhileObserver.java @@ -45,8 +45,8 @@ public ForEachWhileObserver(Predicate onNext, } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override diff --git a/src/main/java/io/reactivex/internal/observers/FutureObserver.java b/src/main/java/io/reactivex/internal/observers/FutureObserver.java index 48f6ef0971..b3de7f40b8 100644 --- a/src/main/java/io/reactivex/internal/observers/FutureObserver.java +++ b/src/main/java/io/reactivex/internal/observers/FutureObserver.java @@ -35,22 +35,22 @@ public final class FutureObserver extends CountDownLatch T value; Throwable error; - final AtomicReference s; + final AtomicReference upstream; public FutureObserver() { super(1); - this.s = new AtomicReference(); + this.upstream = new AtomicReference(); } @Override public boolean cancel(boolean mayInterruptIfRunning) { for (;;) { - Disposable a = s.get(); + Disposable a = upstream.get(); if (a == this || a == DisposableHelper.DISPOSED) { return false; } - if (s.compareAndSet(a, DisposableHelper.DISPOSED)) { + if (upstream.compareAndSet(a, DisposableHelper.DISPOSED)) { if (a != null) { a.dispose(); } @@ -62,7 +62,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { @Override public boolean isCancelled() { - return DisposableHelper.isDisposed(s.get()); + return DisposableHelper.isDisposed(upstream.get()); } @Override @@ -108,14 +108,14 @@ public T get(long timeout, TimeUnit unit) throws InterruptedException, Execution } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this.s, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this.upstream, d); } @Override public void onNext(T t) { if (value != null) { - s.get().dispose(); + upstream.get().dispose(); onError(new IndexOutOfBoundsException("More than one element received")); return; } @@ -128,12 +128,12 @@ public void onError(Throwable t) { error = t; for (;;) { - Disposable a = s.get(); + Disposable a = upstream.get(); if (a == this || a == DisposableHelper.DISPOSED) { RxJavaPlugins.onError(t); return; } - if (s.compareAndSet(a, this)) { + if (upstream.compareAndSet(a, this)) { countDown(); return; } @@ -150,11 +150,11 @@ public void onComplete() { return; } for (;;) { - Disposable a = s.get(); + Disposable a = upstream.get(); if (a == this || a == DisposableHelper.DISPOSED) { return; } - if (s.compareAndSet(a, this)) { + if (upstream.compareAndSet(a, this)) { countDown(); return; } diff --git a/src/main/java/io/reactivex/internal/observers/FutureSingleObserver.java b/src/main/java/io/reactivex/internal/observers/FutureSingleObserver.java index 33b5b8099a..fb3b096855 100644 --- a/src/main/java/io/reactivex/internal/observers/FutureSingleObserver.java +++ b/src/main/java/io/reactivex/internal/observers/FutureSingleObserver.java @@ -34,22 +34,22 @@ public final class FutureSingleObserver extends CountDownLatch T value; Throwable error; - final AtomicReference s; + final AtomicReference upstream; public FutureSingleObserver() { super(1); - this.s = new AtomicReference(); + this.upstream = new AtomicReference(); } @Override public boolean cancel(boolean mayInterruptIfRunning) { for (;;) { - Disposable a = s.get(); + Disposable a = upstream.get(); if (a == this || a == DisposableHelper.DISPOSED) { return false; } - if (s.compareAndSet(a, DisposableHelper.DISPOSED)) { + if (upstream.compareAndSet(a, DisposableHelper.DISPOSED)) { if (a != null) { a.dispose(); } @@ -61,7 +61,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { @Override public boolean isCancelled() { - return DisposableHelper.isDisposed(s.get()); + return DisposableHelper.isDisposed(upstream.get()); } @Override @@ -107,31 +107,31 @@ public T get(long timeout, TimeUnit unit) throws InterruptedException, Execution } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this.s, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this.upstream, d); } @Override public void onSuccess(T t) { - Disposable a = s.get(); + Disposable a = upstream.get(); if (a == DisposableHelper.DISPOSED) { return; } value = t; - s.compareAndSet(a, this); + upstream.compareAndSet(a, this); countDown(); } @Override public void onError(Throwable t) { for (;;) { - Disposable a = s.get(); + Disposable a = upstream.get(); if (a == DisposableHelper.DISPOSED) { RxJavaPlugins.onError(t); return; } error = t; - if (s.compareAndSet(a, this)) { + if (upstream.compareAndSet(a, this)) { countDown(); return; } diff --git a/src/main/java/io/reactivex/internal/observers/InnerQueuedObserver.java b/src/main/java/io/reactivex/internal/observers/InnerQueuedObserver.java index 3588db20ef..27d800e183 100644 --- a/src/main/java/io/reactivex/internal/observers/InnerQueuedObserver.java +++ b/src/main/java/io/reactivex/internal/observers/InnerQueuedObserver.java @@ -50,23 +50,23 @@ public InnerQueuedObserver(InnerQueuedObserverSupport parent, int prefetch) { } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.setOnce(this, s)) { - if (s instanceof QueueDisposable) { + public void onSubscribe(Disposable d) { + if (DisposableHelper.setOnce(this, d)) { + if (d instanceof QueueDisposable) { @SuppressWarnings("unchecked") - QueueDisposable qs = (QueueDisposable) s; + QueueDisposable qd = (QueueDisposable) d; - int m = qs.requestFusion(QueueDisposable.ANY); + int m = qd.requestFusion(QueueDisposable.ANY); if (m == QueueSubscription.SYNC) { fusionMode = m; - queue = qs; + queue = qd; done = true; parent.innerComplete(this); return; } if (m == QueueDisposable.ASYNC) { fusionMode = m; - queue = qs; + queue = qd; return; } } diff --git a/src/main/java/io/reactivex/internal/observers/LambdaObserver.java b/src/main/java/io/reactivex/internal/observers/LambdaObserver.java index da3a2b85db..7549910637 100644 --- a/src/main/java/io/reactivex/internal/observers/LambdaObserver.java +++ b/src/main/java/io/reactivex/internal/observers/LambdaObserver.java @@ -44,13 +44,13 @@ public LambdaObserver(Consumer onNext, Consumer on } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.setOnce(this, s)) { + public void onSubscribe(Disposable d) { + if (DisposableHelper.setOnce(this, d)) { try { onSubscribe.accept(this); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.dispose(); + d.dispose(); onError(ex); } } diff --git a/src/main/java/io/reactivex/internal/observers/QueueDrainObserver.java b/src/main/java/io/reactivex/internal/observers/QueueDrainObserver.java index 366639340a..ab24a709f0 100644 --- a/src/main/java/io/reactivex/internal/observers/QueueDrainObserver.java +++ b/src/main/java/io/reactivex/internal/observers/QueueDrainObserver.java @@ -29,7 +29,7 @@ * @param the value type the child subscriber accepts */ public abstract class QueueDrainObserver extends QueueDrainSubscriberPad2 implements Observer, ObservableQueueDrain { - protected final Observer actual; + protected final Observer downstream; protected final SimplePlainQueue queue; protected volatile boolean cancelled; @@ -38,7 +38,7 @@ public abstract class QueueDrainObserver extends QueueDrainSubscriberPa protected Throwable error; public QueueDrainObserver(Observer actual, SimplePlainQueue queue) { - this.actual = actual; + this.downstream = actual; this.queue = queue; } @@ -62,7 +62,7 @@ public final boolean fastEnter() { } protected final void fastPathEmit(U value, boolean delayError, Disposable dispose) { - final Observer observer = actual; + final Observer observer = downstream; final SimplePlainQueue q = queue; if (wip.get() == 0 && wip.compareAndSet(0, 1)) { @@ -86,7 +86,7 @@ protected final void fastPathEmit(U value, boolean delayError, Disposable dispos * @param disposable the resource to dispose if the drain terminates */ protected final void fastPathOrderedEmit(U value, boolean delayError, Disposable disposable) { - final Observer observer = actual; + final Observer observer = downstream; final SimplePlainQueue q = queue; if (wip.get() == 0 && wip.compareAndSet(0, 1)) { diff --git a/src/main/java/io/reactivex/internal/observers/ResumeSingleObserver.java b/src/main/java/io/reactivex/internal/observers/ResumeSingleObserver.java index 980b4335d9..1dc1c5fa29 100644 --- a/src/main/java/io/reactivex/internal/observers/ResumeSingleObserver.java +++ b/src/main/java/io/reactivex/internal/observers/ResumeSingleObserver.java @@ -29,11 +29,11 @@ public final class ResumeSingleObserver implements SingleObserver { final AtomicReference parent; - final SingleObserver actual; + final SingleObserver downstream; - public ResumeSingleObserver(AtomicReference parent, SingleObserver actual) { + public ResumeSingleObserver(AtomicReference parent, SingleObserver downstream) { this.parent = parent; - this.actual = actual; + this.downstream = downstream; } @Override @@ -43,11 +43,11 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/observers/SubscriberCompletableObserver.java b/src/main/java/io/reactivex/internal/observers/SubscriberCompletableObserver.java index 425b7c5463..8a5255d937 100644 --- a/src/main/java/io/reactivex/internal/observers/SubscriberCompletableObserver.java +++ b/src/main/java/io/reactivex/internal/observers/SubscriberCompletableObserver.java @@ -22,7 +22,7 @@ public final class SubscriberCompletableObserver implements CompletableObserver, Subscription { final Subscriber subscriber; - Disposable d; + Disposable upstream; public SubscriberCompletableObserver(Subscriber subscriber) { this.subscriber = subscriber; @@ -40,8 +40,8 @@ public void onError(Throwable e) { @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; subscriber.onSubscribe(this); } @@ -54,6 +54,6 @@ public void request(long n) { @Override public void cancel() { - d.dispose(); + upstream.dispose(); } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableCache.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableCache.java index 9a333d3dde..ef1cc3c65f 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableCache.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableCache.java @@ -76,7 +76,7 @@ public void onError(Throwable e) { error = e; for (InnerCompletableCache inner : observers.getAndSet(TERMINATED)) { if (!inner.get()) { - inner.actual.onError(e); + inner.downstream.onError(e); } } } @@ -85,7 +85,7 @@ public void onError(Throwable e) { public void onComplete() { for (InnerCompletableCache inner : observers.getAndSet(TERMINATED)) { if (!inner.get()) { - inner.actual.onComplete(); + inner.downstream.onComplete(); } } } @@ -149,10 +149,10 @@ final class InnerCompletableCache private static final long serialVersionUID = 8943152917179642732L; - final CompletableObserver actual; + final CompletableObserver downstream; - InnerCompletableCache(CompletableObserver actual) { - this.actual = actual; + InnerCompletableCache(CompletableObserver downstream) { + this.downstream = downstream; } @Override diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcat.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcat.java index 055ae5086e..cf52bf9755 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcat.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcat.java @@ -45,7 +45,7 @@ static final class CompletableConcatSubscriber implements FlowableSubscriber, Disposable { private static final long serialVersionUID = 9032184911934499404L; - final CompletableObserver actual; + final CompletableObserver downstream; final int prefetch; @@ -61,14 +61,14 @@ static final class CompletableConcatSubscriber SimpleQueue queue; - Subscription s; + Subscription upstream; volatile boolean done; volatile boolean active; CompletableConcatSubscriber(CompletableObserver actual, int prefetch) { - this.actual = actual; + this.downstream = actual; this.prefetch = prefetch; this.inner = new ConcatInnerObserver(this); this.once = new AtomicBoolean(); @@ -77,8 +77,8 @@ static final class CompletableConcatSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; long r = prefetch == Integer.MAX_VALUE ? Long.MAX_VALUE : prefetch; @@ -92,14 +92,14 @@ public void onSubscribe(Subscription s) { sourceFused = m; queue = qs; done = true; - actual.onSubscribe(this); + downstream.onSubscribe(this); drain(); return; } if (m == QueueSubscription.ASYNC) { sourceFused = m; queue = qs; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(r); return; } @@ -111,7 +111,7 @@ public void onSubscribe(Subscription s) { queue = new SpscArrayQueue(prefetch); } - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(r); } @@ -132,7 +132,7 @@ public void onNext(CompletableSource t) { public void onError(Throwable t) { if (once.compareAndSet(false, true)) { DisposableHelper.dispose(inner); - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -146,7 +146,7 @@ public void onComplete() { @Override public void dispose() { - s.cancel(); + upstream.cancel(); DisposableHelper.dispose(inner); } @@ -183,7 +183,7 @@ void drain() { if (d && empty) { if (once.compareAndSet(false, true)) { - actual.onComplete(); + downstream.onComplete(); } return; } @@ -206,7 +206,7 @@ void request() { int p = consumed + 1; if (p == limit) { consumed = 0; - s.request(p); + upstream.request(p); } else { consumed = p; } @@ -215,8 +215,8 @@ void request() { void innerError(Throwable e) { if (once.compareAndSet(false, true)) { - s.cancel(); - actual.onError(e); + upstream.cancel(); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatArray.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatArray.java index f87f2a72ea..6bcf9d5516 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatArray.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatArray.java @@ -37,7 +37,7 @@ static final class ConcatInnerObserver extends AtomicInteger implements Completa private static final long serialVersionUID = -7965400327305809232L; - final CompletableObserver actual; + final CompletableObserver downstream; final CompletableSource[] sources; int index; @@ -45,7 +45,7 @@ static final class ConcatInnerObserver extends AtomicInteger implements Completa final SequentialDisposable sd; ConcatInnerObserver(CompletableObserver actual, CompletableSource[] sources) { - this.actual = actual; + this.downstream = actual; this.sources = sources; this.sd = new SequentialDisposable(); } @@ -57,7 +57,7 @@ public void onSubscribe(Disposable d) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override @@ -82,7 +82,7 @@ void next() { int idx = index++; if (idx == a.length) { - actual.onComplete(); + downstream.onComplete(); return; } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatIterable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatIterable.java index 9ca4d919d8..acc2d12fd0 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatIterable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableConcatIterable.java @@ -51,13 +51,13 @@ static final class ConcatInnerObserver extends AtomicInteger implements Completa private static final long serialVersionUID = -7965400327305809232L; - final CompletableObserver actual; + final CompletableObserver downstream; final Iterator sources; final SequentialDisposable sd; ConcatInnerObserver(CompletableObserver actual, Iterator sources) { - this.actual = actual; + this.downstream = actual; this.sources = sources; this.sd = new SequentialDisposable(); } @@ -69,7 +69,7 @@ public void onSubscribe(Disposable d) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override @@ -97,12 +97,12 @@ void next() { b = a.hasNext(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } if (!b) { - actual.onComplete(); + downstream.onComplete(); return; } @@ -112,7 +112,7 @@ void next() { c = ObjectHelper.requireNonNull(a.next(), "The CompletableSource returned is null"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableCreate.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableCreate.java index c831d899ae..1e2bc74f79 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableCreate.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableCreate.java @@ -49,10 +49,10 @@ static final class Emitter private static final long serialVersionUID = -2467358622224974244L; - final CompletableObserver actual; + final CompletableObserver downstream; - Emitter(CompletableObserver actual) { - this.actual = actual; + Emitter(CompletableObserver downstream) { + this.downstream = downstream; } @Override @@ -61,7 +61,7 @@ public void onComplete() { Disposable d = getAndSet(DisposableHelper.DISPOSED); if (d != DisposableHelper.DISPOSED) { try { - actual.onComplete(); + downstream.onComplete(); } finally { if (d != null) { d.dispose(); @@ -87,7 +87,7 @@ public boolean tryOnError(Throwable t) { Disposable d = getAndSet(DisposableHelper.DISPOSED); if (d != DisposableHelper.DISPOSED) { try { - actual.onError(t); + downstream.onError(t); } finally { if (d != null) { d.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDetach.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDetach.java index 14e74c0485..f19a0a045d 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDetach.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDetach.java @@ -37,51 +37,51 @@ protected void subscribeActual(CompletableObserver observer) { static final class DetachCompletableObserver implements CompletableObserver, Disposable { - CompletableObserver actual; + CompletableObserver downstream; - Disposable d; + Disposable upstream; - DetachCompletableObserver(CompletableObserver actual) { - this.actual = actual; + DetachCompletableObserver(CompletableObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - actual = null; - d.dispose(); - d = DisposableHelper.DISPOSED; + downstream = null; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - CompletableObserver a = actual; + upstream = DisposableHelper.DISPOSED; + CompletableObserver a = downstream; if (a != null) { - actual = null; + downstream = null; a.onError(e); } } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; - CompletableObserver a = actual; + upstream = DisposableHelper.DISPOSED; + CompletableObserver a = downstream; if (a != null) { - actual = null; + downstream = null; a.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDisposeOn.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDisposeOn.java index df2cfa5e25..904894df7c 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDisposeOn.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDisposeOn.java @@ -31,19 +31,19 @@ public CompletableDisposeOn(CompletableSource source, Scheduler scheduler) { @Override protected void subscribeActual(final CompletableObserver observer) { - source.subscribe(new CompletableObserverImplementation(observer, scheduler)); + source.subscribe(new DisposeOnObserver(observer, scheduler)); } - static final class CompletableObserverImplementation implements CompletableObserver, Disposable, Runnable { + static final class DisposeOnObserver implements CompletableObserver, Disposable, Runnable { final CompletableObserver downstream; final Scheduler scheduler; - Disposable d; + Disposable upstream; volatile boolean disposed; - CompletableObserverImplementation(CompletableObserver observer, Scheduler scheduler) { + DisposeOnObserver(CompletableObserver observer, Scheduler scheduler) { this.downstream = observer; this.scheduler = scheduler; } @@ -67,8 +67,8 @@ public void onError(Throwable e) { @Override public void onSubscribe(final Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; downstream.onSubscribe(this); } @@ -87,8 +87,8 @@ public boolean isDisposed() { @Override public void run() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java index d74169d91c..67e4ad5da1 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableDoFinally.java @@ -47,47 +47,47 @@ static final class DoFinallyObserver extends AtomicInteger implements Completabl private static final long serialVersionUID = 4109457741734051389L; - final CompletableObserver actual; + final CompletableObserver downstream; final Action onFinally; - Disposable d; + Disposable upstream; DoFinallyObserver(CompletableObserver actual, Action onFinally) { - this.actual = actual; + this.downstream = actual; this.onFinally = onFinally; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); runFinally(); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); runFinally(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); runFinally(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } void runFinally() { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromPublisher.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromPublisher.java index 4d0be70d35..3791931e92 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromPublisher.java @@ -28,26 +28,26 @@ public CompletableFromPublisher(Publisher flowable) { } @Override - protected void subscribeActual(final CompletableObserver cs) { - flowable.subscribe(new FromPublisherSubscriber(cs)); + protected void subscribeActual(final CompletableObserver downstream) { + flowable.subscribe(new FromPublisherSubscriber(downstream)); } static final class FromPublisherSubscriber implements FlowableSubscriber, Disposable { - final CompletableObserver cs; + final CompletableObserver downstream; - Subscription s; + Subscription upstream; - FromPublisherSubscriber(CompletableObserver actual) { - this.cs = actual; + FromPublisherSubscriber(CompletableObserver downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - cs.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -61,23 +61,23 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - cs.onError(t); + downstream.onError(t); } @Override public void onComplete() { - cs.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableHide.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableHide.java index a05e63cda7..0e1828dccb 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableHide.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableHide.java @@ -37,42 +37,42 @@ protected void subscribeActual(CompletableObserver observer) { static final class HideCompletableObserver implements CompletableObserver, Disposable { - final CompletableObserver actual; + final CompletableObserver downstream; - Disposable d; + Disposable upstream; - HideCompletableObserver(CompletableObserver actual) { - this.actual = actual; + HideCompletableObserver(CompletableObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMerge.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMerge.java index 890e036d74..a1dff5b342 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableMerge.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMerge.java @@ -47,7 +47,7 @@ static final class CompletableMergeSubscriber private static final long serialVersionUID = -2108443387387077490L; - final CompletableObserver actual; + final CompletableObserver downstream; final int maxConcurrency; final boolean delayErrors; @@ -55,10 +55,10 @@ static final class CompletableMergeSubscriber final CompositeDisposable set; - Subscription s; + Subscription upstream; CompletableMergeSubscriber(CompletableObserver actual, int maxConcurrency, boolean delayErrors) { - this.actual = actual; + this.downstream = actual; this.maxConcurrency = maxConcurrency; this.delayErrors = delayErrors; this.set = new CompositeDisposable(); @@ -68,7 +68,7 @@ static final class CompletableMergeSubscriber @Override public void dispose() { - s.cancel(); + upstream.cancel(); set.dispose(); } @@ -79,9 +79,9 @@ public boolean isDisposed() { @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); if (maxConcurrency == Integer.MAX_VALUE) { s.request(Long.MAX_VALUE); } else { @@ -106,7 +106,7 @@ public void onError(Throwable t) { if (error.addThrowable(t)) { if (getAndSet(0) > 0) { - actual.onError(error.terminate()); + downstream.onError(error.terminate()); } } else { RxJavaPlugins.onError(t); @@ -114,7 +114,7 @@ public void onError(Throwable t) { } else { if (error.addThrowable(t)) { if (decrementAndGet() == 0) { - actual.onError(error.terminate()); + downstream.onError(error.terminate()); } } else { RxJavaPlugins.onError(t); @@ -127,9 +127,9 @@ public void onComplete() { if (decrementAndGet() == 0) { Throwable ex = error.get(); if (ex != null) { - actual.onError(error.terminate()); + downstream.onError(error.terminate()); } else { - actual.onComplete(); + downstream.onComplete(); } } } @@ -137,12 +137,12 @@ public void onComplete() { void innerError(MergeInnerObserver inner, Throwable t) { set.delete(inner); if (!delayErrors) { - s.cancel(); + upstream.cancel(); set.dispose(); if (error.addThrowable(t)) { if (getAndSet(0) > 0) { - actual.onError(error.terminate()); + downstream.onError(error.terminate()); } } else { RxJavaPlugins.onError(t); @@ -150,10 +150,10 @@ void innerError(MergeInnerObserver inner, Throwable t) { } else { if (error.addThrowable(t)) { if (decrementAndGet() == 0) { - actual.onError(error.terminate()); + downstream.onError(error.terminate()); } else { if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } } else { @@ -167,13 +167,13 @@ void innerComplete(MergeInnerObserver inner) { if (decrementAndGet() == 0) { Throwable ex = error.get(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } } else { if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeArray.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeArray.java index 64a5b6e8a4..e6a42b105b 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeArray.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeArray.java @@ -55,14 +55,14 @@ public void subscribeActual(final CompletableObserver observer) { static final class InnerCompletableObserver extends AtomicInteger implements CompletableObserver { private static final long serialVersionUID = -8360547806504310570L; - final CompletableObserver actual; + final CompletableObserver downstream; final AtomicBoolean once; final CompositeDisposable set; InnerCompletableObserver(CompletableObserver actual, AtomicBoolean once, CompositeDisposable set, int n) { - this.actual = actual; + this.downstream = actual; this.once = once; this.set = set; this.lazySet(n); @@ -77,7 +77,7 @@ public void onSubscribe(Disposable d) { public void onError(Throwable e) { set.dispose(); if (once.compareAndSet(false, true)) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -87,7 +87,7 @@ public void onError(Throwable e) { public void onComplete() { if (decrementAndGet() == 0) { if (once.compareAndSet(false, true)) { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorArray.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorArray.java index 733fa88b40..c2508a46dd 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorArray.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeDelayErrorArray.java @@ -64,14 +64,14 @@ public void subscribeActual(final CompletableObserver observer) { static final class MergeInnerCompletableObserver implements CompletableObserver { - final CompletableObserver actual; + final CompletableObserver downstream; final CompositeDisposable set; final AtomicThrowable error; final AtomicInteger wip; MergeInnerCompletableObserver(CompletableObserver observer, CompositeDisposable set, AtomicThrowable error, AtomicInteger wip) { - this.actual = observer; + this.downstream = observer; this.set = set; this.error = error; this.wip = wip; @@ -100,9 +100,9 @@ void tryTerminate() { if (wip.decrementAndGet() == 0) { Throwable ex = error.terminate(); if (ex == null) { - actual.onComplete(); + downstream.onComplete(); } else { - actual.onError(ex); + downstream.onError(ex); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeIterable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeIterable.java index 6c22819e19..0130250225 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeIterable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMergeIterable.java @@ -100,12 +100,12 @@ static final class MergeCompletableObserver extends AtomicBoolean implements Com final CompositeDisposable set; - final CompletableObserver actual; + final CompletableObserver downstream; final AtomicInteger wip; MergeCompletableObserver(CompletableObserver actual, CompositeDisposable set, AtomicInteger wip) { - this.actual = actual; + this.downstream = actual; this.set = set; this.wip = wip; } @@ -119,7 +119,7 @@ public void onSubscribe(Disposable d) { public void onError(Throwable e) { set.dispose(); if (compareAndSet(false, true)) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -129,7 +129,7 @@ public void onError(Throwable e) { public void onComplete() { if (wip.decrementAndGet() == 0) { if (compareAndSet(false, true)) { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java index 73c86873da..11dbebe280 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java @@ -41,14 +41,14 @@ static final class ObserveOnCompletableObserver private static final long serialVersionUID = 8571289934935992137L; - final CompletableObserver actual; + final CompletableObserver downstream; final Scheduler scheduler; Throwable error; ObserveOnCompletableObserver(CompletableObserver actual, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.scheduler = scheduler; } @@ -65,7 +65,7 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -85,9 +85,9 @@ public void run() { Throwable ex = error; if (ex != null) { error = null; - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java b/src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java index 6584131483..327cee0116 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java @@ -53,12 +53,12 @@ protected void subscribeActual(final CompletableObserver observer) { final class CompletableObserverImplementation implements CompletableObserver, Disposable { - final CompletableObserver actual; + final CompletableObserver downstream; - Disposable d; + Disposable upstream; - CompletableObserverImplementation(CompletableObserver actual) { - this.actual = actual; + CompletableObserverImplementation(CompletableObserver downstream) { + this.downstream = downstream; } @@ -69,19 +69,19 @@ public void onSubscribe(final Disposable d) { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); d.dispose(); - this.d = DisposableHelper.DISPOSED; - EmptyDisposable.error(ex, actual); + this.upstream = DisposableHelper.DISPOSED; + EmptyDisposable.error(ex, downstream); return; } - if (DisposableHelper.validate(this.d, d)) { - this.d = d; - actual.onSubscribe(this); + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void onError(Throwable e) { - if (d == DisposableHelper.DISPOSED) { + if (upstream == DisposableHelper.DISPOSED) { RxJavaPlugins.onError(e); return; } @@ -93,14 +93,14 @@ public void onError(Throwable e) { e = new CompositeException(e, ex); } - actual.onError(e); + downstream.onError(e); doAfter(); } @Override public void onComplete() { - if (d == DisposableHelper.DISPOSED) { + if (upstream == DisposableHelper.DISPOSED) { return; } @@ -109,11 +109,11 @@ public void onComplete() { onTerminate.run(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } - actual.onComplete(); + downstream.onComplete(); doAfter(); } @@ -135,12 +135,12 @@ public void dispose() { Exceptions.throwIfFatal(e); RxJavaPlugins.onError(e); } - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableSubscribeOn.java index d386009f22..3b2b394694 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableSubscribeOn.java @@ -47,14 +47,14 @@ static final class SubscribeOnObserver private static final long serialVersionUID = 7000911171163930287L; - final CompletableObserver actual; + final CompletableObserver downstream; final SequentialDisposable task; final CompletableSource source; SubscribeOnObserver(CompletableObserver actual, CompletableSource source) { - this.actual = actual; + this.downstream = actual; this.source = source; this.task = new SequentialDisposable(); } @@ -71,12 +71,12 @@ public void onSubscribe(Disposable d) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableTimer.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableTimer.java index 5b85346629..4f1eae40c4 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableTimer.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableTimer.java @@ -45,15 +45,15 @@ protected void subscribeActual(final CompletableObserver observer) { static final class TimerDisposable extends AtomicReference implements Disposable, Runnable { private static final long serialVersionUID = 3167244060586201109L; - final CompletableObserver actual; + final CompletableObserver downstream; - TimerDisposable(final CompletableObserver actual) { - this.actual = actual; + TimerDisposable(final CompletableObserver downstream) { + this.downstream = downstream; } @Override public void run() { - actual.onComplete(); + downstream.onComplete(); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java index 88f8a57516..a114199a91 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java @@ -92,25 +92,25 @@ static final class UsingObserver private static final long serialVersionUID = -674404550052917487L; - final CompletableObserver actual; + final CompletableObserver downstream; final Consumer disposer; final boolean eager; - Disposable d; + Disposable upstream; UsingObserver(CompletableObserver actual, R resource, Consumer disposer, boolean eager) { super(resource); - this.actual = actual; + this.downstream = actual; this.disposer = disposer; this.eager = eager; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; disposeResourceAfter(); } @@ -129,22 +129,22 @@ void disposeResourceAfter() { @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @SuppressWarnings("unchecked") @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; if (eager) { Object resource = getAndSet(this); if (resource != this) { @@ -159,7 +159,7 @@ public void onError(Throwable e) { } } - actual.onError(e); + downstream.onError(e); if (!eager) { disposeResourceAfter(); @@ -169,7 +169,7 @@ public void onError(Throwable e) { @SuppressWarnings("unchecked") @Override public void onComplete() { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; if (eager) { Object resource = getAndSet(this); if (resource != this) { @@ -177,7 +177,7 @@ public void onComplete() { disposer.accept((R)resource); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } } else { @@ -185,7 +185,7 @@ public void onComplete() { } } - actual.onComplete(); + downstream.onComplete(); if (!eager) { disposeResourceAfter(); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAll.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAll.java index 6d7faa61dd..b3f6076f43 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAll.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAll.java @@ -39,7 +39,7 @@ static final class AllSubscriber extends DeferredScalarSubscription private static final long serialVersionUID = -3521127104134758517L; final Predicate predicate; - Subscription s; + Subscription upstream; boolean done; @@ -49,9 +49,9 @@ static final class AllSubscriber extends DeferredScalarSubscription } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -66,13 +66,13 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); onError(e); return; } if (!b) { done = true; - s.cancel(); + upstream.cancel(); complete(false); } } @@ -84,7 +84,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -100,7 +100,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java index c3bbc19481..b26087b840 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java @@ -45,23 +45,23 @@ public Flowable fuseToFlowable() { static final class AllSubscriber implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final Predicate predicate; - Subscription s; + Subscription upstream; boolean done; AllSubscriber(SingleObserver actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -76,16 +76,16 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; onError(e); return; } if (!b) { done = true; - s.cancel(); - s = SubscriptionHelper.CANCELLED; - actual.onSuccess(false); + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; + downstream.onSuccess(false); } } @@ -96,8 +96,8 @@ public void onError(Throwable t) { return; } done = true; - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override @@ -106,20 +106,20 @@ public void onComplete() { return; } done = true; - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; - actual.onSuccess(true); + downstream.onSuccess(true); } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAmb.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAmb.java index 1e14453afa..203c62f999 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAmb.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAmb.java @@ -74,14 +74,14 @@ public void subscribeActual(Subscriber s) { } static final class AmbCoordinator implements Subscription { - final Subscriber actual; + final Subscriber downstream; final AmbInnerSubscriber[] subscribers; final AtomicInteger winner = new AtomicInteger(); @SuppressWarnings("unchecked") AmbCoordinator(Subscriber actual, int count) { - this.actual = actual; + this.downstream = actual; this.subscribers = new AmbInnerSubscriber[count]; } @@ -89,10 +89,10 @@ public void subscribe(Publisher[] sources) { AmbInnerSubscriber[] as = subscribers; int len = as.length; for (int i = 0; i < len; i++) { - as[i] = new AmbInnerSubscriber(this, i + 1, actual); + as[i] = new AmbInnerSubscriber(this, i + 1, downstream); } winner.lazySet(0); // release the contents of 'as' - actual.onSubscribe(this); + downstream.onSubscribe(this); for (int i = 0; i < len; i++) { if (winner.get() != 0) { @@ -152,16 +152,16 @@ static final class AmbInnerSubscriber extends AtomicReference i private static final long serialVersionUID = -1185974347409665484L; final AmbCoordinator parent; final int index; - final Subscriber actual; + final Subscriber downstream; boolean won; final AtomicLong missedRequested = new AtomicLong(); - AmbInnerSubscriber(AmbCoordinator parent, int index, Subscriber actual) { + AmbInnerSubscriber(AmbCoordinator parent, int index, Subscriber downstream) { this.parent = parent; this.index = index; - this.actual = actual; + this.downstream = downstream; } @Override @@ -177,11 +177,11 @@ public void request(long n) { @Override public void onNext(T t) { if (won) { - actual.onNext(t); + downstream.onNext(t); } else { if (parent.win(index)) { won = true; - actual.onNext(t); + downstream.onNext(t); } else { get().cancel(); } @@ -191,11 +191,11 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (won) { - actual.onError(t); + downstream.onError(t); } else { if (parent.win(index)) { won = true; - actual.onError(t); + downstream.onError(t); } else { get().cancel(); RxJavaPlugins.onError(t); @@ -206,11 +206,11 @@ public void onError(Throwable t) { @Override public void onComplete() { if (won) { - actual.onComplete(); + downstream.onComplete(); } else { if (parent.win(index)) { won = true; - actual.onComplete(); + downstream.onComplete(); } else { get().cancel(); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAny.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAny.java index 39ed01534a..5a3d7c966f 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAny.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAny.java @@ -38,7 +38,7 @@ static final class AnySubscriber extends DeferredScalarSubscription final Predicate predicate; - Subscription s; + Subscription upstream; boolean done; @@ -48,9 +48,9 @@ static final class AnySubscriber extends DeferredScalarSubscription } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -65,13 +65,13 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); onError(e); return; } if (b) { done = true; - s.cancel(); + upstream.cancel(); complete(true); } } @@ -84,7 +84,7 @@ public void onError(Throwable t) { } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -98,7 +98,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java index 47f2ce4ef2..7c665f2ab9 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java @@ -44,23 +44,23 @@ public Flowable fuseToFlowable() { static final class AnySubscriber implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final Predicate predicate; - Subscription s; + Subscription upstream; boolean done; AnySubscriber(SingleObserver actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -75,16 +75,16 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; onError(e); return; } if (b) { done = true; - s.cancel(); - s = SubscriptionHelper.CANCELLED; - actual.onSuccess(true); + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; + downstream.onSuccess(true); } } @@ -96,28 +96,28 @@ public void onError(Throwable t) { } done = true; - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override public void onComplete() { if (!done) { done = true; - s = SubscriptionHelper.CANCELLED; - actual.onSuccess(false); + upstream = SubscriptionHelper.CANCELLED; + downstream.onSuccess(false); } } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBuffer.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBuffer.java index 87b0d7331e..bf0cda25b1 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBuffer.java @@ -55,7 +55,7 @@ public void subscribeActual(Subscriber s) { static final class PublisherBufferExactSubscriber> implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final Callable bufferSupplier; @@ -63,14 +63,14 @@ static final class PublisherBufferExactSubscriber actual, int size, Callable bufferSupplier) { - this.actual = actual; + this.downstream = actual; this.size = size; this.bufferSupplier = bufferSupplier; } @@ -78,21 +78,21 @@ static final class PublisherBufferExactSubscriber actual; + final Subscriber downstream; final Callable bufferSupplier; @@ -172,7 +172,7 @@ static final class PublisherBufferSkipSubscriber actual, int size, int skip, Callable bufferSupplier) { - this.actual = actual; + this.downstream = actual; this.size = size; this.skip = skip; this.bufferSupplier = bufferSupplier; @@ -195,25 +195,25 @@ public void request(long n) { // + (n - 1) gaps long v = BackpressureHelper.multiplyCap(skip - size, n - 1); - s.request(BackpressureHelper.addCap(u, v)); + upstream.request(BackpressureHelper.addCap(u, v)); } else { // n full buffer + gap - s.request(BackpressureHelper.multiplyCap(skip, n)); + upstream.request(BackpressureHelper.multiplyCap(skip, n)); } } } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -245,7 +245,7 @@ public void onNext(T t) { b.add(t); if (b.size() == size) { buffer = null; - actual.onNext(b); + downstream.onNext(b); } } @@ -265,7 +265,7 @@ public void onError(Throwable t) { done = true; buffer = null; - actual.onError(t); + downstream.onError(t); } @Override @@ -279,10 +279,10 @@ public void onComplete() { buffer = null; if (b != null) { - actual.onNext(b); + downstream.onNext(b); } - actual.onComplete(); + downstream.onComplete(); } } @@ -293,7 +293,7 @@ static final class PublisherBufferOverlappingSubscriber actual; + final Subscriber downstream; final Callable bufferSupplier; @@ -305,7 +305,7 @@ static final class PublisherBufferOverlappingSubscriber actual, int size, int skip, Callable bufferSupplier) { - this.actual = actual; + this.downstream = actual; this.size = size; this.skip = skip; this.bufferSupplier = bufferSupplier; @@ -333,7 +333,7 @@ public boolean getAsBoolean() { @Override public void request(long n) { if (SubscriptionHelper.validate(n)) { - if (QueueDrainHelper.postCompleteRequest(n, actual, buffers, this, this)) { + if (QueueDrainHelper.postCompleteRequest(n, downstream, buffers, this, this)) { return; } @@ -343,11 +343,11 @@ public void request(long n) { // + 1 full buffer long r = BackpressureHelper.addCap(size, u); - s.request(r); + upstream.request(r); } else { // n skips long r = BackpressureHelper.multiplyCap(skip, n); - s.request(r); + upstream.request(r); } } } @@ -355,15 +355,15 @@ public void request(long n) { @Override public void cancel() { cancelled = true; - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -401,7 +401,7 @@ public void onNext(T t) { produced++; - actual.onNext(b); + downstream.onNext(b); } for (C b0 : bs) { @@ -424,7 +424,7 @@ public void onError(Throwable t) { done = true; buffers.clear(); - actual.onError(t); + downstream.onError(t); } @Override @@ -439,7 +439,7 @@ public void onComplete() { if (p != 0L) { BackpressureHelper.produced(this, p); } - QueueDrainHelper.postComplete(actual, buffers, this, this); + QueueDrainHelper.postComplete(downstream, buffers, this, this); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundary.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundary.java index 317ad249ee..44146a5829 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundary.java @@ -58,7 +58,7 @@ static final class BufferBoundarySubscriber, private static final long serialVersionUID = -8466418554264089604L; - final Subscriber actual; + final Subscriber downstream; final Callable bufferSupplier; @@ -91,7 +91,7 @@ static final class BufferBoundarySubscriber, Function> bufferClose, Callable bufferSupplier ) { - this.actual = actual; + this.downstream = actual; this.bufferSupplier = bufferSupplier; this.bufferOpen = bufferOpen; this.bufferClose = bufferClose; @@ -250,7 +250,7 @@ void drain() { int missed = 1; long e = emitted; - Subscriber a = actual; + Subscriber a = downstream; SpscLinkedArrayQueue q = queue; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundarySupplier.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundarySupplier.java index a4cdcb8ced..8c544d958d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundarySupplier.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundarySupplier.java @@ -53,7 +53,7 @@ static final class BufferBoundarySupplierSubscriber bufferSupplier; final Callable> boundarySupplier; - Subscription s; + Subscription upstream; final AtomicReference other = new AtomicReference(); @@ -68,12 +68,12 @@ static final class BufferBoundarySupplierSubscriber actual = this.actual; + Subscriber actual = this.downstream; U b; @@ -127,7 +127,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { cancel(); - actual.onError(t); + downstream.onError(t); } @Override @@ -143,7 +143,7 @@ public void onComplete() { queue.offer(b); done = true; if (enter()) { - QueueDrainHelper.drainMaxLoop(queue, actual, false, this, this); + QueueDrainHelper.drainMaxLoop(queue, downstream, false, this, this); } } @@ -156,7 +156,7 @@ public void request(long n) { public void cancel() { if (!cancelled) { cancelled = true; - s.cancel(); + upstream.cancel(); disposeOther(); if (enter()) { @@ -178,7 +178,7 @@ void next() { } catch (Throwable e) { Exceptions.throwIfFatal(e); cancel(); - actual.onError(e); + downstream.onError(e); return; } @@ -189,8 +189,8 @@ void next() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); cancelled = true; - s.cancel(); - actual.onError(ex); + upstream.cancel(); + downstream.onError(ex); return; } @@ -214,7 +214,7 @@ void next() { @Override public void dispose() { - s.cancel(); + upstream.cancel(); disposeOther(); } @@ -225,7 +225,7 @@ public boolean isDisposed() { @Override public boolean accept(Subscriber a, U v) { - actual.onNext(v); + downstream.onNext(v); return true; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferExactBoundary.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferExactBoundary.java index 5ed7f84b08..82215ae967 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferExactBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferExactBoundary.java @@ -50,7 +50,7 @@ static final class BufferExactBoundarySubscriber bufferSupplier; final Publisher boundary; - Subscription s; + Subscription upstream; Disposable other; @@ -65,10 +65,10 @@ static final class BufferExactBoundarySubscriber bs = new BufferBoundarySubscriber(this); other = bs; - actual.onSubscribe(this); + downstream.onSubscribe(this); if (!cancelled) { s.request(Long.MAX_VALUE); @@ -110,7 +110,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { cancel(); - actual.onError(t); + downstream.onError(t); } @Override @@ -126,7 +126,7 @@ public void onComplete() { queue.offer(b); done = true; if (enter()) { - QueueDrainHelper.drainMaxLoop(queue, actual, false, this, this); + QueueDrainHelper.drainMaxLoop(queue, downstream, false, this, this); } } @@ -140,7 +140,7 @@ public void cancel() { if (!cancelled) { cancelled = true; other.dispose(); - s.cancel(); + upstream.cancel(); if (enter()) { queue.clear(); @@ -157,7 +157,7 @@ void next() { } catch (Throwable e) { Exceptions.throwIfFatal(e); cancel(); - actual.onError(e); + downstream.onError(e); return; } @@ -185,7 +185,7 @@ public boolean isDisposed() { @Override public boolean accept(Subscriber a, U v) { - actual.onNext(v); + downstream.onNext(v); return true; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java index 8c220a506a..0fb2b19e6a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java @@ -86,7 +86,7 @@ static final class BufferExactUnboundedSubscriber a, U v) { - actual.onNext(v); + downstream.onNext(v); return true; } @@ -234,7 +234,7 @@ static final class BufferSkipBoundedSubscriber buffers; - Subscription s; + Subscription upstream; BufferSkipBoundedSubscriber(Subscriber actual, @@ -251,10 +251,10 @@ static final class BufferSkipBoundedSubscriber extends DeferredScalarSubscription final U u; - Subscription s; + Subscription upstream; boolean done; @@ -67,9 +67,9 @@ static final class CollectSubscriber extends DeferredScalarSubscription @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -83,7 +83,7 @@ public void onNext(T t) { collector.accept(u, t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); onError(e); } } @@ -95,7 +95,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -110,7 +110,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCollectSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCollectSingle.java index cda031ebbc..c5d3dc188d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCollectSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCollectSingle.java @@ -59,27 +59,27 @@ public Flowable fuseToFlowable() { static final class CollectSubscriber implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final BiConsumer collector; final U u; - Subscription s; + Subscription upstream; boolean done; CollectSubscriber(SingleObserver actual, U u, BiConsumer collector) { - this.actual = actual; + this.downstream = actual; this.collector = collector; this.u = u; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -93,7 +93,7 @@ public void onNext(T t) { collector.accept(u, t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); onError(e); } } @@ -105,8 +105,8 @@ public void onError(Throwable t) { return; } done = true; - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override @@ -115,19 +115,19 @@ public void onComplete() { return; } done = true; - s = SubscriptionHelper.CANCELLED; - actual.onSuccess(u); + upstream = SubscriptionHelper.CANCELLED; + downstream.onSuccess(u); } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCombineLatest.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCombineLatest.java index 6ed1f116ef..a4bc8f6bc4 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCombineLatest.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCombineLatest.java @@ -151,7 +151,7 @@ static final class CombineLatestCoordinator private static final long serialVersionUID = -5082275438355852221L; - final Subscriber actual; + final Subscriber downstream; final Function combiner; @@ -180,7 +180,7 @@ static final class CombineLatestCoordinator CombineLatestCoordinator(Subscriber actual, Function combiner, int n, int bufferSize, boolean delayErrors) { - this.actual = actual; + this.downstream = actual; this.combiner = combiner; @SuppressWarnings("unchecked") CombineLatestInnerSubscriber[] a = new CombineLatestInnerSubscriber[n]; @@ -289,7 +289,7 @@ void innerError(int index, Throwable e) { } void drainOutput() { - final Subscriber a = actual; + final Subscriber a = downstream; final SpscLinkedArrayQueue q = queue; int missed = 1; @@ -331,7 +331,7 @@ void drainOutput() { @SuppressWarnings("unchecked") void drainAsync() { - final Subscriber a = actual; + final Subscriber a = downstream; final SpscLinkedArrayQueue q = queue; int missed = 1; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatArray.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatArray.java index c2ca5de3b3..c06cffa80a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatArray.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatArray.java @@ -44,7 +44,7 @@ static final class ConcatArraySubscriber extends SubscriptionArbiter implemen private static final long serialVersionUID = -8158322871608889516L; - final Subscriber actual; + final Subscriber downstream; final Publisher[] sources; @@ -58,8 +58,8 @@ static final class ConcatArraySubscriber extends SubscriptionArbiter implemen long produced; - ConcatArraySubscriber(Publisher[] sources, boolean delayError, Subscriber actual) { - this.actual = actual; + ConcatArraySubscriber(Publisher[] sources, boolean delayError, Subscriber downstream) { + this.downstream = downstream; this.sources = sources; this.delayError = delayError; this.wip = new AtomicInteger(); @@ -73,7 +73,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { produced++; - actual.onNext(t); + downstream.onNext(t); } @Override @@ -87,7 +87,7 @@ public void onError(Throwable t) { list.add(t); onComplete(); } else { - actual.onError(t); + downstream.onError(t); } } @@ -103,12 +103,12 @@ public void onComplete() { List list = errors; if (list != null) { if (list.size() == 1) { - actual.onError(list.get(0)); + downstream.onError(list.get(0)); } else { - actual.onError(new CompositeException(list)); + downstream.onError(new CompositeException(list)); } } else { - actual.onComplete(); + downstream.onComplete(); } return; } @@ -127,7 +127,7 @@ public void onComplete() { i++; continue; } else { - actual.onError(ex); + downstream.onError(ex); return; } } else { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java index 6aee2f7c80..27016a1dd8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java @@ -80,7 +80,7 @@ abstract static class BaseConcatMapSubscriber final int limit; - Subscription s; + Subscription upstream; int consumed; @@ -108,8 +108,8 @@ abstract static class BaseConcatMapSubscriber @Override public final void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") QueueSubscription f = (QueueSubscription)s; @@ -151,7 +151,7 @@ public final void onSubscribe(Subscription s) { public final void onNext(T t) { if (sourceMode != QueueSubscription.ASYNC) { if (!queue.offer(t)) { - s.cancel(); + upstream.cancel(); onError(new IllegalStateException("Queue full?!")); return; } @@ -180,7 +180,7 @@ static final class ConcatMapImmediate private static final long serialVersionUID = 7898995095634264146L; - final Subscriber actual; + final Subscriber downstream; final AtomicInteger wip; @@ -188,13 +188,13 @@ static final class ConcatMapImmediate Function> mapper, int prefetch) { super(mapper, prefetch); - this.actual = actual; + this.downstream = actual; this.wip = new AtomicInteger(); } @Override void subscribeActual() { - actual.onSubscribe(this); + downstream.onSubscribe(this); } @Override @@ -203,7 +203,7 @@ public void onError(Throwable t) { inner.cancel(); if (getAndIncrement() == 0) { - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); } } else { RxJavaPlugins.onError(t); @@ -213,21 +213,21 @@ public void onError(Throwable t) { @Override public void innerNext(R value) { if (get() == 0 && compareAndSet(0, 1)) { - actual.onNext(value); + downstream.onNext(value); if (compareAndSet(1, 0)) { return; } - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); } } @Override public void innerError(Throwable e) { if (errors.addThrowable(e)) { - s.cancel(); + upstream.cancel(); if (getAndIncrement() == 0) { - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); } } else { RxJavaPlugins.onError(e); @@ -245,7 +245,7 @@ public void cancel() { cancelled = true; inner.cancel(); - s.cancel(); + upstream.cancel(); } } @@ -266,16 +266,16 @@ void drain() { v = queue.poll(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); errors.addThrowable(e); - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); return; } boolean empty = v == null; if (d && empty) { - actual.onComplete(); + downstream.onComplete(); return; } @@ -287,9 +287,9 @@ void drain() { } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); errors.addThrowable(e); - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); return; } @@ -297,7 +297,7 @@ void drain() { int c = consumed + 1; if (c == limit) { consumed = 0; - s.request(c); + upstream.request(c); } else { consumed = c; } @@ -314,9 +314,9 @@ void drain() { vr = callable.call(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); errors.addThrowable(e); - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); return; } @@ -327,9 +327,9 @@ void drain() { if (inner.isUnbounded()) { if (get() == 0 && compareAndSet(0, 1)) { - actual.onNext(vr); + downstream.onNext(vr); if (!compareAndSet(1, 0)) { - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); return; } } @@ -354,20 +354,20 @@ void drain() { } static final class WeakScalarSubscription implements Subscription { - final Subscriber actual; + final Subscriber downstream; final T value; boolean once; - WeakScalarSubscription(T value, Subscriber actual) { + WeakScalarSubscription(T value, Subscriber downstream) { this.value = value; - this.actual = actual; + this.downstream = downstream; } @Override public void request(long n) { if (n > 0 && !once) { once = true; - Subscriber a = actual; + Subscriber a = downstream; a.onNext(value); a.onComplete(); } @@ -385,7 +385,7 @@ static final class ConcatMapDelayed private static final long serialVersionUID = -2945777694260521066L; - final Subscriber actual; + final Subscriber downstream; final boolean veryEnd; @@ -393,13 +393,13 @@ static final class ConcatMapDelayed Function> mapper, int prefetch, boolean veryEnd) { super(mapper, prefetch); - this.actual = actual; + this.downstream = actual; this.veryEnd = veryEnd; } @Override void subscribeActual() { - actual.onSubscribe(this); + downstream.onSubscribe(this); } @Override @@ -414,7 +414,7 @@ public void onError(Throwable t) { @Override public void innerNext(R value) { - actual.onNext(value); + downstream.onNext(value); } @@ -422,7 +422,7 @@ public void innerNext(R value) { public void innerError(Throwable e) { if (errors.addThrowable(e)) { if (!veryEnd) { - s.cancel(); + upstream.cancel(); done = true; } active = false; @@ -443,7 +443,7 @@ public void cancel() { cancelled = true; inner.cancel(); - s.cancel(); + upstream.cancel(); } } @@ -463,7 +463,7 @@ void drain() { if (d && !veryEnd) { Throwable ex = errors.get(); if (ex != null) { - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); return; } } @@ -474,9 +474,9 @@ void drain() { v = queue.poll(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); errors.addThrowable(e); - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); return; } @@ -485,9 +485,9 @@ void drain() { if (d && empty) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } return; } @@ -500,9 +500,9 @@ void drain() { } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); errors.addThrowable(e); - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); return; } @@ -510,7 +510,7 @@ void drain() { int c = consumed + 1; if (c == limit) { consumed = 0; - s.request(c); + upstream.request(c); } else { consumed = c; } @@ -526,9 +526,9 @@ void drain() { vr = supplier.call(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); errors.addThrowable(e); - actual.onError(errors.terminate()); + downstream.onError(errors.terminate()); return; } @@ -537,7 +537,7 @@ void drain() { } if (inner.isUnbounded()) { - actual.onNext(vr); + downstream.onNext(vr); continue; } else { active = true; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEager.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEager.java index 991a96f45c..87ee235704 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEager.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEager.java @@ -62,7 +62,7 @@ static final class ConcatMapEagerDelayErrorSubscriber private static final long serialVersionUID = -4255299542215038287L; - final Subscriber actual; + final Subscriber downstream; final Function> mapper; @@ -78,7 +78,7 @@ static final class ConcatMapEagerDelayErrorSubscriber final SpscLinkedArrayQueue> subscribers; - Subscription s; + Subscription upstream; volatile boolean cancelled; @@ -89,7 +89,7 @@ static final class ConcatMapEagerDelayErrorSubscriber ConcatMapEagerDelayErrorSubscriber(Subscriber actual, Function> mapper, int maxConcurrency, int prefetch, ErrorMode errorMode) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.maxConcurrency = maxConcurrency; this.prefetch = prefetch; @@ -101,10 +101,10 @@ static final class ConcatMapEagerDelayErrorSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(maxConcurrency == Integer.MAX_VALUE ? Long.MAX_VALUE : maxConcurrency); } @@ -119,7 +119,7 @@ public void onNext(T t) { p = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); return; } @@ -162,7 +162,7 @@ public void cancel() { return; } cancelled = true; - s.cancel(); + upstream.cancel(); drainAndCancel(); } @@ -206,7 +206,7 @@ public void innerError(InnerQueuedSubscriber inner, Throwable e) { if (errors.addThrowable(e)) { inner.setDone(); if (errorMode != ErrorMode.END) { - s.cancel(); + upstream.cancel(); } drain(); } else { @@ -228,7 +228,7 @@ public void drain() { int missed = 1; InnerQueuedSubscriber inner = current; - Subscriber a = actual; + Subscriber a = downstream; ErrorMode em = errorMode; for (;;) { @@ -309,7 +309,7 @@ public void drain() { if (d && empty) { inner = null; current = null; - s.request(1); + upstream.request(1); continueNextSource = true; break; } @@ -350,7 +350,7 @@ public void drain() { if (d && empty) { inner = null; current = null; - s.request(1); + upstream.request(1); continueNextSource = true; } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletable.java index 5523614a9a..8928d20139 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletable.java @@ -49,7 +49,7 @@ static final class ConcatWithSubscriber private static final long serialVersionUID = -7346385463600070225L; - final Subscriber actual; + final Subscriber downstream; Subscription upstream; @@ -58,7 +58,7 @@ static final class ConcatWithSubscriber boolean inCompletable; ConcatWithSubscriber(Subscriber actual, CompletableSource other) { - this.actual = actual; + this.downstream = actual; this.other = other; } @@ -66,7 +66,7 @@ static final class ConcatWithSubscriber public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(upstream, s)) { this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -77,18 +77,18 @@ public void onSubscribe(Disposable d) { @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (inCompletable) { - actual.onComplete(); + downstream.onComplete(); } else { inCompletable = true; upstream = SubscriptionHelper.CANCELLED; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybe.java index 3250e0c82c..0081d91feb 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybe.java @@ -70,12 +70,12 @@ public void onSubscribe(Disposable d) { @Override public void onNext(T t) { produced++; - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -86,10 +86,10 @@ public void onSuccess(T t) { @Override public void onComplete() { if (inMaybe) { - actual.onComplete(); + downstream.onComplete(); } else { inMaybe = true; - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; MaybeSource ms = other; other = null; ms.subscribe(this); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithSingle.java index a85090166b..23c60ea4fc 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatWithSingle.java @@ -68,12 +68,12 @@ public void onSubscribe(Disposable d) { @Override public void onNext(T t) { produced++; - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -83,7 +83,7 @@ public void onSuccess(T t) { @Override public void onComplete() { - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; SingleSource ss = other; other = null; ss.subscribe(this); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCount.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCount.java index 95bbfb0d2e..ebe2b07024 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCount.java @@ -35,19 +35,19 @@ static final class CountSubscriber extends DeferredScalarSubscription private static final long serialVersionUID = 4973004223787171406L; - Subscription s; + Subscription upstream; long count; - CountSubscriber(Subscriber actual) { - super(actual); + CountSubscriber(Subscriber downstream) { + super(downstream); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -59,7 +59,7 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -70,7 +70,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCountSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCountSingle.java index 13bf0bd9a8..c43f0314f0 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCountSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCountSingle.java @@ -41,21 +41,21 @@ public Flowable fuseToFlowable() { static final class CountSubscriber implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; - Subscription s; + Subscription upstream; long count; - CountSubscriber(SingleObserver actual) { - this.actual = actual; + CountSubscriber(SingleObserver downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -67,25 +67,25 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override public void onComplete() { - s = SubscriptionHelper.CANCELLED; - actual.onSuccess(count); + upstream = SubscriptionHelper.CANCELLED; + downstream.onSuccess(count); } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCreate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCreate.java index c1f506abc1..e7d43e466b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCreate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCreate.java @@ -210,8 +210,8 @@ void drainLoop() { } @Override - public void setDisposable(Disposable s) { - emitter.setDisposable(s); + public void setDisposable(Disposable d) { + emitter.setDisposable(d); } @Override @@ -245,12 +245,12 @@ abstract static class BaseEmitter implements FlowableEmitter, Subscription { private static final long serialVersionUID = 7326289992464377023L; - final Subscriber actual; + final Subscriber downstream; final SequentialDisposable serial; - BaseEmitter(Subscriber actual) { - this.actual = actual; + BaseEmitter(Subscriber downstream) { + this.downstream = downstream; this.serial = new SequentialDisposable(); } @@ -264,7 +264,7 @@ protected void complete() { return; } try { - actual.onComplete(); + downstream.onComplete(); } finally { serial.dispose(); } @@ -290,7 +290,7 @@ protected boolean error(Throwable e) { return false; } try { - actual.onError(e); + downstream.onError(e); } finally { serial.dispose(); } @@ -325,8 +325,8 @@ void onRequested() { } @Override - public final void setDisposable(Disposable s) { - serial.update(s); + public final void setDisposable(Disposable d) { + serial.update(d); } @Override @@ -355,8 +355,8 @@ static final class MissingEmitter extends BaseEmitter { private static final long serialVersionUID = 3776720187248809713L; - MissingEmitter(Subscriber actual) { - super(actual); + MissingEmitter(Subscriber downstream) { + super(downstream); } @Override @@ -366,7 +366,7 @@ public void onNext(T t) { } if (t != null) { - actual.onNext(t); + downstream.onNext(t); } else { onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; @@ -386,8 +386,8 @@ abstract static class NoOverflowBaseAsyncEmitter extends BaseEmitter { private static final long serialVersionUID = 4127754106204442833L; - NoOverflowBaseAsyncEmitter(Subscriber actual) { - super(actual); + NoOverflowBaseAsyncEmitter(Subscriber downstream) { + super(downstream); } @Override @@ -402,7 +402,7 @@ public final void onNext(T t) { } if (get() != 0) { - actual.onNext(t); + downstream.onNext(t); BackpressureHelper.produced(this, 1); } else { onOverflow(); @@ -417,8 +417,8 @@ static final class DropAsyncEmitter extends NoOverflowBaseAsyncEmitter { private static final long serialVersionUID = 8360058422307496563L; - DropAsyncEmitter(Subscriber actual) { - super(actual); + DropAsyncEmitter(Subscriber downstream) { + super(downstream); } @Override @@ -433,8 +433,8 @@ static final class ErrorAsyncEmitter extends NoOverflowBaseAsyncEmitter { private static final long serialVersionUID = 338953216916120960L; - ErrorAsyncEmitter(Subscriber actual) { - super(actual); + ErrorAsyncEmitter(Subscriber downstream) { + super(downstream); } @Override @@ -516,7 +516,7 @@ void drain() { } int missed = 1; - final Subscriber a = actual; + final Subscriber a = downstream; final SpscLinkedArrayQueue q = queue; for (;;) { @@ -599,8 +599,8 @@ static final class LatestAsyncEmitter extends BaseEmitter { final AtomicInteger wip; - LatestAsyncEmitter(Subscriber actual) { - super(actual); + LatestAsyncEmitter(Subscriber downstream) { + super(downstream); this.queue = new AtomicReference(); this.wip = new AtomicInteger(); } @@ -657,7 +657,7 @@ void drain() { } int missed = 1; - final Subscriber a = actual; + final Subscriber a = downstream; final AtomicReference q = queue; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounce.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounce.java index 34bc84c4c3..92b1c48254 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounce.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounce.java @@ -45,10 +45,10 @@ static final class DebounceSubscriber extends AtomicLong implements FlowableSubscriber, Subscription { private static final long serialVersionUID = 6725975399620862591L; - final Subscriber actual; + final Subscriber downstream; final Function> debounceSelector; - Subscription s; + Subscription upstream; final AtomicReference debouncer = new AtomicReference(); @@ -58,15 +58,15 @@ static final class DebounceSubscriber extends AtomicLong DebounceSubscriber(Subscriber actual, Function> debounceSelector) { - this.actual = actual; + this.downstream = actual; this.debounceSelector = debounceSelector; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -92,7 +92,7 @@ public void onNext(T t) { } catch (Throwable e) { Exceptions.throwIfFatal(e); cancel(); - actual.onError(e); + downstream.onError(e); return; } @@ -106,7 +106,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { DisposableHelper.dispose(debouncer); - actual.onError(t); + downstream.onError(t); } @Override @@ -121,7 +121,7 @@ public void onComplete() { DebounceInnerSubscriber dis = (DebounceInnerSubscriber)d; dis.emit(); DisposableHelper.dispose(debouncer); - actual.onComplete(); + downstream.onComplete(); } } @@ -134,7 +134,7 @@ public void request(long n) { @Override public void cancel() { - s.cancel(); + upstream.cancel(); DisposableHelper.dispose(debouncer); } @@ -142,11 +142,11 @@ void emit(long idx, T value) { if (idx == index) { long r = get(); if (r != 0L) { - actual.onNext(value); + downstream.onNext(value); BackpressureHelper.produced(this, 1); } else { cancel(); - actual.onError(new MissingBackpressureException("Could not deliver value due to lack of requests")); + downstream.onError(new MissingBackpressureException("Could not deliver value due to lack of requests")); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java index aea5af63e7..36ece502bd 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java @@ -51,12 +51,12 @@ static final class DebounceTimedSubscriber extends AtomicLong implements FlowableSubscriber, Subscription { private static final long serialVersionUID = -9102637559663639004L; - final Subscriber actual; + final Subscriber downstream; final long timeout; final TimeUnit unit; final Scheduler.Worker worker; - Subscription s; + Subscription upstream; Disposable timer; @@ -65,7 +65,7 @@ static final class DebounceTimedSubscriber extends AtomicLong boolean done; DebounceTimedSubscriber(Subscriber actual, long timeout, TimeUnit unit, Worker worker) { - this.actual = actual; + this.downstream = actual; this.timeout = timeout; this.unit = unit; this.worker = worker; @@ -73,9 +73,9 @@ static final class DebounceTimedSubscriber extends AtomicLong @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -110,7 +110,7 @@ public void onError(Throwable t) { if (d != null) { d.dispose(); } - actual.onError(t); + downstream.onError(t); worker.dispose(); } @@ -131,7 +131,7 @@ public void onComplete() { de.emit(); } - actual.onComplete(); + downstream.onComplete(); worker.dispose(); } @@ -144,7 +144,7 @@ public void request(long n) { @Override public void cancel() { - s.cancel(); + upstream.cancel(); worker.dispose(); } @@ -152,13 +152,13 @@ void emit(long idx, T t, DebounceEmitter emitter) { if (idx == index) { long r = get(); if (r != 0L) { - actual.onNext(t); + downstream.onNext(t); BackpressureHelper.produced(this, 1); emitter.dispose(); } else { cancel(); - actual.onError(new MissingBackpressureException("Could not deliver value due to lack of requests")); + downstream.onError(new MissingBackpressureException("Could not deliver value due to lack of requests")); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelay.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelay.java index 3732c48d63..684c11f549 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelay.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelay.java @@ -38,30 +38,30 @@ public FlowableDelay(Flowable source, long delay, TimeUnit unit, Scheduler sc @Override protected void subscribeActual(Subscriber t) { - Subscriber s; + Subscriber downstream; if (delayError) { - s = t; + downstream = t; } else { - s = new SerializedSubscriber(t); + downstream = new SerializedSubscriber(t); } Scheduler.Worker w = scheduler.createWorker(); - source.subscribe(new DelaySubscriber(s, delay, unit, w, delayError)); + source.subscribe(new DelaySubscriber(downstream, delay, unit, w, delayError)); } static final class DelaySubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final long delay; final TimeUnit unit; final Scheduler.Worker w; final boolean delayError; - Subscription s; + Subscription upstream; DelaySubscriber(Subscriber actual, long delay, TimeUnit unit, Worker w, boolean delayError) { super(); - this.actual = actual; + this.downstream = actual; this.delay = delay; this.unit = unit; this.w = w; @@ -70,9 +70,9 @@ static final class DelaySubscriber implements FlowableSubscriber, Subscrip @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -93,12 +93,12 @@ public void onComplete() { @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); w.dispose(); } @@ -111,7 +111,7 @@ final class OnNext implements Runnable { @Override public void run() { - actual.onNext(t); + downstream.onNext(t); } } @@ -125,7 +125,7 @@ final class OnError implements Runnable { @Override public void run() { try { - actual.onError(t); + downstream.onError(t); } finally { w.dispose(); } @@ -136,7 +136,7 @@ final class OnComplete implements Runnable { @Override public void run() { try { - actual.onComplete(); + downstream.onComplete(); } finally { w.dispose(); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOther.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOther.java index 0d0a37db3e..a98892a01c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOther.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOther.java @@ -85,10 +85,11 @@ public void onComplete() { } final class DelaySubscription implements Subscription { - private final Subscription s; + + final Subscription upstream; DelaySubscription(Subscription s) { - this.s = s; + this.upstream = s; } @Override @@ -98,7 +99,7 @@ public void request(long n) { @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java index 5ce85197c3..6257f48803 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java @@ -31,21 +31,21 @@ protected void subscribeActual(Subscriber s) { } static final class DematerializeSubscriber implements FlowableSubscriber>, Subscription { - final Subscriber actual; + final Subscriber downstream; boolean done; - Subscription s; + Subscription upstream; - DematerializeSubscriber(Subscriber actual) { - this.actual = actual; + DematerializeSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -58,14 +58,14 @@ public void onNext(Notification t) { return; } if (t.isOnError()) { - s.cancel(); + upstream.cancel(); onError(t.getError()); } else if (t.isOnComplete()) { - s.cancel(); + upstream.cancel(); onComplete(); } else { - actual.onNext(t.getValue()); + downstream.onNext(t.getValue()); } } @@ -77,7 +77,7 @@ public void onError(Throwable t) { } done = true; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { @@ -86,17 +86,17 @@ public void onComplete() { } done = true; - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDetach.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDetach.java index de618949d4..7679ee152e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDetach.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDetach.java @@ -32,54 +32,54 @@ protected void subscribeActual(Subscriber s) { static final class DetachSubscriber implements FlowableSubscriber, Subscription { - Subscriber actual; + Subscriber downstream; - Subscription s; + Subscription upstream; - DetachSubscriber(Subscriber actual) { - this.actual = actual; + DetachSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - Subscription s = this.s; - this.s = EmptyComponent.INSTANCE; - this.actual = EmptyComponent.asSubscriber(); + Subscription s = this.upstream; + this.upstream = EmptyComponent.INSTANCE; + this.downstream = EmptyComponent.asSubscriber(); s.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - Subscriber a = actual; - this.s = EmptyComponent.INSTANCE; - this.actual = EmptyComponent.asSubscriber(); + Subscriber a = downstream; + this.upstream = EmptyComponent.INSTANCE; + this.downstream = EmptyComponent.asSubscriber(); a.onError(t); } @Override public void onComplete() { - Subscriber a = actual; - this.s = EmptyComponent.INSTANCE; - this.actual = EmptyComponent.asSubscriber(); + Subscriber a = downstream; + this.upstream = EmptyComponent.INSTANCE; + this.downstream = EmptyComponent.asSubscriber(); a.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinct.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinct.java index f12b637737..4e9bc5e1bf 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinct.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinct.java @@ -85,12 +85,12 @@ public void onNext(T value) { } if (b) { - actual.onNext(value); + downstream.onNext(value); } else { - s.request(1); + upstream.request(1); } } else { - actual.onNext(null); + downstream.onNext(null); } } @@ -101,7 +101,7 @@ public void onError(Throwable e) { } else { done = true; collection.clear(); - actual.onError(e); + downstream.onError(e); } } @@ -110,7 +110,7 @@ public void onComplete() { if (!done) { done = true; collection.clear(); - actual.onComplete(); + downstream.onComplete(); } } @@ -129,7 +129,7 @@ public T poll() throws Exception { return v; } else { if (sourceMode == QueueFuseable.ASYNC) { - s.request(1); + upstream.request(1); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChanged.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChanged.java index 9b1944977b..f54be6360b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChanged.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChanged.java @@ -66,7 +66,7 @@ static final class DistinctUntilChangedSubscriber extends BasicFuseableSub @Override public void onNext(T t) { if (!tryOnNext(t)) { - s.request(1); + upstream.request(1); } } @@ -76,7 +76,7 @@ public boolean tryOnNext(T t) { return false; } if (sourceMode != NONE) { - actual.onNext(t); + downstream.onNext(t); return true; } @@ -99,7 +99,7 @@ public boolean tryOnNext(T t) { return true; } - actual.onNext(t); + downstream.onNext(t); return true; } @@ -129,7 +129,7 @@ public T poll() throws Exception { } last = key; if (sourceMode != SYNC) { - s.request(1); + upstream.request(1); } } } @@ -157,7 +157,7 @@ static final class DistinctUntilChangedConditionalSubscriber extends Basic @Override public void onNext(T t) { if (!tryOnNext(t)) { - s.request(1); + upstream.request(1); } } @@ -167,7 +167,7 @@ public boolean tryOnNext(T t) { return false; } if (sourceMode != NONE) { - return actual.tryOnNext(t); + return downstream.tryOnNext(t); } K key; @@ -189,7 +189,7 @@ public boolean tryOnNext(T t) { return true; } - actual.onNext(t); + downstream.onNext(t); return true; } @@ -219,7 +219,7 @@ public T poll() throws Exception { } last = key; if (sourceMode != SYNC) { - s.request(1); + upstream.request(1); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNext.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNext.java index f7a079d4b7..968c589e2c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNext.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNext.java @@ -59,7 +59,7 @@ public void onNext(T t) { if (done) { return; } - actual.onNext(t); + downstream.onNext(t); if (sourceMode == NONE) { try { @@ -97,7 +97,7 @@ static final class DoAfterConditionalSubscriber extends BasicFuseableConditio @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); if (sourceMode == NONE) { try { @@ -110,7 +110,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { - boolean b = actual.tryOnNext(t); + boolean b = downstream.tryOnNext(t); try { onAfterNext.accept(t); } catch (Throwable ex) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoFinally.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoFinally.java index 116f81b712..023c55bf7f 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoFinally.java @@ -51,60 +51,60 @@ static final class DoFinallySubscriber extends BasicIntQueueSubscription i private static final long serialVersionUID = 4109457741734051389L; - final Subscriber actual; + final Subscriber downstream; final Action onFinally; - Subscription s; + Subscription upstream; QueueSubscription qs; boolean syncFused; DoFinallySubscriber(Subscriber actual, Action onFinally) { - this.actual = actual; + this.downstream = actual; this.onFinally = onFinally; } @SuppressWarnings("unchecked") @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; if (s instanceof QueueSubscription) { this.qs = (QueueSubscription)s; } - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); runFinally(); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); runFinally(); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); runFinally(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override @@ -156,65 +156,65 @@ static final class DoFinallyConditionalSubscriber extends BasicIntQueueSubscr private static final long serialVersionUID = 4109457741734051389L; - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; final Action onFinally; - Subscription s; + Subscription upstream; QueueSubscription qs; boolean syncFused; DoFinallyConditionalSubscriber(ConditionalSubscriber actual, Action onFinally) { - this.actual = actual; + this.downstream = actual; this.onFinally = onFinally; } @SuppressWarnings("unchecked") @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; if (s instanceof QueueSubscription) { this.qs = (QueueSubscription)s; } - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public boolean tryOnNext(T t) { - return actual.tryOnNext(t); + return downstream.tryOnNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); runFinally(); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); runFinally(); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); runFinally(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnEach.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnEach.java index 2d7d49ca46..e913675f69 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnEach.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnEach.java @@ -78,7 +78,7 @@ public void onNext(T t) { } if (sourceMode != NONE) { - actual.onNext(null); + downstream.onNext(null); return; } @@ -89,7 +89,7 @@ public void onNext(T t) { return; } - actual.onNext(t); + downstream.onNext(t); } @Override @@ -104,11 +104,11 @@ public void onError(Throwable t) { onError.accept(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); relay = false; } if (relay) { - actual.onError(t); + downstream.onError(t); } try { @@ -132,7 +132,7 @@ public void onComplete() { } done = true; - actual.onComplete(); + downstream.onComplete(); try { onAfterTerminate.run(); @@ -217,7 +217,7 @@ public void onNext(T t) { } if (sourceMode != NONE) { - actual.onNext(null); + downstream.onNext(null); return; } @@ -228,7 +228,7 @@ public void onNext(T t) { return; } - actual.onNext(t); + downstream.onNext(t); } @Override @@ -244,7 +244,7 @@ public boolean tryOnNext(T t) { return false; } - return actual.tryOnNext(t); + return downstream.tryOnNext(t); } @Override @@ -259,11 +259,11 @@ public void onError(Throwable t) { onError.accept(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); relay = false; } if (relay) { - actual.onError(t); + downstream.onError(t); } try { @@ -287,7 +287,7 @@ public void onComplete() { } done = true; - actual.onComplete(); + downstream.onComplete(); try { onAfterTerminate.run(); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycle.java index e68f1a01e2..f0d233881d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycle.java @@ -39,18 +39,18 @@ protected void subscribeActual(Subscriber s) { } static final class SubscriptionLambdaSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final Consumer onSubscribe; final LongConsumer onRequest; final Action onCancel; - Subscription s; + Subscription upstream; SubscriptionLambdaSubscriber(Subscriber actual, Consumer onSubscribe, LongConsumer onRequest, Action onCancel) { - this.actual = actual; + this.downstream = actual; this.onSubscribe = onSubscribe; this.onCancel = onCancel; this.onRequest = onRequest; @@ -64,25 +64,25 @@ public void onSubscribe(Subscription s) { } catch (Throwable e) { Exceptions.throwIfFatal(e); s.cancel(); - this.s = SubscriptionHelper.CANCELLED; - EmptySubscription.error(e, actual); + this.upstream = SubscriptionHelper.CANCELLED; + EmptySubscription.error(e, downstream); return; } - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - if (s != SubscriptionHelper.CANCELLED) { - actual.onError(t); + if (upstream != SubscriptionHelper.CANCELLED) { + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -90,8 +90,8 @@ public void onError(Throwable t) { @Override public void onComplete() { - if (s != SubscriptionHelper.CANCELLED) { - actual.onComplete(); + if (upstream != SubscriptionHelper.CANCELLED) { + downstream.onComplete(); } } @@ -103,7 +103,7 @@ public void request(long n) { Exceptions.throwIfFatal(e); RxJavaPlugins.onError(e); } - s.request(n); + upstream.request(n); } @Override @@ -114,7 +114,7 @@ public void cancel() { Exceptions.throwIfFatal(e); RxJavaPlugins.onError(e); } - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAt.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAt.java index 261cbd88cf..9d3ead4a46 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAt.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAt.java @@ -46,7 +46,7 @@ static final class ElementAtSubscriber extends DeferredScalarSubscription final T defaultValue; final boolean errorOnFewer; - Subscription s; + Subscription upstream; long count; @@ -61,9 +61,9 @@ static final class ElementAtSubscriber extends DeferredScalarSubscription @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -76,7 +76,7 @@ public void onNext(T t) { long c = count; if (c == index) { done = true; - s.cancel(); + upstream.cancel(); complete(t); return; } @@ -90,7 +90,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -100,9 +100,9 @@ public void onComplete() { T v = defaultValue; if (v == null) { if (errorOnFewer) { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } else { - actual.onComplete(); + downstream.onComplete(); } } else { complete(v); @@ -113,7 +113,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtMaybe.java index 5293af4722..4d411990ac 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtMaybe.java @@ -43,26 +43,26 @@ public Flowable fuseToFlowable() { static final class ElementAtSubscriber implements FlowableSubscriber, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final long index; - Subscription s; + Subscription upstream; long count; boolean done; ElementAtSubscriber(MaybeObserver actual, long index) { - this.actual = actual; + this.downstream = actual; this.index = index; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -75,9 +75,9 @@ public void onNext(T t) { long c = count; if (c == index) { done = true; - s.cancel(); - s = SubscriptionHelper.CANCELLED; - actual.onSuccess(t); + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; + downstream.onSuccess(t); return; } count = c + 1; @@ -90,28 +90,28 @@ public void onError(Throwable t) { return; } done = true; - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override public void onComplete() { - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); } } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtSingle.java index 0a08f47fee..7cd542d497 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableElementAtSingle.java @@ -48,28 +48,28 @@ public Flowable fuseToFlowable() { static final class ElementAtSubscriber implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final long index; final T defaultValue; - Subscription s; + Subscription upstream; long count; boolean done; ElementAtSubscriber(SingleObserver actual, long index, T defaultValue) { - this.actual = actual; + this.downstream = actual; this.index = index; this.defaultValue = defaultValue; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -82,9 +82,9 @@ public void onNext(T t) { long c = count; if (c == index) { done = true; - s.cancel(); - s = SubscriptionHelper.CANCELLED; - actual.onSuccess(t); + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; + downstream.onSuccess(t); return; } count = c + 1; @@ -97,35 +97,35 @@ public void onError(Throwable t) { return; } done = true; - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override public void onComplete() { - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; if (!done) { done = true; T v = defaultValue; if (v != null) { - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } } } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFilter.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFilter.java index 96b529f3f2..30487f90d7 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFilter.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFilter.java @@ -50,7 +50,7 @@ static final class FilterSubscriber extends BasicFuseableSubscriber @Override public void onNext(T t) { if (!tryOnNext(t)) { - s.request(1); + upstream.request(1); } } @@ -60,7 +60,7 @@ public boolean tryOnNext(T t) { return false; } if (sourceMode != NONE) { - actual.onNext(null); + downstream.onNext(null); return true; } boolean b; @@ -71,7 +71,7 @@ public boolean tryOnNext(T t) { return true; } if (b) { - actual.onNext(t); + downstream.onNext(t); } return b; } @@ -117,7 +117,7 @@ static final class FilterConditionalSubscriber extends BasicFuseableCondition @Override public void onNext(T t) { if (!tryOnNext(t)) { - s.request(1); + upstream.request(1); } } @@ -128,7 +128,7 @@ public boolean tryOnNext(T t) { } if (sourceMode != NONE) { - return actual.tryOnNext(null); + return downstream.tryOnNext(null); } boolean b; @@ -138,7 +138,7 @@ public boolean tryOnNext(T t) { fail(e); return true; } - return b && actual.tryOnNext(t); + return b && downstream.tryOnNext(t); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java index 58e185d12d..07e2b20db3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java @@ -63,7 +63,7 @@ static final class MergeSubscriber extends AtomicInteger implements Flowab private static final long serialVersionUID = -2117620485640801370L; - final Subscriber actual; + final Subscriber downstream; final Function> mapper; final boolean delayErrors; final int maxConcurrency; @@ -96,7 +96,7 @@ static final class MergeSubscriber extends AtomicInteger implements Flowab MergeSubscriber(Subscriber actual, Function> mapper, boolean delayErrors, int maxConcurrency, int bufferSize) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.delayErrors = delayErrors; this.maxConcurrency = maxConcurrency; @@ -109,7 +109,7 @@ static final class MergeSubscriber extends AtomicInteger implements Flowab public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.upstream, s)) { this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); if (!cancelled) { if (maxConcurrency == Integer.MAX_VALUE) { s.request(Long.MAX_VALUE); @@ -231,7 +231,7 @@ void tryEmitScalar(U value) { long r = requested.get(); SimpleQueue q = queue; if (r != 0L && (q == null || q.isEmpty())) { - actual.onNext(value); + downstream.onNext(value); if (r != Long.MAX_VALUE) { requested.decrementAndGet(); } @@ -279,7 +279,7 @@ void tryEmit(U value, InnerSubscriber inner) { long r = requested.get(); SimpleQueue q = inner.queue; if (r != 0L && (q == null || q.isEmpty())) { - actual.onNext(value); + downstream.onNext(value); if (r != Long.MAX_VALUE) { requested.decrementAndGet(); } @@ -368,7 +368,7 @@ void drain() { } void drainLoop() { - final Subscriber child = this.actual; + final Subscriber child = this.downstream; int missed = 1; for (;;) { if (checkTerminate()) { @@ -563,7 +563,7 @@ boolean checkTerminate() { clearScalarQueue(); Throwable ex = errs.terminate(); if (ex != ExceptionHelper.TERMINATED) { - actual.onError(ex); + downstream.onError(ex); } return true; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletable.java index 43546d1376..86311bc27d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletable.java @@ -58,7 +58,7 @@ static final class FlatMapCompletableMainSubscriber extends BasicIntQueueSubs implements FlowableSubscriber { private static final long serialVersionUID = 8443155186132538303L; - final Subscriber actual; + final Subscriber downstream; final AtomicThrowable errors; @@ -70,14 +70,14 @@ static final class FlatMapCompletableMainSubscriber extends BasicIntQueueSubs final int maxConcurrency; - Subscription s; + Subscription upstream; volatile boolean cancelled; FlatMapCompletableMainSubscriber(Subscriber subscriber, Function mapper, boolean delayErrors, int maxConcurrency) { - this.actual = subscriber; + this.downstream = subscriber; this.mapper = mapper; this.delayErrors = delayErrors; this.errors = new AtomicThrowable(); @@ -88,10 +88,10 @@ static final class FlatMapCompletableMainSubscriber extends BasicIntQueueSubs @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); int m = maxConcurrency; if (m == Integer.MAX_VALUE) { @@ -110,7 +110,7 @@ public void onNext(T value) { cs = ObjectHelper.requireNonNull(mapper.apply(value), "The mapper returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); return; } @@ -130,17 +130,17 @@ public void onError(Throwable e) { if (delayErrors) { if (decrementAndGet() == 0) { Throwable ex = errors.terminate(); - actual.onError(ex); + downstream.onError(ex); } else { if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } } else { cancel(); if (getAndSet(0) > 0) { Throwable ex = errors.terminate(); - actual.onError(ex); + downstream.onError(ex); } } } else { @@ -153,13 +153,13 @@ public void onComplete() { if (decrementAndGet() == 0) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } } else { if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } } @@ -167,7 +167,7 @@ public void onComplete() { @Override public void cancel() { cancelled = true; - s.cancel(); + upstream.cancel(); set.dispose(); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableCompletable.java index 16f126b363..ad5434273b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableCompletable.java @@ -65,7 +65,7 @@ static final class FlatMapCompletableMainSubscriber extends AtomicInteger implements FlowableSubscriber, Disposable { private static final long serialVersionUID = 8443155186132538303L; - final CompletableObserver actual; + final CompletableObserver downstream; final AtomicThrowable errors; @@ -77,14 +77,14 @@ static final class FlatMapCompletableMainSubscriber extends AtomicInteger final int maxConcurrency; - Subscription s; + Subscription upstream; volatile boolean disposed; FlatMapCompletableMainSubscriber(CompletableObserver observer, Function mapper, boolean delayErrors, int maxConcurrency) { - this.actual = observer; + this.downstream = observer; this.mapper = mapper; this.delayErrors = delayErrors; this.errors = new AtomicThrowable(); @@ -95,10 +95,10 @@ static final class FlatMapCompletableMainSubscriber extends AtomicInteger @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); int m = maxConcurrency; if (m == Integer.MAX_VALUE) { @@ -117,7 +117,7 @@ public void onNext(T value) { cs = ObjectHelper.requireNonNull(mapper.apply(value), "The mapper returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); return; } @@ -137,17 +137,17 @@ public void onError(Throwable e) { if (delayErrors) { if (decrementAndGet() == 0) { Throwable ex = errors.terminate(); - actual.onError(ex); + downstream.onError(ex); } else { if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } } else { dispose(); if (getAndSet(0) > 0) { Throwable ex = errors.terminate(); - actual.onError(ex); + downstream.onError(ex); } } } else { @@ -160,13 +160,13 @@ public void onComplete() { if (decrementAndGet() == 0) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } } else { if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } } @@ -174,7 +174,7 @@ public void onComplete() { @Override public void dispose() { disposed = true; - s.cancel(); + upstream.cancel(); set.dispose(); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybe.java index 8b27fe702a..ab2950e2a3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybe.java @@ -60,7 +60,7 @@ static final class FlatMapMaybeSubscriber private static final long serialVersionUID = 8600231336733376951L; - final Subscriber actual; + final Subscriber downstream; final boolean delayErrors; @@ -78,13 +78,13 @@ static final class FlatMapMaybeSubscriber final AtomicReference> queue; - Subscription s; + Subscription upstream; volatile boolean cancelled; FlatMapMaybeSubscriber(Subscriber actual, Function> mapper, boolean delayErrors, int maxConcurrency) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.delayErrors = delayErrors; this.maxConcurrency = maxConcurrency; @@ -97,10 +97,10 @@ static final class FlatMapMaybeSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); int m = maxConcurrency; if (m == Integer.MAX_VALUE) { @@ -119,7 +119,7 @@ public void onNext(T t) { ms = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); return; } @@ -155,7 +155,7 @@ public void onComplete() { @Override public void cancel() { cancelled = true; - s.cancel(); + upstream.cancel(); set.dispose(); } @@ -172,22 +172,22 @@ void innerSuccess(InnerObserver inner, R value) { if (get() == 0 && compareAndSet(0, 1)) { boolean d = active.decrementAndGet() == 0; if (requested.get() != 0) { - actual.onNext(value); + downstream.onNext(value); SpscLinkedArrayQueue q = queue.get(); if (d && (q == null || q.isEmpty())) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } return; } BackpressureHelper.produced(requested, 1); if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } else { SpscLinkedArrayQueue q = getOrCreateQueue(); @@ -228,11 +228,11 @@ void innerError(InnerObserver inner, Throwable e) { set.delete(inner); if (errors.addThrowable(e)) { if (!delayErrors) { - s.cancel(); + upstream.cancel(); set.dispose(); } else { if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } active.decrementAndGet(); @@ -252,15 +252,15 @@ void innerComplete(InnerObserver inner) { if (d && (q == null || q.isEmpty())) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } return; } if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } if (decrementAndGet() == 0) { return; @@ -269,7 +269,7 @@ void innerComplete(InnerObserver inner) { } else { active.decrementAndGet(); if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } drain(); } @@ -290,7 +290,7 @@ void clear() { void drainLoop() { int missed = 1; - Subscriber a = actual; + Subscriber a = downstream; AtomicInteger n = active; AtomicReference> qr = queue; @@ -372,7 +372,7 @@ void drainLoop() { if (e != 0L) { BackpressureHelper.produced(requested, e); if (maxConcurrency != Integer.MAX_VALUE) { - s.request(e); + upstream.request(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingle.java index 0b6c4bc9be..0633248d8c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingle.java @@ -60,7 +60,7 @@ static final class FlatMapSingleSubscriber private static final long serialVersionUID = 8600231336733376951L; - final Subscriber actual; + final Subscriber downstream; final boolean delayErrors; @@ -78,13 +78,13 @@ static final class FlatMapSingleSubscriber final AtomicReference> queue; - Subscription s; + Subscription upstream; volatile boolean cancelled; FlatMapSingleSubscriber(Subscriber actual, Function> mapper, boolean delayErrors, int maxConcurrency) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.delayErrors = delayErrors; this.maxConcurrency = maxConcurrency; @@ -97,10 +97,10 @@ static final class FlatMapSingleSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); int m = maxConcurrency; if (m == Integer.MAX_VALUE) { @@ -119,7 +119,7 @@ public void onNext(T t) { ms = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null SingleSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); return; } @@ -155,7 +155,7 @@ public void onComplete() { @Override public void cancel() { cancelled = true; - s.cancel(); + upstream.cancel(); set.dispose(); } @@ -172,22 +172,22 @@ void innerSuccess(InnerObserver inner, R value) { if (get() == 0 && compareAndSet(0, 1)) { boolean d = active.decrementAndGet() == 0; if (requested.get() != 0) { - actual.onNext(value); + downstream.onNext(value); SpscLinkedArrayQueue q = queue.get(); if (d && (q == null || q.isEmpty())) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } return; } BackpressureHelper.produced(requested, 1); if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } else { SpscLinkedArrayQueue q = getOrCreateQueue(); @@ -228,11 +228,11 @@ void innerError(InnerObserver inner, Throwable e) { set.delete(inner); if (errors.addThrowable(e)) { if (!delayErrors) { - s.cancel(); + upstream.cancel(); set.dispose(); } else { if (maxConcurrency != Integer.MAX_VALUE) { - s.request(1); + upstream.request(1); } } active.decrementAndGet(); @@ -257,7 +257,7 @@ void clear() { void drainLoop() { int missed = 1; - Subscriber a = actual; + Subscriber a = downstream; AtomicInteger n = active; AtomicReference> qr = queue; @@ -339,7 +339,7 @@ void drainLoop() { if (e != 0L) { BackpressureHelper.produced(requested, e); if (maxConcurrency != Integer.MAX_VALUE) { - s.request(e); + upstream.request(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterable.java index 12b1095fa8..29e425f58e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterable.java @@ -88,7 +88,7 @@ static final class FlattenIterableSubscriber private static final long serialVersionUID = -3096000382929934955L; - final Subscriber actual; + final Subscriber downstream; final Function> mapper; @@ -98,7 +98,7 @@ static final class FlattenIterableSubscriber final AtomicLong requested; - Subscription s; + Subscription upstream; SimpleQueue queue; @@ -116,7 +116,7 @@ static final class FlattenIterableSubscriber FlattenIterableSubscriber(Subscriber actual, Function> mapper, int prefetch) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.prefetch = prefetch; this.limit = prefetch - (prefetch >> 2); @@ -126,8 +126,8 @@ static final class FlattenIterableSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") @@ -140,7 +140,7 @@ public void onSubscribe(Subscription s) { this.queue = qs; done = true; - actual.onSubscribe(this); + downstream.onSubscribe(this); return; } @@ -148,7 +148,7 @@ public void onSubscribe(Subscription s) { fusionMode = m; this.queue = qs; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(prefetch); return; @@ -157,7 +157,7 @@ public void onSubscribe(Subscription s) { queue = new SpscArrayQueue(prefetch); - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(prefetch); } @@ -207,7 +207,7 @@ public void cancel() { if (!cancelled) { cancelled = true; - s.cancel(); + upstream.cancel(); if (getAndIncrement() == 0) { queue.clear(); @@ -220,7 +220,7 @@ void drain() { return; } - final Subscriber a = actual; + final Subscriber a = downstream; final SimpleQueue q = queue; final boolean replenish = fusionMode != SYNC; @@ -240,7 +240,7 @@ void drain() { t = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); ExceptionHelper.addThrowable(error, ex); ex = ExceptionHelper.terminate(error); @@ -270,7 +270,7 @@ void drain() { b = it.hasNext(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); ExceptionHelper.addThrowable(error, ex); ex = ExceptionHelper.terminate(error); a.onError(ex); @@ -303,7 +303,7 @@ void drain() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); current = null; - s.cancel(); + upstream.cancel(); ExceptionHelper.addThrowable(error, ex); ex = ExceptionHelper.terminate(error); a.onError(ex); @@ -325,7 +325,7 @@ void drain() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); current = null; - s.cancel(); + upstream.cancel(); ExceptionHelper.addThrowable(error, ex); ex = ExceptionHelper.terminate(error); a.onError(ex); @@ -372,7 +372,7 @@ void consumedOne(boolean enabled) { int c = consumed + 1; if (c == limit) { consumed = 0; - s.request(c); + upstream.request(c); } else { consumed = c; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java index b6819d06d5..462a72481f 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java @@ -109,18 +109,18 @@ static final class ArraySubscription extends BaseArraySubscription { private static final long serialVersionUID = 2587302975077663557L; - final Subscriber actual; + final Subscriber downstream; ArraySubscription(Subscriber actual, T[] array) { super(array); - this.actual = actual; + this.downstream = actual; } @Override void fastPath() { T[] arr = array; int f = arr.length; - Subscriber a = actual; + Subscriber a = downstream; for (int i = index; i != f; i++) { if (cancelled) { @@ -146,7 +146,7 @@ void slowPath(long r) { T[] arr = array; int f = arr.length; int i = index; - Subscriber a = actual; + Subscriber a = downstream; for (;;) { @@ -193,18 +193,18 @@ static final class ArrayConditionalSubscription extends BaseArraySubscription private static final long serialVersionUID = 2587302975077663557L; - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; ArrayConditionalSubscription(ConditionalSubscriber actual, T[] array) { super(array); - this.actual = actual; + this.downstream = actual; } @Override void fastPath() { T[] arr = array; int f = arr.length; - ConditionalSubscriber a = actual; + ConditionalSubscriber a = downstream; for (int i = index; i != f; i++) { if (cancelled) { @@ -230,7 +230,7 @@ void slowPath(long r) { T[] arr = array; int f = arr.length; int i = index; - ConditionalSubscriber a = actual; + ConditionalSubscriber a = downstream; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java index ac1b0238dc..9cf14837b6 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java @@ -144,17 +144,17 @@ static final class IteratorSubscription extends BaseRangeSubscription { private static final long serialVersionUID = -6022804456014692607L; - final Subscriber actual; + final Subscriber downstream; IteratorSubscription(Subscriber actual, Iterator it) { super(it); - this.actual = actual; + this.downstream = actual; } @Override void fastPath() { Iterator it = this.it; - Subscriber a = actual; + Subscriber a = downstream; for (;;) { if (cancelled) { return; @@ -209,7 +209,7 @@ void fastPath() { void slowPath(long r) { long e = 0L; Iterator it = this.it; - Subscriber a = actual; + Subscriber a = downstream; for (;;) { @@ -282,17 +282,17 @@ static final class IteratorConditionalSubscription extends BaseRangeSubscript private static final long serialVersionUID = -6022804456014692607L; - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; IteratorConditionalSubscription(ConditionalSubscriber actual, Iterator it) { super(it); - this.actual = actual; + this.downstream = actual; } @Override void fastPath() { Iterator it = this.it; - ConditionalSubscriber a = actual; + ConditionalSubscriber a = downstream; for (;;) { if (cancelled) { return; @@ -346,7 +346,7 @@ void fastPath() { void slowPath(long r) { long e = 0L; Iterator it = this.it; - ConditionalSubscriber a = actual; + ConditionalSubscriber a = downstream; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromObservable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromObservable.java index 7b24ab0ce1..7ad4edb269 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromObservable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromObservable.java @@ -29,37 +29,39 @@ protected void subscribeActual(Subscriber s) { upstream.subscribe(new SubscriberObserver(s)); } - static class SubscriberObserver implements Observer, Subscription { - private final Subscriber s; - private Disposable d; + static final class SubscriberObserver implements Observer, Subscription { + + final Subscriber downstream; + + Disposable upstream; SubscriberObserver(Subscriber s) { - this.s = s; + this.downstream = s; } @Override public void onComplete() { - s.onComplete(); + downstream.onComplete(); } @Override public void onError(Throwable e) { - s.onError(e); + downstream.onError(e); } @Override public void onNext(T value) { - s.onNext(value); + downstream.onNext(value); } @Override public void onSubscribe(Disposable d) { - this.d = d; - s.onSubscribe(this); + this.upstream = d; + downstream.onSubscribe(this); } @Override public void cancel() { - d.dispose(); + upstream.dispose(); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGenerate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGenerate.java index 54a44151f3..17bdd790b9 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGenerate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGenerate.java @@ -58,7 +58,7 @@ static final class GeneratorSubscription private static final long serialVersionUID = 7565982551505011832L; - final Subscriber actual; + final Subscriber downstream; final BiFunction, S> generator; final Consumer disposeState; @@ -73,7 +73,7 @@ static final class GeneratorSubscription GeneratorSubscription(Subscriber actual, BiFunction, S> generator, Consumer disposeState, S initialState) { - this.actual = actual; + this.downstream = actual; this.generator = generator; this.disposeState = disposeState; this.state = initialState; @@ -171,7 +171,7 @@ public void onNext(T t) { onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); } else { hasNext = true; - actual.onNext(t); + downstream.onNext(t); } } } @@ -186,7 +186,7 @@ public void onError(Throwable t) { t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } terminate = true; - actual.onError(t); + downstream.onError(t); } } @@ -194,7 +194,7 @@ public void onError(Throwable t) { public void onComplete() { if (!terminate) { terminate = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java index 568cd5141c..14fbc74b99 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java @@ -84,7 +84,7 @@ public static final class GroupBySubscriber private static final long serialVersionUID = -3688291656102519502L; - final Subscriber> actual; + final Subscriber> downstream; final Function keySelector; final Function valueSelector; final int bufferSize; @@ -95,7 +95,7 @@ public static final class GroupBySubscriber static final Object NULL_KEY = new Object(); - Subscription s; + Subscription upstream; final AtomicBoolean cancelled = new AtomicBoolean(); @@ -112,7 +112,7 @@ public static final class GroupBySubscriber public GroupBySubscriber(Subscriber> actual, Function keySelector, Function valueSelector, int bufferSize, boolean delayError, Map> groups, Queue> evictedGroups) { - this.actual = actual; + this.downstream = actual; this.keySelector = keySelector; this.valueSelector = valueSelector; this.bufferSize = bufferSize; @@ -124,9 +124,9 @@ public GroupBySubscriber(Subscriber> actual, Funct @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(bufferSize); } } @@ -144,7 +144,7 @@ public void onNext(T t) { key = keySelector.apply(t); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); return; } @@ -172,7 +172,7 @@ public void onNext(T t) { v = ObjectHelper.requireNonNull(valueSelector.apply(t), "The valueSelector returned null"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); return; } @@ -237,7 +237,7 @@ public void cancel() { if (cancelled.compareAndSet(false, true)) { completeEvictions(); if (groupCount.decrementAndGet() == 0) { - s.cancel(); + upstream.cancel(); } } } @@ -260,7 +260,7 @@ public void cancel(K key) { Object mapKey = key != null ? key : NULL_KEY; groups.remove(mapKey); if (groupCount.decrementAndGet() == 0) { - s.cancel(); + upstream.cancel(); if (getAndIncrement() == 0) { queue.clear(); @@ -284,7 +284,7 @@ void drainFused() { int missed = 1; final SpscLinkedArrayQueue> q = this.queue; - final Subscriber> a = this.actual; + final Subscriber> a = this.downstream; for (;;) { if (cancelled.get()) { @@ -326,7 +326,7 @@ void drainNormal() { int missed = 1; final SpscLinkedArrayQueue> q = this.queue; - final Subscriber> a = this.actual; + final Subscriber> a = this.downstream; for (;;) { @@ -361,7 +361,7 @@ void drainNormal() { if (r != Long.MAX_VALUE) { requested.addAndGet(-e); } - s.request(e); + upstream.request(e); } missed = addAndGet(-missed); @@ -645,7 +645,7 @@ void drainNormal() { if (r != Long.MAX_VALUE) { requested.addAndGet(-e); } - parent.s.request(e); + parent.upstream.request(e); } } @@ -713,7 +713,7 @@ public T poll() { int p = produced; if (p != 0) { produced = 0; - parent.s.request(p); + parent.upstream.request(p); } return null; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java index c0bfb84e6f..d42e3e05af 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java @@ -92,7 +92,7 @@ static final class GroupJoinSubscription private static final long serialVersionUID = -6071216598687999801L; - final Subscriber actual; + final Subscriber downstream; final AtomicLong requested; @@ -131,7 +131,7 @@ static final class GroupJoinSubscription GroupJoinSubscription(Subscriber actual, Function> leftEnd, Function> rightEnd, BiFunction, ? extends R> resultSelector) { - this.actual = actual; + this.downstream = actual; this.requested = new AtomicLong(); this.disposables = new CompositeDisposable(); this.queue = new SpscLinkedArrayQueue(bufferSize()); @@ -195,7 +195,7 @@ void drain() { int missed = 1; SpscLinkedArrayQueue q = queue; - Subscriber a = actual; + Subscriber a = downstream; for (;;) { for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableHide.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableHide.java index a0d3a33467..0e5f7cc14f 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableHide.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableHide.java @@ -37,45 +37,45 @@ protected void subscribeActual(Subscriber s) { static final class HideSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; - Subscription s; + Subscription upstream; - HideSubscriber(Subscriber actual) { - this.actual = actual; + HideSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElements.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElements.java index 270f99e31f..443baf3989 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElements.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElements.java @@ -32,19 +32,19 @@ protected void subscribeActual(final Subscriber t) { } static final class IgnoreElementsSubscriber implements FlowableSubscriber, QueueSubscription { - final Subscriber actual; + final Subscriber downstream; - Subscription s; + Subscription upstream; - IgnoreElementsSubscriber(Subscriber actual) { - this.actual = actual; + IgnoreElementsSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -56,12 +56,12 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override @@ -97,7 +97,7 @@ public void request(long n) { @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsCompletable.java index 88e7577c5a..fc59ae9d8e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsCompletable.java @@ -40,19 +40,19 @@ public Flowable fuseToFlowable() { } static final class IgnoreElementsSubscriber implements FlowableSubscriber, Disposable { - final CompletableObserver actual; + final CompletableObserver downstream; - Subscription s; + Subscription upstream; - IgnoreElementsSubscriber(CompletableObserver actual) { - this.actual = actual; + IgnoreElementsSubscriber(CompletableObserver downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -64,25 +64,25 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override public void onComplete() { - s = SubscriptionHelper.CANCELLED; - actual.onComplete(); + upstream = SubscriptionHelper.CANCELLED; + downstream.onComplete(); } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableInterval.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableInterval.java index ca97aa34e6..35a09373cc 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableInterval.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableInterval.java @@ -62,14 +62,14 @@ static final class IntervalSubscriber extends AtomicLong private static final long serialVersionUID = -2809475196591179431L; - final Subscriber actual; + final Subscriber downstream; long count; final AtomicReference resource = new AtomicReference(); - IntervalSubscriber(Subscriber actual) { - this.actual = actual; + IntervalSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override @@ -90,10 +90,10 @@ public void run() { long r = get(); if (r != 0L) { - actual.onNext(count++); + downstream.onNext(count++); BackpressureHelper.produced(this, 1); } else { - actual.onError(new MissingBackpressureException("Can't deliver value " + count + " due to lack of requests")); + downstream.onError(new MissingBackpressureException("Can't deliver value " + count + " due to lack of requests")); DisposableHelper.dispose(resource); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableIntervalRange.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableIntervalRange.java index fa697dba41..739460884b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableIntervalRange.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableIntervalRange.java @@ -66,7 +66,7 @@ static final class IntervalRangeSubscriber extends AtomicLong private static final long serialVersionUID = -2809475196591179431L; - final Subscriber actual; + final Subscriber downstream; final long end; long count; @@ -74,7 +74,7 @@ static final class IntervalRangeSubscriber extends AtomicLong final AtomicReference resource = new AtomicReference(); IntervalRangeSubscriber(Subscriber actual, long start, long end) { - this.actual = actual; + this.downstream = actual; this.count = start; this.end = end; } @@ -98,11 +98,11 @@ public void run() { if (r != 0L) { long c = count; - actual.onNext(c); + downstream.onNext(c); if (c == end) { if (resource.get() != DisposableHelper.DISPOSED) { - actual.onComplete(); + downstream.onComplete(); } DisposableHelper.dispose(resource); return; @@ -114,7 +114,7 @@ public void run() { decrementAndGet(); } } else { - actual.onError(new MissingBackpressureException("Can't deliver value " + count + " due to lack of requests")); + downstream.onError(new MissingBackpressureException("Can't deliver value " + count + " due to lack of requests")); DisposableHelper.dispose(resource); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableJoin.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableJoin.java index 36674f13fd..5ff5c97c3f 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableJoin.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableJoin.java @@ -76,7 +76,7 @@ static final class JoinSubscription private static final long serialVersionUID = -6071216598687999801L; - final Subscriber actual; + final Subscriber downstream; final AtomicLong requested; @@ -115,7 +115,7 @@ static final class JoinSubscription JoinSubscription(Subscriber actual, Function> leftEnd, Function> rightEnd, BiFunction resultSelector) { - this.actual = actual; + this.downstream = actual; this.requested = new AtomicLong(); this.disposables = new CompositeDisposable(); this.queue = new SpscLinkedArrayQueue(bufferSize()); @@ -175,7 +175,7 @@ void drain() { int missed = 1; SpscLinkedArrayQueue q = queue; - Subscriber a = actual; + Subscriber a = downstream; for (;;) { for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableLastMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableLastMaybe.java index ef36a4bd80..e27efeb403 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableLastMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableLastMaybe.java @@ -41,33 +41,33 @@ protected void subscribeActual(MaybeObserver observer) { static final class LastSubscriber implements FlowableSubscriber, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Subscription s; + Subscription upstream; T item; - LastSubscriber(MaybeObserver actual) { - this.actual = actual; + LastSubscriber(MaybeObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -80,20 +80,20 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; item = null; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; T v = item; if (v != null) { item = null; - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableLastSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableLastSingle.java index 8c8a12ee05..344c6f3668 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableLastSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableLastSingle.java @@ -47,36 +47,36 @@ protected void subscribeActual(SingleObserver observer) { static final class LastSubscriber implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final T defaultItem; - Subscription s; + Subscription upstream; T item; LastSubscriber(SingleObserver actual, T defaultItem) { - this.actual = actual; + this.downstream = actual; this.defaultItem = defaultItem; } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -89,25 +89,25 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; item = null; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; T v = item; if (v != null) { item = null; - actual.onSuccess(v); + downstream.onSuccess(v); } else { v = defaultItem; if (v != null) { - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableLimit.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableLimit.java index a49758dd53..58004d0c69 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableLimit.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableLimit.java @@ -47,14 +47,14 @@ static final class LimitSubscriber private static final long serialVersionUID = 2288246011222124525L; - final Subscriber actual; + final Subscriber downstream; long remaining; Subscription upstream; LimitSubscriber(Subscriber actual, long remaining) { - this.actual = actual; + this.downstream = actual; this.remaining = remaining; lazySet(remaining); } @@ -64,10 +64,10 @@ public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.upstream, s)) { if (remaining == 0L) { s.cancel(); - EmptySubscription.complete(actual); + EmptySubscription.complete(downstream); } else { this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } } @@ -77,10 +77,10 @@ public void onNext(T t) { long r = remaining; if (r > 0L) { remaining = --r; - actual.onNext(t); + downstream.onNext(t); if (r == 0L) { upstream.cancel(); - actual.onComplete(); + downstream.onComplete(); } } } @@ -89,7 +89,7 @@ public void onNext(T t) { public void onError(Throwable t) { if (remaining > 0L) { remaining = 0L; - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -99,7 +99,7 @@ public void onError(Throwable t) { public void onComplete() { if (remaining > 0L) { remaining = 0L; - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMap.java index e9df5a6726..905f3cb6cb 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMap.java @@ -54,7 +54,7 @@ public void onNext(T t) { } if (sourceMode != NONE) { - actual.onNext(null); + downstream.onNext(null); return; } @@ -66,7 +66,7 @@ public void onNext(T t) { fail(ex); return; } - actual.onNext(v); + downstream.onNext(v); } @Override @@ -97,7 +97,7 @@ public void onNext(T t) { } if (sourceMode != NONE) { - actual.onNext(null); + downstream.onNext(null); return; } @@ -109,7 +109,7 @@ public void onNext(T t) { fail(ex); return; } - actual.onNext(v); + downstream.onNext(v); } @Override @@ -126,7 +126,7 @@ public boolean tryOnNext(T t) { fail(ex); return true; } - return actual.tryOnNext(v); + return downstream.tryOnNext(v); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapNotification.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapNotification.java index 0f0ec91d68..4b90d60ea3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapNotification.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapNotification.java @@ -71,12 +71,12 @@ public void onNext(T t) { p = ObjectHelper.requireNonNull(onNextMapper.apply(t), "The onNext publisher returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } produced++; - actual.onNext(p); + downstream.onNext(p); } @Override @@ -87,7 +87,7 @@ public void onError(Throwable t) { p = ObjectHelper.requireNonNull(onErrorMapper.apply(t), "The onError publisher returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); return; } @@ -102,7 +102,7 @@ public void onComplete() { p = ObjectHelper.requireNonNull(onCompleteSupplier.call(), "The onComplete publisher returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMaterialize.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMaterialize.java index 3bceba2dea..91f58105ee 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMaterialize.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMaterialize.java @@ -34,14 +34,14 @@ static final class MaterializeSubscriber extends SinglePostCompleteSubscriber private static final long serialVersionUID = -3740826063558713822L; - MaterializeSubscriber(Subscriber> actual) { - super(actual); + MaterializeSubscriber(Subscriber> downstream) { + super(downstream); } @Override public void onNext(T t) { produced++; - actual.onNext(Notification.createOnNext(t)); + downstream.onNext(Notification.createOnNext(t)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java index 27f8652ff3..271bd9c50d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java @@ -52,7 +52,7 @@ static final class MergeWithSubscriber extends AtomicInteger private static final long serialVersionUID = -4592979584110982903L; - final Subscriber actual; + final Subscriber downstream; final AtomicReference mainSubscription; @@ -66,8 +66,8 @@ static final class MergeWithSubscriber extends AtomicInteger volatile boolean otherDone; - MergeWithSubscriber(Subscriber actual) { - this.actual = actual; + MergeWithSubscriber(Subscriber downstream) { + this.downstream = downstream; this.mainSubscription = new AtomicReference(); this.otherObserver = new OtherObserver(this); this.error = new AtomicThrowable(); @@ -75,26 +75,26 @@ static final class MergeWithSubscriber extends AtomicInteger } @Override - public void onSubscribe(Subscription d) { - SubscriptionHelper.deferredSetOnce(mainSubscription, requested, d); + public void onSubscribe(Subscription s) { + SubscriptionHelper.deferredSetOnce(mainSubscription, requested, s); } @Override public void onNext(T t) { - HalfSerializer.onNext(actual, t, this, error); + HalfSerializer.onNext(downstream, t, this, error); } @Override public void onError(Throwable ex) { SubscriptionHelper.cancel(mainSubscription); - HalfSerializer.onError(actual, ex, this, error); + HalfSerializer.onError(downstream, ex, this, error); } @Override public void onComplete() { mainDone = true; if (otherDone) { - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } } @@ -111,13 +111,13 @@ public void cancel() { void otherError(Throwable ex) { SubscriptionHelper.cancel(mainSubscription); - HalfSerializer.onError(actual, ex, this, error); + HalfSerializer.onError(downstream, ex, this, error); } void otherComplete() { otherDone = true; if (mainDone) { - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java index 08430c4a70..a32a0c92fc 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java @@ -55,7 +55,7 @@ static final class MergeWithObserver extends AtomicInteger private static final long serialVersionUID = -4592979584110982903L; - final Subscriber actual; + final Subscriber downstream; final AtomicReference mainSubscription; @@ -87,8 +87,8 @@ static final class MergeWithObserver extends AtomicInteger static final int OTHER_STATE_CONSUMED_OR_EMPTY = 2; - MergeWithObserver(Subscriber actual) { - this.actual = actual; + MergeWithObserver(Subscriber downstream) { + this.downstream = downstream; this.mainSubscription = new AtomicReference(); this.otherObserver = new OtherObserver(this); this.error = new AtomicThrowable(); @@ -111,7 +111,7 @@ public void onNext(T t) { if (q == null || q.isEmpty()) { emitted = e + 1; - actual.onNext(t); + downstream.onNext(t); int c = consumed + 1; if (c == limit) { @@ -179,7 +179,7 @@ void otherSuccess(T value) { if (requested.get() != e) { emitted = e + 1; - actual.onNext(value); + downstream.onNext(value); otherState = OTHER_STATE_CONSUMED_OR_EMPTY; } else { singleItem = value; @@ -228,7 +228,7 @@ void drain() { } void drainLoop() { - Subscriber actual = this.actual; + Subscriber actual = this.downstream; int missed = 1; long e = emitted; int c = consumed; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java index 0fee2fa12c..586bc07c07 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java @@ -55,7 +55,7 @@ static final class MergeWithObserver extends AtomicInteger private static final long serialVersionUID = -4592979584110982903L; - final Subscriber actual; + final Subscriber downstream; final AtomicReference mainSubscription; @@ -87,8 +87,8 @@ static final class MergeWithObserver extends AtomicInteger static final int OTHER_STATE_CONSUMED_OR_EMPTY = 2; - MergeWithObserver(Subscriber actual) { - this.actual = actual; + MergeWithObserver(Subscriber downstream) { + this.downstream = downstream; this.mainSubscription = new AtomicReference(); this.otherObserver = new OtherObserver(this); this.error = new AtomicThrowable(); @@ -111,7 +111,7 @@ public void onNext(T t) { if (q == null || q.isEmpty()) { emitted = e + 1; - actual.onNext(t); + downstream.onNext(t); int c = consumed + 1; if (c == limit) { @@ -179,7 +179,7 @@ void otherSuccess(T value) { if (requested.get() != e) { emitted = e + 1; - actual.onNext(value); + downstream.onNext(value); otherState = OTHER_STATE_CONSUMED_OR_EMPTY; } else { singleItem = value; @@ -223,7 +223,7 @@ void drain() { } void drainLoop() { - Subscriber actual = this.actual; + Subscriber actual = this.downstream; int missed = 1; long e = emitted; int c = consumed; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java index aaf515bf77..d1c97b6801 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java @@ -72,7 +72,7 @@ abstract static class BaseObserveOnSubscriber final AtomicLong requested; - Subscription s; + Subscription upstream; SimpleQueue queue; @@ -109,7 +109,7 @@ public final void onNext(T t) { return; } if (!queue.offer(t)) { - s.cancel(); + upstream.cancel(); error = new MissingBackpressureException("Queue is full?!"); done = true; @@ -151,7 +151,7 @@ public final void cancel() { } cancelled = true; - s.cancel(); + upstream.cancel(); worker.dispose(); if (getAndIncrement() == 0) { @@ -244,7 +244,7 @@ static final class ObserveOnSubscriber extends BaseObserveOnSubscriber private static final long serialVersionUID = -4547113800637756442L; - final Subscriber actual; + final Subscriber downstream; ObserveOnSubscriber( Subscriber actual, @@ -252,13 +252,13 @@ static final class ObserveOnSubscriber extends BaseObserveOnSubscriber boolean delayError, int prefetch) { super(worker, delayError, prefetch); - this.actual = actual; + this.downstream = actual; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") @@ -271,14 +271,14 @@ public void onSubscribe(Subscription s) { queue = f; done = true; - actual.onSubscribe(this); + downstream.onSubscribe(this); return; } else if (m == ASYNC) { sourceMode = ASYNC; queue = f; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(prefetch); @@ -288,7 +288,7 @@ public void onSubscribe(Subscription s) { queue = new SpscArrayQueue(prefetch); - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(prefetch); } @@ -298,7 +298,7 @@ public void onSubscribe(Subscription s) { void runSync() { int missed = 1; - final Subscriber a = actual; + final Subscriber a = downstream; final SimpleQueue q = queue; long e = produced; @@ -314,7 +314,7 @@ void runSync() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); a.onError(ex); worker.dispose(); return; @@ -361,7 +361,7 @@ void runSync() { void runAsync() { int missed = 1; - final Subscriber a = actual; + final Subscriber a = downstream; final SimpleQueue q = queue; long e = produced; @@ -379,7 +379,7 @@ void runAsync() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); q.clear(); a.onError(ex); @@ -404,7 +404,7 @@ void runAsync() { if (r != Long.MAX_VALUE) { r = requested.addAndGet(-e); } - s.request(e); + upstream.request(e); e = 0L; } } @@ -438,14 +438,14 @@ void runBackfused() { boolean d = done; - actual.onNext(null); + downstream.onNext(null); if (d) { Throwable e = error; if (e != null) { - actual.onError(e); + downstream.onError(e); } else { - actual.onComplete(); + downstream.onComplete(); } worker.dispose(); return; @@ -466,7 +466,7 @@ public T poll() throws Exception { long p = produced + 1; if (p == limit) { produced = 0; - s.request(p); + upstream.request(p); } else { produced = p; } @@ -481,7 +481,7 @@ static final class ObserveOnConditionalSubscriber private static final long serialVersionUID = 644624475404284533L; - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; long consumed; @@ -491,13 +491,13 @@ static final class ObserveOnConditionalSubscriber boolean delayError, int prefetch) { super(worker, delayError, prefetch); - this.actual = actual; + this.downstream = actual; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") @@ -510,14 +510,14 @@ public void onSubscribe(Subscription s) { queue = f; done = true; - actual.onSubscribe(this); + downstream.onSubscribe(this); return; } else if (m == ASYNC) { sourceMode = ASYNC; queue = f; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(prefetch); @@ -527,7 +527,7 @@ public void onSubscribe(Subscription s) { queue = new SpscArrayQueue(prefetch); - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(prefetch); } @@ -537,7 +537,7 @@ public void onSubscribe(Subscription s) { void runSync() { int missed = 1; - final ConditionalSubscriber a = actual; + final ConditionalSubscriber a = downstream; final SimpleQueue q = queue; long e = produced; @@ -552,7 +552,7 @@ void runSync() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); a.onError(ex); worker.dispose(); return; @@ -599,7 +599,7 @@ void runSync() { void runAsync() { int missed = 1; - final ConditionalSubscriber a = actual; + final ConditionalSubscriber a = downstream; final SimpleQueue q = queue; long emitted = produced; @@ -617,7 +617,7 @@ void runAsync() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); q.clear(); a.onError(ex); @@ -641,7 +641,7 @@ void runAsync() { polled++; if (polled == limit) { - s.request(polled); + upstream.request(polled); polled = 0L; } } @@ -677,14 +677,14 @@ void runBackfused() { boolean d = done; - actual.onNext(null); + downstream.onNext(null); if (d) { Throwable e = error; if (e != null) { - actual.onError(e); + downstream.onError(e); } else { - actual.onComplete(); + downstream.onComplete(); } worker.dispose(); return; @@ -705,7 +705,7 @@ public T poll() throws Exception { long p = consumed + 1; if (p == limit) { consumed = 0; - s.request(p); + upstream.request(p); } else { consumed = p; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBuffer.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBuffer.java index 341cda93c8..20caa2c7e3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBuffer.java @@ -50,12 +50,12 @@ static final class BackpressureBufferSubscriber extends BasicIntQueueSubscrip private static final long serialVersionUID = -2514538129242366402L; - final Subscriber actual; + final Subscriber downstream; final SimplePlainQueue queue; final boolean delayError; final Action onOverflow; - Subscription s; + Subscription upstream; volatile boolean cancelled; @@ -68,7 +68,7 @@ static final class BackpressureBufferSubscriber extends BasicIntQueueSubscrip BackpressureBufferSubscriber(Subscriber actual, int bufferSize, boolean unbounded, boolean delayError, Action onOverflow) { - this.actual = actual; + this.downstream = actual; this.onOverflow = onOverflow; this.delayError = delayError; @@ -85,9 +85,9 @@ static final class BackpressureBufferSubscriber extends BasicIntQueueSubscrip @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -95,7 +95,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (!queue.offer(t)) { - s.cancel(); + upstream.cancel(); MissingBackpressureException ex = new MissingBackpressureException("Buffer is full"); try { onOverflow.run(); @@ -107,7 +107,7 @@ public void onNext(T t) { return; } if (outputFused) { - actual.onNext(null); + downstream.onNext(null); } else { drain(); } @@ -118,7 +118,7 @@ public void onError(Throwable t) { error = t; done = true; if (outputFused) { - actual.onError(t); + downstream.onError(t); } else { drain(); } @@ -128,7 +128,7 @@ public void onError(Throwable t) { public void onComplete() { done = true; if (outputFused) { - actual.onComplete(); + downstream.onComplete(); } else { drain(); } @@ -148,7 +148,7 @@ public void request(long n) { public void cancel() { if (!cancelled) { cancelled = true; - s.cancel(); + upstream.cancel(); if (getAndIncrement() == 0) { queue.clear(); @@ -160,7 +160,7 @@ void drain() { if (getAndIncrement() == 0) { int missed = 1; final SimplePlainQueue q = queue; - final Subscriber a = actual; + final Subscriber a = downstream; for (;;) { if (checkTerminated(done, q.isEmpty(), a)) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategy.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategy.java index 7f3cdf8017..f11a520e7b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategy.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategy.java @@ -57,7 +57,7 @@ static final class OnBackpressureBufferStrategySubscriber private static final long serialVersionUID = 3240706908776709697L; - final Subscriber actual; + final Subscriber downstream; final Action onOverflow; @@ -69,7 +69,7 @@ static final class OnBackpressureBufferStrategySubscriber final Deque deque; - Subscription s; + Subscription upstream; volatile boolean cancelled; @@ -78,7 +78,7 @@ static final class OnBackpressureBufferStrategySubscriber OnBackpressureBufferStrategySubscriber(Subscriber actual, Action onOverflow, BackpressureOverflowStrategy strategy, long bufferSize) { - this.actual = actual; + this.downstream = actual; this.onOverflow = onOverflow; this.strategy = strategy; this.bufferSize = bufferSize; @@ -88,10 +88,10 @@ static final class OnBackpressureBufferStrategySubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -134,12 +134,12 @@ public void onNext(T t) { onOverflow.run(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); } } } else if (callError) { - s.cancel(); + upstream.cancel(); onError(new MissingBackpressureException()); } else { drain(); @@ -174,7 +174,7 @@ public void request(long n) { @Override public void cancel() { cancelled = true; - s.cancel(); + upstream.cancel(); if (getAndIncrement() == 0) { clear(deque); @@ -194,7 +194,7 @@ void drain() { int missed = 1; Deque dq = deque; - Subscriber a = actual; + Subscriber a = downstream; for (;;) { long r = requested.get(); long e = 0L; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureDrop.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureDrop.java index eb633af079..df5f4a7e86 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureDrop.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureDrop.java @@ -53,23 +53,23 @@ static final class BackpressureDropSubscriber private static final long serialVersionUID = -6246093802440953054L; - final Subscriber actual; + final Subscriber downstream; final Consumer onDrop; - Subscription s; + Subscription upstream; boolean done; BackpressureDropSubscriber(Subscriber actual, Consumer onDrop) { - this.actual = actual; + this.downstream = actual; this.onDrop = onDrop; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -81,7 +81,7 @@ public void onNext(T t) { } long r = get(); if (r != 0L) { - actual.onNext(t); + downstream.onNext(t); BackpressureHelper.produced(this, 1); } else { try { @@ -101,7 +101,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -110,7 +110,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } @Override @@ -122,7 +122,7 @@ public void request(long n) { @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java index a40f92aefd..139e61d410 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java @@ -40,19 +40,19 @@ static final class BackpressureErrorSubscriber extends AtomicLong implements FlowableSubscriber, Subscription { private static final long serialVersionUID = -3176480756392482682L; - final Subscriber actual; - Subscription s; + final Subscriber downstream; + Subscription upstream; boolean done; - BackpressureErrorSubscriber(Subscriber actual) { - this.actual = actual; + BackpressureErrorSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -64,7 +64,7 @@ public void onNext(T t) { } long r = get(); if (r != 0L) { - actual.onNext(t); + downstream.onNext(t); BackpressureHelper.produced(this, 1); } else { onError(new MissingBackpressureException("could not emit value due to lack of requests")); @@ -78,7 +78,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -87,7 +87,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } @Override @@ -99,7 +99,7 @@ public void request(long n) { @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatest.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatest.java index 2cd36a6ef0..f981b738e6 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatest.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatest.java @@ -36,9 +36,9 @@ static final class BackpressureLatestSubscriber extends AtomicInteger impleme private static final long serialVersionUID = 163080509307634843L; - final Subscriber actual; + final Subscriber downstream; - Subscription s; + Subscription upstream; volatile boolean done; Throwable error; @@ -49,15 +49,15 @@ static final class BackpressureLatestSubscriber extends AtomicInteger impleme final AtomicReference current = new AtomicReference(); - BackpressureLatestSubscriber(Subscriber actual) { - this.actual = actual; + BackpressureLatestSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -93,7 +93,7 @@ public void request(long n) { public void cancel() { if (!cancelled) { cancelled = true; - s.cancel(); + upstream.cancel(); if (getAndIncrement() == 0) { current.lazySet(null); @@ -105,7 +105,7 @@ void drain() { if (getAndIncrement() != 0) { return; } - final Subscriber a = actual; + final Subscriber a = downstream; int missed = 1; final AtomicLong r = requested; final AtomicReference q = current; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java index 8a36aad3ce..4d5b86c880 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java @@ -45,7 +45,7 @@ static final class OnErrorNextSubscriber implements FlowableSubscriber { private static final long serialVersionUID = 4063763155303814625L; - final Subscriber actual; + final Subscriber downstream; final Function> nextSupplier; @@ -58,7 +58,7 @@ static final class OnErrorNextSubscriber long produced; OnErrorNextSubscriber(Subscriber actual, Function> nextSupplier, boolean allowFatal) { - this.actual = actual; + this.downstream = actual; this.nextSupplier = nextSupplier; this.allowFatal = allowFatal; } @@ -76,7 +76,7 @@ public void onNext(T t) { if (!once) { produced++; } - actual.onNext(t); + downstream.onNext(t); } @Override @@ -86,13 +86,13 @@ public void onError(Throwable t) { RxJavaPlugins.onError(t); return; } - actual.onError(t); + downstream.onError(t); return; } once = true; if (allowFatal && !(t instanceof Exception)) { - actual.onError(t); + downstream.onError(t); return; } @@ -102,7 +102,7 @@ public void onError(Throwable t) { p = ObjectHelper.requireNonNull(nextSupplier.apply(t), "The nextSupplier returned a null Publisher"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); return; } @@ -121,7 +121,7 @@ public void onComplete() { } done = true; once = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturn.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturn.java index 333aa1cb27..baf47d608a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturn.java @@ -47,7 +47,7 @@ static final class OnErrorReturnSubscriber @Override public void onNext(T t) { produced++; - actual.onNext(t); + downstream.onNext(t); } @Override @@ -57,7 +57,7 @@ public void onError(Throwable t) { v = ObjectHelper.requireNonNull(valueSupplier.apply(t), "The valueSupplier returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(new CompositeException(t, ex)); + downstream.onError(new CompositeException(t, ex)); return; } complete(v); @@ -65,7 +65,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticast.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticast.java index 079ef019c6..b68e4cf711 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticast.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticast.java @@ -75,51 +75,51 @@ protected void subscribeActual(Subscriber s) { } static final class OutputCanceller implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final MulticastProcessor processor; - Subscription s; + Subscription upstream; OutputCanceller(Subscriber actual, MulticastProcessor processor) { - this.actual = actual; + this.downstream = actual; this.processor = processor; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(R t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); processor.dispose(); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); processor.dispose(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); processor.dispose(); } } @@ -142,7 +142,7 @@ static final class MulticastProcessor extends Flowable implements Flowable final boolean delayError; - final AtomicReference s; + final AtomicReference upstream; volatile SimpleQueue queue; @@ -159,13 +159,13 @@ static final class MulticastProcessor extends Flowable implements Flowable this.limit = prefetch - (prefetch >> 2); // request after 75% consumption this.delayError = delayError; this.wip = new AtomicInteger(); - this.s = new AtomicReference(); + this.upstream = new AtomicReference(); this.subscribers = new AtomicReference[]>(EMPTY); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.setOnce(this.s, s)) { + if (SubscriptionHelper.setOnce(this.upstream, s)) { if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") QueueSubscription qs = (QueueSubscription) s; @@ -194,7 +194,7 @@ public void onSubscribe(Subscription s) { @Override public void dispose() { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); if (wip.getAndIncrement() == 0) { SimpleQueue q = queue; if (q != null) { @@ -205,7 +205,7 @@ public void dispose() { @Override public boolean isDisposed() { - return SubscriptionHelper.isCancelled(s.get()); + return SubscriptionHelper.isCancelled(upstream.get()); } @Override @@ -214,7 +214,7 @@ public void onNext(T t) { return; } if (sourceMode == QueueSubscription.NONE && !queue.offer(t)) { - s.get().cancel(); + upstream.get().cancel(); onError(new MissingBackpressureException()); return; } @@ -372,7 +372,7 @@ void drain() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); errorAll(ex); return; } @@ -401,7 +401,7 @@ void drain() { if (msr != Long.MAX_VALUE) { ms.emitted++; } - ms.actual.onNext(v); + ms.downstream.onNext(v); } else { subscribersChange = true; } @@ -411,7 +411,7 @@ void drain() { if (canRequest && ++upstreamConsumed == localLimit) { upstreamConsumed = 0; - s.get().request(localLimit); + upstream.get().request(localLimit); } MulticastSubscription[] freshArray = subs.get(); @@ -465,7 +465,7 @@ void drain() { void errorAll(Throwable ex) { for (MulticastSubscription ms : subscribers.getAndSet(TERMINATED)) { if (ms.get() != Long.MIN_VALUE) { - ms.actual.onError(ex); + ms.downstream.onError(ex); } } } @@ -474,7 +474,7 @@ void errorAll(Throwable ex) { void completeAll() { for (MulticastSubscription ms : subscribers.getAndSet(TERMINATED)) { if (ms.get() != Long.MIN_VALUE) { - ms.actual.onComplete(); + ms.downstream.onComplete(); } } } @@ -486,14 +486,14 @@ static final class MulticastSubscription private static final long serialVersionUID = 8664815189257569791L; - final Subscriber actual; + final Subscriber downstream; final MulticastProcessor parent; long emitted; MulticastSubscription(Subscriber actual, MulticastProcessor parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java index 71e50073b8..198721943b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java @@ -111,17 +111,17 @@ static final class RangeSubscription extends BaseRangeSubscription { private static final long serialVersionUID = 2587302975077663557L; - final Subscriber actual; + final Subscriber downstream; RangeSubscription(Subscriber actual, int index, int end) { super(index, end); - this.actual = actual; + this.downstream = actual; } @Override void fastPath() { int f = end; - Subscriber a = actual; + Subscriber a = downstream; for (int i = index; i != f; i++) { if (cancelled) { @@ -140,7 +140,7 @@ void slowPath(long r) { long e = 0; int f = end; int i = index; - Subscriber a = actual; + Subscriber a = downstream; for (;;) { @@ -180,17 +180,17 @@ static final class RangeConditionalSubscription extends BaseRangeSubscription { private static final long serialVersionUID = 2587302975077663557L; - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; RangeConditionalSubscription(ConditionalSubscriber actual, int index, int end) { super(index, end); - this.actual = actual; + this.downstream = actual; } @Override void fastPath() { int f = end; - ConditionalSubscriber a = actual; + ConditionalSubscriber a = downstream; for (int i = index; i != f; i++) { if (cancelled) { @@ -209,7 +209,7 @@ void slowPath(long r) { long e = 0; int f = end; int i = index; - ConditionalSubscriber a = actual; + ConditionalSubscriber a = downstream; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRangeLong.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRangeLong.java index e049feb815..96bc5cddb0 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRangeLong.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRangeLong.java @@ -112,17 +112,17 @@ static final class RangeSubscription extends BaseRangeSubscription { private static final long serialVersionUID = 2587302975077663557L; - final Subscriber actual; + final Subscriber downstream; RangeSubscription(Subscriber actual, long index, long end) { super(index, end); - this.actual = actual; + this.downstream = actual; } @Override void fastPath() { long f = end; - Subscriber a = actual; + Subscriber a = downstream; for (long i = index; i != f; i++) { if (cancelled) { @@ -141,7 +141,7 @@ void slowPath(long r) { long e = 0; long f = end; long i = index; - Subscriber a = actual; + Subscriber a = downstream; for (;;) { @@ -181,17 +181,17 @@ static final class RangeConditionalSubscription extends BaseRangeSubscription { private static final long serialVersionUID = 2587302975077663557L; - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; RangeConditionalSubscription(ConditionalSubscriber actual, long index, long end) { super(index, end); - this.actual = actual; + this.downstream = actual; } @Override void fastPath() { long f = end; - ConditionalSubscriber a = actual; + ConditionalSubscriber a = downstream; for (long i = index; i != f; i++) { if (cancelled) { @@ -210,7 +210,7 @@ void slowPath(long r) { long e = 0; long f = end; long i = index; - ConditionalSubscriber a = actual; + ConditionalSubscriber a = downstream; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduce.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduce.java index b83fffd4f6..67be1d18fd 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduce.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduce.java @@ -48,7 +48,7 @@ static final class ReduceSubscriber extends DeferredScalarSubscription imp final BiFunction reducer; - Subscription s; + Subscription upstream; ReduceSubscriber(Subscriber actual, BiFunction reducer) { super(actual); @@ -57,10 +57,10 @@ static final class ReduceSubscriber extends DeferredScalarSubscription imp @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -68,7 +68,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { - if (s == SubscriptionHelper.CANCELLED) { + if (upstream == SubscriptionHelper.CANCELLED) { return; } @@ -80,7 +80,7 @@ public void onNext(T t) { value = ObjectHelper.requireNonNull(reducer.apply(v, t), "The reducer returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); } } @@ -88,34 +88,34 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - if (s == SubscriptionHelper.CANCELLED) { + if (upstream == SubscriptionHelper.CANCELLED) { RxJavaPlugins.onError(t); return; } - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override public void onComplete() { - if (s == SubscriptionHelper.CANCELLED) { + if (upstream == SubscriptionHelper.CANCELLED) { return; } - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; T v = value; if (v != null) { complete(v); } else { - actual.onComplete(); + downstream.onComplete(); } } @Override public void cancel() { super.cancel(); - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceMaybe.java index d6d4781033..7745c047a7 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceMaybe.java @@ -58,24 +58,24 @@ protected void subscribeActual(MaybeObserver observer) { } static final class ReduceSubscriber implements FlowableSubscriber, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final BiFunction reducer; T value; - Subscription s; + Subscription upstream; boolean done; ReduceSubscriber(MaybeObserver actual, BiFunction reducer) { - this.actual = actual; + this.downstream = actual; this.reducer = reducer; } @Override public void dispose() { - s.cancel(); + upstream.cancel(); done = true; } @@ -86,10 +86,10 @@ public boolean isDisposed() { @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -108,7 +108,7 @@ public void onNext(T t) { value = ObjectHelper.requireNonNull(reducer.apply(v, t), "The reducer returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); } } @@ -121,7 +121,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -133,9 +133,9 @@ public void onComplete() { T v = value; if (v != null) { // value = null; - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceSeedSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceSeedSingle.java index 5201f1b396..bcd1042d48 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceSeedSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceSeedSingle.java @@ -51,26 +51,26 @@ protected void subscribeActual(SingleObserver observer) { static final class ReduceSeedObserver implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final BiFunction reducer; R value; - Subscription s; + Subscription upstream; ReduceSeedObserver(SingleObserver actual, BiFunction reducer, R value) { - this.actual = actual; + this.downstream = actual; this.value = value; this.reducer = reducer; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -84,7 +84,7 @@ public void onNext(T value) { this.value = ObjectHelper.requireNonNull(reducer.apply(v, value), "The reducer returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); } } @@ -94,8 +94,8 @@ public void onNext(T value) { public void onError(Throwable e) { if (value != null) { value = null; - s = SubscriptionHelper.CANCELLED; - actual.onError(e); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -106,20 +106,20 @@ public void onComplete() { R v = value; if (v != null) { value = null; - s = SubscriptionHelper.CANCELLED; - actual.onSuccess(v); + upstream = SubscriptionHelper.CANCELLED; + downstream.onSuccess(v); } } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java index c9f03fdf2c..deec615b20 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java @@ -174,7 +174,7 @@ static final class RefCountSubscriber private static final long serialVersionUID = -7419642935409022375L; - final Subscriber actual; + final Subscriber downstream; final FlowableRefCount parent; @@ -183,21 +183,21 @@ static final class RefCountSubscriber Subscription upstream; RefCountSubscriber(Subscriber actual, FlowableRefCount parent, RefConnection connection) { - this.actual = actual; + this.downstream = actual; this.parent = parent; this.connection = connection; } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { if (compareAndSet(false, true)) { parent.terminated(connection); - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -207,7 +207,7 @@ public void onError(Throwable t) { public void onComplete() { if (compareAndSet(false, true)) { parent.terminated(connection); - actual.onComplete(); + downstream.onComplete(); } } @@ -229,7 +229,7 @@ public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(upstream, s)) { this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java index a3f7e15d09..fe48ac17ea 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java @@ -40,7 +40,7 @@ static final class RepeatSubscriber extends AtomicInteger implements Flowable private static final long serialVersionUID = -7098360935104053232L; - final Subscriber actual; + final Subscriber downstream; final SubscriptionArbiter sa; final Publisher source; long remaining; @@ -48,7 +48,7 @@ static final class RepeatSubscriber extends AtomicInteger implements Flowable long produced; RepeatSubscriber(Subscriber actual, long count, SubscriptionArbiter sa, Publisher source) { - this.actual = actual; + this.downstream = actual; this.sa = sa; this.source = source; this.remaining = count; @@ -62,11 +62,11 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { produced++; - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -78,7 +78,7 @@ public void onComplete() { if (r != 0L) { subscribeNext(); } else { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java index 250502c8b4..e2dbd532e8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java @@ -42,7 +42,7 @@ static final class RepeatSubscriber extends AtomicInteger implements Flowable private static final long serialVersionUID = -7098360935104053232L; - final Subscriber actual; + final Subscriber downstream; final SubscriptionArbiter sa; final Publisher source; final BooleanSupplier stop; @@ -50,7 +50,7 @@ static final class RepeatSubscriber extends AtomicInteger implements Flowable long produced; RepeatSubscriber(Subscriber actual, BooleanSupplier until, SubscriptionArbiter sa, Publisher source) { - this.actual = actual; + this.downstream = actual; this.sa = sa; this.source = source; this.stop = until; @@ -64,11 +64,11 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { produced++; - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -78,11 +78,11 @@ public void onComplete() { b = stop.getAsBoolean(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } if (b) { - actual.onComplete(); + downstream.onComplete(); } else { subscribeNext(); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java index a95433a74d..ce137d4f52 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java @@ -68,12 +68,11 @@ static final class WhenReceiver extends AtomicInteger implements FlowableSubscriber, Subscription { - private static final long serialVersionUID = 2827772011130406689L; final Publisher source; - final AtomicReference subscription; + final AtomicReference upstream; final AtomicLong requested; @@ -81,20 +80,20 @@ static final class WhenReceiver WhenReceiver(Publisher source) { this.source = source; - this.subscription = new AtomicReference(); + this.upstream = new AtomicReference(); this.requested = new AtomicLong(); } @Override public void onSubscribe(Subscription s) { - SubscriptionHelper.deferredSetOnce(subscription, requested, s); + SubscriptionHelper.deferredSetOnce(upstream, requested, s); } @Override public void onNext(Object t) { if (getAndIncrement() == 0) { for (;;) { - if (SubscriptionHelper.isCancelled(subscription.get())) { + if (SubscriptionHelper.isCancelled(upstream.get())) { return; } @@ -110,23 +109,23 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { subscriber.cancel(); - subscriber.actual.onError(t); + subscriber.downstream.onError(t); } @Override public void onComplete() { subscriber.cancel(); - subscriber.actual.onComplete(); + subscriber.downstream.onComplete(); } @Override public void request(long n) { - SubscriptionHelper.deferredRequest(subscription, requested, n); + SubscriptionHelper.deferredRequest(upstream, requested, n); } @Override public void cancel() { - SubscriptionHelper.cancel(subscription); + SubscriptionHelper.cancel(upstream); } } @@ -134,7 +133,7 @@ abstract static class WhenSourceSubscriber extends SubscriptionArbiter imp private static final long serialVersionUID = -5604623027276966720L; - protected final Subscriber actual; + protected final Subscriber downstream; protected final FlowableProcessor processor; @@ -144,7 +143,7 @@ abstract static class WhenSourceSubscriber extends SubscriptionArbiter imp WhenSourceSubscriber(Subscriber actual, FlowableProcessor processor, Subscription receiver) { - this.actual = actual; + this.downstream = actual; this.processor = processor; this.receiver = receiver; } @@ -157,7 +156,7 @@ public final void onSubscribe(Subscription s) { @Override public final void onNext(T t) { produced++; - actual.onNext(t); + downstream.onNext(t); } protected final void again(U signal) { @@ -190,7 +189,7 @@ static final class RepeatWhenSubscriber extends WhenSourceSubscriber extends AtomicInteger implements Flowabl private static final long serialVersionUID = -7098360935104053232L; - final Subscriber actual; + final Subscriber downstream; final SubscriptionArbiter sa; final Publisher source; final BiPredicate predicate; @@ -54,7 +54,7 @@ static final class RetryBiSubscriber extends AtomicInteger implements Flowabl RetryBiSubscriber(Subscriber actual, BiPredicate predicate, SubscriptionArbiter sa, Publisher source) { - this.actual = actual; + this.downstream = actual; this.sa = sa; this.source = source; this.predicate = predicate; @@ -68,7 +68,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { produced++; - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { @@ -77,11 +77,11 @@ public void onError(Throwable t) { b = predicate.test(++retries, t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); return; } if (!b) { - actual.onError(t); + downstream.onError(t); return; } subscribeNext(); @@ -89,7 +89,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } /** diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java index 11c4732274..b29b97b70a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java @@ -46,7 +46,7 @@ static final class RetrySubscriber extends AtomicInteger implements FlowableS private static final long serialVersionUID = -7098360935104053232L; - final Subscriber actual; + final Subscriber downstream; final SubscriptionArbiter sa; final Publisher source; final Predicate predicate; @@ -56,7 +56,7 @@ static final class RetrySubscriber extends AtomicInteger implements FlowableS RetrySubscriber(Subscriber actual, long count, Predicate predicate, SubscriptionArbiter sa, Publisher source) { - this.actual = actual; + this.downstream = actual; this.sa = sa; this.source = source; this.predicate = predicate; @@ -71,7 +71,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { produced++; - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { @@ -80,18 +80,18 @@ public void onError(Throwable t) { remaining = r - 1; } if (r == 0) { - actual.onError(t); + downstream.onError(t); } else { boolean b; try { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); return; } if (!b) { - actual.onError(t); + downstream.onError(t); return; } subscribeNext(); @@ -100,7 +100,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } /** diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryWhen.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryWhen.java index 27785e5075..4cf535cd90 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryWhen.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryWhen.java @@ -80,7 +80,7 @@ public void onError(Throwable t) { @Override public void onComplete() { receiver.cancel(); - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSamplePublisher.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSamplePublisher.java index a75f4c1e05..55439eee69 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSamplePublisher.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSamplePublisher.java @@ -49,25 +49,25 @@ abstract static class SamplePublisherSubscriber extends AtomicReference im private static final long serialVersionUID = -3517602651313910099L; - final Subscriber actual; + final Subscriber downstream; final Publisher sampler; final AtomicLong requested = new AtomicLong(); final AtomicReference other = new AtomicReference(); - Subscription s; + Subscription upstream; SamplePublisherSubscriber(Subscriber actual, Publisher other) { - this.actual = actual; + this.downstream = actual; this.sampler = other; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); if (other.get() == null) { sampler.subscribe(new SamplerSubscriber(this)); s.request(Long.MAX_VALUE); @@ -84,7 +84,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { SubscriptionHelper.cancel(other); - actual.onError(t); + downstream.onError(t); } @Override @@ -107,16 +107,16 @@ public void request(long n) { @Override public void cancel() { SubscriptionHelper.cancel(other); - s.cancel(); + upstream.cancel(); } public void error(Throwable e) { - s.cancel(); - actual.onError(e); + upstream.cancel(); + downstream.onError(e); } public void complete() { - s.cancel(); + upstream.cancel(); completeOther(); } @@ -125,11 +125,11 @@ void emit() { if (value != null) { long r = requested.get(); if (r != 0L) { - actual.onNext(value); + downstream.onNext(value); BackpressureHelper.produced(requested, 1); } else { cancel(); - actual.onError(new MissingBackpressureException("Couldn't emit value due to lack of requests!")); + downstream.onError(new MissingBackpressureException("Couldn't emit value due to lack of requests!")); } } } @@ -179,12 +179,12 @@ static final class SampleMainNoLast extends SamplePublisherSubscriber { @Override void completeMain() { - actual.onComplete(); + downstream.onComplete(); } @Override void completeOther() { - actual.onComplete(); + downstream.onComplete(); } @Override @@ -211,7 +211,7 @@ void completeMain() { done = true; if (wip.getAndIncrement() == 0) { emit(); - actual.onComplete(); + downstream.onComplete(); } } @@ -220,7 +220,7 @@ void completeOther() { done = true; if (wip.getAndIncrement() == 0) { emit(); - actual.onComplete(); + downstream.onComplete(); } } @@ -231,7 +231,7 @@ void run() { boolean d = done; emit(); if (d) { - actual.onComplete(); + downstream.onComplete(); return; } } while (wip.decrementAndGet() != 0); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSampleTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSampleTimed.java index 4308b99165..47ed31f052 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSampleTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSampleTimed.java @@ -54,7 +54,7 @@ abstract static class SampleTimedSubscriber extends AtomicReference implem private static final long serialVersionUID = -3517602651313910099L; - final Subscriber actual; + final Subscriber downstream; final long period; final TimeUnit unit; final Scheduler scheduler; @@ -63,10 +63,10 @@ abstract static class SampleTimedSubscriber extends AtomicReference implem final SequentialDisposable timer = new SequentialDisposable(); - Subscription s; + Subscription upstream; SampleTimedSubscriber(Subscriber actual, long period, TimeUnit unit, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.period = period; this.unit = unit; this.scheduler = scheduler; @@ -74,9 +74,9 @@ abstract static class SampleTimedSubscriber extends AtomicReference implem @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); timer.replace(scheduler.schedulePeriodicallyDirect(this, period, period, unit)); s.request(Long.MAX_VALUE); } @@ -90,7 +90,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { cancelTimer(); - actual.onError(t); + downstream.onError(t); } @Override @@ -113,7 +113,7 @@ public void request(long n) { @Override public void cancel() { cancelTimer(); - s.cancel(); + upstream.cancel(); } void emit() { @@ -121,11 +121,11 @@ void emit() { if (value != null) { long r = requested.get(); if (r != 0L) { - actual.onNext(value); + downstream.onNext(value); BackpressureHelper.produced(requested, 1); } else { cancel(); - actual.onError(new MissingBackpressureException("Couldn't emit value due to lack of requests!")); + downstream.onError(new MissingBackpressureException("Couldn't emit value due to lack of requests!")); } } } @@ -143,7 +143,7 @@ static final class SampleTimedNoLast extends SampleTimedSubscriber { @Override void complete() { - actual.onComplete(); + downstream.onComplete(); } @Override @@ -167,7 +167,7 @@ static final class SampleTimedEmitLast extends SampleTimedSubscriber { void complete() { emit(); if (wip.decrementAndGet() == 0) { - actual.onComplete(); + downstream.onComplete(); } } @@ -176,7 +176,7 @@ public void run() { if (wip.incrementAndGet() == 2) { emit(); if (wip.decrementAndGet() == 0) { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableScan.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableScan.java index 91bb5cc274..0c5aca6bf6 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableScan.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableScan.java @@ -35,25 +35,25 @@ protected void subscribeActual(Subscriber s) { } static final class ScanSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final BiFunction accumulator; - Subscription s; + Subscription upstream; T value; boolean done; ScanSubscriber(Subscriber actual, BiFunction accumulator) { - this.actual = actual; + this.downstream = actual; this.accumulator = accumulator; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -62,7 +62,7 @@ public void onNext(T t) { if (done) { return; } - final Subscriber a = actual; + final Subscriber a = downstream; T v = value; if (v == null) { value = t; @@ -74,7 +74,7 @@ public void onNext(T t) { u = ObjectHelper.requireNonNull(accumulator.apply(v, t), "The value returned by the accumulator is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); onError(e); return; } @@ -91,7 +91,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -100,17 +100,17 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableScanSeed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableScanSeed.java index 19b4f3fc68..6586b55253 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableScanSeed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableScanSeed.java @@ -57,7 +57,7 @@ static final class ScanSeedSubscriber implements FlowableSubscriber, Subscription { private static final long serialVersionUID = -1776795561228106469L; - final Subscriber actual; + final Subscriber downstream; final BiFunction accumulator; @@ -74,14 +74,14 @@ static final class ScanSeedSubscriber volatile boolean done; Throwable error; - Subscription s; + Subscription upstream; R value; int consumed; ScanSeedSubscriber(Subscriber actual, BiFunction accumulator, R value, int prefetch) { - this.actual = actual; + this.downstream = actual; this.accumulator = accumulator; this.value = value; this.prefetch = prefetch; @@ -93,10 +93,10 @@ static final class ScanSeedSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(prefetch - 1); } @@ -113,7 +113,7 @@ public void onNext(T t) { v = ObjectHelper.requireNonNull(accumulator.apply(v, t), "The accumulator returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); onError(ex); return; } @@ -146,7 +146,7 @@ public void onComplete() { @Override public void cancel() { cancelled = true; - s.cancel(); + upstream.cancel(); if (getAndIncrement() == 0) { queue.clear(); } @@ -166,7 +166,7 @@ void drain() { } int missed = 1; - Subscriber a = actual; + Subscriber a = downstream; SimplePlainQueue q = queue; int lim = limit; int c = consumed; @@ -209,7 +209,7 @@ void drain() { e++; if (++c == lim) { c = 0; - s.request(lim); + upstream.request(lim); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqual.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqual.java index be145c3499..fd10367248 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqual.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqual.java @@ -132,7 +132,7 @@ public void drain() { if (ex != null) { cancelAndClear(); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } @@ -146,7 +146,7 @@ public void drain() { Exceptions.throwIfFatal(exc); cancelAndClear(); error.addThrowable(exc); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } v1 = a; @@ -162,7 +162,7 @@ public void drain() { Exceptions.throwIfFatal(exc); cancelAndClear(); error.addThrowable(exc); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } v2 = b; @@ -192,7 +192,7 @@ public void drain() { Exceptions.throwIfFatal(exc); cancelAndClear(); error.addThrowable(exc); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } @@ -220,7 +220,7 @@ public void drain() { if (ex != null) { cancelAndClear(); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java index cd0d958c49..c37bd0bac9 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java @@ -59,7 +59,7 @@ static final class EqualCoordinator private static final long serialVersionUID = -6178010334400373240L; - final SingleObserver actual; + final SingleObserver downstream; final BiPredicate comparer; @@ -74,7 +74,7 @@ static final class EqualCoordinator T v2; EqualCoordinator(SingleObserver actual, int prefetch, BiPredicate comparer) { - this.actual = actual; + this.downstream = actual; this.comparer = comparer; this.first = new EqualSubscriber(this, prefetch); this.second = new EqualSubscriber(this, prefetch); @@ -132,7 +132,7 @@ public void drain() { if (ex != null) { cancelAndClear(); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } @@ -146,7 +146,7 @@ public void drain() { Exceptions.throwIfFatal(exc); cancelAndClear(); error.addThrowable(exc); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } v1 = a; @@ -162,7 +162,7 @@ public void drain() { Exceptions.throwIfFatal(exc); cancelAndClear(); error.addThrowable(exc); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } v2 = b; @@ -171,12 +171,12 @@ public void drain() { boolean e2 = b == null; if (d1 && d2 && e1 && e2) { - actual.onSuccess(true); + downstream.onSuccess(true); return; } if ((d1 && d2) && (e1 != e2)) { cancelAndClear(); - actual.onSuccess(false); + downstream.onSuccess(false); return; } @@ -192,13 +192,13 @@ public void drain() { Exceptions.throwIfFatal(exc); cancelAndClear(); error.addThrowable(exc); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } if (!c) { cancelAndClear(); - actual.onSuccess(false); + downstream.onSuccess(false); return; } @@ -220,7 +220,7 @@ public void drain() { if (ex != null) { cancelAndClear(); - actual.onError(error.terminate()); + downstream.onError(error.terminate()); return; } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingle.java index 70d29e7ad5..7b4ace56f0 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingle.java @@ -47,7 +47,7 @@ static final class SingleElementSubscriber extends DeferredScalarSubscription final boolean failOnEmpty; - Subscription s; + Subscription upstream; boolean done; @@ -59,9 +59,9 @@ static final class SingleElementSubscriber extends DeferredScalarSubscription @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -73,8 +73,8 @@ public void onNext(T t) { } if (value != null) { done = true; - s.cancel(); - actual.onError(new IllegalArgumentException("Sequence contains more than one element!")); + upstream.cancel(); + downstream.onError(new IllegalArgumentException("Sequence contains more than one element!")); return; } value = t; @@ -87,7 +87,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -103,9 +103,9 @@ public void onComplete() { } if (v == null) { if (failOnEmpty) { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } else { - actual.onComplete(); + downstream.onComplete(); } } else { complete(v); @@ -115,7 +115,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleMaybe.java index 4fcc466df0..14be53915a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleMaybe.java @@ -42,23 +42,23 @@ public Flowable fuseToFlowable() { static final class SingleElementSubscriber implements FlowableSubscriber, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Subscription s; + Subscription upstream; boolean done; T value; - SingleElementSubscriber(MaybeObserver actual) { - this.actual = actual; + SingleElementSubscriber(MaybeObserver downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -70,9 +70,9 @@ public void onNext(T t) { } if (value != null) { done = true; - s.cancel(); - s = SubscriptionHelper.CANCELLED; - actual.onError(new IllegalArgumentException("Sequence contains more than one element!")); + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(new IllegalArgumentException("Sequence contains more than one element!")); return; } value = t; @@ -85,8 +85,8 @@ public void onError(Throwable t) { return; } done = true; - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override @@ -95,25 +95,25 @@ public void onComplete() { return; } done = true; - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; T v = value; value = null; if (v == null) { - actual.onComplete(); + downstream.onComplete(); } else { - actual.onSuccess(v); + downstream.onSuccess(v); } } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleSingle.java index 3ee049ecf2..cb4bce53c5 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSingleSingle.java @@ -47,26 +47,26 @@ public Flowable fuseToFlowable() { static final class SingleElementSubscriber implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final T defaultValue; - Subscription s; + Subscription upstream; boolean done; T value; SingleElementSubscriber(SingleObserver actual, T defaultValue) { - this.actual = actual; + this.downstream = actual; this.defaultValue = defaultValue; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -78,9 +78,9 @@ public void onNext(T t) { } if (value != null) { done = true; - s.cancel(); - s = SubscriptionHelper.CANCELLED; - actual.onError(new IllegalArgumentException("Sequence contains more than one element!")); + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(new IllegalArgumentException("Sequence contains more than one element!")); return; } value = t; @@ -93,8 +93,8 @@ public void onError(Throwable t) { return; } done = true; - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override @@ -103,7 +103,7 @@ public void onComplete() { return; } done = true; - s = SubscriptionHelper.CANCELLED; + upstream = SubscriptionHelper.CANCELLED; T v = value; value = null; if (v == null) { @@ -111,21 +111,21 @@ public void onComplete() { } if (v != null) { - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkip.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkip.java index 6957ff66c3..58a0446b98 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkip.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkip.java @@ -31,22 +31,22 @@ protected void subscribeActual(Subscriber s) { } static final class SkipSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; long remaining; - Subscription s; + Subscription upstream; SkipSubscriber(Subscriber actual, long n) { - this.actual = actual; + this.downstream = actual; this.remaining = n; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { + if (SubscriptionHelper.validate(this.upstream, s)) { long n = remaining; - this.s = s; - actual.onSubscribe(this); + this.upstream = s; + downstream.onSubscribe(this); s.request(n); } } @@ -56,28 +56,28 @@ public void onNext(T t) { if (remaining != 0L) { remaining--; } else { - actual.onNext(t); + downstream.onNext(t); } } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipLast.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipLast.java index a0ed02a567..bbda349db2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipLast.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipLast.java @@ -36,53 +36,53 @@ protected void subscribeActual(Subscriber s) { static final class SkipLastSubscriber extends ArrayDeque implements FlowableSubscriber, Subscription { private static final long serialVersionUID = -3807491841935125653L; - final Subscriber actual; + final Subscriber downstream; final int skip; - Subscription s; + Subscription upstream; SkipLastSubscriber(Subscriber actual, int skip) { super(skip); - this.actual = actual; + this.downstream = actual; this.skip = skip; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { if (skip == size()) { - actual.onNext(poll()); + downstream.onNext(poll()); } else { - s.request(1); + upstream.request(1); } offer(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimed.java index 5cad43dd87..0ffd249f15 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimed.java @@ -47,14 +47,14 @@ protected void subscribeActual(Subscriber s) { static final class SkipLastTimedSubscriber extends AtomicInteger implements FlowableSubscriber, Subscription { private static final long serialVersionUID = -5677354903406201275L; - final Subscriber actual; + final Subscriber downstream; final long time; final TimeUnit unit; final Scheduler scheduler; final SpscLinkedArrayQueue queue; final boolean delayError; - Subscription s; + Subscription upstream; final AtomicLong requested = new AtomicLong(); @@ -64,7 +64,7 @@ static final class SkipLastTimedSubscriber extends AtomicInteger implements F Throwable error; SkipLastTimedSubscriber(Subscriber actual, long time, TimeUnit unit, Scheduler scheduler, int bufferSize, boolean delayError) { - this.actual = actual; + this.downstream = actual; this.time = time; this.unit = unit; this.scheduler = scheduler; @@ -74,9 +74,9 @@ static final class SkipLastTimedSubscriber extends AtomicInteger implements F @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -115,7 +115,7 @@ public void request(long n) { public void cancel() { if (!cancelled) { cancelled = true; - s.cancel(); + upstream.cancel(); if (getAndIncrement() == 0) { queue.clear(); @@ -130,7 +130,7 @@ void drain() { int missed = 1; - final Subscriber a = actual; + final Subscriber a = downstream; final SpscLinkedArrayQueue q = queue; final boolean delayError = this.delayError; final TimeUnit unit = this.unit; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipUntil.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipUntil.java index 0f980ac883..0324c720a2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipUntil.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipUntil.java @@ -43,9 +43,9 @@ static final class SkipUntilMainSubscriber extends AtomicInteger implements ConditionalSubscriber, Subscription { private static final long serialVersionUID = -6270983465606289181L; - final Subscriber actual; + final Subscriber downstream; - final AtomicReference s; + final AtomicReference upstream; final AtomicLong requested; @@ -55,9 +55,9 @@ static final class SkipUntilMainSubscriber extends AtomicInteger volatile boolean gate; - SkipUntilMainSubscriber(Subscriber actual) { - this.actual = actual; - this.s = new AtomicReference(); + SkipUntilMainSubscriber(Subscriber downstream) { + this.downstream = downstream; + this.upstream = new AtomicReference(); this.requested = new AtomicLong(); this.other = new OtherSubscriber(); this.error = new AtomicThrowable(); @@ -65,20 +65,20 @@ static final class SkipUntilMainSubscriber extends AtomicInteger @Override public void onSubscribe(Subscription s) { - SubscriptionHelper.deferredSetOnce(this.s, requested, s); + SubscriptionHelper.deferredSetOnce(this.upstream, requested, s); } @Override public void onNext(T t) { if (!tryOnNext(t)) { - s.get().request(1); + upstream.get().request(1); } } @Override public boolean tryOnNext(T t) { if (gate) { - HalfSerializer.onNext(actual, t, this, error); + HalfSerializer.onNext(downstream, t, this, error); return true; } return false; @@ -87,23 +87,23 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { SubscriptionHelper.cancel(other); - HalfSerializer.onError(actual, t, SkipUntilMainSubscriber.this, error); + HalfSerializer.onError(downstream, t, SkipUntilMainSubscriber.this, error); } @Override public void onComplete() { SubscriptionHelper.cancel(other); - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } @Override public void request(long n) { - SubscriptionHelper.deferredRequest(s, requested, n); + SubscriptionHelper.deferredRequest(upstream, requested, n); } @Override public void cancel() { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); SubscriptionHelper.cancel(other); } @@ -125,8 +125,8 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { - SubscriptionHelper.cancel(s); - HalfSerializer.onError(actual, t, SkipUntilMainSubscriber.this, error); + SubscriptionHelper.cancel(upstream); + HalfSerializer.onError(downstream, t, SkipUntilMainSubscriber.this, error); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipWhile.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipWhile.java index 3a2ba35df3..8123be6782 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipWhile.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSkipWhile.java @@ -33,64 +33,64 @@ protected void subscribeActual(Subscriber s) { } static final class SkipWhileSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final Predicate predicate; - Subscription s; + Subscription upstream; boolean notSkipping; SkipWhileSubscriber(Subscriber actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { if (notSkipping) { - actual.onNext(t); + downstream.onNext(t); } else { boolean b; try { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); - actual.onError(e); + upstream.cancel(); + downstream.onError(e); return; } if (b) { - s.request(1); + upstream.request(1); } else { notSkipping = true; - actual.onNext(t); + downstream.onNext(t); } } } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOn.java index 1bb3f1e829..f603aca819 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOn.java @@ -53,11 +53,11 @@ static final class SubscribeOnSubscriber extends AtomicReference private static final long serialVersionUID = 8094547886072529208L; - final Subscriber actual; + final Subscriber downstream; final Scheduler.Worker worker; - final AtomicReference s; + final AtomicReference upstream; final AtomicLong requested; @@ -66,10 +66,10 @@ static final class SubscribeOnSubscriber extends AtomicReference Publisher source; SubscribeOnSubscriber(Subscriber actual, Scheduler.Worker worker, Publisher source, boolean requestOn) { - this.actual = actual; + this.downstream = actual; this.worker = worker; this.source = source; - this.s = new AtomicReference(); + this.upstream = new AtomicReference(); this.requested = new AtomicLong(); this.nonScheduledRequests = !requestOn; } @@ -84,7 +84,7 @@ public void run() { @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.setOnce(this.s, s)) { + if (SubscriptionHelper.setOnce(this.upstream, s)) { long r = requested.getAndSet(0L); if (r != 0L) { requestUpstream(r, s); @@ -94,30 +94,30 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); worker.dispose(); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); worker.dispose(); } @Override public void request(final long n) { if (SubscriptionHelper.validate(n)) { - Subscription s = this.s.get(); + Subscription s = this.upstream.get(); if (s != null) { requestUpstream(n, s); } else { BackpressureHelper.add(requested, n); - s = this.s.get(); + s = this.upstream.get(); if (s != null) { long r = requested.getAndSet(0L); if (r != 0L) { @@ -138,22 +138,22 @@ void requestUpstream(final long n, final Subscription s) { @Override public void cancel() { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); worker.dispose(); } static final class Request implements Runnable { - private final Subscription s; - private final long n; + final Subscription upstream; + final long n; Request(Subscription s, long n) { - this.s = s; + this.upstream = s; this.n = n; } @Override public void run() { - s.request(n); + upstream.request(n); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmpty.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmpty.java index 33f215bf3d..f9fc7ebc4c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmpty.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmpty.java @@ -33,14 +33,14 @@ protected void subscribeActual(Subscriber s) { } static final class SwitchIfEmptySubscriber implements FlowableSubscriber { - final Subscriber actual; + final Subscriber downstream; final Publisher other; final SubscriptionArbiter arbiter; boolean empty; SwitchIfEmptySubscriber(Subscriber actual, Publisher other) { - this.actual = actual; + this.downstream = actual; this.other = other; this.empty = true; this.arbiter = new SubscriptionArbiter(); @@ -56,12 +56,12 @@ public void onNext(T t) { if (empty) { empty = false; } - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -70,7 +70,7 @@ public void onComplete() { empty = false; other.subscribe(this); } else { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java index b7cbe1d3fc..0b00c03c9a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java @@ -52,7 +52,7 @@ protected void subscribeActual(Subscriber s) { static final class SwitchMapSubscriber extends AtomicInteger implements FlowableSubscriber, Subscription { private static final long serialVersionUID = -3491074160481096299L; - final Subscriber actual; + final Subscriber downstream; final Function> mapper; final int bufferSize; final boolean delayErrors; @@ -63,7 +63,7 @@ static final class SwitchMapSubscriber extends AtomicInteger implements Fl volatile boolean cancelled; - Subscription s; + Subscription upstream; final AtomicReference> active = new AtomicReference>(); @@ -80,7 +80,7 @@ static final class SwitchMapSubscriber extends AtomicInteger implements Fl SwitchMapSubscriber(Subscriber actual, Function> mapper, int bufferSize, boolean delayErrors) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.bufferSize = bufferSize; this.delayErrors = delayErrors; @@ -89,9 +89,9 @@ static final class SwitchMapSubscriber extends AtomicInteger implements Fl @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -114,7 +114,7 @@ public void onNext(T t) { p = ObjectHelper.requireNonNull(mapper.apply(t), "The publisher returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); onError(e); return; } @@ -160,7 +160,7 @@ public void request(long n) { if (SubscriptionHelper.validate(n)) { BackpressureHelper.add(requested, n); if (unique == 0L) { - s.request(Long.MAX_VALUE); + upstream.request(Long.MAX_VALUE); } else { drain(); } @@ -171,7 +171,7 @@ public void request(long n) { public void cancel() { if (!cancelled) { cancelled = true; - s.cancel(); + upstream.cancel(); disposeInner(); } @@ -193,7 +193,7 @@ void drain() { return; } - final Subscriber a = actual; + final Subscriber a = downstream; int missing = 1; @@ -398,7 +398,7 @@ public void onError(Throwable t) { SwitchMapSubscriber p = parent; if (index == p.unique && p.error.addThrowable(t)) { if (!p.delayErrors) { - p.s.cancel(); + p.upstream.cancel(); } done = true; p.drain(); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTake.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTake.java index e15abaef84..badf1d8146 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTake.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTake.java @@ -36,26 +36,32 @@ protected void subscribeActual(Subscriber s) { static final class TakeSubscriber extends AtomicBoolean implements FlowableSubscriber, Subscription { private static final long serialVersionUID = -5636543848937116287L; - boolean done; - Subscription subscription; - final Subscriber actual; + + final Subscriber downstream; + final long limit; + + boolean done; + + Subscription upstream; + long remaining; + TakeSubscriber(Subscriber actual, long limit) { - this.actual = actual; + this.downstream = actual; this.limit = limit; this.remaining = limit; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.subscription, s)) { - subscription = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + upstream = s; if (limit == 0L) { s.cancel(); done = true; - EmptySubscription.complete(actual); + EmptySubscription.complete(downstream); } else { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } } @@ -63,9 +69,9 @@ public void onSubscribe(Subscription s) { public void onNext(T t) { if (!done && remaining-- > 0) { boolean stop = remaining == 0; - actual.onNext(t); + downstream.onNext(t); if (stop) { - subscription.cancel(); + upstream.cancel(); onComplete(); } } @@ -74,8 +80,8 @@ public void onNext(T t) { public void onError(Throwable t) { if (!done) { done = true; - subscription.cancel(); - actual.onError(t); + upstream.cancel(); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -84,7 +90,7 @@ public void onError(Throwable t) { public void onComplete() { if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); } } @Override @@ -94,15 +100,15 @@ public void request(long n) { } if (!get() && compareAndSet(false, true)) { if (n >= limit) { - subscription.request(Long.MAX_VALUE); + upstream.request(Long.MAX_VALUE); return; } } - subscription.request(n); + upstream.request(n); } @Override public void cancel() { - subscription.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLast.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLast.java index 4ff36f5c56..60318d0b08 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLast.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLast.java @@ -38,10 +38,10 @@ protected void subscribeActual(Subscriber s) { static final class TakeLastSubscriber extends ArrayDeque implements FlowableSubscriber, Subscription { private static final long serialVersionUID = 7240042530241604978L; - final Subscriber actual; + final Subscriber downstream; final int count; - Subscription s; + Subscription upstream; volatile boolean done; volatile boolean cancelled; @@ -50,15 +50,15 @@ static final class TakeLastSubscriber extends ArrayDeque implements Flowab final AtomicInteger wip = new AtomicInteger(); TakeLastSubscriber(Subscriber actual, int count) { - this.actual = actual; + this.downstream = actual; this.count = count; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -73,7 +73,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -93,12 +93,12 @@ public void request(long n) { @Override public void cancel() { cancelled = true; - s.cancel(); + upstream.cancel(); } void drain() { if (wip.getAndIncrement() == 0) { - Subscriber a = actual; + Subscriber a = downstream; long r = requested.get(); do { if (cancelled) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOne.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOne.java index 1372bd874e..570bf3c823 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOne.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOne.java @@ -33,17 +33,17 @@ static final class TakeLastOneSubscriber extends DeferredScalarSubscription actual) { - super(actual); + TakeLastOneSubscriber(Subscriber downstream) { + super(downstream); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -56,7 +56,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { value = null; - actual.onError(t); + downstream.onError(t); } @Override @@ -65,14 +65,14 @@ public void onComplete() { if (v != null) { complete(v); } else { - actual.onComplete(); + downstream.onComplete(); } } @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimed.java index b139d31995..b48cdddc0b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimed.java @@ -51,7 +51,7 @@ protected void subscribeActual(Subscriber s) { static final class TakeLastTimedSubscriber extends AtomicInteger implements FlowableSubscriber, Subscription { private static final long serialVersionUID = -5677354903406201275L; - final Subscriber actual; + final Subscriber downstream; final long count; final long time; final TimeUnit unit; @@ -59,7 +59,7 @@ static final class TakeLastTimedSubscriber extends AtomicInteger implements F final SpscLinkedArrayQueue queue; final boolean delayError; - Subscription s; + Subscription upstream; final AtomicLong requested = new AtomicLong(); @@ -69,7 +69,7 @@ static final class TakeLastTimedSubscriber extends AtomicInteger implements F Throwable error; TakeLastTimedSubscriber(Subscriber actual, long count, long time, TimeUnit unit, Scheduler scheduler, int bufferSize, boolean delayError) { - this.actual = actual; + this.downstream = actual; this.count = count; this.time = time; this.unit = unit; @@ -80,9 +80,9 @@ static final class TakeLastTimedSubscriber extends AtomicInteger implements F @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -143,7 +143,7 @@ public void request(long n) { public void cancel() { if (!cancelled) { cancelled = true; - s.cancel(); + upstream.cancel(); if (getAndIncrement() == 0) { queue.clear(); @@ -158,7 +158,7 @@ void drain() { int missed = 1; - final Subscriber a = actual; + final Subscriber a = downstream; final SpscLinkedArrayQueue q = queue; final boolean delayError = this.delayError; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeUntil.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeUntil.java index 0743eb1d00..180a77ec68 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeUntil.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeUntil.java @@ -42,54 +42,54 @@ static final class TakeUntilMainSubscriber extends AtomicInteger implements F private static final long serialVersionUID = -4945480365982832967L; - final Subscriber actual; + final Subscriber downstream; final AtomicLong requested; - final AtomicReference s; + final AtomicReference upstream; final AtomicThrowable error; final OtherSubscriber other; - TakeUntilMainSubscriber(Subscriber actual) { - this.actual = actual; + TakeUntilMainSubscriber(Subscriber downstream) { + this.downstream = downstream; this.requested = new AtomicLong(); - this.s = new AtomicReference(); + this.upstream = new AtomicReference(); this.other = new OtherSubscriber(); this.error = new AtomicThrowable(); } @Override public void onSubscribe(Subscription s) { - SubscriptionHelper.deferredSetOnce(this.s, requested, s); + SubscriptionHelper.deferredSetOnce(this.upstream, requested, s); } @Override public void onNext(T t) { - HalfSerializer.onNext(actual, t, this, error); + HalfSerializer.onNext(downstream, t, this, error); } @Override public void onError(Throwable t) { SubscriptionHelper.cancel(other); - HalfSerializer.onError(actual, t, this, error); + HalfSerializer.onError(downstream, t, this, error); } @Override public void onComplete() { SubscriptionHelper.cancel(other); - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } @Override public void request(long n) { - SubscriptionHelper.deferredRequest(s, requested, n); + SubscriptionHelper.deferredRequest(upstream, requested, n); } @Override public void cancel() { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); SubscriptionHelper.cancel(other); } @@ -110,14 +110,14 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { - SubscriptionHelper.cancel(s); - HalfSerializer.onError(actual, t, TakeUntilMainSubscriber.this, error); + SubscriptionHelper.cancel(upstream); + HalfSerializer.onError(downstream, t, TakeUntilMainSubscriber.this, error); } @Override public void onComplete() { - SubscriptionHelper.cancel(s); - HalfSerializer.onComplete(actual, TakeUntilMainSubscriber.this, error); + SubscriptionHelper.cancel(upstream); + HalfSerializer.onComplete(downstream, TakeUntilMainSubscriber.this, error); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicate.java index 790800dc9d..cad253b254 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicate.java @@ -34,40 +34,40 @@ protected void subscribeActual(Subscriber s) { } static final class InnerSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final Predicate predicate; - Subscription s; + Subscription upstream; boolean done; InnerSubscriber(Subscriber actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { if (!done) { - actual.onNext(t); + downstream.onNext(t); boolean b; try { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); onError(e); return; } if (b) { done = true; - s.cancel(); - actual.onComplete(); + upstream.cancel(); + downstream.onComplete(); } } } @@ -76,7 +76,7 @@ public void onNext(T t) { public void onError(Throwable t) { if (!done) { done = true; - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -86,18 +86,18 @@ public void onError(Throwable t) { public void onComplete() { if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); } } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeWhile.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeWhile.java index 2190f0518c..d4436bd0a0 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeWhile.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTakeWhile.java @@ -34,23 +34,23 @@ protected void subscribeActual(Subscriber s) { } static final class TakeWhileSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final Predicate predicate; - Subscription s; + Subscription upstream; boolean done; TakeWhileSubscriber(Subscriber actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -64,19 +64,19 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.cancel(); + upstream.cancel(); onError(e); return; } if (!b) { done = true; - s.cancel(); - actual.onComplete(); + upstream.cancel(); + downstream.onComplete(); return; } - actual.onNext(t); + downstream.onNext(t); } @Override @@ -86,7 +86,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -95,17 +95,17 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTimed.java index fd6b821609..727bd4d484 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTimed.java @@ -52,12 +52,12 @@ static final class DebounceTimedSubscriber implements FlowableSubscriber, Subscription, Runnable { private static final long serialVersionUID = -9102637559663639004L; - final Subscriber actual; + final Subscriber downstream; final long timeout; final TimeUnit unit; final Scheduler.Worker worker; - Subscription s; + Subscription upstream; final SequentialDisposable timer = new SequentialDisposable(); @@ -66,7 +66,7 @@ static final class DebounceTimedSubscriber boolean done; DebounceTimedSubscriber(Subscriber actual, long timeout, TimeUnit unit, Worker worker) { - this.actual = actual; + this.downstream = actual; this.timeout = timeout; this.unit = unit; this.worker = worker; @@ -74,9 +74,9 @@ static final class DebounceTimedSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -91,12 +91,12 @@ public void onNext(T t) { gate = true; long r = get(); if (r != 0L) { - actual.onNext(t); + downstream.onNext(t); BackpressureHelper.produced(this, 1); } else { done = true; cancel(); - actual.onError(new MissingBackpressureException("Could not deliver value due to lack of requests")); + downstream.onError(new MissingBackpressureException("Could not deliver value due to lack of requests")); return; } @@ -123,7 +123,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); worker.dispose(); } @@ -133,7 +133,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); worker.dispose(); } @@ -146,7 +146,7 @@ public void request(long n) { @Override public void cancel() { - s.cancel(); + upstream.cancel(); worker.dispose(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeInterval.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeInterval.java index e578736192..4e673da5e6 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeInterval.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeInterval.java @@ -38,26 +38,26 @@ protected void subscribeActual(Subscriber> s) { } static final class TimeIntervalSubscriber implements FlowableSubscriber, Subscription { - final Subscriber> actual; + final Subscriber> downstream; final TimeUnit unit; final Scheduler scheduler; - Subscription s; + Subscription upstream; long lastTime; TimeIntervalSubscriber(Subscriber> actual, TimeUnit unit, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.scheduler = scheduler; this.unit = unit; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { + if (SubscriptionHelper.validate(this.upstream, s)) { lastTime = scheduler.now(unit); - this.s = s; - actual.onSubscribe(this); + this.upstream = s; + downstream.onSubscribe(this); } } @@ -67,27 +67,27 @@ public void onNext(T t) { long last = lastTime; lastTime = now; long delta = now - last; - actual.onNext(new Timed(t, delta, unit)); + downstream.onNext(new Timed(t, delta, unit)); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java index 99def36def..6d8300f234 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java @@ -68,7 +68,7 @@ static final class TimeoutSubscriber extends AtomicLong private static final long serialVersionUID = 3764492702657003550L; - final Subscriber actual; + final Subscriber downstream; final Function> itemTimeoutIndicator; @@ -79,7 +79,7 @@ static final class TimeoutSubscriber extends AtomicLong final AtomicLong requested; TimeoutSubscriber(Subscriber actual, Function> itemTimeoutIndicator) { - this.actual = actual; + this.downstream = actual; this.itemTimeoutIndicator = itemTimeoutIndicator; this.task = new SequentialDisposable(); this.upstream = new AtomicReference(); @@ -103,7 +103,7 @@ public void onNext(T t) { d.dispose(); } - actual.onNext(t); + downstream.onNext(t); Publisher itemTimeoutPublisher; @@ -115,7 +115,7 @@ public void onNext(T t) { Exceptions.throwIfFatal(ex); upstream.get().cancel(); getAndSet(Long.MAX_VALUE); - actual.onError(ex); + downstream.onError(ex); return; } @@ -139,7 +139,7 @@ public void onError(Throwable t) { if (getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -150,7 +150,7 @@ public void onComplete() { if (getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onComplete(); + downstream.onComplete(); } } @@ -159,7 +159,7 @@ public void onTimeout(long idx) { if (compareAndSet(idx, Long.MAX_VALUE)) { SubscriptionHelper.cancel(upstream); - actual.onError(new TimeoutException()); + downstream.onError(new TimeoutException()); } } @@ -168,7 +168,7 @@ public void onTimeoutError(long idx, Throwable ex) { if (compareAndSet(idx, Long.MAX_VALUE)) { SubscriptionHelper.cancel(upstream); - actual.onError(ex); + downstream.onError(ex); } else { RxJavaPlugins.onError(ex); } @@ -191,7 +191,7 @@ static final class TimeoutFallbackSubscriber extends SubscriptionArbiter private static final long serialVersionUID = 3764492702657003550L; - final Subscriber actual; + final Subscriber downstream; final Function> itemTimeoutIndicator; @@ -208,7 +208,7 @@ static final class TimeoutFallbackSubscriber extends SubscriptionArbiter TimeoutFallbackSubscriber(Subscriber actual, Function> itemTimeoutIndicator, Publisher fallback) { - this.actual = actual; + this.downstream = actual; this.itemTimeoutIndicator = itemTimeoutIndicator; this.task = new SequentialDisposable(); this.upstream = new AtomicReference(); @@ -237,7 +237,7 @@ public void onNext(T t) { consumed++; - actual.onNext(t); + downstream.onNext(t); Publisher itemTimeoutPublisher; @@ -249,7 +249,7 @@ public void onNext(T t) { Exceptions.throwIfFatal(ex); upstream.get().cancel(); index.getAndSet(Long.MAX_VALUE); - actual.onError(ex); + downstream.onError(ex); return; } @@ -273,7 +273,7 @@ public void onError(Throwable t) { if (index.getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onError(t); + downstream.onError(t); task.dispose(); } else { @@ -286,7 +286,7 @@ public void onComplete() { if (index.getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onComplete(); + downstream.onComplete(); task.dispose(); } @@ -305,7 +305,7 @@ public void onTimeout(long idx) { produced(c); } - f.subscribe(new FlowableTimeoutTimed.FallbackSubscriber(actual, this)); + f.subscribe(new FlowableTimeoutTimed.FallbackSubscriber(downstream, this)); } } @@ -314,7 +314,7 @@ public void onTimeoutError(long idx, Throwable ex) { if (index.compareAndSet(idx, Long.MAX_VALUE)) { SubscriptionHelper.cancel(upstream); - actual.onError(ex); + downstream.onError(ex); } else { RxJavaPlugins.onError(ex); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java index e16f894736..9be6bc847b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java @@ -58,7 +58,7 @@ static final class TimeoutSubscriber extends AtomicLong private static final long serialVersionUID = 3764492702657003550L; - final Subscriber actual; + final Subscriber downstream; final long timeout; @@ -73,7 +73,7 @@ static final class TimeoutSubscriber extends AtomicLong final AtomicLong requested; TimeoutSubscriber(Subscriber actual, long timeout, TimeUnit unit, Scheduler.Worker worker) { - this.actual = actual; + this.downstream = actual; this.timeout = timeout; this.unit = unit; this.worker = worker; @@ -96,7 +96,7 @@ public void onNext(T t) { task.get().dispose(); - actual.onNext(t); + downstream.onNext(t); startTimeout(idx + 1); } @@ -110,7 +110,7 @@ public void onError(Throwable t) { if (getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onError(t); + downstream.onError(t); worker.dispose(); } else { @@ -123,7 +123,7 @@ public void onComplete() { if (getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onComplete(); + downstream.onComplete(); worker.dispose(); } @@ -134,7 +134,7 @@ public void onTimeout(long idx) { if (compareAndSet(idx, Long.MAX_VALUE)) { SubscriptionHelper.cancel(upstream); - actual.onError(new TimeoutException()); + downstream.onError(new TimeoutException()); worker.dispose(); } @@ -175,7 +175,7 @@ static final class TimeoutFallbackSubscriber extends SubscriptionArbiter private static final long serialVersionUID = 3764492702657003550L; - final Subscriber actual; + final Subscriber downstream; final long timeout; @@ -195,7 +195,7 @@ static final class TimeoutFallbackSubscriber extends SubscriptionArbiter TimeoutFallbackSubscriber(Subscriber actual, long timeout, TimeUnit unit, Scheduler.Worker worker, Publisher fallback) { - this.actual = actual; + this.downstream = actual; this.timeout = timeout; this.unit = unit; this.worker = worker; @@ -223,7 +223,7 @@ public void onNext(T t) { consumed++; - actual.onNext(t); + downstream.onNext(t); startTimeout(idx + 1); } @@ -237,7 +237,7 @@ public void onError(Throwable t) { if (index.getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onError(t); + downstream.onError(t); worker.dispose(); } else { @@ -250,7 +250,7 @@ public void onComplete() { if (index.getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onComplete(); + downstream.onComplete(); worker.dispose(); } @@ -269,7 +269,7 @@ public void onTimeout(long idx) { Publisher f = fallback; fallback = null; - f.subscribe(new FallbackSubscriber(actual, this)); + f.subscribe(new FallbackSubscriber(downstream, this)); worker.dispose(); } @@ -284,12 +284,12 @@ public void cancel() { static final class FallbackSubscriber implements FlowableSubscriber { - final Subscriber actual; + final Subscriber downstream; final SubscriptionArbiter arbiter; FallbackSubscriber(Subscriber actual, SubscriptionArbiter arbiter) { - this.actual = actual; + this.downstream = actual; this.arbiter = arbiter; } @@ -300,17 +300,17 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimer.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimer.java index b7241ea4ac..7c829267cf 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimer.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimer.java @@ -49,12 +49,12 @@ static final class TimerSubscriber extends AtomicReference private static final long serialVersionUID = -2809475196591179431L; - final Subscriber actual; + final Subscriber downstream; volatile boolean requested; - TimerSubscriber(Subscriber actual) { - this.actual = actual; + TimerSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override @@ -73,12 +73,12 @@ public void cancel() { public void run() { if (get() != DisposableHelper.DISPOSED) { if (requested) { - actual.onNext(0L); + downstream.onNext(0L); lazySet(EmptyDisposable.INSTANCE); - actual.onComplete(); + downstream.onComplete(); } else { lazySet(EmptyDisposable.INSTANCE); - actual.onError(new MissingBackpressureException("Can't deliver value due to lack of requests")); + downstream.onError(new MissingBackpressureException("Can't deliver value due to lack of requests")); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableToList.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableToList.java index 75ef64ce2f..a49c3dcc8c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableToList.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableToList.java @@ -51,7 +51,7 @@ static final class ToListSubscriber> private static final long serialVersionUID = -8134157938864266736L; - Subscription s; + Subscription upstream; ToListSubscriber(Subscriber actual, U collection) { super(actual); @@ -60,9 +60,9 @@ static final class ToListSubscriber> @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -78,7 +78,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { value = null; - actual.onError(t); + downstream.onError(t); } @Override @@ -89,7 +89,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableToListSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableToListSingle.java index a0738acf11..e4a8abd565 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableToListSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableToListSingle.java @@ -65,22 +65,22 @@ public Flowable fuseToFlowable() { static final class ToListSubscriber> implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; - Subscription s; + Subscription upstream; U value; ToListSubscriber(SingleObserver actual, U collection) { - this.actual = actual; + this.downstream = actual; this.value = collection; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @@ -93,25 +93,25 @@ public void onNext(T t) { @Override public void onError(Throwable t) { value = null; - s = SubscriptionHelper.CANCELLED; - actual.onError(t); + upstream = SubscriptionHelper.CANCELLED; + downstream.onError(t); } @Override public void onComplete() { - s = SubscriptionHelper.CANCELLED; - actual.onSuccess(value); + upstream = SubscriptionHelper.CANCELLED; + downstream.onSuccess(value); } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOn.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOn.java index b5d6a1d001..0790d4b444 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOn.java @@ -37,28 +37,28 @@ static final class UnsubscribeSubscriber extends AtomicBoolean implements Flo private static final long serialVersionUID = 1015244841293359600L; - final Subscriber actual; + final Subscriber downstream; final Scheduler scheduler; - Subscription s; + Subscription upstream; UnsubscribeSubscriber(Subscriber actual, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.scheduler = scheduler; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { if (!get()) { - actual.onNext(t); + downstream.onNext(t); } } @@ -68,19 +68,19 @@ public void onError(Throwable t) { RxJavaPlugins.onError(t); return; } - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (!get()) { - actual.onComplete(); + downstream.onComplete(); } } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override @@ -93,7 +93,7 @@ public void cancel() { final class Cancellation implements Runnable { @Override public void run() { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableUsing.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableUsing.java index 9cc64d860f..2d3a83fc4a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableUsing.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableUsing.java @@ -78,15 +78,15 @@ static final class UsingSubscriber extends AtomicBoolean implements Flowab private static final long serialVersionUID = 5904473792286235046L; - final Subscriber actual; + final Subscriber downstream; final D resource; final Consumer disposer; final boolean eager; - Subscription s; + Subscription upstream; UsingSubscriber(Subscriber actual, D resource, Consumer disposer, boolean eager) { - this.actual = actual; + this.downstream = actual; this.resource = resource; this.disposer = disposer; this.eager = eager; @@ -94,15 +94,15 @@ static final class UsingSubscriber extends AtomicBoolean implements Flowab @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override @@ -118,15 +118,15 @@ public void onError(Throwable t) { } } - s.cancel(); + upstream.cancel(); if (innerError != null) { - actual.onError(new CompositeException(t, innerError)); + downstream.onError(new CompositeException(t, innerError)); } else { - actual.onError(t); + downstream.onError(t); } } else { - actual.onError(t); - s.cancel(); + downstream.onError(t); + upstream.cancel(); disposeAfter(); } } @@ -139,29 +139,29 @@ public void onComplete() { disposer.accept(resource); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } } - s.cancel(); - actual.onComplete(); + upstream.cancel(); + downstream.onComplete(); } else { - actual.onComplete(); - s.cancel(); + downstream.onComplete(); + upstream.cancel(); disposeAfter(); } } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { disposeAfter(); - s.cancel(); + upstream.cancel(); } void disposeAfter() { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindow.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindow.java index f678e73ee2..bbe2f2b6e0 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindow.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindow.java @@ -58,7 +58,7 @@ static final class WindowExactSubscriber private static final long serialVersionUID = -2365647875069161133L; - final Subscriber> actual; + final Subscriber> downstream; final long size; @@ -68,13 +68,13 @@ static final class WindowExactSubscriber long index; - Subscription s; + Subscription upstream; UnicastProcessor window; WindowExactSubscriber(Subscriber> actual, long size, int bufferSize) { super(1); - this.actual = actual; + this.downstream = actual; this.size = size; this.once = new AtomicBoolean(); this.bufferSize = bufferSize; @@ -82,9 +82,9 @@ static final class WindowExactSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -99,7 +99,7 @@ public void onNext(T t) { w = UnicastProcessor.create(bufferSize, this); window = w; - actual.onNext(w); + downstream.onNext(w); } i++; @@ -123,7 +123,7 @@ public void onError(Throwable t) { w.onError(t); } - actual.onError(t); + downstream.onError(t); } @Override @@ -134,14 +134,14 @@ public void onComplete() { w.onComplete(); } - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { if (SubscriptionHelper.validate(n)) { long u = BackpressureHelper.multiplyCap(size, n); - s.request(u); + upstream.request(u); } } @@ -155,7 +155,7 @@ public void cancel() { @Override public void run() { if (decrementAndGet() == 0) { - s.cancel(); + upstream.cancel(); } } } @@ -167,7 +167,7 @@ static final class WindowSkipSubscriber private static final long serialVersionUID = -8792836352386833856L; - final Subscriber> actual; + final Subscriber> downstream; final long size; @@ -181,13 +181,13 @@ static final class WindowSkipSubscriber long index; - Subscription s; + Subscription upstream; UnicastProcessor window; WindowSkipSubscriber(Subscriber> actual, long size, long skip, int bufferSize) { super(1); - this.actual = actual; + this.downstream = actual; this.size = size; this.skip = skip; this.once = new AtomicBoolean(); @@ -197,9 +197,9 @@ static final class WindowSkipSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -215,7 +215,7 @@ public void onNext(T t) { w = UnicastProcessor.create(bufferSize, this); window = w; - actual.onNext(w); + downstream.onNext(w); } i++; @@ -244,7 +244,7 @@ public void onError(Throwable t) { w.onError(t); } - actual.onError(t); + downstream.onError(t); } @Override @@ -255,7 +255,7 @@ public void onComplete() { w.onComplete(); } - actual.onComplete(); + downstream.onComplete(); } @Override @@ -265,10 +265,10 @@ public void request(long n) { long u = BackpressureHelper.multiplyCap(size, n); long v = BackpressureHelper.multiplyCap(skip - size, n - 1); long w = BackpressureHelper.addCap(u, v); - s.request(w); + upstream.request(w); } else { long u = BackpressureHelper.multiplyCap(skip, n); - s.request(u); + upstream.request(u); } } } @@ -283,7 +283,7 @@ public void cancel() { @Override public void run() { if (decrementAndGet() == 0) { - s.cancel(); + upstream.cancel(); } } } @@ -295,7 +295,7 @@ static final class WindowOverlapSubscriber private static final long serialVersionUID = 2428527070996323976L; - final Subscriber> actual; + final Subscriber> downstream; final SpscLinkedArrayQueue> queue; @@ -319,7 +319,7 @@ static final class WindowOverlapSubscriber long produced; - Subscription s; + Subscription upstream; volatile boolean done; Throwable error; @@ -328,7 +328,7 @@ static final class WindowOverlapSubscriber WindowOverlapSubscriber(Subscriber> actual, long size, long skip, int bufferSize) { super(1); - this.actual = actual; + this.downstream = actual; this.size = size; this.skip = skip; this.queue = new SpscLinkedArrayQueue>(bufferSize); @@ -342,9 +342,9 @@ static final class WindowOverlapSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -431,7 +431,7 @@ void drain() { return; } - final Subscriber> a = actual; + final Subscriber> a = downstream; final SpscLinkedArrayQueue> q = queue; int missed = 1; @@ -508,10 +508,10 @@ public void request(long n) { if (!firstRequest.get() && firstRequest.compareAndSet(false, true)) { long u = BackpressureHelper.multiplyCap(skip, n - 1); long v = BackpressureHelper.addCap(size, u); - s.request(v); + upstream.request(v); } else { long u = BackpressureHelper.multiplyCap(skip, n); - s.request(u); + upstream.request(u); } drain(); @@ -529,7 +529,7 @@ public void cancel() { @Override public void run() { if (decrementAndGet() == 0) { - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundary.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundary.java index 46e445bd26..a398eb040f 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundary.java @@ -94,8 +94,8 @@ static final class WindowBoundaryMainSubscriber } @Override - public void onSubscribe(Subscription d) { - SubscriptionHelper.setOnce(upstream, d, Long.MAX_VALUE); + public void onSubscribe(Subscription s) { + SubscriptionHelper.setOnce(upstream, s, Long.MAX_VALUE); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java index 55fee47d51..246b1be106 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java @@ -63,7 +63,7 @@ static final class WindowBoundaryMainSubscriber final int bufferSize; final CompositeDisposable resources; - Subscription s; + Subscription upstream; final AtomicReference boundary = new AtomicReference(); @@ -84,10 +84,10 @@ static final class WindowBoundaryMainSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); if (cancelled) { return; @@ -141,7 +141,7 @@ public void onError(Throwable t) { resources.dispose(); } - actual.onError(t); + downstream.onError(t); } @Override @@ -159,15 +159,15 @@ public void onComplete() { resources.dispose(); } - actual.onComplete(); + downstream.onComplete(); } void error(Throwable t) { - s.cancel(); + upstream.cancel(); resources.dispose(); DisposableHelper.dispose(boundary); - actual.onError(t); + downstream.onError(t); } @Override @@ -187,7 +187,7 @@ void dispose() { void drainLoop() { final SimplePlainQueue q = queue; - final Subscriber> a = actual; + final Subscriber> a = downstream; final List> ws = this.ws; int missed = 1; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySupplier.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySupplier.java index faaf1e7384..f82c56a889 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySupplier.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySupplier.java @@ -96,13 +96,13 @@ static final class WindowBoundaryMainSubscriber } @Override - public void onSubscribe(Subscription d) { - if (SubscriptionHelper.validate(upstream, d)) { - upstream = d; + public void onSubscribe(Subscription s) { + if (SubscriptionHelper.validate(upstream, s)) { + upstream = s; downstream.onSubscribe(this); queue.offer(NEXT_WINDOW); drain(); - d.request(Long.MAX_VALUE); + s.request(Long.MAX_VALUE); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java index 460fd7d814..ae284ef27a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java @@ -82,7 +82,7 @@ static final class WindowExactUnboundedSubscriber final Scheduler scheduler; final int bufferSize; - Subscription s; + Subscription upstream; UnicastProcessor window; @@ -103,12 +103,12 @@ static final class WindowExactUnboundedSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; window = UnicastProcessor.create(bufferSize); - Subscriber> a = actual; + Subscriber> a = downstream; a.onSubscribe(this); long r = requested(); @@ -159,7 +159,7 @@ public void onError(Throwable t) { drainLoop(); } - actual.onError(t); + downstream.onError(t); dispose(); } @@ -170,7 +170,7 @@ public void onComplete() { drainLoop(); } - actual.onComplete(); + downstream.onComplete(); dispose(); } @@ -205,7 +205,7 @@ public void run() { void drainLoop() { final SimplePlainQueue q = queue; - final Subscriber> a = actual; + final Subscriber> a = downstream; UnicastProcessor w = window; int missed = 1; @@ -250,13 +250,13 @@ void drainLoop() { } else { window = null; queue.clear(); - s.cancel(); + upstream.cancel(); dispose(); a.onError(new MissingBackpressureException("Could not deliver first window due to lack of requests.")); return; } } else { - s.cancel(); + upstream.cancel(); } continue; } @@ -287,7 +287,7 @@ static final class WindowExactBoundedSubscriber long producerIndex; - Subscription s; + Subscription upstream; UnicastProcessor window; @@ -315,11 +315,11 @@ static final class WindowExactBoundedSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { + if (SubscriptionHelper.validate(this.upstream, s)) { - this.s = s; + this.upstream = s; - Subscriber> a = actual; + Subscriber> a = downstream; a.onSubscribe(this); @@ -343,15 +343,15 @@ public void onSubscribe(Subscription s) { return; } - Disposable d; + Disposable task; ConsumerIndexHolder consumerIndexHolder = new ConsumerIndexHolder(producerIndex, this); if (restartTimerOnMaxSize) { - d = worker.schedulePeriodically(consumerIndexHolder, timespan, timespan, unit); + task = worker.schedulePeriodically(consumerIndexHolder, timespan, timespan, unit); } else { - d = scheduler.schedulePeriodicallyDirect(consumerIndexHolder, timespan, timespan, unit); + task = scheduler.schedulePeriodicallyDirect(consumerIndexHolder, timespan, timespan, unit); } - if (timer.replace(d)) { + if (timer.replace(task)) { s.request(Long.MAX_VALUE); } } @@ -380,7 +380,7 @@ public void onNext(T t) { if (r != 0L) { w = UnicastProcessor.create(bufferSize); window = w; - actual.onNext(w); + downstream.onNext(w); if (r != Long.MAX_VALUE) { produced(1); } @@ -394,8 +394,8 @@ public void onNext(T t) { } } else { window = null; - s.cancel(); - actual.onError(new MissingBackpressureException("Could not deliver window due to lack of requests")); + upstream.cancel(); + downstream.onError(new MissingBackpressureException("Could not deliver window due to lack of requests")); dispose(); return; } @@ -423,7 +423,7 @@ public void onError(Throwable t) { drainLoop(); } - actual.onError(t); + downstream.onError(t); dispose(); } @@ -434,7 +434,7 @@ public void onComplete() { drainLoop(); } - actual.onComplete(); + downstream.onComplete(); dispose(); } @@ -458,7 +458,7 @@ public void dispose() { void drainLoop() { final SimplePlainQueue q = queue; - final Subscriber> a = actual; + final Subscriber> a = downstream; UnicastProcessor w = window; int missed = 1; @@ -466,7 +466,7 @@ void drainLoop() { for (;;) { if (terminated) { - s.cancel(); + upstream.cancel(); q.clear(); dispose(); return; @@ -513,7 +513,7 @@ void drainLoop() { } else { window = null; queue.clear(); - s.cancel(); + upstream.cancel(); a.onError(new MissingBackpressureException("Could not deliver first window due to lack of requests.")); dispose(); return; @@ -536,7 +536,7 @@ void drainLoop() { if (r != 0L) { w = UnicastProcessor.create(bufferSize); window = w; - actual.onNext(w); + downstream.onNext(w); if (r != Long.MAX_VALUE) { produced(1); } @@ -552,8 +552,8 @@ void drainLoop() { } else { window = null; - s.cancel(); - actual.onError(new MissingBackpressureException("Could not deliver window due to lack of requests")); + upstream.cancel(); + downstream.onError(new MissingBackpressureException("Could not deliver window due to lack of requests")); dispose(); return; } @@ -605,7 +605,7 @@ static final class WindowSkipSubscriber final List> windows; - Subscription s; + Subscription upstream; volatile boolean terminated; @@ -623,11 +623,11 @@ static final class WindowSkipSubscriber @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { + if (SubscriptionHelper.validate(this.upstream, s)) { - this.s = s; + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); if (cancelled) { return; @@ -638,7 +638,7 @@ public void onSubscribe(Subscription s) { final UnicastProcessor w = UnicastProcessor.create(bufferSize); windows.add(w); - actual.onNext(w); + downstream.onNext(w); if (r != Long.MAX_VALUE) { produced(1); } @@ -650,7 +650,7 @@ public void onSubscribe(Subscription s) { } else { s.cancel(); - actual.onError(new MissingBackpressureException("Could not emit the first window due to lack of requests")); + downstream.onError(new MissingBackpressureException("Could not emit the first window due to lack of requests")); } } } @@ -681,7 +681,7 @@ public void onError(Throwable t) { drainLoop(); } - actual.onError(t); + downstream.onError(t); dispose(); } @@ -692,7 +692,7 @@ public void onComplete() { drainLoop(); } - actual.onComplete(); + downstream.onComplete(); dispose(); } @@ -720,7 +720,7 @@ void complete(UnicastProcessor w) { @SuppressWarnings("unchecked") void drainLoop() { final SimplePlainQueue q = queue; - final Subscriber> a = actual; + final Subscriber> a = downstream; final List> ws = windows; int missed = 1; @@ -729,7 +729,7 @@ void drainLoop() { for (;;) { if (terminated) { - s.cancel(); + upstream.cancel(); dispose(); q.clear(); ws.clear(); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFrom.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFrom.java index e51c6435e5..5f403fb150 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFrom.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFrom.java @@ -51,7 +51,8 @@ static final class WithLatestFromSubscriber extends AtomicReference private static final long serialVersionUID = -312246233408980075L; - final Subscriber actual; + final Subscriber downstream; + final BiFunction combiner; final AtomicReference s = new AtomicReference(); @@ -61,7 +62,7 @@ static final class WithLatestFromSubscriber extends AtomicReference final AtomicReference other = new AtomicReference(); WithLatestFromSubscriber(Subscriber actual, BiFunction combiner) { - this.actual = actual; + this.downstream = actual; this.combiner = combiner; } @Override @@ -86,10 +87,10 @@ public boolean tryOnNext(T t) { } catch (Throwable e) { Exceptions.throwIfFatal(e); cancel(); - actual.onError(e); + downstream.onError(e); return false; } - actual.onNext(r); + downstream.onNext(r); return true; } else { return false; @@ -99,13 +100,13 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { SubscriptionHelper.cancel(other); - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { SubscriptionHelper.cancel(other); - actual.onComplete(); + downstream.onComplete(); } @Override @@ -125,7 +126,7 @@ public boolean setOther(Subscription o) { public void otherError(Throwable e) { SubscriptionHelper.cancel(s); - actual.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java index 2566fe3e5c..f0a2231f02 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java @@ -99,7 +99,7 @@ static final class WithLatestFromSubscriber private static final long serialVersionUID = 1577321883966341961L; - final Subscriber actual; + final Subscriber downstream; final Function combiner; @@ -107,7 +107,7 @@ static final class WithLatestFromSubscriber final AtomicReferenceArray values; - final AtomicReference s; + final AtomicReference upstream; final AtomicLong requested; @@ -116,7 +116,7 @@ static final class WithLatestFromSubscriber volatile boolean done; WithLatestFromSubscriber(Subscriber actual, Function combiner, int n) { - this.actual = actual; + this.downstream = actual; this.combiner = combiner; WithLatestInnerSubscriber[] s = new WithLatestInnerSubscriber[n]; for (int i = 0; i < n; i++) { @@ -124,14 +124,14 @@ static final class WithLatestFromSubscriber } this.subscribers = s; this.values = new AtomicReferenceArray(n); - this.s = new AtomicReference(); + this.upstream = new AtomicReference(); this.requested = new AtomicLong(); this.error = new AtomicThrowable(); } void subscribe(Publisher[] others, int n) { WithLatestInnerSubscriber[] subscribers = this.subscribers; - AtomicReference s = this.s; + AtomicReference s = this.upstream; for (int i = 0; i < n; i++) { if (SubscriptionHelper.isCancelled(s.get())) { return; @@ -142,13 +142,13 @@ void subscribe(Publisher[] others, int n) { @Override public void onSubscribe(Subscription s) { - SubscriptionHelper.deferredSetOnce(this.s, requested, s); + SubscriptionHelper.deferredSetOnce(this.upstream, requested, s); } @Override public void onNext(T t) { if (!tryOnNext(t) && !done) { - s.get().request(1); + upstream.get().request(1); } } @@ -182,7 +182,7 @@ public boolean tryOnNext(T t) { return false; } - HalfSerializer.onNext(actual, v, this, error); + HalfSerializer.onNext(downstream, v, this, error); return true; } @@ -194,7 +194,7 @@ public void onError(Throwable t) { } done = true; cancelAllBut(-1); - HalfSerializer.onError(actual, t, this, error); + HalfSerializer.onError(downstream, t, this, error); } @Override @@ -202,18 +202,18 @@ public void onComplete() { if (!done) { done = true; cancelAllBut(-1); - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } } @Override public void request(long n) { - SubscriptionHelper.deferredRequest(s, requested, n); + SubscriptionHelper.deferredRequest(upstream, requested, n); } @Override public void cancel() { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); for (WithLatestInnerSubscriber s : subscribers) { s.dispose(); } @@ -225,17 +225,17 @@ void innerNext(int index, Object o) { void innerError(int index, Throwable t) { done = true; - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); cancelAllBut(index); - HalfSerializer.onError(actual, t, this, error); + HalfSerializer.onError(downstream, t, this, error); } void innerComplete(int index, boolean nonEmpty) { if (!nonEmpty) { done = true; - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); cancelAllBut(index); - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableZip.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableZip.java index c154c2e820..1d585cc02c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableZip.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableZip.java @@ -86,7 +86,7 @@ static final class ZipCoordinator private static final long serialVersionUID = -2434867452883857743L; - final Subscriber actual; + final Subscriber downstream; final ZipSubscriber[] subscribers; @@ -104,7 +104,7 @@ static final class ZipCoordinator ZipCoordinator(Subscriber actual, Function zipper, int n, int prefetch, boolean delayErrors) { - this.actual = actual; + this.downstream = actual; this.zipper = zipper; this.delayErrors = delayErrors; @SuppressWarnings("unchecked") @@ -166,7 +166,7 @@ void drain() { return; } - final Subscriber a = actual; + final Subscriber a = downstream; final ZipSubscriber[] qs = subscribers; final int n = qs.length; Object[] values = current; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableZipIterable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableZipIterable.java index ffec85365d..7a81c2dcba 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableZipIterable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableZipIterable.java @@ -67,26 +67,26 @@ public void subscribeActual(Subscriber t) { } static final class ZipIterableSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final Iterator iterator; final BiFunction zipper; - Subscription s; + Subscription upstream; boolean done; ZipIterableSubscriber(Subscriber actual, Iterator iterator, BiFunction zipper) { - this.actual = actual; + this.downstream = actual; this.iterator = iterator; this.zipper = zipper; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -113,7 +113,7 @@ public void onNext(T t) { return; } - actual.onNext(v); + downstream.onNext(v); boolean b; @@ -126,16 +126,16 @@ public void onNext(T t) { if (!b) { done = true; - s.cancel(); - actual.onComplete(); + upstream.cancel(); + downstream.onComplete(); } } void error(Throwable e) { Exceptions.throwIfFatal(e); done = true; - s.cancel(); - actual.onError(e); + upstream.cancel(); + downstream.onError(e); } @Override @@ -145,7 +145,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -154,17 +154,17 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java index 9087d2ed76..fb6940c479 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java @@ -94,12 +94,12 @@ static final class AmbMaybeObserver private static final long serialVersionUID = -7044685185359438206L; - final MaybeObserver actual; + final MaybeObserver downstream; final CompositeDisposable set; - AmbMaybeObserver(MaybeObserver actual) { - this.actual = actual; + AmbMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; this.set = new CompositeDisposable(); } @@ -125,7 +125,7 @@ public void onSuccess(T value) { if (compareAndSet(false, true)) { set.dispose(); - actual.onSuccess(value); + downstream.onSuccess(value); } } @@ -134,7 +134,7 @@ public void onError(Throwable e) { if (compareAndSet(false, true)) { set.dispose(); - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -145,7 +145,7 @@ public void onComplete() { if (compareAndSet(false, true)) { set.dispose(); - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCache.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCache.java index fd7747f18b..c8adbd7ab8 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCache.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCache.java @@ -89,7 +89,7 @@ public void onSuccess(T value) { this.value = value; for (CacheDisposable inner : observers.getAndSet(TERMINATED)) { if (!inner.isDisposed()) { - inner.actual.onSuccess(value); + inner.downstream.onSuccess(value); } } } @@ -100,7 +100,7 @@ public void onError(Throwable e) { this.error = e; for (CacheDisposable inner : observers.getAndSet(TERMINATED)) { if (!inner.isDisposed()) { - inner.actual.onError(e); + inner.downstream.onError(e); } } } @@ -110,7 +110,7 @@ public void onError(Throwable e) { public void onComplete() { for (CacheDisposable inner : observers.getAndSet(TERMINATED)) { if (!inner.isDisposed()) { - inner.actual.onComplete(); + inner.downstream.onComplete(); } } } @@ -175,11 +175,11 @@ static final class CacheDisposable private static final long serialVersionUID = -5791853038359966195L; - final MaybeObserver actual; + final MaybeObserver downstream; CacheDisposable(MaybeObserver actual, MaybeCache parent) { super(parent); - this.actual = actual; + this.downstream = actual; } @Override diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatArray.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatArray.java index b67534ade9..0584c47b45 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatArray.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatArray.java @@ -49,7 +49,7 @@ static final class ConcatMaybeObserver private static final long serialVersionUID = 3520831347801429610L; - final Subscriber actual; + final Subscriber downstream; final AtomicLong requested; @@ -64,7 +64,7 @@ static final class ConcatMaybeObserver long produced; ConcatMaybeObserver(Subscriber actual, MaybeSource[] sources) { - this.actual = actual; + this.downstream = actual; this.sources = sources; this.requested = new AtomicLong(); this.disposables = new SequentialDisposable(); @@ -97,7 +97,7 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override @@ -113,7 +113,7 @@ void drain() { } AtomicReference c = current; - Subscriber a = actual; + Subscriber a = downstream; Disposable cancelled = disposables; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayDelayError.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayDelayError.java index ebff9986d9..6c2e1604ab 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayDelayError.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayDelayError.java @@ -51,7 +51,7 @@ static final class ConcatMaybeObserver private static final long serialVersionUID = 3520831347801429610L; - final Subscriber actual; + final Subscriber downstream; final AtomicLong requested; @@ -68,7 +68,7 @@ static final class ConcatMaybeObserver long produced; ConcatMaybeObserver(Subscriber actual, MaybeSource[] sources) { - this.actual = actual; + this.downstream = actual; this.sources = sources; this.requested = new AtomicLong(); this.disposables = new SequentialDisposable(); @@ -123,7 +123,7 @@ void drain() { } AtomicReference c = current; - Subscriber a = actual; + Subscriber a = downstream; Disposable cancelled = disposables; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatIterable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatIterable.java index 1a3c286c71..353afadf83 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatIterable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeConcatIterable.java @@ -63,7 +63,7 @@ static final class ConcatMaybeObserver private static final long serialVersionUID = 3520831347801429610L; - final Subscriber actual; + final Subscriber downstream; final AtomicLong requested; @@ -76,7 +76,7 @@ static final class ConcatMaybeObserver long produced; ConcatMaybeObserver(Subscriber actual, Iterator> sources) { - this.actual = actual; + this.downstream = actual; this.sources = sources; this.requested = new AtomicLong(); this.disposables = new SequentialDisposable(); @@ -109,7 +109,7 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override @@ -125,7 +125,7 @@ void drain() { } AtomicReference c = current; - Subscriber a = actual; + Subscriber a = downstream; Disposable cancelled = disposables; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeContains.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeContains.java index 3399e84996..aa167b2a08 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeContains.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeContains.java @@ -48,52 +48,52 @@ protected void subscribeActual(SingleObserver observer) { static final class ContainsMaybeObserver implements MaybeObserver, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final Object value; - Disposable d; + Disposable upstream; ContainsMaybeObserver(SingleObserver actual, Object value) { - this.actual = actual; + this.downstream = actual; this.value = value; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; - actual.onSubscribe(this); + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void onSuccess(Object value) { - d = DisposableHelper.DISPOSED; - actual.onSuccess(ObjectHelper.equals(value, this.value)); + upstream = DisposableHelper.DISPOSED; + downstream.onSuccess(ObjectHelper.equals(value, this.value)); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; - actual.onSuccess(false); + upstream = DisposableHelper.DISPOSED; + downstream.onSuccess(false); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCount.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCount.java index 63d8880d42..df36c7d755 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCount.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCount.java @@ -42,50 +42,50 @@ protected void subscribeActual(SingleObserver observer) { } static final class CountMaybeObserver implements MaybeObserver, Disposable { - final SingleObserver actual; + final SingleObserver downstream; - Disposable d; + Disposable upstream; - CountMaybeObserver(SingleObserver actual) { - this.actual = actual; + CountMaybeObserver(SingleObserver downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(Object value) { - d = DisposableHelper.DISPOSED; - actual.onSuccess(1L); + upstream = DisposableHelper.DISPOSED; + downstream.onSuccess(1L); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; - actual.onSuccess(0L); + upstream = DisposableHelper.DISPOSED; + downstream.onSuccess(0L); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java index 4c6de982af..5a3852662a 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java @@ -53,10 +53,10 @@ static final class Emitter extends AtomicReference implements MaybeEmitter, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Emitter(MaybeObserver actual) { - this.actual = actual; + Emitter(MaybeObserver downstream) { + this.downstream = downstream; } @@ -69,9 +69,9 @@ public void onSuccess(T value) { if (d != DisposableHelper.DISPOSED) { try { if (value == null) { - actual.onError(new NullPointerException("onSuccess called with null. Null values are generally not allowed in 2.x operators and sources.")); + downstream.onError(new NullPointerException("onSuccess called with null. Null values are generally not allowed in 2.x operators and sources.")); } else { - actual.onSuccess(value); + downstream.onSuccess(value); } } finally { if (d != null) { @@ -98,7 +98,7 @@ public boolean tryOnError(Throwable t) { Disposable d = getAndSet(DisposableHelper.DISPOSED); if (d != DisposableHelper.DISPOSED) { try { - actual.onError(t); + downstream.onError(t); } finally { if (d != null) { d.dispose(); @@ -116,7 +116,7 @@ public void onComplete() { Disposable d = getAndSet(DisposableHelper.DISPOSED); if (d != DisposableHelper.DISPOSED) { try { - actual.onComplete(); + downstream.onComplete(); } finally { if (d != null) { d.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelay.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelay.java index 1cc31495ed..68a1508195 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelay.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelay.java @@ -51,7 +51,7 @@ static final class DelayMaybeObserver private static final long serialVersionUID = 5566860102500855068L; - final MaybeObserver actual; + final MaybeObserver downstream; final long delay; @@ -64,7 +64,7 @@ static final class DelayMaybeObserver Throwable error; DelayMaybeObserver(MaybeObserver actual, long delay, TimeUnit unit, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.delay = delay; this.unit = unit; this.scheduler = scheduler; @@ -74,13 +74,13 @@ static final class DelayMaybeObserver public void run() { Throwable ex = error; if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { T v = value; if (v != null) { - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onComplete(); + downstream.onComplete(); } } } @@ -98,7 +98,7 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherPublisher.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherPublisher.java index 61ae58f62a..55049d5c95 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherPublisher.java @@ -49,7 +49,7 @@ static final class DelayMaybeObserver final Publisher otherSource; - Disposable d; + Disposable upstream; DelayMaybeObserver(MaybeObserver actual, Publisher otherSource) { this.other = new OtherSubscriber(actual); @@ -58,8 +58,8 @@ static final class DelayMaybeObserver @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; SubscriptionHelper.cancel(other); } @@ -70,30 +70,30 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - other.actual.onSubscribe(this); + other.downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; other.value = value; subscribeNext(); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; other.error = e; subscribeNext(); } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; subscribeNext(); } @@ -108,14 +108,14 @@ static final class OtherSubscriber extends private static final long serialVersionUID = -1215060610805418006L; - final MaybeObserver actual; + final MaybeObserver downstream; T value; Throwable error; - OtherSubscriber(MaybeObserver actual) { - this.actual = actual; + OtherSubscriber(MaybeObserver downstream) { + this.downstream = downstream; } @Override @@ -137,9 +137,9 @@ public void onNext(Object t) { public void onError(Throwable t) { Throwable e = error; if (e == null) { - actual.onError(t); + downstream.onError(t); } else { - actual.onError(new CompositeException(e, t)); + downstream.onError(new CompositeException(e, t)); } } @@ -147,13 +147,13 @@ public void onError(Throwable t) { public void onComplete() { Throwable e = error; if (e != null) { - actual.onError(e); + downstream.onError(e); } else { T v = value; if (v != null) { - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionOtherPublisher.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionOtherPublisher.java index 9a52d4af7c..c29fb3fc0a 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionOtherPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionOtherPublisher.java @@ -48,7 +48,7 @@ static final class OtherSubscriber implements FlowableSubscriber, Dis MaybeSource source; - Subscription s; + Subscription upstream; OtherSubscriber(MaybeObserver actual, MaybeSource source) { this.main = new DelayMaybeObserver(actual); @@ -57,10 +57,10 @@ static final class OtherSubscriber implements FlowableSubscriber, Dis @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - main.actual.onSubscribe(this); + main.downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -68,9 +68,9 @@ public void onSubscribe(Subscription s) { @Override public void onNext(Object t) { - if (s != SubscriptionHelper.CANCELLED) { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + if (upstream != SubscriptionHelper.CANCELLED) { + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; subscribeNext(); } @@ -78,10 +78,10 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { - if (s != SubscriptionHelper.CANCELLED) { - s = SubscriptionHelper.CANCELLED; + if (upstream != SubscriptionHelper.CANCELLED) { + upstream = SubscriptionHelper.CANCELLED; - main.actual.onError(t); + main.downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -89,8 +89,8 @@ public void onError(Throwable t) { @Override public void onComplete() { - if (s != SubscriptionHelper.CANCELLED) { - s = SubscriptionHelper.CANCELLED; + if (upstream != SubscriptionHelper.CANCELLED) { + upstream = SubscriptionHelper.CANCELLED; subscribeNext(); } @@ -110,8 +110,8 @@ public boolean isDisposed() { @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; DisposableHelper.dispose(main); } } @@ -121,10 +121,10 @@ static final class DelayMaybeObserver extends AtomicReference private static final long serialVersionUID = 706635022205076709L; - final MaybeObserver actual; + final MaybeObserver downstream; - DelayMaybeObserver(MaybeObserver actual) { - this.actual = actual; + DelayMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override @@ -134,17 +134,17 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayWithCompletable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayWithCompletable.java index a56f8c9360..da9ff60e81 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayWithCompletable.java @@ -43,12 +43,12 @@ static final class OtherObserver implements CompletableObserver, Disposable { private static final long serialVersionUID = 703409937383992161L; - final MaybeObserver actual; + final MaybeObserver downstream; final MaybeSource source; OtherObserver(MaybeObserver actual, MaybeSource source) { - this.actual = actual; + this.downstream = actual; this.source = source; } @@ -56,18 +56,18 @@ static final class OtherObserver public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - source.subscribe(new DelayWithMainObserver(this, actual)); + source.subscribe(new DelayWithMainObserver(this, downstream)); } @Override @@ -85,11 +85,11 @@ static final class DelayWithMainObserver implements MaybeObserver { final AtomicReference parent; - final MaybeObserver actual; + final MaybeObserver downstream; - DelayWithMainObserver(AtomicReference parent, MaybeObserver actual) { + DelayWithMainObserver(AtomicReference parent, MaybeObserver downstream) { this.parent = parent; - this.actual = actual; + this.downstream = downstream; } @Override @@ -99,17 +99,17 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDetach.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDetach.java index 8d0883c45e..c6da27b3bd 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDetach.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDetach.java @@ -35,61 +35,61 @@ protected void subscribeActual(MaybeObserver observer) { static final class DetachMaybeObserver implements MaybeObserver, Disposable { - MaybeObserver actual; + MaybeObserver downstream; - Disposable d; + Disposable upstream; - DetachMaybeObserver(MaybeObserver actual) { - this.actual = actual; + DetachMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - actual = null; - d.dispose(); - d = DisposableHelper.DISPOSED; + downstream = null; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; - MaybeObserver a = actual; + upstream = DisposableHelper.DISPOSED; + MaybeObserver a = downstream; if (a != null) { - actual = null; + downstream = null; a.onSuccess(value); } } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - MaybeObserver a = actual; + upstream = DisposableHelper.DISPOSED; + MaybeObserver a = downstream; if (a != null) { - actual = null; + downstream = null; a.onError(e); } } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; - MaybeObserver a = actual; + upstream = DisposableHelper.DISPOSED; + MaybeObserver a = downstream; if (a != null) { - actual = null; + downstream = null; a.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java index 017412ff41..e87790321f 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccess.java @@ -42,29 +42,29 @@ protected void subscribeActual(MaybeObserver observer) { static final class DoAfterObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final Consumer onAfterSuccess; - Disposable d; + Disposable upstream; DoAfterObserver(MaybeObserver actual, Consumer onAfterSuccess) { - this.actual = actual; + this.downstream = actual; this.onAfterSuccess = onAfterSuccess; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T t) { - actual.onSuccess(t); + downstream.onSuccess(t); try { onAfterSuccess.accept(t); @@ -77,22 +77,22 @@ public void onSuccess(T t) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java index c1db295b50..7b5573661f 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoFinally.java @@ -46,53 +46,53 @@ static final class DoFinallyObserver extends AtomicInteger implements MaybeOb private static final long serialVersionUID = 4109457741734051389L; - final MaybeObserver actual; + final MaybeObserver downstream; final Action onFinally; - Disposable d; + Disposable upstream; DoFinallyObserver(MaybeObserver actual, Action onFinally) { - this.actual = actual; + this.downstream = actual; this.onFinally = onFinally; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T t) { - actual.onSuccess(t); + downstream.onSuccess(t); runFinally(); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); runFinally(); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); runFinally(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); runFinally(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } void runFinally() { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoOnEvent.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoOnEvent.java index a4c624ebb1..4769ee79f4 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoOnEvent.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoOnEvent.java @@ -40,55 +40,55 @@ protected void subscribeActual(MaybeObserver observer) { } static final class DoOnEventMaybeObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final BiConsumer onEvent; - Disposable d; + Disposable upstream; DoOnEventMaybeObserver(MaybeObserver actual, BiConsumer onEvent) { - this.actual = actual; + this.downstream = actual; this.onEvent = onEvent; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; try { onEvent.accept(value, null); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; try { onEvent.accept(null, e); @@ -97,22 +97,22 @@ public void onError(Throwable e) { e = new CompositeException(e, ex); } - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; try { onEvent.accept(null, null); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeEqualSingle.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeEqualSingle.java index f2d69368e3..4f843635aa 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeEqualSingle.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeEqualSingle.java @@ -53,7 +53,7 @@ protected void subscribeActual(SingleObserver observer) { static final class EqualCoordinator extends AtomicInteger implements Disposable { - final SingleObserver actual; + final SingleObserver downstream; final EqualObserver observer1; @@ -63,7 +63,7 @@ static final class EqualCoordinator EqualCoordinator(SingleObserver actual, BiPredicate isEqual) { super(2); - this.actual = actual; + this.downstream = actual; this.isEqual = isEqual; this.observer1 = new EqualObserver(this); this.observer2 = new EqualObserver(this); @@ -98,13 +98,13 @@ void done() { b = isEqual.test((T)o1, (T)o2); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } - actual.onSuccess(b); + downstream.onSuccess(b); } else { - actual.onSuccess(o1 == null && o2 == null); + downstream.onSuccess(o1 == null && o2 == null); } } } @@ -116,7 +116,7 @@ void error(EqualObserver sender, Throwable ex) { } else { observer1.dispose(); } - actual.onError(ex); + downstream.onError(ex); } else { RxJavaPlugins.onError(ex); } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilter.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilter.java index b77b1459f8..fd556c3a66 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilter.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilter.java @@ -41,35 +41,35 @@ protected void subscribeActual(MaybeObserver observer) { static final class FilterMaybeObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final Predicate predicate; - Disposable d; + Disposable upstream; FilterMaybeObserver(MaybeObserver actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override public void dispose() { - Disposable d = this.d; - this.d = DisposableHelper.DISPOSED; + Disposable d = this.upstream; + this.upstream = DisposableHelper.DISPOSED; d.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -81,25 +81,25 @@ public void onSuccess(T value) { b = predicate.test(value); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } if (b) { - actual.onSuccess(value); + downstream.onSuccess(value); } else { - actual.onComplete(); + downstream.onComplete(); } } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilterSingle.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilterSingle.java index b1495f5cef..820bc8b7ae 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilterSingle.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilterSingle.java @@ -42,35 +42,35 @@ protected void subscribeActual(MaybeObserver observer) { static final class FilterMaybeObserver implements SingleObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final Predicate predicate; - Disposable d; + Disposable upstream; FilterMaybeObserver(MaybeObserver actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override public void dispose() { - Disposable d = this.d; - this.d = DisposableHelper.DISPOSED; + Disposable d = this.upstream; + this.upstream = DisposableHelper.DISPOSED; d.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -82,20 +82,20 @@ public void onSuccess(T value) { b = predicate.test(value); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } if (b) { - actual.onSuccess(value); + downstream.onSuccess(value); } else { - actual.onComplete(); + downstream.onComplete(); } } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapBiSelector.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapBiSelector.java index f7735d0a8e..2b9b8ec339 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapBiSelector.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapBiSelector.java @@ -76,7 +76,7 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(inner, d)) { - inner.actual.onSubscribe(this); + inner.downstream.onSubscribe(this); } } @@ -88,7 +88,7 @@ public void onSuccess(T value) { next = ObjectHelper.requireNonNull(mapper.apply(value), "The mapper returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - inner.actual.onError(ex); + inner.downstream.onError(ex); return; } @@ -100,12 +100,12 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - inner.actual.onError(e); + inner.downstream.onError(e); } @Override public void onComplete() { - inner.actual.onComplete(); + inner.downstream.onComplete(); } static final class InnerObserver @@ -114,7 +114,7 @@ static final class InnerObserver private static final long serialVersionUID = -2897979525538174559L; - final MaybeObserver actual; + final MaybeObserver downstream; final BiFunction resultSelector; @@ -122,7 +122,7 @@ static final class InnerObserver InnerObserver(MaybeObserver actual, BiFunction resultSelector) { - this.actual = actual; + this.downstream = actual; this.resultSelector = resultSelector; } @@ -142,21 +142,21 @@ public void onSuccess(U value) { r = ObjectHelper.requireNonNull(resultSelector.apply(t, value), "The resultSelector returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } - actual.onSuccess(r); + downstream.onSuccess(r); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletable.java index f0bb42e89d..aa0a7f93bc 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletable.java @@ -50,13 +50,13 @@ static final class FlatMapCompletableObserver private static final long serialVersionUID = -2177128922851101253L; - final CompletableObserver actual; + final CompletableObserver downstream; final Function mapper; FlatMapCompletableObserver(CompletableObserver actual, Function mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @@ -94,12 +94,12 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowable.java index b93574e23a..5ea9adb386 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowable.java @@ -57,13 +57,13 @@ static final class FlatMapIterableObserver private static final long serialVersionUID = -8938804753851907758L; - final Subscriber actual; + final Subscriber downstream; final Function> mapper; final AtomicLong requested; - Disposable d; + Disposable upstream; volatile Iterator it; @@ -73,17 +73,17 @@ static final class FlatMapIterableObserver FlatMapIterableObserver(Subscriber actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.requested = new AtomicLong(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -97,12 +97,12 @@ public void onSuccess(T value) { has = iterator.hasNext(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } if (!has) { - actual.onComplete(); + downstream.onComplete(); return; } @@ -112,13 +112,13 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override @@ -132,8 +132,8 @@ public void request(long n) { @Override public void cancel() { cancelled = true; - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } void fastPath(Subscriber a, Iterator iterator) { @@ -181,7 +181,7 @@ void drain() { return; } - Subscriber a = actual; + Subscriber a = downstream; Iterator iterator = this.it; if (outputFused && iterator != null) { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java index 1d3ca89756..4e5755fb8f 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java @@ -51,11 +51,11 @@ static final class FlatMapIterableObserver extends BasicQueueDisposable implements MaybeObserver { - final Observer actual; + final Observer downstream; final Function> mapper; - Disposable d; + Disposable upstream; volatile Iterator it; @@ -65,22 +65,22 @@ static final class FlatMapIterableObserver FlatMapIterableObserver(Observer actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - Observer a = actual; + Observer a = downstream; Iterator iterator; boolean has; @@ -148,20 +148,20 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { cancelled = true; - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotification.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotification.java index f5c4ea8084..f5bb71e110 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotification.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotification.java @@ -59,7 +59,7 @@ static final class FlatMapMaybeObserver private static final long serialVersionUID = 4375739915521278546L; - final MaybeObserver actual; + final MaybeObserver downstream; final Function> onSuccessMapper; @@ -67,13 +67,13 @@ static final class FlatMapMaybeObserver final Callable> onCompleteSupplier; - Disposable d; + Disposable upstream; FlatMapMaybeObserver(MaybeObserver actual, Function> onSuccessMapper, Function> onErrorMapper, Callable> onCompleteSupplier) { - this.actual = actual; + this.downstream = actual; this.onSuccessMapper = onSuccessMapper; this.onErrorMapper = onErrorMapper; this.onCompleteSupplier = onCompleteSupplier; @@ -82,7 +82,7 @@ static final class FlatMapMaybeObserver @Override public void dispose() { DisposableHelper.dispose(this); - d.dispose(); + upstream.dispose(); } @Override @@ -92,10 +92,10 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -107,7 +107,7 @@ public void onSuccess(T value) { source = ObjectHelper.requireNonNull(onSuccessMapper.apply(value), "The onSuccessMapper returned a null MaybeSource"); } catch (Exception ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } @@ -122,7 +122,7 @@ public void onError(Throwable e) { source = ObjectHelper.requireNonNull(onErrorMapper.apply(e), "The onErrorMapper returned a null MaybeSource"); } catch (Exception ex) { Exceptions.throwIfFatal(ex); - actual.onError(new CompositeException(e, ex)); + downstream.onError(new CompositeException(e, ex)); return; } @@ -137,7 +137,7 @@ public void onComplete() { source = ObjectHelper.requireNonNull(onCompleteSupplier.call(), "The onCompleteSupplier returned a null MaybeSource"); } catch (Exception ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } @@ -153,17 +153,17 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(R value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingle.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingle.java index 240cfa8015..af55a7a57d 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingle.java @@ -43,8 +43,8 @@ public MaybeFlatMapSingle(MaybeSource source, Function actual) { - source.subscribe(new FlatMapMaybeObserver(actual, mapper)); + protected void subscribeActual(SingleObserver downstream) { + source.subscribe(new FlatMapMaybeObserver(downstream, mapper)); } static final class FlatMapMaybeObserver @@ -53,12 +53,12 @@ static final class FlatMapMaybeObserver private static final long serialVersionUID = 4827726964688405508L; - final SingleObserver actual; + final SingleObserver downstream; final Function> mapper; FlatMapMaybeObserver(SingleObserver actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @@ -75,7 +75,7 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -92,18 +92,18 @@ public void onSuccess(T value) { } if (!isDisposed()) { - ss.subscribe(new FlatMapSingleObserver(this, actual)); + ss.subscribe(new FlatMapSingleObserver(this, downstream)); } } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } } @@ -111,11 +111,11 @@ static final class FlatMapSingleObserver implements SingleObserver { final AtomicReference parent; - final SingleObserver actual; + final SingleObserver downstream; - FlatMapSingleObserver(AtomicReference parent, SingleObserver actual) { + FlatMapSingleObserver(AtomicReference parent, SingleObserver downstream) { this.parent = parent; - this.actual = actual; + this.downstream = downstream; } @Override @@ -125,12 +125,12 @@ public void onSubscribe(final Disposable d) { @Override public void onSuccess(final R value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(final Throwable e) { - actual.onError(e); + downstream.onError(e); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElement.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElement.java index 91e41562d1..37795729b8 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElement.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElement.java @@ -41,8 +41,8 @@ public MaybeFlatMapSingleElement(MaybeSource source, Function actual) { - source.subscribe(new FlatMapMaybeObserver(actual, mapper)); + protected void subscribeActual(MaybeObserver downstream) { + source.subscribe(new FlatMapMaybeObserver(downstream, mapper)); } static final class FlatMapMaybeObserver @@ -51,12 +51,12 @@ static final class FlatMapMaybeObserver private static final long serialVersionUID = 4827726964688405508L; - final MaybeObserver actual; + final MaybeObserver downstream; final Function> mapper; FlatMapMaybeObserver(MaybeObserver actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @@ -73,7 +73,7 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -89,17 +89,17 @@ public void onSuccess(T value) { return; } - ss.subscribe(new FlatMapSingleObserver(this, actual)); + ss.subscribe(new FlatMapSingleObserver(this, downstream)); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } @@ -107,11 +107,11 @@ static final class FlatMapSingleObserver implements SingleObserver { final AtomicReference parent; - final MaybeObserver actual; + final MaybeObserver downstream; - FlatMapSingleObserver(AtomicReference parent, MaybeObserver actual) { + FlatMapSingleObserver(AtomicReference parent, MaybeObserver downstream) { this.parent = parent; - this.actual = actual; + this.downstream = downstream; } @Override @@ -121,12 +121,12 @@ public void onSubscribe(final Disposable d) { @Override public void onSuccess(final R value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(final Throwable e) { - actual.onError(e); + downstream.onError(e); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatten.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatten.java index bca244ac4d..b05aebd236 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatten.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatten.java @@ -49,22 +49,22 @@ static final class FlatMapMaybeObserver private static final long serialVersionUID = 4375739915521278546L; - final MaybeObserver actual; + final MaybeObserver downstream; final Function> mapper; - Disposable d; + Disposable upstream; FlatMapMaybeObserver(MaybeObserver actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @Override public void dispose() { DisposableHelper.dispose(this); - d.dispose(); + upstream.dispose(); } @Override @@ -74,10 +74,10 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -89,7 +89,7 @@ public void onSuccess(T value) { source = ObjectHelper.requireNonNull(mapper.apply(value), "The mapper returned a null MaybeSource"); } catch (Exception ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } @@ -100,12 +100,12 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } final class InnerObserver implements MaybeObserver { @@ -117,17 +117,17 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(R value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFromCompletable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFromCompletable.java index 183588f290..2753d992da 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFromCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFromCompletable.java @@ -42,44 +42,44 @@ protected void subscribeActual(MaybeObserver observer) { } static final class FromCompletableObserver implements CompletableObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Disposable d; + Disposable upstream; - FromCompletableObserver(MaybeObserver actual) { - this.actual = actual; + FromCompletableObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; - actual.onComplete(); + upstream = DisposableHelper.DISPOSED; + downstream.onComplete(); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFromSingle.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFromSingle.java index 66dab6d1ab..b610a06a12 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFromSingle.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFromSingle.java @@ -42,44 +42,44 @@ protected void subscribeActual(MaybeObserver observer) { } static final class FromSingleObserver implements SingleObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Disposable d; + Disposable upstream; - FromSingleObserver(MaybeObserver actual) { - this.actual = actual; + FromSingleObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; - actual.onSuccess(value); + upstream = DisposableHelper.DISPOSED; + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeHide.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeHide.java index 80454b81f8..805f7cdc0d 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeHide.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeHide.java @@ -35,47 +35,47 @@ protected void subscribeActual(MaybeObserver observer) { static final class HideMaybeObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Disposable d; + Disposable upstream; - HideMaybeObserver(MaybeObserver actual) { - this.actual = actual; + HideMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElement.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElement.java index 8b3c40e1f3..000de8cf0e 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElement.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElement.java @@ -35,50 +35,50 @@ protected void subscribeActual(MaybeObserver observer) { static final class IgnoreMaybeObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Disposable d; + Disposable upstream; - IgnoreMaybeObserver(MaybeObserver actual) { - this.actual = actual; + IgnoreMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; - actual.onComplete(); + upstream = DisposableHelper.DISPOSED; + downstream.onComplete(); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; - actual.onComplete(); + upstream = DisposableHelper.DISPOSED; + downstream.onComplete(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElementCompletable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElementCompletable.java index 10f6b028a3..ac49d66e04 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElementCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElementCompletable.java @@ -44,50 +44,50 @@ public Maybe fuseToMaybe() { static final class IgnoreMaybeObserver implements MaybeObserver, Disposable { - final CompletableObserver actual; + final CompletableObserver downstream; - Disposable d; + Disposable upstream; - IgnoreMaybeObserver(CompletableObserver actual) { - this.actual = actual; + IgnoreMaybeObserver(CompletableObserver downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; - actual.onComplete(); + upstream = DisposableHelper.DISPOSED; + downstream.onComplete(); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; - actual.onComplete(); + upstream = DisposableHelper.DISPOSED; + downstream.onComplete(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeIsEmpty.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeIsEmpty.java index 284977787a..642dc641ce 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeIsEmpty.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeIsEmpty.java @@ -37,46 +37,46 @@ protected void subscribeActual(MaybeObserver observer) { static final class IsEmptyMaybeObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Disposable d; + Disposable upstream; - IsEmptyMaybeObserver(MaybeObserver actual) { - this.actual = actual; + IsEmptyMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(false); + downstream.onSuccess(false); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onSuccess(true); + downstream.onSuccess(true); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeIsEmptySingle.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeIsEmptySingle.java index 84811071f5..c8acdff348 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeIsEmptySingle.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeIsEmptySingle.java @@ -52,50 +52,50 @@ protected void subscribeActual(SingleObserver observer) { static final class IsEmptyMaybeObserver implements MaybeObserver, Disposable { - final SingleObserver actual; + final SingleObserver downstream; - Disposable d; + Disposable upstream; - IsEmptyMaybeObserver(SingleObserver actual) { - this.actual = actual; + IsEmptyMaybeObserver(SingleObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; - actual.onSuccess(false); + upstream = DisposableHelper.DISPOSED; + downstream.onSuccess(false); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; - actual.onSuccess(true); + upstream = DisposableHelper.DISPOSED; + downstream.onSuccess(true); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeMap.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMap.java index 578d9b319d..cda167855c 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeMap.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMap.java @@ -42,35 +42,35 @@ protected void subscribeActual(MaybeObserver observer) { static final class MapMaybeObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final Function mapper; - Disposable d; + Disposable upstream; MapMaybeObserver(MaybeObserver actual, Function mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @Override public void dispose() { - Disposable d = this.d; - this.d = DisposableHelper.DISPOSED; + Disposable d = this.upstream; + this.upstream = DisposableHelper.DISPOSED; d.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -82,21 +82,21 @@ public void onSuccess(T value) { v = ObjectHelper.requireNonNull(mapper.apply(value), "The mapper returned a null item"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } - actual.onSuccess(v); + downstream.onSuccess(v); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeMergeArray.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMergeArray.java index a012deecf8..762452ba7a 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeMergeArray.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMergeArray.java @@ -72,7 +72,7 @@ static final class MergeMaybeObserver private static final long serialVersionUID = -660395290758764731L; - final Subscriber actual; + final Subscriber downstream; final CompositeDisposable set; @@ -91,7 +91,7 @@ static final class MergeMaybeObserver long consumed; MergeMaybeObserver(Subscriber actual, int sourceCount, SimpleQueueWithConsumerIndex queue) { - this.actual = actual; + this.downstream = actual; this.sourceCount = sourceCount; this.set = new CompositeDisposable(); this.requested = new AtomicLong(); @@ -184,7 +184,7 @@ boolean isCancelled() { @SuppressWarnings("unchecked") void drainNormal() { int missed = 1; - Subscriber a = actual; + Subscriber a = downstream; SimpleQueueWithConsumerIndex q = queue; long e = consumed; @@ -252,7 +252,7 @@ void drainNormal() { void drainFused() { int missed = 1; - Subscriber a = actual; + Subscriber a = downstream; SimpleQueueWithConsumerIndex q = queue; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeObserveOn.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeObserveOn.java index 3feda9db3e..a3d83612d5 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeObserveOn.java @@ -45,7 +45,7 @@ static final class ObserveOnMaybeObserver private static final long serialVersionUID = 8571289934935992137L; - final MaybeObserver actual; + final MaybeObserver downstream; final Scheduler scheduler; @@ -53,7 +53,7 @@ static final class ObserveOnMaybeObserver Throwable error; ObserveOnMaybeObserver(MaybeObserver actual, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.scheduler = scheduler; } @@ -70,7 +70,7 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -96,14 +96,14 @@ public void run() { Throwable ex = error; if (ex != null) { error = null; - actual.onError(ex); + downstream.onError(ex); } else { T v = value; if (v != null) { value = null; - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorComplete.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorComplete.java index 54825485d4..10fe0610bc 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorComplete.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorComplete.java @@ -42,29 +42,29 @@ protected void subscribeActual(MaybeObserver observer) { static final class OnErrorCompleteMaybeObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final Predicate predicate; - Disposable d; + Disposable upstream; OnErrorCompleteMaybeObserver(MaybeObserver actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override @@ -75,30 +75,30 @@ public void onError(Throwable e) { b = predicate.test(e); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(new CompositeException(e, ex)); + downstream.onError(new CompositeException(e, ex)); return; } if (b) { - actual.onComplete(); + downstream.onComplete(); } else { - actual.onError(e); + downstream.onError(e); } } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorNext.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorNext.java index ebd866c667..5591d41c20 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorNext.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorNext.java @@ -53,7 +53,7 @@ static final class OnErrorNextMaybeObserver private static final long serialVersionUID = 2026620218879969836L; - final MaybeObserver actual; + final MaybeObserver downstream; final Function> resumeFunction; @@ -62,7 +62,7 @@ static final class OnErrorNextMaybeObserver OnErrorNextMaybeObserver(MaybeObserver actual, Function> resumeFunction, boolean allowFatal) { - this.actual = actual; + this.downstream = actual; this.resumeFunction = resumeFunction; this.allowFatal = allowFatal; } @@ -80,19 +80,19 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { if (!allowFatal && !(e instanceof Exception)) { - actual.onError(e); + downstream.onError(e); return; } MaybeSource m; @@ -101,48 +101,48 @@ public void onError(Throwable e) { m = ObjectHelper.requireNonNull(resumeFunction.apply(e), "The resumeFunction returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(new CompositeException(e, ex)); + downstream.onError(new CompositeException(e, ex)); return; } DisposableHelper.replace(this, null); - m.subscribe(new NextMaybeObserver(actual, this)); + m.subscribe(new NextMaybeObserver(downstream, this)); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } static final class NextMaybeObserver implements MaybeObserver { - final MaybeObserver actual; + final MaybeObserver downstream; - final AtomicReference d; + final AtomicReference upstream; NextMaybeObserver(MaybeObserver actual, AtomicReference d) { - this.actual = actual; - this.d = d; + this.downstream = actual; + this.upstream = d; } @Override public void onSubscribe(Disposable d) { - DisposableHelper.setOnce(this.d, d); + DisposableHelper.setOnce(this.upstream, d); } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorReturn.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorReturn.java index dda373fdb8..568f15009a 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorReturn.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorReturn.java @@ -41,40 +41,40 @@ protected void subscribeActual(MaybeObserver observer) { static final class OnErrorReturnMaybeObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final Function valueSupplier; - Disposable d; + Disposable upstream; OnErrorReturnMaybeObserver(MaybeObserver actual, Function valueSupplier) { - this.actual = actual; + this.downstream = actual; this.valueSupplier = valueSupplier; } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override @@ -85,16 +85,16 @@ public void onError(Throwable e) { v = ObjectHelper.requireNonNull(valueSupplier.apply(e), "The valueSupplier returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(new CompositeException(e, ex)); + downstream.onError(new CompositeException(e, ex)); return; } - actual.onSuccess(v); + downstream.onSuccess(v); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybePeek.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybePeek.java index 46fcf24e01..1d6179abf4 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybePeek.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybePeek.java @@ -57,14 +57,14 @@ protected void subscribeActual(MaybeObserver observer) { } static final class MaybePeekObserver implements MaybeObserver, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final MaybePeek parent; - Disposable d; + Disposable upstream; MaybePeekObserver(MaybeObserver actual, MaybePeek parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } @@ -77,37 +77,37 @@ public void dispose() { RxJavaPlugins.onError(ex); } - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { + if (DisposableHelper.validate(this.upstream, d)) { try { parent.onSubscribeCall.accept(d); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); d.dispose(); - this.d = DisposableHelper.DISPOSED; - EmptyDisposable.error(ex, actual); + this.upstream = DisposableHelper.DISPOSED; + EmptyDisposable.error(ex, downstream); return; } - this.d = d; + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - if (this.d == DisposableHelper.DISPOSED) { + if (this.upstream == DisposableHelper.DISPOSED) { return; } try { @@ -117,16 +117,16 @@ public void onSuccess(T value) { onErrorInner(ex); return; } - this.d = DisposableHelper.DISPOSED; + this.upstream = DisposableHelper.DISPOSED; - actual.onSuccess(value); + downstream.onSuccess(value); onAfterTerminate(); } @Override public void onError(Throwable e) { - if (this.d == DisposableHelper.DISPOSED) { + if (this.upstream == DisposableHelper.DISPOSED) { RxJavaPlugins.onError(e); return; } @@ -142,16 +142,16 @@ void onErrorInner(Throwable e) { e = new CompositeException(e, ex); } - this.d = DisposableHelper.DISPOSED; + this.upstream = DisposableHelper.DISPOSED; - actual.onError(e); + downstream.onError(e); onAfterTerminate(); } @Override public void onComplete() { - if (this.d == DisposableHelper.DISPOSED) { + if (this.upstream == DisposableHelper.DISPOSED) { return; } @@ -162,9 +162,9 @@ public void onComplete() { onErrorInner(ex); return; } - this.d = DisposableHelper.DISPOSED; + this.upstream = DisposableHelper.DISPOSED; - actual.onComplete(); + downstream.onComplete(); onAfterTerminate(); } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSubscribeOn.java index 9a7da8dfa0..da2ba08070 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSubscribeOn.java @@ -63,10 +63,10 @@ static final class SubscribeOnMaybeObserver private static final long serialVersionUID = 8571289934935992137L; - final MaybeObserver actual; + final MaybeObserver downstream; - SubscribeOnMaybeObserver(MaybeObserver actual) { - this.actual = actual; + SubscribeOnMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; this.task = new SequentialDisposable(); } @@ -88,17 +88,17 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmpty.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmpty.java index 396714eb7b..77d2d8f333 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmpty.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmpty.java @@ -44,12 +44,12 @@ static final class SwitchIfEmptyMaybeObserver private static final long serialVersionUID = -2223459372976438024L; - final MaybeObserver actual; + final MaybeObserver downstream; final MaybeSource other; SwitchIfEmptyMaybeObserver(MaybeObserver actual, MaybeSource other) { - this.actual = actual; + this.downstream = actual; this.other = other; } @@ -66,18 +66,18 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override @@ -85,18 +85,18 @@ public void onComplete() { Disposable d = get(); if (d != DisposableHelper.DISPOSED) { if (compareAndSet(d, null)) { - other.subscribe(new OtherMaybeObserver(actual, this)); + other.subscribe(new OtherMaybeObserver(downstream, this)); } } } static final class OtherMaybeObserver implements MaybeObserver { - final MaybeObserver actual; + final MaybeObserver downstream; final AtomicReference parent; OtherMaybeObserver(MaybeObserver actual, AtomicReference parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } @Override @@ -105,15 +105,15 @@ public void onSubscribe(Disposable d) { } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingle.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingle.java index 89615edd03..798b3ef24f 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingle.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingle.java @@ -51,12 +51,12 @@ static final class SwitchIfEmptyMaybeObserver private static final long serialVersionUID = 4603919676453758899L; - final SingleObserver actual; + final SingleObserver downstream; final SingleSource other; SwitchIfEmptyMaybeObserver(SingleObserver actual, SingleSource other) { - this.actual = actual; + this.downstream = actual; this.other = other; } @@ -73,18 +73,18 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override @@ -92,18 +92,18 @@ public void onComplete() { Disposable d = get(); if (d != DisposableHelper.DISPOSED) { if (compareAndSet(d, null)) { - other.subscribe(new OtherSingleObserver(actual, this)); + other.subscribe(new OtherSingleObserver(downstream, this)); } } } static final class OtherSingleObserver implements SingleObserver { - final SingleObserver actual; + final SingleObserver downstream; final AtomicReference parent; OtherSingleObserver(SingleObserver actual, AtomicReference parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } @Override @@ -112,11 +112,11 @@ public void onSubscribe(Disposable d) { } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilMaybe.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilMaybe.java index 14f030e5a1..56a5cac4f7 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilMaybe.java @@ -51,12 +51,12 @@ static final class TakeUntilMainMaybeObserver private static final long serialVersionUID = -2187421758664251153L; - final MaybeObserver actual; + final MaybeObserver downstream; final TakeUntilOtherMaybeObserver other; - TakeUntilMainMaybeObserver(MaybeObserver actual) { - this.actual = actual; + TakeUntilMainMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; this.other = new TakeUntilOtherMaybeObserver(this); } @@ -80,7 +80,7 @@ public void onSubscribe(Disposable d) { public void onSuccess(T value) { DisposableHelper.dispose(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onSuccess(value); + downstream.onSuccess(value); } } @@ -88,7 +88,7 @@ public void onSuccess(T value) { public void onError(Throwable e) { DisposableHelper.dispose(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -98,13 +98,13 @@ public void onError(Throwable e) { public void onComplete() { DisposableHelper.dispose(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onComplete(); + downstream.onComplete(); } } void otherError(Throwable e) { if (DisposableHelper.dispose(this)) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -112,7 +112,7 @@ void otherError(Throwable e) { void otherComplete() { if (DisposableHelper.dispose(this)) { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilPublisher.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilPublisher.java index 793436526d..656cf473b5 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilPublisher.java @@ -54,12 +54,12 @@ static final class TakeUntilMainMaybeObserver private static final long serialVersionUID = -2187421758664251153L; - final MaybeObserver actual; + final MaybeObserver downstream; final TakeUntilOtherMaybeObserver other; - TakeUntilMainMaybeObserver(MaybeObserver actual) { - this.actual = actual; + TakeUntilMainMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; this.other = new TakeUntilOtherMaybeObserver(this); } @@ -83,7 +83,7 @@ public void onSubscribe(Disposable d) { public void onSuccess(T value) { SubscriptionHelper.cancel(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onSuccess(value); + downstream.onSuccess(value); } } @@ -91,7 +91,7 @@ public void onSuccess(T value) { public void onError(Throwable e) { SubscriptionHelper.cancel(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -101,13 +101,13 @@ public void onError(Throwable e) { public void onComplete() { SubscriptionHelper.cancel(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onComplete(); + downstream.onComplete(); } } void otherError(Throwable e) { if (DisposableHelper.dispose(this)) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -115,7 +115,7 @@ void otherError(Throwable e) { void otherComplete() { if (DisposableHelper.dispose(this)) { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutMaybe.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutMaybe.java index 3e8a9ad050..d162573139 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutMaybe.java @@ -57,7 +57,7 @@ static final class TimeoutMainMaybeObserver private static final long serialVersionUID = -5955289211445418871L; - final MaybeObserver actual; + final MaybeObserver downstream; final TimeoutOtherMaybeObserver other; @@ -66,7 +66,7 @@ static final class TimeoutMainMaybeObserver final TimeoutFallbackMaybeObserver otherObserver; TimeoutMainMaybeObserver(MaybeObserver actual, MaybeSource fallback) { - this.actual = actual; + this.downstream = actual; this.other = new TimeoutOtherMaybeObserver(this); this.fallback = fallback; this.otherObserver = fallback != null ? new TimeoutFallbackMaybeObserver(actual) : null; @@ -96,7 +96,7 @@ public void onSubscribe(Disposable d) { public void onSuccess(T value) { DisposableHelper.dispose(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onSuccess(value); + downstream.onSuccess(value); } } @@ -104,7 +104,7 @@ public void onSuccess(T value) { public void onError(Throwable e) { DisposableHelper.dispose(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -114,13 +114,13 @@ public void onError(Throwable e) { public void onComplete() { DisposableHelper.dispose(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onComplete(); + downstream.onComplete(); } } public void otherError(Throwable e) { if (DisposableHelper.dispose(this)) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -129,7 +129,7 @@ public void otherError(Throwable e) { public void otherComplete() { if (DisposableHelper.dispose(this)) { if (fallback == null) { - actual.onError(new TimeoutException()); + downstream.onError(new TimeoutException()); } else { fallback.subscribe(otherObserver); } @@ -177,10 +177,10 @@ static final class TimeoutFallbackMaybeObserver private static final long serialVersionUID = 8663801314800248617L; - final MaybeObserver actual; + final MaybeObserver downstream; - TimeoutFallbackMaybeObserver(MaybeObserver actual) { - this.actual = actual; + TimeoutFallbackMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override @@ -190,17 +190,17 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisher.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisher.java index 801e646e7b..64ab706f5e 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisher.java @@ -60,7 +60,7 @@ static final class TimeoutMainMaybeObserver private static final long serialVersionUID = -5955289211445418871L; - final MaybeObserver actual; + final MaybeObserver downstream; final TimeoutOtherMaybeObserver other; @@ -69,7 +69,7 @@ static final class TimeoutMainMaybeObserver final TimeoutFallbackMaybeObserver otherObserver; TimeoutMainMaybeObserver(MaybeObserver actual, MaybeSource fallback) { - this.actual = actual; + this.downstream = actual; this.other = new TimeoutOtherMaybeObserver(this); this.fallback = fallback; this.otherObserver = fallback != null ? new TimeoutFallbackMaybeObserver(actual) : null; @@ -99,7 +99,7 @@ public void onSubscribe(Disposable d) { public void onSuccess(T value) { SubscriptionHelper.cancel(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onSuccess(value); + downstream.onSuccess(value); } } @@ -107,7 +107,7 @@ public void onSuccess(T value) { public void onError(Throwable e) { SubscriptionHelper.cancel(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -117,13 +117,13 @@ public void onError(Throwable e) { public void onComplete() { SubscriptionHelper.cancel(other); if (getAndSet(DisposableHelper.DISPOSED) != DisposableHelper.DISPOSED) { - actual.onComplete(); + downstream.onComplete(); } } public void otherError(Throwable e) { if (DisposableHelper.dispose(this)) { - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -132,7 +132,7 @@ public void otherError(Throwable e) { public void otherComplete() { if (DisposableHelper.dispose(this)) { if (fallback == null) { - actual.onError(new TimeoutException()); + downstream.onError(new TimeoutException()); } else { fallback.subscribe(otherObserver); } @@ -182,10 +182,10 @@ static final class TimeoutFallbackMaybeObserver private static final long serialVersionUID = 8663801314800248617L; - final MaybeObserver actual; + final MaybeObserver downstream; - TimeoutFallbackMaybeObserver(MaybeObserver actual) { - this.actual = actual; + TimeoutFallbackMaybeObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override @@ -195,17 +195,17 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimer.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimer.java index 3aaacd98d3..5d2c1c4151 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimer.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimer.java @@ -47,15 +47,15 @@ protected void subscribeActual(final MaybeObserver observer) { static final class TimerDisposable extends AtomicReference implements Disposable, Runnable { private static final long serialVersionUID = 2875964065294031672L; - final MaybeObserver actual; + final MaybeObserver downstream; - TimerDisposable(final MaybeObserver actual) { - this.actual = actual; + TimerDisposable(final MaybeObserver downstream) { + this.downstream = downstream; } @Override public void run() { - actual.onSuccess(0L); + downstream.onSuccess(0L); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToFlowable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToFlowable.java index 7c6fb1e7f8..c477a86b50 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToFlowable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToFlowable.java @@ -50,18 +50,18 @@ static final class MaybeToFlowableSubscriber extends DeferredScalarSubscripti private static final long serialVersionUID = 7603343402964826922L; - Disposable d; + Disposable upstream; - MaybeToFlowableSubscriber(Subscriber actual) { - super(actual); + MaybeToFlowableSubscriber(Subscriber downstream) { + super(downstream); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -72,18 +72,18 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void cancel() { super.cancel(); - d.dispose(); + upstream.dispose(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java index 9b543c6472..8caa294718 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToObservable.java @@ -60,18 +60,18 @@ static final class MaybeToObservableObserver extends DeferredScalarDisposable private static final long serialVersionUID = 7603343402964826922L; - Disposable d; + Disposable upstream; - MaybeToObservableObserver(Observer actual) { - super(actual); + MaybeToObservableObserver(Observer downstream) { + super(downstream); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -93,7 +93,7 @@ public void onComplete() { @Override public void dispose() { super.dispose(); - d.dispose(); + upstream.dispose(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToSingle.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToSingle.java index a15eb0f167..146bbb23f8 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeToSingle.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeToSingle.java @@ -47,55 +47,55 @@ protected void subscribeActual(SingleObserver observer) { } static final class ToSingleMaybeSubscriber implements MaybeObserver, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final T defaultValue; - Disposable d; + Disposable upstream; ToSingleMaybeSubscriber(SingleObserver actual, T defaultValue) { - this.actual = actual; + this.downstream = actual; this.defaultValue = defaultValue; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; - actual.onSuccess(value); + upstream = DisposableHelper.DISPOSED; + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; if (defaultValue != null) { - actual.onSuccess(defaultValue); + downstream.onSuccess(defaultValue); } else { - actual.onError(new NoSuchElementException("The MaybeSource is empty")); + downstream.onError(new NoSuchElementException("The MaybeSource is empty")); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeUnsubscribeOn.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeUnsubscribeOn.java index 2375c01221..a6afe4c51a 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeUnsubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeUnsubscribeOn.java @@ -43,14 +43,14 @@ static final class UnsubscribeOnMaybeObserver extends AtomicReference actual; + final MaybeObserver downstream; final Scheduler scheduler; Disposable ds; UnsubscribeOnMaybeObserver(MaybeObserver actual, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.scheduler = scheduler; } @@ -76,23 +76,23 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeUsing.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeUsing.java index 130043471f..786772eacf 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeUsing.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeUsing.java @@ -102,25 +102,25 @@ static final class UsingObserver private static final long serialVersionUID = -674404550052917487L; - final MaybeObserver actual; + final MaybeObserver downstream; final Consumer disposer; final boolean eager; - Disposable d; + Disposable upstream; UsingObserver(MaybeObserver actual, D resource, Consumer disposer, boolean eager) { super(resource); - this.actual = actual; + this.downstream = actual; this.disposer = disposer; this.eager = eager; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; disposeResourceAfter(); } @@ -139,22 +139,22 @@ void disposeResourceAfter() { @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @SuppressWarnings("unchecked") @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; if (eager) { Object resource = getAndSet(this); if (resource != this) { @@ -162,7 +162,7 @@ public void onSuccess(T value) { disposer.accept((D)resource); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } } else { @@ -170,7 +170,7 @@ public void onSuccess(T value) { } } - actual.onSuccess(value); + downstream.onSuccess(value); if (!eager) { disposeResourceAfter(); @@ -180,7 +180,7 @@ public void onSuccess(T value) { @SuppressWarnings("unchecked") @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; if (eager) { Object resource = getAndSet(this); if (resource != this) { @@ -195,7 +195,7 @@ public void onError(Throwable e) { } } - actual.onError(e); + downstream.onError(e); if (!eager) { disposeResourceAfter(); @@ -205,7 +205,7 @@ public void onError(Throwable e) { @SuppressWarnings("unchecked") @Override public void onComplete() { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; if (eager) { Object resource = getAndSet(this); if (resource != this) { @@ -213,7 +213,7 @@ public void onComplete() { disposer.accept((D)resource); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } } else { @@ -221,7 +221,7 @@ public void onComplete() { } } - actual.onComplete(); + downstream.onComplete(); if (!eager) { disposeResourceAfter(); diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeZipArray.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeZipArray.java index eeda31ac19..430d3ff2b6 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeZipArray.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeZipArray.java @@ -69,7 +69,7 @@ static final class ZipCoordinator extends AtomicInteger implements Disposa private static final long serialVersionUID = -5556924161382950569L; - final MaybeObserver actual; + final MaybeObserver downstream; final Function zipper; @@ -80,7 +80,7 @@ static final class ZipCoordinator extends AtomicInteger implements Disposa @SuppressWarnings("unchecked") ZipCoordinator(MaybeObserver observer, int n, Function zipper) { super(n); - this.actual = observer; + this.downstream = observer; this.zipper = zipper; ZipMaybeObserver[] o = new ZipMaybeObserver[n]; for (int i = 0; i < n; i++) { @@ -113,11 +113,11 @@ void innerSuccess(T value, int index) { v = ObjectHelper.requireNonNull(zipper.apply(values), "The zipper returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } - actual.onSuccess(v); + downstream.onSuccess(v); } } @@ -135,7 +135,7 @@ void disposeExcept(int index) { void innerError(Throwable ex, int index) { if (getAndSet(0) > 0) { disposeExcept(index); - actual.onError(ex); + downstream.onError(ex); } else { RxJavaPlugins.onError(ex); } @@ -144,7 +144,7 @@ void innerError(Throwable ex, int index) { void innerComplete(int index) { if (getAndSet(0) > 0) { disposeExcept(index); - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java index 48a503c13c..41fa298128 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletable.java @@ -100,12 +100,12 @@ static final class ConcatMapCompletableObserver } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(upstream, s)) { - this.upstream = s; - if (s instanceof QueueDisposable) { + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(upstream, d)) { + this.upstream = d; + if (d instanceof QueueDisposable) { @SuppressWarnings("unchecked") - QueueDisposable qd = (QueueDisposable) s; + QueueDisposable qd = (QueueDisposable) d; int m = qd.requestFusion(QueueDisposable.ANY); if (m == QueueDisposable.SYNC) { diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java index 1a52327c72..32b174a19f 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybe.java @@ -108,9 +108,9 @@ static final class ConcatMapMaybeMainObserver } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(upstream, s)) { - upstream = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(upstream, d)) { + upstream = d; downstream.onSubscribe(this); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java index b272f27218..1358e1ed9c 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingle.java @@ -108,9 +108,9 @@ static final class ConcatMapSingleMainObserver } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(upstream, s)) { - upstream = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(upstream, d)) { + upstream = d; downstream.onSubscribe(this); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java index 7ffe99b707..1d4e8d247d 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletable.java @@ -82,9 +82,9 @@ static final class SwitchMapCompletableObserver implements Observer, Dispo } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(upstream, s)) { - this.upstream = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(upstream, d)) { + this.upstream = d; downstream.onSubscribe(this); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java index d6e904cec2..89086255e6 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybe.java @@ -91,9 +91,9 @@ static final class SwitchMapMaybeMainObserver extends AtomicInteger } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(upstream, s)) { - upstream = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(upstream, d)) { + upstream = d; downstream.onSubscribe(this); } } diff --git a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java index f739b10161..f9871aa6f9 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingle.java @@ -91,9 +91,9 @@ static final class SwitchMapSingleMainObserver extends AtomicInteger } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(upstream, s)) { - upstream = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(upstream, d)) { + upstream = d; downstream.onSubscribe(this); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java index a9d2e92cb3..776721c84e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java @@ -107,8 +107,8 @@ public T next() { } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAll.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAll.java index 7fffa31214..71d0c32ebf 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAll.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAll.java @@ -32,22 +32,22 @@ protected void subscribeActual(Observer t) { } static final class AllObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Predicate predicate; - Disposable s; + Disposable upstream; boolean done; AllObserver(Observer actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -61,15 +61,15 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } if (!b) { done = true; - s.dispose(); - actual.onNext(false); - actual.onComplete(); + upstream.dispose(); + downstream.onNext(false); + downstream.onComplete(); } } @@ -80,7 +80,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -89,18 +89,18 @@ public void onComplete() { return; } done = true; - actual.onNext(true); - actual.onComplete(); + downstream.onNext(true); + downstream.onComplete(); } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAllSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAllSingle.java index 59388fe651..3089007d6d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAllSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAllSingle.java @@ -40,22 +40,22 @@ public Observable fuseToObservable() { } static final class AllObserver implements Observer, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final Predicate predicate; - Disposable s; + Disposable upstream; boolean done; AllObserver(SingleObserver actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -69,14 +69,14 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } if (!b) { done = true; - s.dispose(); - actual.onSuccess(false); + upstream.dispose(); + downstream.onSuccess(false); } } @@ -87,7 +87,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -96,17 +96,17 @@ public void onComplete() { return; } done = true; - actual.onSuccess(true); + downstream.onSuccess(true); } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java index 65e2493f7e..2ed4fcd93b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java @@ -73,14 +73,14 @@ public void subscribeActual(Observer observer) { } static final class AmbCoordinator implements Disposable { - final Observer actual; + final Observer downstream; final AmbInnerObserver[] observers; final AtomicInteger winner = new AtomicInteger(); @SuppressWarnings("unchecked") AmbCoordinator(Observer actual, int count) { - this.actual = actual; + this.downstream = actual; this.observers = new AmbInnerObserver[count]; } @@ -88,10 +88,10 @@ public void subscribe(ObservableSource[] sources) { AmbInnerObserver[] as = observers; int len = as.length; for (int i = 0; i < len; i++) { - as[i] = new AmbInnerObserver(this, i + 1, actual); + as[i] = new AmbInnerObserver(this, i + 1, downstream); } winner.lazySet(0); // release the contents of 'as' - actual.onSubscribe(this); + downstream.onSubscribe(this); for (int i = 0; i < len; i++) { if (winner.get() != 0) { @@ -142,29 +142,29 @@ static final class AmbInnerObserver extends AtomicReference imple private static final long serialVersionUID = -1185974347409665484L; final AmbCoordinator parent; final int index; - final Observer actual; + final Observer downstream; boolean won; - AmbInnerObserver(AmbCoordinator parent, int index, Observer actual) { + AmbInnerObserver(AmbCoordinator parent, int index, Observer downstream) { this.parent = parent; this.index = index; - this.actual = actual; + this.downstream = downstream; } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override public void onNext(T t) { if (won) { - actual.onNext(t); + downstream.onNext(t); } else { if (parent.win(index)) { won = true; - actual.onNext(t); + downstream.onNext(t); } else { get().dispose(); } @@ -174,11 +174,11 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (won) { - actual.onError(t); + downstream.onError(t); } else { if (parent.win(index)) { won = true; - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -188,11 +188,11 @@ public void onError(Throwable t) { @Override public void onComplete() { if (won) { - actual.onComplete(); + downstream.onComplete(); } else { if (parent.win(index)) { won = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAny.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAny.java index a3c919067b..92f3aa02cf 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAny.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAny.java @@ -33,22 +33,22 @@ protected void subscribeActual(Observer t) { static final class AnyObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Predicate predicate; - Disposable s; + Disposable upstream; boolean done; AnyObserver(Observer actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -62,15 +62,15 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } if (b) { done = true; - s.dispose(); - actual.onNext(true); - actual.onComplete(); + upstream.dispose(); + downstream.onNext(true); + downstream.onComplete(); } } @@ -82,26 +82,26 @@ public void onError(Throwable t) { } done = true; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (!done) { done = true; - actual.onNext(false); - actual.onComplete(); + downstream.onNext(false); + downstream.onComplete(); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAnySingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAnySingle.java index 0b9c9db0fb..87f0d7c64c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAnySingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAnySingle.java @@ -42,22 +42,22 @@ public Observable fuseToObservable() { static final class AnyObserver implements Observer, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final Predicate predicate; - Disposable s; + Disposable upstream; boolean done; AnyObserver(SingleObserver actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -71,14 +71,14 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } if (b) { done = true; - s.dispose(); - actual.onSuccess(true); + upstream.dispose(); + downstream.onSuccess(true); } } @@ -90,25 +90,25 @@ public void onError(Throwable t) { } done = true; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (!done) { done = true; - actual.onSuccess(false); + downstream.onSuccess(false); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java index 9471c0b24a..9cb6ba3de3 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java @@ -49,17 +49,17 @@ protected void subscribeActual(Observer t) { } static final class BufferExactObserver> implements Observer, Disposable { - final Observer actual; + final Observer downstream; final int count; final Callable bufferSupplier; U buffer; int size; - Disposable s; + Disposable upstream; BufferExactObserver(Observer actual, int count, Callable bufferSupplier) { - this.actual = actual; + this.downstream = actual; this.count = count; this.bufferSupplier = bufferSupplier; } @@ -71,11 +71,11 @@ boolean createBuffer() { } catch (Throwable t) { Exceptions.throwIfFatal(t); buffer = null; - if (s == null) { - EmptyDisposable.error(t, actual); + if (upstream == null) { + EmptyDisposable.error(t, downstream); } else { - s.dispose(); - actual.onError(t); + upstream.dispose(); + downstream.onError(t); } return false; } @@ -86,21 +86,21 @@ boolean createBuffer() { } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override @@ -110,7 +110,7 @@ public void onNext(T t) { b.add(t); if (++size >= count) { - actual.onNext(b); + downstream.onNext(b); size = 0; createBuffer(); @@ -121,7 +121,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { buffer = null; - actual.onError(t); + downstream.onError(t); } @Override @@ -130,9 +130,9 @@ public void onComplete() { if (b != null) { buffer = null; if (!b.isEmpty()) { - actual.onNext(b); + downstream.onNext(b); } - actual.onComplete(); + downstream.onComplete(); } } } @@ -141,19 +141,19 @@ static final class BufferSkipObserver> extends AtomicBoolean implements Observer, Disposable { private static final long serialVersionUID = -8223395059921494546L; - final Observer actual; + final Observer downstream; final int count; final int skip; final Callable bufferSupplier; - Disposable s; + Disposable upstream; final ArrayDeque buffers; long index; BufferSkipObserver(Observer actual, int count, int skip, Callable bufferSupplier) { - this.actual = actual; + this.downstream = actual; this.count = count; this.skip = skip; this.bufferSupplier = bufferSupplier; @@ -161,22 +161,22 @@ static final class BufferSkipObserver> } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override @@ -188,8 +188,8 @@ public void onNext(T t) { b = ObjectHelper.requireNonNull(bufferSupplier.call(), "The bufferSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources."); } catch (Throwable e) { buffers.clear(); - s.dispose(); - actual.onError(e); + upstream.dispose(); + downstream.onError(e); return; } @@ -203,7 +203,7 @@ public void onNext(T t) { if (count <= b.size()) { it.remove(); - actual.onNext(b); + downstream.onNext(b); } } } @@ -211,15 +211,15 @@ public void onNext(T t) { @Override public void onError(Throwable t) { buffers.clear(); - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { while (!buffers.isEmpty()) { - actual.onNext(buffers.poll()); + downstream.onNext(buffers.poll()); } - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferBoundary.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferBoundary.java index b88bce3477..09f5b2d3d7 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferBoundary.java @@ -57,7 +57,7 @@ static final class BufferBoundaryObserver, Op private static final long serialVersionUID = -8466418554264089604L; - final Observer actual; + final Observer downstream; final Callable bufferSupplier; @@ -86,7 +86,7 @@ static final class BufferBoundaryObserver, Op Function> bufferClose, Callable bufferSupplier ) { - this.actual = actual; + this.downstream = actual; this.bufferSupplier = bufferSupplier; this.bufferOpen = bufferOpen; this.bufferClose = bufferClose; @@ -98,8 +98,8 @@ static final class BufferBoundaryObserver, Op } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.setOnce(this.upstream, s)) { + public void onSubscribe(Disposable d) { + if (DisposableHelper.setOnce(this.upstream, d)) { BufferOpenObserver open = new BufferOpenObserver(this); observers.add(open); @@ -240,7 +240,7 @@ void drain() { } int missed = 1; - Observer a = actual; + Observer a = downstream; SpscLinkedArrayQueue q = queue; for (;;) { @@ -293,8 +293,8 @@ static final class BufferOpenObserver } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override @@ -342,16 +342,16 @@ static final class BufferCloseObserver> } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override public void onNext(Object t) { - Disposable s = get(); - if (s != DisposableHelper.DISPOSED) { + Disposable upstream = get(); + if (upstream != DisposableHelper.DISPOSED) { lazySet(DisposableHelper.DISPOSED); - s.dispose(); + upstream.dispose(); parent.close(this, index); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferBoundarySupplier.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferBoundarySupplier.java index 15f0dd0a1c..b642bf1c9c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferBoundarySupplier.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferBoundarySupplier.java @@ -50,7 +50,7 @@ static final class BufferBoundarySupplierObserver bufferSupplier; final Callable> boundarySupplier; - Disposable s; + Disposable upstream; final AtomicReference other = new AtomicReference(); @@ -64,11 +64,11 @@ static final class BufferBoundarySupplierObserver actual = this.actual; + Observer actual = this.downstream; U b; @@ -77,7 +77,7 @@ public void onSubscribe(Disposable s) { } catch (Throwable e) { Exceptions.throwIfFatal(e); cancelled = true; - s.dispose(); + d.dispose(); EmptyDisposable.error(e, actual); return; } @@ -91,7 +91,7 @@ public void onSubscribe(Disposable s) { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); cancelled = true; - s.dispose(); + d.dispose(); EmptyDisposable.error(ex, actual); return; } @@ -121,7 +121,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { dispose(); - actual.onError(t); + downstream.onError(t); } @Override @@ -137,7 +137,7 @@ public void onComplete() { queue.offer(b); done = true; if (enter()) { - QueueDrainHelper.drainLoop(queue, actual, false, this, this); + QueueDrainHelper.drainLoop(queue, downstream, false, this, this); } } @@ -145,7 +145,7 @@ public void onComplete() { public void dispose() { if (!cancelled) { cancelled = true; - s.dispose(); + upstream.dispose(); disposeOther(); if (enter()) { @@ -172,7 +172,7 @@ void next() { } catch (Throwable e) { Exceptions.throwIfFatal(e); dispose(); - actual.onError(e); + downstream.onError(e); return; } @@ -183,8 +183,8 @@ void next() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); cancelled = true; - s.dispose(); - actual.onError(ex); + upstream.dispose(); + downstream.onError(ex); return; } @@ -208,7 +208,7 @@ void next() { @Override public void accept(Observer a, U v) { - actual.onNext(v); + downstream.onNext(v); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferExactBoundary.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferExactBoundary.java index 9547e21195..b80d303be2 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferExactBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferExactBoundary.java @@ -48,7 +48,7 @@ static final class BufferExactBoundaryObserver bufferSupplier; final ObservableSource boundary; - Disposable s; + Disposable upstream; Disposable other; @@ -62,9 +62,9 @@ static final class BufferExactBoundaryObserver bs = new BufferBoundaryObserver(this); other = bs; - actual.onSubscribe(this); + downstream.onSubscribe(this); if (!cancelled) { boundary.subscribe(bs); @@ -105,7 +105,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { dispose(); - actual.onError(t); + downstream.onError(t); } @Override @@ -121,7 +121,7 @@ public void onComplete() { queue.offer(b); done = true; if (enter()) { - QueueDrainHelper.drainLoop(queue, actual, false, this, this); + QueueDrainHelper.drainLoop(queue, downstream, false, this, this); } } @@ -130,7 +130,7 @@ public void dispose() { if (!cancelled) { cancelled = true; other.dispose(); - s.dispose(); + upstream.dispose(); if (enter()) { queue.clear(); @@ -152,7 +152,7 @@ void next() { } catch (Throwable e) { Exceptions.throwIfFatal(e); dispose(); - actual.onError(e); + downstream.onError(e); return; } @@ -170,7 +170,7 @@ void next() { @Override public void accept(Observer a, U v) { - actual.onNext(v); + downstream.onNext(v); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java index 2bc4bfbec9..bbfef8ffae 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java @@ -85,7 +85,7 @@ static final class BufferExactUnboundedObserver a, U v) { - actual.onNext(v); + downstream.onNext(v); } } @@ -224,7 +224,7 @@ static final class BufferSkipBoundedObserver> final List buffers; - Disposable s; + Disposable upstream; BufferSkipBoundedObserver(Observer actual, Callable bufferSupplier, long timespan, @@ -239,9 +239,9 @@ static final class BufferSkipBoundedObserver> } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; final U b; // NOPMD @@ -249,15 +249,15 @@ public void onSubscribe(Disposable s) { b = ObjectHelper.requireNonNull(bufferSupplier.call(), "The buffer supplied is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); - EmptyDisposable.error(e, actual); + d.dispose(); + EmptyDisposable.error(e, downstream); w.dispose(); return; } buffers.add(b); - actual.onSubscribe(this); + downstream.onSubscribe(this); w.schedulePeriodically(this, timeskip, timeskip, unit); @@ -278,7 +278,7 @@ public void onNext(T t) { public void onError(Throwable t) { done = true; clear(); - actual.onError(t); + downstream.onError(t); w.dispose(); } @@ -295,7 +295,7 @@ public void onComplete() { } done = true; if (enter()) { - QueueDrainHelper.drainLoop(queue, actual, false, w, this); + QueueDrainHelper.drainLoop(queue, downstream, false, w, this); } } @@ -304,7 +304,7 @@ public void dispose() { if (!cancelled) { cancelled = true; clear(); - s.dispose(); + upstream.dispose(); w.dispose(); } } @@ -331,7 +331,7 @@ public void run() { b = ObjectHelper.requireNonNull(bufferSupplier.call(), "The bufferSupplier returned a null buffer"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); dispose(); return; } @@ -399,7 +399,7 @@ static final class BufferExactBoundedObserver Disposable timer; - Disposable s; + Disposable upstream; long producerIndex; @@ -420,9 +420,9 @@ static final class BufferExactBoundedObserver } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; U b; @@ -430,15 +430,15 @@ public void onSubscribe(Disposable s) { b = ObjectHelper.requireNonNull(bufferSupplier.call(), "The buffer supplied is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); - EmptyDisposable.error(e, actual); + d.dispose(); + EmptyDisposable.error(e, downstream); w.dispose(); return; } buffer = b; - actual.onSubscribe(this); + downstream.onSubscribe(this); timer = w.schedulePeriodically(this, timespan, timespan, unit); } @@ -472,7 +472,7 @@ public void onNext(T t) { b = ObjectHelper.requireNonNull(bufferSupplier.call(), "The buffer supplied is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); dispose(); return; } @@ -491,7 +491,7 @@ public void onError(Throwable t) { synchronized (this) { buffer = null; } - actual.onError(t); + downstream.onError(t); w.dispose(); } @@ -508,7 +508,7 @@ public void onComplete() { queue.offer(b); done = true; if (enter()) { - QueueDrainHelper.drainLoop(queue, actual, false, this, this); + QueueDrainHelper.drainLoop(queue, downstream, false, this, this); } } @@ -522,7 +522,7 @@ public void accept(Observer a, U v) { public void dispose() { if (!cancelled) { cancelled = true; - s.dispose(); + upstream.dispose(); w.dispose(); synchronized (this) { buffer = null; @@ -544,7 +544,7 @@ public void run() { } catch (Throwable e) { Exceptions.throwIfFatal(e); dispose(); - actual.onError(e); + downstream.onError(e); return; } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java index b623bf2182..4d7563608f 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java @@ -204,8 +204,8 @@ public void removeChild(ReplayDisposable p) { } @Override - public void onSubscribe(Disposable s) { - connection.update(s); + public void onSubscribe(Disposable d) { + connection.update(d); } /** diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCollect.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCollect.java index 3d694dba9b..8deff52c47 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCollect.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCollect.java @@ -47,37 +47,37 @@ protected void subscribeActual(Observer t) { } static final class CollectObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final BiConsumer collector; final U u; - Disposable s; + Disposable upstream; boolean done; CollectObserver(Observer actual, U u, BiConsumer collector) { - this.actual = actual; + this.downstream = actual; this.collector = collector; this.u = u; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -89,7 +89,7 @@ public void onNext(T t) { try { collector.accept(u, t); } catch (Throwable e) { - s.dispose(); + upstream.dispose(); onError(e); } } @@ -101,7 +101,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -110,8 +110,8 @@ public void onComplete() { return; } done = true; - actual.onNext(u); - actual.onComplete(); + downstream.onNext(u); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCollectSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCollectSingle.java index 92e36a26a7..04753eae0a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCollectSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCollectSingle.java @@ -55,37 +55,37 @@ public Observable fuseToObservable() { } static final class CollectObserver implements Observer, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final BiConsumer collector; final U u; - Disposable s; + Disposable upstream; boolean done; CollectObserver(SingleObserver actual, U u, BiConsumer collector) { - this.actual = actual; + this.downstream = actual; this.collector = collector; this.u = u; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -97,7 +97,7 @@ public void onNext(T t) { try { collector.accept(u, t); } catch (Throwable e) { - s.dispose(); + upstream.dispose(); onError(e); } } @@ -109,7 +109,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -118,7 +118,7 @@ public void onComplete() { return; } done = true; - actual.onSuccess(u); + downstream.onSuccess(u); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java index d8ed6175f6..27b869439a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java @@ -75,7 +75,7 @@ public void subscribeActual(Observer observer) { static final class LatestCoordinator extends AtomicInteger implements Disposable { private static final long serialVersionUID = 8567835998786448817L; - final Observer actual; + final Observer downstream; final Function combiner; final CombinerObserver[] observers; Object[] latest; @@ -95,7 +95,7 @@ static final class LatestCoordinator extends AtomicInteger implements Disp LatestCoordinator(Observer actual, Function combiner, int count, int bufferSize, boolean delayError) { - this.actual = actual; + this.downstream = actual; this.combiner = combiner; this.delayError = delayError; this.latest = new Object[count]; @@ -110,7 +110,7 @@ static final class LatestCoordinator extends AtomicInteger implements Disp public void subscribe(ObservableSource[] sources) { Observer[] as = observers; int len = as.length; - actual.onSubscribe(this); + downstream.onSubscribe(this); for (int i = 0; i < len; i++) { if (done || cancelled) { return; @@ -154,7 +154,7 @@ void drain() { } final SpscLinkedArrayQueue q = queue; - final Observer a = actual; + final Observer a = downstream; final boolean delayError = this.delayError; int missed = 1; @@ -298,8 +298,8 @@ static final class CombinerObserver extends AtomicReference im } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java index f719e0a842..742661690a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java @@ -58,14 +58,14 @@ public void subscribeActual(Observer observer) { static final class SourceObserver extends AtomicInteger implements Observer, Disposable { private static final long serialVersionUID = 8828587559905699186L; - final Observer actual; + final Observer downstream; final Function> mapper; final InnerObserver inner; final int bufferSize; SimpleQueue queue; - Disposable s; + Disposable upstream; volatile boolean active; @@ -77,18 +77,18 @@ static final class SourceObserver extends AtomicInteger implements Observe SourceObserver(Observer actual, Function> mapper, int bufferSize) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.bufferSize = bufferSize; this.inner = new InnerObserver(actual, this); } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - if (s instanceof QueueDisposable) { + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + if (d instanceof QueueDisposable) { @SuppressWarnings("unchecked") - QueueDisposable qd = (QueueDisposable) s; + QueueDisposable qd = (QueueDisposable) d; int m = qd.requestFusion(QueueDisposable.ANY); if (m == QueueDisposable.SYNC) { @@ -96,7 +96,7 @@ public void onSubscribe(Disposable s) { queue = qd; done = true; - actual.onSubscribe(this); + downstream.onSubscribe(this); drain(); return; @@ -106,7 +106,7 @@ public void onSubscribe(Disposable s) { fusionMode = m; queue = qd; - actual.onSubscribe(this); + downstream.onSubscribe(this); return; } @@ -114,7 +114,7 @@ public void onSubscribe(Disposable s) { queue = new SpscLinkedArrayQueue(bufferSize); - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override @@ -135,7 +135,7 @@ public void onError(Throwable t) { } done = true; dispose(); - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { @@ -160,7 +160,7 @@ public boolean isDisposed() { public void dispose() { disposed = true; inner.dispose(); - s.dispose(); + upstream.dispose(); if (getAndIncrement() == 0) { queue.clear(); @@ -189,7 +189,7 @@ void drain() { Exceptions.throwIfFatal(ex); dispose(); queue.clear(); - actual.onError(ex); + downstream.onError(ex); return; } @@ -197,7 +197,7 @@ void drain() { if (d && empty) { disposed = true; - actual.onComplete(); + downstream.onComplete(); return; } @@ -210,7 +210,7 @@ void drain() { Exceptions.throwIfFatal(ex); dispose(); queue.clear(); - actual.onError(ex); + downstream.onError(ex); return; } @@ -229,27 +229,27 @@ static final class InnerObserver extends AtomicReference implemen private static final long serialVersionUID = -7449079488798789337L; - final Observer actual; + final Observer downstream; final SourceObserver parent; InnerObserver(Observer actual, SourceObserver parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.set(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.set(this, d); } @Override public void onNext(U t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { parent.dispose(); - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { @@ -269,7 +269,7 @@ static final class ConcatMapDelayErrorObserver private static final long serialVersionUID = -6951100001833242599L; - final Observer actual; + final Observer downstream; final Function> mapper; @@ -283,7 +283,7 @@ static final class ConcatMapDelayErrorObserver SimpleQueue queue; - Disposable d; + Disposable upstream; volatile boolean active; @@ -296,7 +296,7 @@ static final class ConcatMapDelayErrorObserver ConcatMapDelayErrorObserver(Observer actual, Function> mapper, int bufferSize, boolean tillTheEnd) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.bufferSize = bufferSize; this.tillTheEnd = tillTheEnd; @@ -306,8 +306,8 @@ static final class ConcatMapDelayErrorObserver @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; if (d instanceof QueueDisposable) { @SuppressWarnings("unchecked") @@ -319,7 +319,7 @@ public void onSubscribe(Disposable d) { queue = qd; done = true; - actual.onSubscribe(this); + downstream.onSubscribe(this); drain(); return; @@ -328,7 +328,7 @@ public void onSubscribe(Disposable d) { sourceMode = m; queue = qd; - actual.onSubscribe(this); + downstream.onSubscribe(this); return; } @@ -336,7 +336,7 @@ public void onSubscribe(Disposable d) { queue = new SpscLinkedArrayQueue(bufferSize); - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -372,7 +372,7 @@ public boolean isDisposed() { @Override public void dispose() { cancelled = true; - d.dispose(); + upstream.dispose(); observer.dispose(); } @@ -382,7 +382,7 @@ void drain() { return; } - Observer actual = this.actual; + Observer actual = this.downstream; SimpleQueue queue = this.queue; AtomicThrowable error = this.error; @@ -414,7 +414,7 @@ void drain() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); cancelled = true; - this.d.dispose(); + this.upstream.dispose(); error.addThrowable(ex); actual.onError(error.terminate()); return; @@ -442,7 +442,7 @@ void drain() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); cancelled = true; - this.d.dispose(); + this.upstream.dispose(); queue.clear(); error.addThrowable(ex); actual.onError(error.terminate()); @@ -481,12 +481,12 @@ static final class DelayErrorInnerObserver extends AtomicReference actual; + final Observer downstream; final ConcatMapDelayErrorObserver parent; DelayErrorInnerObserver(Observer actual, ConcatMapDelayErrorObserver parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } @@ -497,7 +497,7 @@ public void onSubscribe(Disposable d) { @Override public void onNext(R value) { - actual.onNext(value); + downstream.onNext(value); } @Override @@ -505,7 +505,7 @@ public void onError(Throwable e) { ConcatMapDelayErrorObserver p = parent; if (p.error.addThrowable(e)) { if (!p.tillTheEnd) { - p.d.dispose(); + p.upstream.dispose(); } p.active = false; p.drain(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMapEager.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMapEager.java index b19ca9bbdf..cb15b10f65 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMapEager.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMapEager.java @@ -60,7 +60,7 @@ static final class ConcatMapEagerMainObserver private static final long serialVersionUID = 8080567949447303262L; - final Observer actual; + final Observer downstream; final Function> mapper; @@ -76,7 +76,7 @@ static final class ConcatMapEagerMainObserver SimpleQueue queue; - Disposable d; + Disposable upstream; volatile boolean done; @@ -91,7 +91,7 @@ static final class ConcatMapEagerMainObserver ConcatMapEagerMainObserver(Observer actual, Function> mapper, int maxConcurrency, int prefetch, ErrorMode errorMode) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.maxConcurrency = maxConcurrency; this.prefetch = prefetch; @@ -103,8 +103,8 @@ static final class ConcatMapEagerMainObserver @SuppressWarnings("unchecked") @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; if (d instanceof QueueDisposable) { QueueDisposable qd = (QueueDisposable) d; @@ -115,7 +115,7 @@ public void onSubscribe(Disposable d) { queue = qd; done = true; - actual.onSubscribe(this); + downstream.onSubscribe(this); drain(); return; @@ -124,7 +124,7 @@ public void onSubscribe(Disposable d) { sourceMode = m; queue = qd; - actual.onSubscribe(this); + downstream.onSubscribe(this); return; } @@ -132,7 +132,7 @@ public void onSubscribe(Disposable d) { queue = new SpscLinkedArrayQueue(prefetch); - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -203,7 +203,7 @@ public void innerNext(InnerQueuedObserver inner, R value) { public void innerError(InnerQueuedObserver inner, Throwable e) { if (error.addThrowable(e)) { if (errorMode == ErrorMode.IMMEDIATE) { - d.dispose(); + upstream.dispose(); } inner.setDone(); drain(); @@ -228,7 +228,7 @@ public void drain() { SimpleQueue q = queue; ArrayDeque> observers = this.observers; - Observer a = this.actual; + Observer a = this.downstream; ErrorMode errorMode = this.errorMode; outer: @@ -267,7 +267,7 @@ public void drain() { source = ObjectHelper.requireNonNull(mapper.apply(v), "The mapper returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); q.clear(); disposeAll(); error.addThrowable(ex); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletable.java index a80795b370..5609455b33 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletable.java @@ -46,38 +46,38 @@ static final class ConcatWithObserver private static final long serialVersionUID = -1953724749712440952L; - final Observer actual; + final Observer downstream; CompletableSource other; boolean inCompletable; ConcatWithObserver(Observer actual, CompletableSource other) { - this.actual = actual; + this.downstream = actual; this.other = other; } @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d) && !inCompletable) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { if (inCompletable) { - actual.onComplete(); + downstream.onComplete(); } else { inCompletable = true; DisposableHelper.replace(this, null); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybe.java index 26af9856eb..ee0f5b9799 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybe.java @@ -46,44 +46,44 @@ static final class ConcatWithObserver private static final long serialVersionUID = -1953724749712440952L; - final Observer actual; + final Observer downstream; MaybeSource other; boolean inMaybe; ConcatWithObserver(Observer actual, MaybeSource other) { - this.actual = actual; + this.downstream = actual; this.other = other; } @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d) && !inMaybe) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onSuccess(T t) { - actual.onNext(t); - actual.onComplete(); + downstream.onNext(t); + downstream.onComplete(); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { if (inMaybe) { - actual.onComplete(); + downstream.onComplete(); } else { inMaybe = true; DisposableHelper.replace(this, null); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingle.java index 09b4da0fdb..f3548e68a0 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingle.java @@ -46,38 +46,38 @@ static final class ConcatWithObserver private static final long serialVersionUID = -1953724749712440952L; - final Observer actual; + final Observer downstream; SingleSource other; boolean inSingle; ConcatWithObserver(Observer actual, SingleSource other) { - this.actual = actual; + this.downstream = actual; this.other = other; } @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d) && !inSingle) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onSuccess(T t) { - actual.onNext(t); - actual.onComplete(); + downstream.onNext(t); + downstream.onComplete(); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCount.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCount.java index 41b8cc94a9..bf961d47c0 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCount.java @@ -28,33 +28,33 @@ public void subscribeActual(Observer t) { } static final class CountObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; - Disposable s; + Disposable upstream; long count; - CountObserver(Observer actual) { - this.actual = actual; + CountObserver(Observer downstream) { + this.downstream = downstream; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override @@ -64,13 +64,13 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onNext(count); - actual.onComplete(); + downstream.onNext(count); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCountSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCountSingle.java index 2bc3febf7b..1568e00f97 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCountSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCountSingle.java @@ -36,34 +36,34 @@ public Observable fuseToObservable() { } static final class CountObserver implements Observer, Disposable { - final SingleObserver actual; + final SingleObserver downstream; - Disposable d; + Disposable upstream; long count; - CountObserver(SingleObserver actual) { - this.actual = actual; + CountObserver(SingleObserver downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; - actual.onSubscribe(this); + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override @@ -73,14 +73,14 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { - d = DisposableHelper.DISPOSED; - actual.onError(t); + upstream = DisposableHelper.DISPOSED; + downstream.onError(t); } @Override public void onComplete() { - d = DisposableHelper.DISPOSED; - actual.onSuccess(count); + upstream = DisposableHelper.DISPOSED; + downstream.onSuccess(count); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCreate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCreate.java index 68ffd7ed82..1e48bdabee 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCreate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCreate.java @@ -266,8 +266,8 @@ void drainLoop() { } @Override - public void setDisposable(Disposable s) { - emitter.setDisposable(s); + public void setDisposable(Disposable d) { + emitter.setDisposable(d); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounce.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounce.java index 2a70f8ba4e..2c056eb70e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounce.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounce.java @@ -39,10 +39,10 @@ public void subscribeActual(Observer t) { static final class DebounceObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Function> debounceSelector; - Disposable s; + Disposable upstream; final AtomicReference debouncer = new AtomicReference(); @@ -52,15 +52,15 @@ static final class DebounceObserver DebounceObserver(Observer actual, Function> debounceSelector) { - this.actual = actual; + this.downstream = actual; this.debounceSelector = debounceSelector; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -85,7 +85,7 @@ public void onNext(T t) { } catch (Throwable e) { Exceptions.throwIfFatal(e); dispose(); - actual.onError(e); + downstream.onError(e); return; } @@ -99,7 +99,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { DisposableHelper.dispose(debouncer); - actual.onError(t); + downstream.onError(t); } @Override @@ -114,24 +114,24 @@ public void onComplete() { DebounceInnerObserver dis = (DebounceInnerObserver)d; dis.emit(); DisposableHelper.dispose(debouncer); - actual.onComplete(); + downstream.onComplete(); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); DisposableHelper.dispose(debouncer); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } void emit(long idx, T value) { if (idx == index) { - actual.onNext(value); + downstream.onNext(value); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounceTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounceTimed.java index dcc56288a7..d37b99ecfd 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounceTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounceTimed.java @@ -44,12 +44,12 @@ public void subscribeActual(Observer t) { static final class DebounceTimedObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final long timeout; final TimeUnit unit; final Scheduler.Worker worker; - Disposable s; + Disposable upstream; Disposable timer; @@ -58,17 +58,17 @@ static final class DebounceTimedObserver boolean done; DebounceTimedObserver(Observer actual, long timeout, TimeUnit unit, Worker worker) { - this.actual = actual; + this.downstream = actual; this.timeout = timeout; this.unit = unit; this.worker = worker; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -102,7 +102,7 @@ public void onError(Throwable t) { d.dispose(); } done = true; - actual.onError(t); + downstream.onError(t); worker.dispose(); } @@ -122,13 +122,13 @@ public void onComplete() { if (de != null) { de.run(); } - actual.onComplete(); + downstream.onComplete(); worker.dispose(); } @Override public void dispose() { - s.dispose(); + upstream.dispose(); worker.dispose(); } @@ -139,7 +139,7 @@ public boolean isDisposed() { void emit(long idx, T t, DebounceEmitter emitter) { if (idx == index) { - actual.onNext(t); + downstream.onNext(t); emitter.dispose(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDelay.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDelay.java index 8dff7222eb..8c07ed6878 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDelay.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDelay.java @@ -51,17 +51,17 @@ public void subscribeActual(Observer t) { } static final class DelayObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final long delay; final TimeUnit unit; final Scheduler.Worker w; final boolean delayError; - Disposable s; + Disposable upstream; DelayObserver(Observer actual, long delay, TimeUnit unit, Worker w, boolean delayError) { super(); - this.actual = actual; + this.downstream = actual; this.delay = delay; this.unit = unit; this.w = w; @@ -69,10 +69,10 @@ static final class DelayObserver implements Observer, Disposable { } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -93,7 +93,7 @@ public void onComplete() { @Override public void dispose() { - s.dispose(); + upstream.dispose(); w.dispose(); } @@ -111,7 +111,7 @@ final class OnNext implements Runnable { @Override public void run() { - actual.onNext(t); + downstream.onNext(t); } } @@ -125,7 +125,7 @@ final class OnError implements Runnable { @Override public void run() { try { - actual.onError(throwable); + downstream.onError(throwable); } finally { w.dispose(); } @@ -136,7 +136,7 @@ final class OnComplete implements Runnable { @Override public void run() { try { - actual.onComplete(); + downstream.onComplete(); } finally { w.dispose(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java index 4fa032db0d..70dd6502b5 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java @@ -30,34 +30,34 @@ public void subscribeActual(Observer t) { } static final class DematerializeObserver implements Observer>, Disposable { - final Observer actual; + final Observer downstream; boolean done; - Disposable s; + Disposable upstream; - DematerializeObserver(Observer actual) { - this.actual = actual; + DematerializeObserver(Observer downstream) { + this.downstream = downstream; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -70,14 +70,14 @@ public void onNext(Notification t) { return; } if (t.isOnError()) { - s.dispose(); + upstream.dispose(); onError(t.getError()); } else if (t.isOnComplete()) { - s.dispose(); + upstream.dispose(); onComplete(); } else { - actual.onNext(t.getValue()); + downstream.onNext(t.getValue()); } } @@ -89,7 +89,7 @@ public void onError(Throwable t) { } done = true; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { @@ -98,7 +98,7 @@ public void onComplete() { } done = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDetach.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDetach.java index b5093e0972..897ac02ebd 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDetach.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDetach.java @@ -37,54 +37,54 @@ protected void subscribeActual(Observer observer) { static final class DetachObserver implements Observer, Disposable { - Observer actual; + Observer downstream; - Disposable s; + Disposable upstream; - DetachObserver(Observer actual) { - this.actual = actual; + DetachObserver(Observer downstream) { + this.downstream = downstream; } @Override public void dispose() { - Disposable s = this.s; - this.s = EmptyComponent.INSTANCE; - this.actual = EmptyComponent.asObserver(); - s.dispose(); + Disposable d = this.upstream; + this.upstream = EmptyComponent.INSTANCE; + this.downstream = EmptyComponent.asObserver(); + d.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - Observer a = actual; - this.s = EmptyComponent.INSTANCE; - this.actual = EmptyComponent.asObserver(); + Observer a = downstream; + this.upstream = EmptyComponent.INSTANCE; + this.downstream = EmptyComponent.asObserver(); a.onError(t); } @Override public void onComplete() { - Observer a = actual; - this.s = EmptyComponent.INSTANCE; - this.actual = EmptyComponent.asObserver(); + Observer a = downstream; + this.upstream = EmptyComponent.INSTANCE; + this.downstream = EmptyComponent.asObserver(); a.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinct.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinct.java index 4e625ee44c..6ebe127e4e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinct.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinct.java @@ -82,10 +82,10 @@ public void onNext(T value) { } if (b) { - actual.onNext(value); + downstream.onNext(value); } } else { - actual.onNext(null); + downstream.onNext(null); } } @@ -96,7 +96,7 @@ public void onError(Throwable e) { } else { done = true; collection.clear(); - actual.onError(e); + downstream.onError(e); } } @@ -105,7 +105,7 @@ public void onComplete() { if (!done) { done = true; collection.clear(); - actual.onComplete(); + downstream.onComplete(); } } @@ -118,7 +118,7 @@ public int requestFusion(int mode) { @Override public T poll() throws Exception { for (;;) { - T v = qs.poll(); + T v = qd.poll(); if (v == null || collection.add(ObjectHelper.requireNonNull(keySelector.apply(v), "The keySelector returned a null key"))) { return v; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChanged.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChanged.java index 065d121b0a..866efd3210 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChanged.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChanged.java @@ -59,7 +59,7 @@ public void onNext(T t) { return; } if (sourceMode != NONE) { - actual.onNext(t); + downstream.onNext(t); return; } @@ -82,7 +82,7 @@ public void onNext(T t) { return; } - actual.onNext(t); + downstream.onNext(t); } @Override @@ -94,7 +94,7 @@ public int requestFusion(int mode) { @Override public T poll() throws Exception { for (;;) { - T v = qs.poll(); + T v = qd.poll(); if (v == null) { return null; } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java index e2d7760413..c84f3571ab 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoAfterNext.java @@ -49,7 +49,7 @@ static final class DoAfterObserver extends BasicFuseableObserver { @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); if (sourceMode == NONE) { try { @@ -68,7 +68,7 @@ public int requestFusion(int mode) { @Nullable @Override public T poll() throws Exception { - T v = qs.poll(); + T v = qd.poll(); if (v != null) { onAfterNext.accept(v); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java index 196a8c78e2..bc305afde5 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoFinally.java @@ -47,60 +47,60 @@ static final class DoFinallyObserver extends BasicIntQueueDisposable imple private static final long serialVersionUID = 4109457741734051389L; - final Observer actual; + final Observer downstream; final Action onFinally; - Disposable d; + Disposable upstream; QueueDisposable qd; boolean syncFused; DoFinallyObserver(Observer actual, Action onFinally) { - this.actual = actual; + this.downstream = actual; this.onFinally = onFinally; } @SuppressWarnings("unchecked") @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; if (d instanceof QueueDisposable) { this.qd = (QueueDisposable)d; } - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); runFinally(); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); runFinally(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); runFinally(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoOnEach.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoOnEach.java index 14ad8fe3df..dc3b4561b2 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoOnEach.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoOnEach.java @@ -43,13 +43,13 @@ public void subscribeActual(Observer t) { } static final class DoOnEachObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Consumer onNext; final Consumer onError; final Action onComplete; final Action onAfterTerminate; - Disposable s; + Disposable upstream; boolean done; @@ -59,7 +59,7 @@ static final class DoOnEachObserver implements Observer, Disposable { Consumer onError, Action onComplete, Action onAfterTerminate) { - this.actual = actual; + this.downstream = actual; this.onNext = onNext; this.onError = onError; this.onComplete = onComplete; @@ -67,22 +67,22 @@ static final class DoOnEachObserver implements Observer, Disposable { } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -95,12 +95,12 @@ public void onNext(T t) { onNext.accept(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } - actual.onNext(t); + downstream.onNext(t); } @Override @@ -116,7 +116,7 @@ public void onError(Throwable t) { Exceptions.throwIfFatal(e); t = new CompositeException(t, e); } - actual.onError(t); + downstream.onError(t); try { onAfterTerminate.run(); @@ -140,7 +140,7 @@ public void onComplete() { } done = true; - actual.onComplete(); + downstream.onComplete(); try { onAfterTerminate.run(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAt.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAt.java index 0870ea812d..7abc421572 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAt.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAt.java @@ -37,41 +37,41 @@ public void subscribeActual(Observer t) { } static final class ElementAtObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final long index; final T defaultValue; final boolean errorOnFewer; - Disposable s; + Disposable upstream; long count; boolean done; ElementAtObserver(Observer actual, long index, T defaultValue, boolean errorOnFewer) { - this.actual = actual; + this.downstream = actual; this.index = index; this.defaultValue = defaultValue; this.errorOnFewer = errorOnFewer; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -83,9 +83,9 @@ public void onNext(T t) { long c = count; if (c == index) { done = true; - s.dispose(); - actual.onNext(t); - actual.onComplete(); + upstream.dispose(); + downstream.onNext(t); + downstream.onComplete(); return; } count = c + 1; @@ -98,7 +98,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -107,12 +107,12 @@ public void onComplete() { done = true; T v = defaultValue; if (v == null && errorOnFewer) { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } else { if (v != null) { - actual.onNext(v); + downstream.onNext(v); } - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtMaybe.java index 1f7db1e68f..84f8d5baf7 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtMaybe.java @@ -37,37 +37,37 @@ public Observable fuseToObservable() { } static final class ElementAtObserver implements Observer, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final long index; - Disposable s; + Disposable upstream; long count; boolean done; ElementAtObserver(MaybeObserver actual, long index) { - this.actual = actual; + this.downstream = actual; this.index = index; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -79,8 +79,8 @@ public void onNext(T t) { long c = count; if (c == index) { done = true; - s.dispose(); - actual.onSuccess(t); + upstream.dispose(); + downstream.onSuccess(t); return; } count = c + 1; @@ -93,14 +93,14 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtSingle.java index dd7e9973f8..6c73a4e91a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtSingle.java @@ -43,39 +43,39 @@ public Observable fuseToObservable() { } static final class ElementAtObserver implements Observer, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final long index; final T defaultValue; - Disposable s; + Disposable upstream; long count; boolean done; ElementAtObserver(SingleObserver actual, long index, T defaultValue) { - this.actual = actual; + this.downstream = actual; this.index = index; this.defaultValue = defaultValue; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -87,8 +87,8 @@ public void onNext(T t) { long c = count; if (c == index) { done = true; - s.dispose(); - actual.onSuccess(t); + upstream.dispose(); + downstream.onSuccess(t); return; } count = c + 1; @@ -101,7 +101,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -112,9 +112,9 @@ public void onComplete() { T v = defaultValue; if (v != null) { - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFilter.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFilter.java index cbe8fa3849..c9ec142a76 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFilter.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFilter.java @@ -49,10 +49,10 @@ public void onNext(T t) { return; } if (b) { - actual.onNext(t); + downstream.onNext(t); } } else { - actual.onNext(null); + downstream.onNext(null); } } @@ -65,7 +65,7 @@ public int requestFusion(int mode) { @Override public T poll() throws Exception { for (;;) { - T v = qs.poll(); + T v = qd.poll(); if (v == null || filter.test(v)) { return v; } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java index 6df47ffa87..76247e8e08 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java @@ -59,7 +59,7 @@ static final class MergeObserver extends AtomicInteger implements Disposab private static final long serialVersionUID = -2117620485640801370L; - final Observer actual; + final Observer downstream; final Function> mapper; final boolean delayErrors; final int maxConcurrency; @@ -79,7 +79,7 @@ static final class MergeObserver extends AtomicInteger implements Disposab static final InnerObserver[] CANCELLED = new InnerObserver[0]; - Disposable s; + Disposable upstream; long uniqueId; long lastId; @@ -91,7 +91,7 @@ static final class MergeObserver extends AtomicInteger implements Disposab MergeObserver(Observer actual, Function> mapper, boolean delayErrors, int maxConcurrency, int bufferSize) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.delayErrors = delayErrors; this.maxConcurrency = maxConcurrency; @@ -103,10 +103,10 @@ static final class MergeObserver extends AtomicInteger implements Disposab } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -121,7 +121,7 @@ public void onNext(T t) { p = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null ObservableSource"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } @@ -234,7 +234,7 @@ boolean tryEmitScalar(Callable value) { if (get() == 0 && compareAndSet(0, 1)) { - actual.onNext(u); + downstream.onNext(u); if (decrementAndGet() == 0) { return true; } @@ -263,7 +263,7 @@ boolean tryEmitScalar(Callable value) { void tryEmit(U value, InnerObserver inner) { if (get() == 0 && compareAndSet(0, 1)) { - actual.onNext(value); + downstream.onNext(value); if (decrementAndGet() == 0) { return; } @@ -329,7 +329,7 @@ void drain() { } void drainLoop() { - final Observer child = this.actual; + final Observer child = this.downstream; int missed = 1; for (;;) { if (checkTerminate()) { @@ -503,7 +503,7 @@ boolean checkTerminate() { disposeAll(); e = errors.terminate(); if (e != ExceptionHelper.TERMINATED) { - actual.onError(e); + downstream.onError(e); } return true; } @@ -511,7 +511,7 @@ boolean checkTerminate() { } boolean disposeAll() { - s.dispose(); + upstream.dispose(); InnerObserver[] a = observers.get(); if (a != CANCELLED) { a = observers.getAndSet(CANCELLED); @@ -543,11 +543,11 @@ static final class InnerObserver extends AtomicReference this.parent = parent; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.setOnce(this, s)) { - if (s instanceof QueueDisposable) { + public void onSubscribe(Disposable d) { + if (DisposableHelper.setOnce(this, d)) { + if (d instanceof QueueDisposable) { @SuppressWarnings("unchecked") - QueueDisposable qd = (QueueDisposable) s; + QueueDisposable qd = (QueueDisposable) d; int m = qd.requestFusion(QueueDisposable.ANY | QueueDisposable.BOUNDARY); if (m == QueueDisposable.SYNC) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletable.java index dc6c1e8dd7..727d0bc2de 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletable.java @@ -52,7 +52,7 @@ static final class FlatMapCompletableMainObserver extends BasicIntQueueDispos implements Observer { private static final long serialVersionUID = 8443155186132538303L; - final Observer actual; + final Observer downstream; final AtomicThrowable errors; @@ -62,12 +62,12 @@ static final class FlatMapCompletableMainObserver extends BasicIntQueueDispos final CompositeDisposable set; - Disposable d; + Disposable upstream; volatile boolean disposed; FlatMapCompletableMainObserver(Observer observer, Function mapper, boolean delayErrors) { - this.actual = observer; + this.downstream = observer; this.mapper = mapper; this.delayErrors = delayErrors; this.errors = new AtomicThrowable(); @@ -77,10 +77,10 @@ static final class FlatMapCompletableMainObserver extends BasicIntQueueDispos @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -92,7 +92,7 @@ public void onNext(T value) { cs = ObjectHelper.requireNonNull(mapper.apply(value), "The mapper returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); onError(ex); return; } @@ -112,13 +112,13 @@ public void onError(Throwable e) { if (delayErrors) { if (decrementAndGet() == 0) { Throwable ex = errors.terminate(); - actual.onError(ex); + downstream.onError(ex); } } else { dispose(); if (getAndSet(0) > 0) { Throwable ex = errors.terminate(); - actual.onError(ex); + downstream.onError(ex); } } } else { @@ -131,9 +131,9 @@ public void onComplete() { if (decrementAndGet() == 0) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } } } @@ -141,13 +141,13 @@ public void onComplete() { @Override public void dispose() { disposed = true; - d.dispose(); + upstream.dispose(); set.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Nullable diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableCompletable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableCompletable.java index 91734a1196..67691a11f8 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableCompletable.java @@ -57,7 +57,7 @@ public Observable fuseToObservable() { static final class FlatMapCompletableMainObserver extends AtomicInteger implements Disposable, Observer { private static final long serialVersionUID = 8443155186132538303L; - final CompletableObserver actual; + final CompletableObserver downstream; final AtomicThrowable errors; @@ -67,12 +67,12 @@ static final class FlatMapCompletableMainObserver extends AtomicInteger imple final CompositeDisposable set; - Disposable d; + Disposable upstream; volatile boolean disposed; FlatMapCompletableMainObserver(CompletableObserver observer, Function mapper, boolean delayErrors) { - this.actual = observer; + this.downstream = observer; this.mapper = mapper; this.delayErrors = delayErrors; this.errors = new AtomicThrowable(); @@ -82,10 +82,10 @@ static final class FlatMapCompletableMainObserver extends AtomicInteger imple @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -97,7 +97,7 @@ public void onNext(T value) { cs = ObjectHelper.requireNonNull(mapper.apply(value), "The mapper returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); onError(ex); return; } @@ -117,13 +117,13 @@ public void onError(Throwable e) { if (delayErrors) { if (decrementAndGet() == 0) { Throwable ex = errors.terminate(); - actual.onError(ex); + downstream.onError(ex); } } else { dispose(); if (getAndSet(0) > 0) { Throwable ex = errors.terminate(); - actual.onError(ex); + downstream.onError(ex); } } } else { @@ -136,9 +136,9 @@ public void onComplete() { if (decrementAndGet() == 0) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } } } @@ -146,13 +146,13 @@ public void onComplete() { @Override public void dispose() { disposed = true; - d.dispose(); + upstream.dispose(); set.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } void innerComplete(InnerObserver inner) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybe.java index 51815b4c1e..122572ac50 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybe.java @@ -54,7 +54,7 @@ static final class FlatMapMaybeObserver private static final long serialVersionUID = 8600231336733376951L; - final Observer actual; + final Observer downstream; final boolean delayErrors; @@ -68,13 +68,13 @@ static final class FlatMapMaybeObserver final AtomicReference> queue; - Disposable d; + Disposable upstream; volatile boolean cancelled; FlatMapMaybeObserver(Observer actual, Function> mapper, boolean delayErrors) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.delayErrors = delayErrors; this.set = new CompositeDisposable(); @@ -85,10 +85,10 @@ static final class FlatMapMaybeObserver @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -100,7 +100,7 @@ public void onNext(T t) { ms = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); onError(ex); return; } @@ -136,7 +136,7 @@ public void onComplete() { @Override public void dispose() { cancelled = true; - d.dispose(); + upstream.dispose(); set.dispose(); } @@ -148,7 +148,7 @@ public boolean isDisposed() { void innerSuccess(InnerObserver inner, R value) { set.delete(inner); if (get() == 0 && compareAndSet(0, 1)) { - actual.onNext(value); + downstream.onNext(value); boolean d = active.decrementAndGet() == 0; SpscLinkedArrayQueue q = queue.get(); @@ -156,9 +156,9 @@ void innerSuccess(InnerObserver inner, R value) { if (d && (q == null || q.isEmpty())) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } return; } @@ -195,7 +195,7 @@ void innerError(InnerObserver inner, Throwable e) { set.delete(inner); if (errors.addThrowable(e)) { if (!delayErrors) { - d.dispose(); + upstream.dispose(); set.dispose(); } active.decrementAndGet(); @@ -215,9 +215,9 @@ void innerComplete(InnerObserver inner) { if (d && (q == null || q.isEmpty())) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } return; } @@ -246,7 +246,7 @@ void clear() { void drainLoop() { int missed = 1; - Observer a = actual; + Observer a = downstream; AtomicInteger n = active; AtomicReference> qr = queue; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingle.java index 4697d8e106..bedda3cb49 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingle.java @@ -54,7 +54,7 @@ static final class FlatMapSingleObserver private static final long serialVersionUID = 8600231336733376951L; - final Observer actual; + final Observer downstream; final boolean delayErrors; @@ -68,13 +68,13 @@ static final class FlatMapSingleObserver final AtomicReference> queue; - Disposable d; + Disposable upstream; volatile boolean cancelled; FlatMapSingleObserver(Observer actual, Function> mapper, boolean delayErrors) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.delayErrors = delayErrors; this.set = new CompositeDisposable(); @@ -85,10 +85,10 @@ static final class FlatMapSingleObserver @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -100,7 +100,7 @@ public void onNext(T t) { ms = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null SingleSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); onError(ex); return; } @@ -136,7 +136,7 @@ public void onComplete() { @Override public void dispose() { cancelled = true; - d.dispose(); + upstream.dispose(); set.dispose(); } @@ -148,7 +148,7 @@ public boolean isDisposed() { void innerSuccess(InnerObserver inner, R value) { set.delete(inner); if (get() == 0 && compareAndSet(0, 1)) { - actual.onNext(value); + downstream.onNext(value); boolean d = active.decrementAndGet() == 0; SpscLinkedArrayQueue q = queue.get(); @@ -156,9 +156,9 @@ void innerSuccess(InnerObserver inner, R value) { if (d && (q == null || q.isEmpty())) { Throwable ex = errors.terminate(); if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } return; } @@ -195,7 +195,7 @@ void innerError(InnerObserver inner, Throwable e) { set.delete(inner); if (errors.addThrowable(e)) { if (!delayErrors) { - d.dispose(); + upstream.dispose(); set.dispose(); } active.decrementAndGet(); @@ -220,7 +220,7 @@ void clear() { void drainLoop() { int missed = 1; - Observer a = actual; + Observer a = downstream; AtomicInteger n = active; AtomicReference> qr = queue; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlattenIterable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlattenIterable.java index 1781f0a03d..74b1839bb8 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlattenIterable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlattenIterable.java @@ -45,29 +45,29 @@ protected void subscribeActual(Observer observer) { } static final class FlattenIterableObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Function> mapper; - Disposable d; + Disposable upstream; FlattenIterableObserver(Observer actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T value) { - if (d == DisposableHelper.DISPOSED) { + if (upstream == DisposableHelper.DISPOSED) { return; } @@ -77,12 +77,12 @@ public void onNext(T value) { it = mapper.apply(value).iterator(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); onError(ex); return; } - Observer a = actual; + Observer a = downstream; for (;;) { boolean b; @@ -91,7 +91,7 @@ public void onNext(T value) { b = it.hasNext(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); onError(ex); return; } @@ -103,7 +103,7 @@ public void onNext(T value) { v = ObjectHelper.requireNonNull(it.next(), "The iterator returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); onError(ex); return; } @@ -117,32 +117,32 @@ public void onNext(T value) { @Override public void onError(Throwable e) { - if (d == DisposableHelper.DISPOSED) { + if (upstream == DisposableHelper.DISPOSED) { RxJavaPlugins.onError(e); return; } - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void onComplete() { - if (d == DisposableHelper.DISPOSED) { + if (upstream == DisposableHelper.DISPOSED) { return; } - d = DisposableHelper.DISPOSED; - actual.onComplete(); + upstream = DisposableHelper.DISPOSED; + downstream.onComplete(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java index bd12bec41c..0633d59726 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java @@ -38,7 +38,7 @@ public void subscribeActual(Observer observer) { static final class FromArrayDisposable extends BasicQueueDisposable { - final Observer actual; + final Observer downstream; final T[] array; @@ -49,7 +49,7 @@ static final class FromArrayDisposable extends BasicQueueDisposable { volatile boolean disposed; FromArrayDisposable(Observer actual, T[] array) { - this.actual = actual; + this.downstream = actual; this.array = array; } @@ -101,13 +101,13 @@ void run() { for (int i = 0; i < n && !isDisposed(); i++) { T value = a[i]; if (value == null) { - actual.onError(new NullPointerException("The " + i + "th element is null")); + downstream.onError(new NullPointerException("The " + i + "th element is null")); return; } - actual.onNext(value); + downstream.onNext(value); } if (!isDisposed()) { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromIterable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromIterable.java index ae7638e142..f937f4ded5 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromIterable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromIterable.java @@ -61,7 +61,7 @@ public void subscribeActual(Observer observer) { static final class FromIterableDisposable extends BasicQueueDisposable { - final Observer actual; + final Observer downstream; final Iterator it; @@ -74,7 +74,7 @@ static final class FromIterableDisposable extends BasicQueueDisposable { boolean checkNext; FromIterableDisposable(Observer actual, Iterator it) { - this.actual = actual; + this.downstream = actual; this.it = it; } @@ -91,11 +91,11 @@ void run() { v = ObjectHelper.requireNonNull(it.next(), "The iterator returned a null value"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } - actual.onNext(v); + downstream.onNext(v); if (isDisposed()) { return; @@ -104,13 +104,13 @@ void run() { hasNext = it.hasNext(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } } while (hasNext); if (!isDisposed()) { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromPublisher.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromPublisher.java index 3de1735670..27b4305c89 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromPublisher.java @@ -34,46 +34,46 @@ protected void subscribeActual(final Observer o) { static final class PublisherSubscriber implements FlowableSubscriber, Disposable { - final Observer actual; - Subscription s; + final Observer downstream; + Subscription upstream; PublisherSubscriber(Observer o) { - this.actual = o; + this.downstream = o; } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } } @Override public void dispose() { - s.cancel(); - s = SubscriptionHelper.CANCELLED; + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; } @Override public boolean isDisposed() { - return s == SubscriptionHelper.CANCELLED; + return upstream == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java index ac33e689ac..c74f697b7d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java @@ -54,7 +54,7 @@ public void subscribeActual(Observer observer) { static final class GeneratorDisposable implements Emitter, Disposable { - final Observer actual; + final Observer downstream; final BiFunction, S> generator; final Consumer disposeState; @@ -69,7 +69,7 @@ static final class GeneratorDisposable GeneratorDisposable(Observer actual, BiFunction, S> generator, Consumer disposeState, S initialState) { - this.actual = actual; + this.downstream = actual; this.generator = generator; this.disposeState = disposeState; this.state = initialState; @@ -147,7 +147,7 @@ public void onNext(T t) { onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); } else { hasNext = true; - actual.onNext(t); + downstream.onNext(t); } } } @@ -162,7 +162,7 @@ public void onError(Throwable t) { t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } terminate = true; - actual.onError(t); + downstream.onError(t); } } @@ -170,7 +170,7 @@ public void onError(Throwable t) { public void onComplete() { if (!terminate) { terminate = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java index 2667401199..0c0390a107 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java @@ -52,7 +52,7 @@ public static final class GroupByObserver extends AtomicInteger impleme private static final long serialVersionUID = -3688291656102519502L; - final Observer> actual; + final Observer> downstream; final Function keySelector; final Function valueSelector; final int bufferSize; @@ -61,12 +61,12 @@ public static final class GroupByObserver extends AtomicInteger impleme static final Object NULL_KEY = new Object(); - Disposable s; + Disposable upstream; final AtomicBoolean cancelled = new AtomicBoolean(); public GroupByObserver(Observer> actual, Function keySelector, Function valueSelector, int bufferSize, boolean delayError) { - this.actual = actual; + this.downstream = actual; this.keySelector = keySelector; this.valueSelector = valueSelector; this.bufferSize = bufferSize; @@ -76,10 +76,10 @@ public GroupByObserver(Observer> actual, Functio } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -90,7 +90,7 @@ public void onNext(T t) { key = keySelector.apply(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } @@ -109,7 +109,7 @@ public void onNext(T t) { getAndIncrement(); - actual.onNext(group); + downstream.onNext(group); } V v; @@ -117,7 +117,7 @@ public void onNext(T t) { v = ObjectHelper.requireNonNull(valueSelector.apply(t), "The value supplied is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } @@ -134,7 +134,7 @@ public void onError(Throwable t) { e.onError(t); } - actual.onError(t); + downstream.onError(t); } @Override @@ -146,7 +146,7 @@ public void onComplete() { e.onComplete(); } - actual.onComplete(); + downstream.onComplete(); } @Override @@ -155,7 +155,7 @@ public void dispose() { // but running groups still require new values if (cancelled.compareAndSet(false, true)) { if (decrementAndGet() == 0) { - s.dispose(); + upstream.dispose(); } } } @@ -169,7 +169,7 @@ public void cancel(K key) { Object mapKey = key != null ? key : NULL_KEY; groups.remove(mapKey); if (decrementAndGet() == 0) { - s.dispose(); + upstream.dispose(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java index bf012297cd..3b4baaa78a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java @@ -91,7 +91,7 @@ static final class GroupJoinDisposable private static final long serialVersionUID = -6071216598687999801L; - final Observer actual; + final Observer downstream; final SpscLinkedArrayQueue queue; @@ -130,7 +130,7 @@ static final class GroupJoinDisposable Function> leftEnd, Function> rightEnd, BiFunction, ? extends R> resultSelector) { - this.actual = actual; + this.downstream = actual; this.disposables = new CompositeDisposable(); this.queue = new SpscLinkedArrayQueue(bufferSize()); this.lefts = new LinkedHashMap>(); @@ -191,7 +191,7 @@ void drain() { int missed = 1; SpscLinkedArrayQueue q = queue; - Observer a = actual; + Observer a = downstream; for (;;) { for (;;) { @@ -405,8 +405,8 @@ public boolean isDisposed() { } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override @@ -456,8 +456,8 @@ public boolean isDisposed() { } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableHide.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableHide.java index f85b92c173..6685146fcb 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableHide.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableHide.java @@ -36,45 +36,45 @@ protected void subscribeActual(Observer o) { static final class HideDisposable implements Observer, Disposable { - final Observer actual; + final Observer downstream; - Disposable d; + Disposable upstream; - HideDisposable(Observer actual) { - this.actual = actual; + HideDisposable(Observer downstream) { + this.downstream = downstream; } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; - actual.onSubscribe(this); + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableIgnoreElements.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableIgnoreElements.java index 58de57c635..b609cdee0c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableIgnoreElements.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableIgnoreElements.java @@ -28,18 +28,18 @@ public void subscribeActual(final Observer t) { } static final class IgnoreObservable implements Observer, Disposable { - final Observer actual; + final Observer downstream; - Disposable d; + Disposable upstream; IgnoreObservable(Observer t) { - this.actual = t; + this.downstream = t; } @Override - public void onSubscribe(Disposable s) { - this.d = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + this.upstream = d; + downstream.onSubscribe(this); } @Override @@ -49,22 +49,22 @@ public void onNext(T v) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableIgnoreElementsCompletable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableIgnoreElementsCompletable.java index 792dd4f456..15b3789e18 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableIgnoreElementsCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableIgnoreElementsCompletable.java @@ -37,18 +37,18 @@ public Observable fuseToObservable() { } static final class IgnoreObservable implements Observer, Disposable { - final CompletableObserver actual; + final CompletableObserver downstream; - Disposable d; + Disposable upstream; IgnoreObservable(CompletableObserver t) { - this.actual = t; + this.downstream = t; } @Override - public void onSubscribe(Disposable s) { - this.d = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + this.upstream = d; + downstream.onSubscribe(this); } @Override @@ -58,22 +58,22 @@ public void onNext(T v) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java index ae5038b525..f786cffaba 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java @@ -59,12 +59,12 @@ static final class IntervalObserver private static final long serialVersionUID = 346773832286157679L; - final Observer actual; + final Observer downstream; long count; - IntervalObserver(Observer actual) { - this.actual = actual; + IntervalObserver(Observer downstream) { + this.downstream = downstream; } @Override @@ -80,7 +80,7 @@ public boolean isDisposed() { @Override public void run() { if (get() != DisposableHelper.DISPOSED) { - actual.onNext(count++); + downstream.onNext(count++); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java index 9d011b3b6b..2e69495e66 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java @@ -63,13 +63,13 @@ static final class IntervalRangeObserver private static final long serialVersionUID = 1891866368734007884L; - final Observer actual; + final Observer downstream; final long end; long count; IntervalRangeObserver(Observer actual, long start, long end) { - this.actual = actual; + this.downstream = actual; this.count = start; this.end = end; } @@ -88,11 +88,11 @@ public boolean isDisposed() { public void run() { if (!isDisposed()) { long c = count; - actual.onNext(c); + downstream.onNext(c); if (c == end) { DisposableHelper.dispose(this); - actual.onComplete(); + downstream.onComplete(); return; } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java index 5cbde302bb..b8393e3f78 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java @@ -77,7 +77,7 @@ static final class JoinDisposable private static final long serialVersionUID = -6071216598687999801L; - final Observer actual; + final Observer downstream; final SpscLinkedArrayQueue queue; @@ -115,7 +115,7 @@ static final class JoinDisposable Function> leftEnd, Function> rightEnd, BiFunction resultSelector) { - this.actual = actual; + this.downstream = actual; this.disposables = new CompositeDisposable(); this.queue = new SpscLinkedArrayQueue(bufferSize()); this.lefts = new LinkedHashMap(); @@ -171,7 +171,7 @@ void drain() { int missed = 1; SpscLinkedArrayQueue q = queue; - Observer a = actual; + Observer a = downstream; for (;;) { for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableLastMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableLastMaybe.java index a5abffc1bd..d6b0da18d0 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableLastMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableLastMaybe.java @@ -40,33 +40,33 @@ protected void subscribeActual(MaybeObserver observer) { static final class LastObserver implements Observer, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Disposable s; + Disposable upstream; T item; - LastObserver(MaybeObserver actual) { - this.actual = actual; + LastObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - s.dispose(); - s = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return s == DisposableHelper.DISPOSED; + return upstream == DisposableHelper.DISPOSED; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -77,20 +77,20 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - s = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; item = null; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - s = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; T v = item; if (v != null) { item = null; - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableLastSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableLastSingle.java index 324bccc04d..b1355f2ca5 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableLastSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableLastSingle.java @@ -45,36 +45,36 @@ protected void subscribeActual(SingleObserver observer) { static final class LastObserver implements Observer, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final T defaultItem; - Disposable s; + Disposable upstream; T item; LastObserver(SingleObserver actual, T defaultItem) { - this.actual = actual; + this.downstream = actual; this.defaultItem = defaultItem; } @Override public void dispose() { - s.dispose(); - s = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return s == DisposableHelper.DISPOSED; + return upstream == DisposableHelper.DISPOSED; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -85,24 +85,24 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - s = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; item = null; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - s = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; T v = item; if (v != null) { item = null; - actual.onSuccess(v); + downstream.onSuccess(v); } else { v = defaultItem; if (v != null) { - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMap.java index caed356c01..5df2a6c341 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMap.java @@ -49,7 +49,7 @@ public void onNext(T t) { } if (sourceMode != NONE) { - actual.onNext(null); + downstream.onNext(null); return; } @@ -61,7 +61,7 @@ public void onNext(T t) { fail(ex); return; } - actual.onNext(v); + downstream.onNext(v); } @Override @@ -72,7 +72,7 @@ public int requestFusion(int mode) { @Nullable @Override public U poll() throws Exception { - T t = qs.poll(); + T t = qd.poll(); return t != null ? ObjectHelper.requireNonNull(mapper.apply(t), "The mapper function returned a null value.") : null; } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMapNotification.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMapNotification.java index 1fb5f94451..d6b6e39f47 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMapNotification.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMapNotification.java @@ -46,40 +46,40 @@ public void subscribeActual(Observer> t) { static final class MapNotificationObserver implements Observer, Disposable { - final Observer> actual; + final Observer> downstream; final Function> onNextMapper; final Function> onErrorMapper; final Callable> onCompleteSupplier; - Disposable s; + Disposable upstream; MapNotificationObserver(Observer> actual, Function> onNextMapper, Function> onErrorMapper, Callable> onCompleteSupplier) { - this.actual = actual; + this.downstream = actual; this.onNextMapper = onNextMapper; this.onErrorMapper = onErrorMapper; this.onCompleteSupplier = onCompleteSupplier; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -91,11 +91,11 @@ public void onNext(T t) { p = ObjectHelper.requireNonNull(onNextMapper.apply(t), "The onNext ObservableSource returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } - actual.onNext(p); + downstream.onNext(p); } @Override @@ -106,12 +106,12 @@ public void onError(Throwable t) { p = ObjectHelper.requireNonNull(onErrorMapper.apply(t), "The onError ObservableSource returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); return; } - actual.onNext(p); - actual.onComplete(); + downstream.onNext(p); + downstream.onComplete(); } @Override @@ -122,12 +122,12 @@ public void onComplete() { p = ObjectHelper.requireNonNull(onCompleteSupplier.call(), "The onComplete ObservableSource returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } - actual.onNext(p); - actual.onComplete(); + downstream.onNext(p); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java index f2db8cc3df..3a89194e97 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java @@ -30,51 +30,51 @@ public void subscribeActual(Observer> t) { } static final class MaterializeObserver implements Observer, Disposable { - final Observer> actual; + final Observer> downstream; - Disposable s; + Disposable upstream; - MaterializeObserver(Observer> actual) { - this.actual = actual; + MaterializeObserver(Observer> downstream) { + this.downstream = downstream; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override public void onNext(T t) { - actual.onNext(Notification.createOnNext(t)); + downstream.onNext(Notification.createOnNext(t)); } @Override public void onError(Throwable t) { Notification v = Notification.createOnError(t); - actual.onNext(v); - actual.onComplete(); + downstream.onNext(v); + downstream.onComplete(); } @Override public void onComplete() { Notification v = Notification.createOnComplete(); - actual.onNext(v); - actual.onComplete(); + downstream.onNext(v); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java index 8fa2f7e2cd..fa020b6ae4 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java @@ -49,7 +49,7 @@ static final class MergeWithObserver extends AtomicInteger private static final long serialVersionUID = -4592979584110982903L; - final Observer actual; + final Observer downstream; final AtomicReference mainDisposable; @@ -61,8 +61,8 @@ static final class MergeWithObserver extends AtomicInteger volatile boolean otherDone; - MergeWithObserver(Observer actual) { - this.actual = actual; + MergeWithObserver(Observer downstream) { + this.downstream = downstream; this.mainDisposable = new AtomicReference(); this.otherObserver = new OtherObserver(this); this.error = new AtomicThrowable(); @@ -75,20 +75,20 @@ public void onSubscribe(Disposable d) { @Override public void onNext(T t) { - HalfSerializer.onNext(actual, t, this, error); + HalfSerializer.onNext(downstream, t, this, error); } @Override public void onError(Throwable ex) { DisposableHelper.dispose(mainDisposable); - HalfSerializer.onError(actual, ex, this, error); + HalfSerializer.onError(downstream, ex, this, error); } @Override public void onComplete() { mainDone = true; if (otherDone) { - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } } @@ -105,13 +105,13 @@ public void dispose() { void otherError(Throwable ex) { DisposableHelper.dispose(mainDisposable); - HalfSerializer.onError(actual, ex, this, error); + HalfSerializer.onError(downstream, ex, this, error); } void otherComplete() { otherDone = true; if (mainDone) { - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java index cefa778ebd..23b2532d9b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java @@ -52,7 +52,7 @@ static final class MergeWithObserver extends AtomicInteger private static final long serialVersionUID = -4592979584110982903L; - final Observer actual; + final Observer downstream; final AtomicReference mainDisposable; @@ -74,8 +74,8 @@ static final class MergeWithObserver extends AtomicInteger static final int OTHER_STATE_CONSUMED_OR_EMPTY = 2; - MergeWithObserver(Observer actual) { - this.actual = actual; + MergeWithObserver(Observer downstream) { + this.downstream = downstream; this.mainDisposable = new AtomicReference(); this.otherObserver = new OtherObserver(this); this.error = new AtomicThrowable(); @@ -89,7 +89,7 @@ public void onSubscribe(Disposable d) { @Override public void onNext(T t) { if (compareAndSet(0, 1)) { - actual.onNext(t); + downstream.onNext(t); if (decrementAndGet() == 0) { return; } @@ -137,7 +137,7 @@ public void dispose() { void otherSuccess(T value) { if (compareAndSet(0, 1)) { - actual.onNext(value); + downstream.onNext(value); otherState = OTHER_STATE_CONSUMED_OR_EMPTY; } else { singleItem = value; @@ -179,7 +179,7 @@ void drain() { } void drainLoop() { - Observer actual = this.actual; + Observer actual = this.downstream; int missed = 1; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java index 28f6596915..20c4d21b5c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java @@ -52,7 +52,7 @@ static final class MergeWithObserver extends AtomicInteger private static final long serialVersionUID = -4592979584110982903L; - final Observer actual; + final Observer downstream; final AtomicReference mainDisposable; @@ -74,8 +74,8 @@ static final class MergeWithObserver extends AtomicInteger static final int OTHER_STATE_CONSUMED_OR_EMPTY = 2; - MergeWithObserver(Observer actual) { - this.actual = actual; + MergeWithObserver(Observer downstream) { + this.downstream = downstream; this.mainDisposable = new AtomicReference(); this.otherObserver = new OtherObserver(this); this.error = new AtomicThrowable(); @@ -89,7 +89,7 @@ public void onSubscribe(Disposable d) { @Override public void onNext(T t) { if (compareAndSet(0, 1)) { - actual.onNext(t); + downstream.onNext(t); if (decrementAndGet() == 0) { return; } @@ -137,7 +137,7 @@ public void dispose() { void otherSuccess(T value) { if (compareAndSet(0, 1)) { - actual.onNext(value); + downstream.onNext(value); otherState = OTHER_STATE_CONSUMED_OR_EMPTY; } else { singleItem = value; @@ -174,7 +174,7 @@ void drain() { } void drainLoop() { - Observer actual = this.actual; + Observer actual = this.downstream; int missed = 1; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java index b54b671a86..f415e7016f 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java @@ -50,14 +50,14 @@ static final class ObserveOnObserver extends BasicIntQueueDisposable implements Observer, Runnable { private static final long serialVersionUID = 6576896619930983584L; - final Observer actual; + final Observer downstream; final Scheduler.Worker worker; final boolean delayError; final int bufferSize; SimpleQueue queue; - Disposable s; + Disposable upstream; Throwable error; volatile boolean done; @@ -69,19 +69,19 @@ static final class ObserveOnObserver extends BasicIntQueueDisposable boolean outputFused; ObserveOnObserver(Observer actual, Scheduler.Worker worker, boolean delayError, int bufferSize) { - this.actual = actual; + this.downstream = actual; this.worker = worker; this.delayError = delayError; this.bufferSize = bufferSize; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - if (s instanceof QueueDisposable) { + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + if (d instanceof QueueDisposable) { @SuppressWarnings("unchecked") - QueueDisposable qd = (QueueDisposable) s; + QueueDisposable qd = (QueueDisposable) d; int m = qd.requestFusion(QueueDisposable.ANY | QueueDisposable.BOUNDARY); @@ -89,21 +89,21 @@ public void onSubscribe(Disposable s) { sourceMode = m; queue = qd; done = true; - actual.onSubscribe(this); + downstream.onSubscribe(this); schedule(); return; } if (m == QueueDisposable.ASYNC) { sourceMode = m; queue = qd; - actual.onSubscribe(this); + downstream.onSubscribe(this); return; } } queue = new SpscLinkedArrayQueue(bufferSize); - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -143,7 +143,7 @@ public void onComplete() { public void dispose() { if (!cancelled) { cancelled = true; - s.dispose(); + upstream.dispose(); worker.dispose(); if (getAndIncrement() == 0) { queue.clear(); @@ -166,7 +166,7 @@ void drainNormal() { int missed = 1; final SimpleQueue q = queue; - final Observer a = actual; + final Observer a = downstream; for (;;) { if (checkTerminated(done, q.isEmpty(), a)) { @@ -181,7 +181,7 @@ void drainNormal() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.dispose(); + upstream.dispose(); q.clear(); a.onError(ex); worker.dispose(); @@ -219,19 +219,19 @@ void drainFused() { Throwable ex = error; if (!delayError && d && ex != null) { - actual.onError(error); + downstream.onError(error); worker.dispose(); return; } - actual.onNext(null); + downstream.onNext(null); if (d) { ex = error; if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onComplete(); + downstream.onComplete(); } worker.dispose(); return; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorNext.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorNext.java index 93df2a0548..649831d59f 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorNext.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorNext.java @@ -39,7 +39,7 @@ public void subscribeActual(Observer t) { } static final class OnErrorNextObserver implements Observer { - final Observer actual; + final Observer downstream; final Function> nextSupplier; final boolean allowFatal; final SequentialDisposable arbiter; @@ -49,15 +49,15 @@ static final class OnErrorNextObserver implements Observer { boolean done; OnErrorNextObserver(Observer actual, Function> nextSupplier, boolean allowFatal) { - this.actual = actual; + this.downstream = actual; this.nextSupplier = nextSupplier; this.allowFatal = allowFatal; this.arbiter = new SequentialDisposable(); } @Override - public void onSubscribe(Disposable s) { - arbiter.replace(s); + public void onSubscribe(Disposable d) { + arbiter.replace(d); } @Override @@ -65,7 +65,7 @@ public void onNext(T t) { if (done) { return; } - actual.onNext(t); + downstream.onNext(t); } @Override @@ -75,13 +75,13 @@ public void onError(Throwable t) { RxJavaPlugins.onError(t); return; } - actual.onError(t); + downstream.onError(t); return; } once = true; if (allowFatal && !(t instanceof Exception)) { - actual.onError(t); + downstream.onError(t); return; } @@ -91,14 +91,14 @@ public void onError(Throwable t) { p = nextSupplier.apply(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); return; } if (p == null) { NullPointerException npe = new NullPointerException("Observable is null"); npe.initCause(t); - actual.onError(npe); + downstream.onError(npe); return; } @@ -112,7 +112,7 @@ public void onComplete() { } done = true; once = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturn.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturn.java index 087aa47b24..2ed68d48e9 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturn.java @@ -32,38 +32,38 @@ public void subscribeActual(Observer t) { } static final class OnErrorReturnObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Function valueSupplier; - Disposable s; + Disposable upstream; OnErrorReturnObserver(Observer actual, Function valueSupplier) { - this.actual = actual; + this.downstream = actual; this.valueSupplier = valueSupplier; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override @@ -73,24 +73,24 @@ public void onError(Throwable t) { v = valueSupplier.apply(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); return; } if (v == null) { NullPointerException e = new NullPointerException("The supplied value is null"); e.initCause(t); - actual.onError(e); + downstream.onError(e); return; } - actual.onNext(v); - actual.onComplete(); + downstream.onNext(v); + downstream.onComplete(); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java index d5fa94eb76..39975af10b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java @@ -136,7 +136,7 @@ static final class PublishObserver */ final AtomicBoolean shouldConnect; - final AtomicReference s = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); @SuppressWarnings("unchecked") PublishObserver(AtomicReference> current) { @@ -152,7 +152,7 @@ public void dispose() { if (ps != TERMINATED) { current.compareAndSet(PublishObserver.this, null); - DisposableHelper.dispose(s); + DisposableHelper.dispose(upstream); } } @@ -162,8 +162,8 @@ public boolean isDisposed() { } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this.s, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this.upstream, d); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishSelector.java b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishSelector.java index 05abfd6181..17824fb4ca 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishSelector.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishSelector.java @@ -95,49 +95,49 @@ static final class TargetObserver extends AtomicReference implements Observer, Disposable { private static final long serialVersionUID = 854110278590336484L; - final Observer actual; + final Observer downstream; - Disposable d; + Disposable upstream; - TargetObserver(Observer actual) { - this.actual = actual; + TargetObserver(Observer downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(R value) { - actual.onNext(value); + downstream.onNext(value); } @Override public void onError(Throwable e) { DisposableHelper.dispose(this); - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { DisposableHelper.dispose(this); - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); DisposableHelper.dispose(this); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRange.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRange.java index 2718ef6c8e..19cb08cc21 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRange.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRange.java @@ -40,7 +40,7 @@ static final class RangeDisposable private static final long serialVersionUID = 396518478098735504L; - final Observer actual; + final Observer downstream; final long end; @@ -49,7 +49,7 @@ static final class RangeDisposable boolean fused; RangeDisposable(Observer actual, long start, long end) { - this.actual = actual; + this.downstream = actual; this.index = start; this.end = end; } @@ -58,7 +58,7 @@ void run() { if (fused) { return; } - Observer actual = this.actual; + Observer actual = this.downstream; long e = end; for (long i = index; i != e && get() == 0; i++) { actual.onNext((int)i); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRangeLong.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRangeLong.java index 851a5ecea3..55d23d28f1 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRangeLong.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRangeLong.java @@ -37,7 +37,7 @@ static final class RangeDisposable private static final long serialVersionUID = 396518478098735504L; - final Observer actual; + final Observer downstream; final long end; @@ -46,7 +46,7 @@ static final class RangeDisposable boolean fused; RangeDisposable(Observer actual, long start, long end) { - this.actual = actual; + this.downstream = actual; this.index = start; this.end = end; } @@ -55,7 +55,7 @@ void run() { if (fused) { return; } - Observer actual = this.actual; + Observer actual = this.downstream; long e = end; for (long i = index; i != e && get() == 0; i++) { actual.onNext(i); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableReduceMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableReduceMaybe.java index 0215e73fb4..63d0e6c2d1 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableReduceMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableReduceMaybe.java @@ -45,7 +45,7 @@ protected void subscribeActual(MaybeObserver observer) { static final class ReduceObserver implements Observer, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; final BiFunction reducer; @@ -53,19 +53,19 @@ static final class ReduceObserver implements Observer, Disposable { T value; - Disposable d; + Disposable upstream; ReduceObserver(MaybeObserver observer, BiFunction reducer) { - this.actual = observer; + this.downstream = observer; this.reducer = reducer; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -81,7 +81,7 @@ public void onNext(T value) { this.value = ObjectHelper.requireNonNull(reducer.apply(v, value), "The reducer returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); onError(ex); } } @@ -96,7 +96,7 @@ public void onError(Throwable e) { } done = true; value = null; - actual.onError(e); + downstream.onError(e); } @Override @@ -108,20 +108,20 @@ public void onComplete() { T v = value; value = null; if (v != null) { - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onComplete(); + downstream.onComplete(); } } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableReduceSeedSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableReduceSeedSingle.java index 9006957348..6a11b91631 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableReduceSeedSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableReduceSeedSingle.java @@ -49,26 +49,26 @@ protected void subscribeActual(SingleObserver observer) { static final class ReduceSeedObserver implements Observer, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final BiFunction reducer; R value; - Disposable d; + Disposable upstream; ReduceSeedObserver(SingleObserver actual, BiFunction reducer, R value) { - this.actual = actual; + this.downstream = actual; this.value = value; this.reducer = reducer; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -80,7 +80,7 @@ public void onNext(T value) { this.value = ObjectHelper.requireNonNull(reducer.apply(v, value), "The reducer returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - d.dispose(); + upstream.dispose(); onError(ex); } } @@ -91,7 +91,7 @@ public void onError(Throwable e) { R v = value; if (v != null) { value = null; - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } @@ -102,18 +102,18 @@ public void onComplete() { R v = value; if (v != null) { value = null; - actual.onSuccess(v); + downstream.onSuccess(v); } } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java index 73b1e0c1db..59b571640d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java @@ -170,7 +170,7 @@ static final class RefCountObserver private static final long serialVersionUID = -7419642935409022375L; - final Observer actual; + final Observer downstream; final ObservableRefCount parent; @@ -178,22 +178,22 @@ static final class RefCountObserver Disposable upstream; - RefCountObserver(Observer actual, ObservableRefCount parent, RefConnection connection) { - this.actual = actual; + RefCountObserver(Observer downstream, ObservableRefCount parent, RefConnection connection) { + this.downstream = downstream; this.parent = parent; this.connection = connection; } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { if (compareAndSet(false, true)) { parent.terminated(connection); - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -203,7 +203,7 @@ public void onError(Throwable t) { public void onComplete() { if (compareAndSet(false, true)) { parent.terminated(connection); - actual.onComplete(); + downstream.onComplete(); } } @@ -225,7 +225,7 @@ public void onSubscribe(Disposable d) { if (DisposableHelper.validate(upstream, d)) { this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java index c5ce8d1763..426bed7dd9 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java @@ -39,29 +39,29 @@ static final class RepeatObserver extends AtomicInteger implements Observer actual; + final Observer downstream; final SequentialDisposable sd; final ObservableSource source; long remaining; RepeatObserver(Observer actual, long count, SequentialDisposable sd, ObservableSource source) { - this.actual = actual; + this.downstream = actual; this.sd = sd; this.source = source; this.remaining = count; } @Override - public void onSubscribe(Disposable s) { - sd.replace(s); + public void onSubscribe(Disposable d) { + sd.replace(d); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -73,7 +73,7 @@ public void onComplete() { if (r != 0L) { subscribeNext(); } else { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java index 595c5e3b03..8d8b9e29ac 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java @@ -41,29 +41,29 @@ static final class RepeatUntilObserver extends AtomicInteger implements Obser private static final long serialVersionUID = -7098360935104053232L; - final Observer actual; - final SequentialDisposable sd; + final Observer downstream; + final SequentialDisposable upstream; final ObservableSource source; final BooleanSupplier stop; RepeatUntilObserver(Observer actual, BooleanSupplier until, SequentialDisposable sd, ObservableSource source) { - this.actual = actual; - this.sd = sd; + this.downstream = actual; + this.upstream = sd; this.source = source; this.stop = until; } @Override - public void onSubscribe(Disposable s) { - sd.replace(s); + public void onSubscribe(Disposable d) { + upstream.replace(d); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -73,11 +73,11 @@ public void onComplete() { b = stop.getAsBoolean(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } if (b) { - actual.onComplete(); + downstream.onComplete(); } else { subscribeNext(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java index 36143ebc00..4b8e194973 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java @@ -64,7 +64,7 @@ static final class RepeatWhenObserver extends AtomicInteger implements Observ private static final long serialVersionUID = 802743776666017014L; - final Observer actual; + final Observer downstream; final AtomicInteger wip; @@ -74,36 +74,36 @@ static final class RepeatWhenObserver extends AtomicInteger implements Observ final InnerRepeatObserver inner; - final AtomicReference d; + final AtomicReference upstream; final ObservableSource source; volatile boolean active; RepeatWhenObserver(Observer actual, Subject signaller, ObservableSource source) { - this.actual = actual; + this.downstream = actual; this.signaller = signaller; this.source = source; this.wip = new AtomicInteger(); this.error = new AtomicThrowable(); this.inner = new InnerRepeatObserver(); - this.d = new AtomicReference(); + this.upstream = new AtomicReference(); } @Override public void onSubscribe(Disposable d) { - DisposableHelper.replace(this.d, d); + DisposableHelper.replace(this.upstream, d); } @Override public void onNext(T t) { - HalfSerializer.onNext(actual, t, this, error); + HalfSerializer.onNext(downstream, t, this, error); } @Override public void onError(Throwable e) { DisposableHelper.dispose(inner); - HalfSerializer.onError(actual, e, this, error); + HalfSerializer.onError(downstream, e, this, error); } @Override @@ -114,12 +114,12 @@ public void onComplete() { @Override public boolean isDisposed() { - return DisposableHelper.isDisposed(d.get()); + return DisposableHelper.isDisposed(upstream.get()); } @Override public void dispose() { - DisposableHelper.dispose(d); + DisposableHelper.dispose(upstream); DisposableHelper.dispose(inner); } @@ -128,13 +128,13 @@ void innerNext() { } void innerError(Throwable ex) { - DisposableHelper.dispose(d); - HalfSerializer.onError(actual, ex, this, error); + DisposableHelper.dispose(upstream); + HalfSerializer.onError(downstream, ex, this, error); } void innerComplete() { - DisposableHelper.dispose(d); - HalfSerializer.onComplete(actual, this, error); + DisposableHelper.dispose(upstream); + HalfSerializer.onComplete(downstream, this, error); } void subscribeNext() { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java index cbf1111400..a743ae55c6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java @@ -43,27 +43,27 @@ static final class RetryBiObserver extends AtomicInteger implements Observer< private static final long serialVersionUID = -7098360935104053232L; - final Observer actual; - final SequentialDisposable sa; + final Observer downstream; + final SequentialDisposable upstream; final ObservableSource source; final BiPredicate predicate; int retries; RetryBiObserver(Observer actual, BiPredicate predicate, SequentialDisposable sa, ObservableSource source) { - this.actual = actual; - this.sa = sa; + this.downstream = actual; + this.upstream = sa; this.source = source; this.predicate = predicate; } @Override - public void onSubscribe(Disposable s) { - sa.update(s); + public void onSubscribe(Disposable d) { + upstream.update(d); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { @@ -72,11 +72,11 @@ public void onError(Throwable t) { b = predicate.test(++retries, t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); return; } if (!b) { - actual.onError(t); + downstream.onError(t); return; } subscribeNext(); @@ -84,7 +84,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } /** @@ -94,7 +94,7 @@ void subscribeNext() { if (getAndIncrement() == 0) { int missed = 1; for (;;) { - if (sa.isDisposed()) { + if (upstream.isDisposed()) { return; } source.subscribe(this); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java index 9c22024a7e..3f98549c1d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java @@ -45,28 +45,28 @@ static final class RepeatObserver extends AtomicInteger implements Observer actual; - final SequentialDisposable sa; + final Observer downstream; + final SequentialDisposable upstream; final ObservableSource source; final Predicate predicate; long remaining; RepeatObserver(Observer actual, long count, Predicate predicate, SequentialDisposable sa, ObservableSource source) { - this.actual = actual; - this.sa = sa; + this.downstream = actual; + this.upstream = sa; this.source = source; this.predicate = predicate; this.remaining = count; } @Override - public void onSubscribe(Disposable s) { - sa.update(s); + public void onSubscribe(Disposable d) { + upstream.update(d); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { @@ -75,18 +75,18 @@ public void onError(Throwable t) { remaining = r - 1; } if (r == 0) { - actual.onError(t); + downstream.onError(t); } else { boolean b; try { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(new CompositeException(t, e)); + downstream.onError(new CompositeException(t, e)); return; } if (!b) { - actual.onError(t); + downstream.onError(t); return; } subscribeNext(); @@ -95,7 +95,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } /** @@ -105,7 +105,7 @@ void subscribeNext() { if (getAndIncrement() == 0) { int missed = 1; for (;;) { - if (sa.isDisposed()) { + if (upstream.isDisposed()) { return; } source.subscribe(this); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryWhen.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryWhen.java index 8c8a780b04..65a17fe269 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryWhen.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryWhen.java @@ -64,7 +64,7 @@ static final class RepeatWhenObserver extends AtomicInteger implements Observ private static final long serialVersionUID = 802743776666017014L; - final Observer actual; + final Observer downstream; final AtomicInteger wip; @@ -74,30 +74,30 @@ static final class RepeatWhenObserver extends AtomicInteger implements Observ final InnerRepeatObserver inner; - final AtomicReference d; + final AtomicReference upstream; final ObservableSource source; volatile boolean active; RepeatWhenObserver(Observer actual, Subject signaller, ObservableSource source) { - this.actual = actual; + this.downstream = actual; this.signaller = signaller; this.source = source; this.wip = new AtomicInteger(); this.error = new AtomicThrowable(); this.inner = new InnerRepeatObserver(); - this.d = new AtomicReference(); + this.upstream = new AtomicReference(); } @Override public void onSubscribe(Disposable d) { - DisposableHelper.replace(this.d, d); + DisposableHelper.replace(this.upstream, d); } @Override public void onNext(T t) { - HalfSerializer.onNext(actual, t, this, error); + HalfSerializer.onNext(downstream, t, this, error); } @Override @@ -109,17 +109,17 @@ public void onError(Throwable e) { @Override public void onComplete() { DisposableHelper.dispose(inner); - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } @Override public boolean isDisposed() { - return DisposableHelper.isDisposed(d.get()); + return DisposableHelper.isDisposed(upstream.get()); } @Override public void dispose() { - DisposableHelper.dispose(d); + DisposableHelper.dispose(upstream); DisposableHelper.dispose(inner); } @@ -128,13 +128,13 @@ void innerNext() { } void innerError(Throwable ex) { - DisposableHelper.dispose(d); - HalfSerializer.onError(actual, ex, this, error); + DisposableHelper.dispose(upstream); + HalfSerializer.onError(downstream, ex, this, error); } void innerComplete() { - DisposableHelper.dispose(d); - HalfSerializer.onComplete(actual, this, error); + DisposableHelper.dispose(upstream); + HalfSerializer.onComplete(downstream, this, error); } void subscribeNext() { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleTimed.java index 9a420fa186..9397438e09 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleTimed.java @@ -51,30 +51,30 @@ abstract static class SampleTimedObserver extends AtomicReference implemen private static final long serialVersionUID = -3517602651313910099L; - final Observer actual; + final Observer downstream; final long period; final TimeUnit unit; final Scheduler scheduler; final AtomicReference timer = new AtomicReference(); - Disposable s; + Disposable upstream; SampleTimedObserver(Observer actual, long period, TimeUnit unit, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.period = period; this.unit = unit; this.scheduler = scheduler; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); - Disposable d = scheduler.schedulePeriodicallyDirect(this, period, period, unit); - DisposableHelper.replace(timer, d); + Disposable task = scheduler.schedulePeriodicallyDirect(this, period, period, unit); + DisposableHelper.replace(timer, task); } } @@ -86,7 +86,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { cancelTimer(); - actual.onError(t); + downstream.onError(t); } @Override @@ -102,18 +102,18 @@ void cancelTimer() { @Override public void dispose() { cancelTimer(); - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } void emit() { T value = getAndSet(null); if (value != null) { - actual.onNext(value); + downstream.onNext(value); } } @@ -130,7 +130,7 @@ static final class SampleTimedNoLast extends SampleTimedObserver { @Override void complete() { - actual.onComplete(); + downstream.onComplete(); } @Override @@ -154,7 +154,7 @@ static final class SampleTimedEmitLast extends SampleTimedObserver { void complete() { emit(); if (wip.decrementAndGet() == 0) { - actual.onComplete(); + downstream.onComplete(); } } @@ -163,7 +163,7 @@ public void run() { if (wip.incrementAndGet() == 2) { emit(); if (wip.decrementAndGet() == 0) { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleWithObservable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleWithObservable.java index 5a6f092ce1..fcb0f33a00 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleWithObservable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleWithObservable.java @@ -47,23 +47,23 @@ abstract static class SampleMainObserver extends AtomicReference private static final long serialVersionUID = -3517602651313910099L; - final Observer actual; + final Observer downstream; final ObservableSource sampler; final AtomicReference other = new AtomicReference(); - Disposable s; + Disposable upstream; SampleMainObserver(Observer actual, ObservableSource other) { - this.actual = actual; + this.downstream = actual; this.sampler = other; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); if (other.get() == null) { sampler.subscribe(new SamplerObserver(this)); } @@ -78,7 +78,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { DisposableHelper.dispose(other); - actual.onError(t); + downstream.onError(t); } @Override @@ -94,7 +94,7 @@ boolean setOther(Disposable o) { @Override public void dispose() { DisposableHelper.dispose(other); - s.dispose(); + upstream.dispose(); } @Override @@ -103,19 +103,19 @@ public boolean isDisposed() { } public void error(Throwable e) { - s.dispose(); - actual.onError(e); + upstream.dispose(); + downstream.onError(e); } public void complete() { - s.dispose(); + upstream.dispose(); completeOther(); } void emit() { T value = getAndSet(null); if (value != null) { - actual.onNext(value); + downstream.onNext(value); } } @@ -134,8 +134,8 @@ static final class SamplerObserver implements Observer { } @Override - public void onSubscribe(Disposable s) { - parent.setOther(s); + public void onSubscribe(Disposable d) { + parent.setOther(d); } @Override @@ -164,12 +164,12 @@ static final class SampleMainNoLast extends SampleMainObserver { @Override void completeMain() { - actual.onComplete(); + downstream.onComplete(); } @Override void completeOther() { - actual.onComplete(); + downstream.onComplete(); } @Override @@ -196,7 +196,7 @@ void completeMain() { done = true; if (wip.getAndIncrement() == 0) { emit(); - actual.onComplete(); + downstream.onComplete(); } } @@ -205,7 +205,7 @@ void completeOther() { done = true; if (wip.getAndIncrement() == 0) { emit(); - actual.onComplete(); + downstream.onComplete(); } } @@ -216,7 +216,7 @@ void run() { boolean d = done; emit(); if (d) { - actual.onComplete(); + downstream.onComplete(); return; } } while (wip.decrementAndGet() != 0); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableScan.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableScan.java index 2e3a6b4fda..13fd31fa1a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableScan.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableScan.java @@ -34,37 +34,37 @@ public void subscribeActual(Observer t) { } static final class ScanObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final BiFunction accumulator; - Disposable s; + Disposable upstream; T value; boolean done; ScanObserver(Observer actual, BiFunction accumulator) { - this.actual = actual; + this.downstream = actual; this.accumulator = accumulator; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -73,7 +73,7 @@ public void onNext(T t) { if (done) { return; } - final Observer a = actual; + final Observer a = downstream; T v = value; if (v == null) { value = t; @@ -85,7 +85,7 @@ public void onNext(T t) { u = ObjectHelper.requireNonNull(accumulator.apply(v, t), "The value returned by the accumulator is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } @@ -102,7 +102,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -111,7 +111,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableScanSeed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableScanSeed.java index 6eda15b035..6f9222fbee 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableScanSeed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableScanSeed.java @@ -48,41 +48,41 @@ public void subscribeActual(Observer t) { } static final class ScanSeedObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final BiFunction accumulator; R value; - Disposable s; + Disposable upstream; boolean done; ScanSeedObserver(Observer actual, BiFunction accumulator, R value) { - this.actual = actual; + this.downstream = actual; this.accumulator = accumulator; this.value = value; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); - actual.onNext(value); + downstream.onNext(value); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override @@ -99,14 +99,14 @@ public void onNext(T t) { u = ObjectHelper.requireNonNull(accumulator.apply(v, t), "The accumulator returned a null value"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } value = u; - actual.onNext(u); + downstream.onNext(u); } @Override @@ -116,7 +116,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -125,7 +125,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqual.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqual.java index aab9dcab05..07da31f3f0 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqual.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqual.java @@ -46,7 +46,7 @@ public void subscribeActual(Observer observer) { static final class EqualCoordinator extends AtomicInteger implements Disposable { private static final long serialVersionUID = -6178010334400373240L; - final Observer actual; + final Observer downstream; final BiPredicate comparer; final ArrayCompositeDisposable resources; final ObservableSource first; @@ -62,7 +62,7 @@ static final class EqualCoordinator extends AtomicInteger implements Disposab EqualCoordinator(Observer actual, int bufferSize, ObservableSource first, ObservableSource second, BiPredicate comparer) { - this.actual = actual; + this.downstream = actual; this.first = first; this.second = second; this.comparer = comparer; @@ -74,8 +74,8 @@ static final class EqualCoordinator extends AtomicInteger implements Disposab this.resources = new ArrayCompositeDisposable(2); } - boolean setDisposable(Disposable s, int index) { - return resources.setResource(index, s); + boolean setDisposable(Disposable d, int index) { + return resources.setResource(index, d); } void subscribe() { @@ -138,7 +138,7 @@ void drain() { if (e != null) { cancel(q1, q2); - actual.onError(e); + downstream.onError(e); return; } } @@ -149,7 +149,7 @@ void drain() { if (e != null) { cancel(q1, q2); - actual.onError(e); + downstream.onError(e); return; } } @@ -165,15 +165,15 @@ void drain() { boolean e2 = v2 == null; if (d1 && d2 && e1 && e2) { - actual.onNext(true); - actual.onComplete(); + downstream.onNext(true); + downstream.onComplete(); return; } if ((d1 && d2) && (e1 != e2)) { cancel(q1, q2); - actual.onNext(false); - actual.onComplete(); + downstream.onNext(false); + downstream.onComplete(); return; } @@ -186,15 +186,15 @@ void drain() { Exceptions.throwIfFatal(ex); cancel(q1, q2); - actual.onError(ex); + downstream.onError(ex); return; } if (!c) { cancel(q1, q2); - actual.onNext(false); - actual.onComplete(); + downstream.onNext(false); + downstream.onComplete(); return; } @@ -230,8 +230,8 @@ static final class EqualObserver implements Observer { } @Override - public void onSubscribe(Disposable s) { - parent.setDisposable(s, index); + public void onSubscribe(Disposable d) { + parent.setDisposable(d, index); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualSingle.java index 742b7fb39c..88e059a5cb 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualSingle.java @@ -53,7 +53,7 @@ public Observable fuseToObservable() { static final class EqualCoordinator extends AtomicInteger implements Disposable { private static final long serialVersionUID = -6178010334400373240L; - final SingleObserver actual; + final SingleObserver downstream; final BiPredicate comparer; final ArrayCompositeDisposable resources; final ObservableSource first; @@ -69,7 +69,7 @@ static final class EqualCoordinator extends AtomicInteger implements Disposab EqualCoordinator(SingleObserver actual, int bufferSize, ObservableSource first, ObservableSource second, BiPredicate comparer) { - this.actual = actual; + this.downstream = actual; this.first = first; this.second = second; this.comparer = comparer; @@ -81,8 +81,8 @@ static final class EqualCoordinator extends AtomicInteger implements Disposab this.resources = new ArrayCompositeDisposable(2); } - boolean setDisposable(Disposable s, int index) { - return resources.setResource(index, s); + boolean setDisposable(Disposable d, int index) { + return resources.setResource(index, d); } void subscribe() { @@ -145,7 +145,7 @@ void drain() { if (e != null) { cancel(q1, q2); - actual.onError(e); + downstream.onError(e); return; } } @@ -156,7 +156,7 @@ void drain() { if (e != null) { cancel(q1, q2); - actual.onError(e); + downstream.onError(e); return; } } @@ -172,13 +172,13 @@ void drain() { boolean e2 = v2 == null; if (d1 && d2 && e1 && e2) { - actual.onSuccess(true); + downstream.onSuccess(true); return; } if ((d1 && d2) && (e1 != e2)) { cancel(q1, q2); - actual.onSuccess(false); + downstream.onSuccess(false); return; } @@ -191,14 +191,14 @@ void drain() { Exceptions.throwIfFatal(ex); cancel(q1, q2); - actual.onError(ex); + downstream.onError(ex); return; } if (!c) { cancel(q1, q2); - actual.onSuccess(false); + downstream.onSuccess(false); return; } @@ -234,8 +234,8 @@ static final class EqualObserver implements Observer { } @Override - public void onSubscribe(Disposable s) { - parent.setDisposable(s, index); + public void onSubscribe(Disposable d) { + parent.setDisposable(d, index); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleMaybe.java index 3dc75441bf..ab45f7b29f 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleMaybe.java @@ -31,35 +31,35 @@ public void subscribeActual(MaybeObserver t) { } static final class SingleElementObserver implements Observer, Disposable { - final MaybeObserver actual; + final MaybeObserver downstream; - Disposable s; + Disposable upstream; T value; boolean done; - SingleElementObserver(MaybeObserver actual) { - this.actual = actual; + SingleElementObserver(MaybeObserver downstream) { + this.downstream = downstream; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -70,8 +70,8 @@ public void onNext(T t) { } if (value != null) { done = true; - s.dispose(); - actual.onError(new IllegalArgumentException("Sequence contains more than one element!")); + upstream.dispose(); + downstream.onError(new IllegalArgumentException("Sequence contains more than one element!")); return; } value = t; @@ -84,7 +84,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -96,9 +96,9 @@ public void onComplete() { T v = value; value = null; if (v == null) { - actual.onComplete(); + downstream.onComplete(); } else { - actual.onSuccess(v); + downstream.onSuccess(v); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleSingle.java index 40ac65da57..79f7aaa4b2 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleSingle.java @@ -36,38 +36,38 @@ public void subscribeActual(SingleObserver t) { } static final class SingleElementObserver implements Observer, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final T defaultValue; - Disposable s; + Disposable upstream; T value; boolean done; SingleElementObserver(SingleObserver actual, T defaultValue) { - this.actual = actual; + this.downstream = actual; this.defaultValue = defaultValue; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -78,8 +78,8 @@ public void onNext(T t) { } if (value != null) { done = true; - s.dispose(); - actual.onError(new IllegalArgumentException("Sequence contains more than one element!")); + upstream.dispose(); + downstream.onError(new IllegalArgumentException("Sequence contains more than one element!")); return; } value = t; @@ -92,7 +92,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -108,9 +108,9 @@ public void onComplete() { } if (v != null) { - actual.onSuccess(v); + downstream.onSuccess(v); } else { - actual.onError(new NoSuchElementException()); + downstream.onError(new NoSuchElementException()); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkip.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkip.java index 570c4e8877..a03bca541f 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkip.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkip.java @@ -30,21 +30,21 @@ public void subscribeActual(Observer observer) { } static final class SkipObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; long remaining; - Disposable d; + Disposable upstream; SkipObserver(Observer actual, long n) { - this.actual = actual; + this.downstream = actual; this.remaining = n; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; - actual.onSubscribe(this); + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -53,28 +53,28 @@ public void onNext(T t) { if (remaining != 0L) { remaining--; } else { - actual.onNext(t); + downstream.onNext(t); } } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java index f22df6fdf7..3c6de3847a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java @@ -35,52 +35,52 @@ public void subscribeActual(Observer observer) { static final class SkipLastObserver extends ArrayDeque implements Observer, Disposable { private static final long serialVersionUID = -3807491841935125653L; - final Observer actual; + final Observer downstream; final int skip; - Disposable s; + Disposable upstream; SkipLastObserver(Observer actual, int skip) { super(skip); - this.actual = actual; + this.downstream = actual; this.skip = skip; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override public void onNext(T t) { if (skip == size()) { - actual.onNext(poll()); + downstream.onNext(poll()); } offer(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimed.java index b24d341245..3c9eb40261 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimed.java @@ -46,14 +46,14 @@ public void subscribeActual(Observer t) { static final class SkipLastTimedObserver extends AtomicInteger implements Observer, Disposable { private static final long serialVersionUID = -5677354903406201275L; - final Observer actual; + final Observer downstream; final long time; final TimeUnit unit; final Scheduler scheduler; final SpscLinkedArrayQueue queue; final boolean delayError; - Disposable s; + Disposable upstream; volatile boolean cancelled; @@ -61,7 +61,7 @@ static final class SkipLastTimedObserver extends AtomicInteger implements Obs Throwable error; SkipLastTimedObserver(Observer actual, long time, TimeUnit unit, Scheduler scheduler, int bufferSize, boolean delayError) { - this.actual = actual; + this.downstream = actual; this.time = time; this.unit = unit; this.scheduler = scheduler; @@ -70,10 +70,10 @@ static final class SkipLastTimedObserver extends AtomicInteger implements Obs } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -105,7 +105,7 @@ public void onComplete() { public void dispose() { if (!cancelled) { cancelled = true; - s.dispose(); + upstream.dispose(); if (getAndIncrement() == 0) { queue.clear(); @@ -125,7 +125,7 @@ void drain() { int missed = 1; - final Observer a = actual; + final Observer a = downstream; final SpscLinkedArrayQueue q = queue; final boolean delayError = this.delayError; final TimeUnit unit = this.unit; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipUntil.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipUntil.java index c9f711ff3e..f02edecf0e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipUntil.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipUntil.java @@ -43,56 +43,56 @@ public void subscribeActual(Observer child) { static final class SkipUntilObserver implements Observer { - final Observer actual; + final Observer downstream; final ArrayCompositeDisposable frc; - Disposable s; + Disposable upstream; volatile boolean notSkipping; boolean notSkippingLocal; SkipUntilObserver(Observer actual, ArrayCompositeDisposable frc) { - this.actual = actual; + this.downstream = actual; this.frc = frc; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - frc.setResource(0, s); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + frc.setResource(0, d); } } @Override public void onNext(T t) { if (notSkippingLocal) { - actual.onNext(t); + downstream.onNext(t); } else if (notSkipping) { notSkippingLocal = true; - actual.onNext(t); + downstream.onNext(t); } } @Override public void onError(Throwable t) { frc.dispose(); - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { frc.dispose(); - actual.onComplete(); + downstream.onComplete(); } } final class SkipUntil implements Observer { - private final ArrayCompositeDisposable frc; - private final SkipUntilObserver sus; - private final SerializedObserver serial; - Disposable s; + final ArrayCompositeDisposable frc; + final SkipUntilObserver sus; + final SerializedObserver serial; + Disposable upstream; SkipUntil(ArrayCompositeDisposable frc, SkipUntilObserver sus, SerializedObserver serial) { this.frc = frc; @@ -101,16 +101,16 @@ final class SkipUntil implements Observer { } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - frc.setResource(1, s); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + frc.setResource(1, d); } } @Override public void onNext(U t) { - s.dispose(); + upstream.dispose(); sus.notSkipping = true; } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java index dfe5fd1d9c..a39b553563 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java @@ -32,64 +32,64 @@ public void subscribeActual(Observer observer) { } static final class SkipWhileObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Predicate predicate; - Disposable s; + Disposable upstream; boolean notSkipping; SkipWhileObserver(Observer actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override public void onNext(T t) { if (notSkipping) { - actual.onNext(t); + downstream.onNext(t); } else { boolean b; try { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); - actual.onError(e); + upstream.dispose(); + downstream.onError(e); return; } if (!b) { notSkipping = true; - actual.onNext(t); + downstream.onNext(t); } } } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSubscribeOn.java index c55a224155..7e697d379a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSubscribeOn.java @@ -39,38 +39,38 @@ public void subscribeActual(final Observer observer) { static final class SubscribeOnObserver extends AtomicReference implements Observer, Disposable { private static final long serialVersionUID = 8094547886072529208L; - final Observer actual; + final Observer downstream; - final AtomicReference s; + final AtomicReference upstream; - SubscribeOnObserver(Observer actual) { - this.actual = actual; - this.s = new AtomicReference(); + SubscribeOnObserver(Observer downstream) { + this.downstream = downstream; + this.upstream = new AtomicReference(); } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this.s, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this.upstream, d); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - DisposableHelper.dispose(s); + DisposableHelper.dispose(upstream); DisposableHelper.dispose(this); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmpty.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmpty.java index aa97b7f18a..6eec37f7a1 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmpty.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmpty.java @@ -32,22 +32,22 @@ public void subscribeActual(Observer t) { } static final class SwitchIfEmptyObserver implements Observer { - final Observer actual; + final Observer downstream; final ObservableSource other; final SequentialDisposable arbiter; boolean empty; SwitchIfEmptyObserver(Observer actual, ObservableSource other) { - this.actual = actual; + this.downstream = actual; this.other = other; this.empty = true; this.arbiter = new SequentialDisposable(); } @Override - public void onSubscribe(Disposable s) { - arbiter.update(s); + public void onSubscribe(Disposable d) { + arbiter.update(d); } @Override @@ -55,12 +55,12 @@ public void onNext(T t) { if (empty) { empty = false; } - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override @@ -69,7 +69,7 @@ public void onComplete() { empty = false; other.subscribe(this); } else { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchMap.java index 032f84dbc6..8c5aa371dc 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchMap.java @@ -54,7 +54,7 @@ public void subscribeActual(Observer t) { static final class SwitchMapObserver extends AtomicInteger implements Observer, Disposable { private static final long serialVersionUID = -3491074160481096299L; - final Observer actual; + final Observer downstream; final Function> mapper; final int bufferSize; @@ -66,7 +66,7 @@ static final class SwitchMapObserver extends AtomicInteger implements Obse volatile boolean cancelled; - Disposable s; + Disposable upstream; final AtomicReference> active = new AtomicReference>(); @@ -81,7 +81,7 @@ static final class SwitchMapObserver extends AtomicInteger implements Obse SwitchMapObserver(Observer actual, Function> mapper, int bufferSize, boolean delayErrors) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.bufferSize = bufferSize; this.delayErrors = delayErrors; @@ -89,10 +89,10 @@ static final class SwitchMapObserver extends AtomicInteger implements Obse } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -111,7 +111,7 @@ public void onNext(T t) { p = ObjectHelper.requireNonNull(mapper.apply(t), "The ObservableSource returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } @@ -155,7 +155,7 @@ public void onComplete() { public void dispose() { if (!cancelled) { cancelled = true; - s.dispose(); + upstream.dispose(); disposeInner(); } } @@ -181,7 +181,7 @@ void drain() { return; } - final Observer a = actual; + final Observer a = downstream; final AtomicReference> active = this.active; final boolean delayErrors = this.delayErrors; @@ -274,7 +274,7 @@ void drain() { active.compareAndSet(inner, null); if (!delayErrors) { disposeInner(); - s.dispose(); + upstream.dispose(); done = true; } else { inner.cancel(); @@ -313,7 +313,7 @@ void drain() { void innerError(SwitchMapInnerObserver inner, Throwable ex) { if (inner.index == unique && errors.addThrowable(ex)) { if (!delayErrors) { - s.dispose(); + upstream.dispose(); } inner.done = true; drain(); @@ -342,11 +342,11 @@ static final class SwitchMapInnerObserver extends AtomicReference qd = (QueueDisposable) s; + QueueDisposable qd = (QueueDisposable) d; int m = qd.requestFusion(QueueDisposable.ANY | QueueDisposable.BOUNDARY); if (m == QueueDisposable.SYNC) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTake.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTake.java index 418ec23e7a..7bda3017d5 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTake.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTake.java @@ -31,27 +31,27 @@ protected void subscribeActual(Observer observer) { } static final class TakeObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; boolean done; - Disposable subscription; + Disposable upstream; long remaining; TakeObserver(Observer actual, long limit) { - this.actual = actual; + this.downstream = actual; this.remaining = limit; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.subscription, s)) { - subscription = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + upstream = d; if (remaining == 0) { done = true; - s.dispose(); - EmptyDisposable.complete(actual); + d.dispose(); + EmptyDisposable.complete(downstream); } else { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } } @@ -59,7 +59,7 @@ public void onSubscribe(Disposable s) { public void onNext(T t) { if (!done && remaining-- > 0) { boolean stop = remaining == 0; - actual.onNext(t); + downstream.onNext(t); if (stop) { onComplete(); } @@ -73,26 +73,26 @@ public void onError(Throwable t) { } done = true; - subscription.dispose(); - actual.onError(t); + upstream.dispose(); + downstream.onError(t); } @Override public void onComplete() { if (!done) { done = true; - subscription.dispose(); - actual.onComplete(); + upstream.dispose(); + downstream.onComplete(); } } @Override public void dispose() { - subscription.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return subscription.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLast.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLast.java index 239ec3dea2..92f0510f11 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLast.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLast.java @@ -35,23 +35,23 @@ public void subscribeActual(Observer t) { static final class TakeLastObserver extends ArrayDeque implements Observer, Disposable { private static final long serialVersionUID = 7240042530241604978L; - final Observer actual; + final Observer downstream; final int count; - Disposable s; + Disposable upstream; volatile boolean cancelled; TakeLastObserver(Observer actual, int count) { - this.actual = actual; + this.downstream = actual; this.count = count; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -65,12 +65,12 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - Observer a = actual; + Observer a = downstream; for (;;) { if (cancelled) { return; @@ -90,7 +90,7 @@ public void onComplete() { public void dispose() { if (!cancelled) { cancelled = true; - s.dispose(); + upstream.dispose(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastOne.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastOne.java index 04ad923c28..353f51fcf9 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastOne.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastOne.java @@ -28,21 +28,21 @@ public void subscribeActual(Observer observer) { } static final class TakeLastOneObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; - Disposable s; + Disposable upstream; T value; - TakeLastOneObserver(Observer actual) { - this.actual = actual; + TakeLastOneObserver(Observer downstream) { + this.downstream = downstream; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -54,7 +54,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { value = null; - actual.onError(t); + downstream.onError(t); } @Override @@ -66,20 +66,20 @@ void emit() { T v = value; if (v != null) { value = null; - actual.onNext(v); + downstream.onNext(v); } - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { value = null; - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimed.java index d72d4c2171..7bd29092b4 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimed.java @@ -49,7 +49,7 @@ static final class TakeLastTimedObserver extends AtomicBoolean implements Observer, Disposable { private static final long serialVersionUID = -5677354903406201275L; - final Observer actual; + final Observer downstream; final long count; final long time; final TimeUnit unit; @@ -57,14 +57,14 @@ static final class TakeLastTimedObserver final SpscLinkedArrayQueue queue; final boolean delayError; - Disposable d; + Disposable upstream; volatile boolean cancelled; Throwable error; TakeLastTimedObserver(Observer actual, long count, long time, TimeUnit unit, Scheduler scheduler, int bufferSize, boolean delayError) { - this.actual = actual; + this.downstream = actual; this.count = count; this.time = time; this.unit = unit; @@ -75,9 +75,9 @@ static final class TakeLastTimedObserver @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; - actual.onSubscribe(this); + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -118,7 +118,7 @@ public void onComplete() { public void dispose() { if (!cancelled) { cancelled = true; - d.dispose(); + upstream.dispose(); if (compareAndSet(false, true)) { queue.clear(); @@ -136,7 +136,7 @@ void drain() { return; } - final Observer a = actual; + final Observer a = downstream; final SpscLinkedArrayQueue q = queue; final boolean delayError = this.delayError; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicate.java index 43cdaf05bd..cd984f2e07 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicate.java @@ -33,50 +33,50 @@ public void subscribeActual(Observer observer) { } static final class TakeUntilPredicateObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Predicate predicate; - Disposable s; + Disposable upstream; boolean done; - TakeUntilPredicateObserver(Observer actual, Predicate predicate) { - this.actual = actual; + TakeUntilPredicateObserver(Observer downstream, Predicate predicate) { + this.downstream = downstream; this.predicate = predicate; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override public void onNext(T t) { if (!done) { - actual.onNext(t); + downstream.onNext(t); boolean b; try { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } if (b) { done = true; - s.dispose(); - actual.onComplete(); + upstream.dispose(); + downstream.onComplete(); } } } @@ -85,7 +85,7 @@ public void onNext(T t) { public void onError(Throwable t) { if (!done) { done = true; - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -95,7 +95,7 @@ public void onError(Throwable t) { public void onComplete() { if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeWhile.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeWhile.java index b91898a652..1b41c6e86b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeWhile.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeWhile.java @@ -33,35 +33,35 @@ public void subscribeActual(Observer t) { } static final class TakeWhileObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Predicate predicate; - Disposable s; + Disposable upstream; boolean done; TakeWhileObserver(Observer actual, Predicate predicate) { - this.actual = actual; + this.downstream = actual; this.predicate = predicate; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -75,19 +75,19 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); - s.dispose(); + upstream.dispose(); onError(e); return; } if (!b) { done = true; - s.dispose(); - actual.onComplete(); + upstream.dispose(); + downstream.onComplete(); return; } - actual.onNext(t); + downstream.onNext(t); } @Override @@ -97,7 +97,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -106,7 +106,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTimed.java index f2512180da..54e94ab0b7 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTimed.java @@ -48,29 +48,29 @@ static final class DebounceTimedObserver implements Observer, Disposable, Runnable { private static final long serialVersionUID = 786994795061867455L; - final Observer actual; + final Observer downstream; final long timeout; final TimeUnit unit; final Scheduler.Worker worker; - Disposable s; + Disposable upstream; volatile boolean gate; boolean done; DebounceTimedObserver(Observer actual, long timeout, TimeUnit unit, Worker worker) { - this.actual = actual; + this.downstream = actual; this.timeout = timeout; this.unit = unit; this.worker = worker; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @@ -79,7 +79,7 @@ public void onNext(T t) { if (!gate && !done) { gate = true; - actual.onNext(t); + downstream.onNext(t); Disposable d = get(); if (d != null) { @@ -102,7 +102,7 @@ public void onError(Throwable t) { RxJavaPlugins.onError(t); } else { done = true; - actual.onError(t); + downstream.onError(t); worker.dispose(); } } @@ -111,14 +111,14 @@ public void onError(Throwable t) { public void onComplete() { if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); worker.dispose(); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); worker.dispose(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java index 00dda7ad6b..39e0f0bfc3 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleLatest.java @@ -97,9 +97,9 @@ static final class ThrottleLatestObserver } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(upstream, s)) { - upstream = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(upstream, d)) { + upstream = d; downstream.onSubscribe(this); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeInterval.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeInterval.java index a9449ecd89..0cc1a2c018 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeInterval.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeInterval.java @@ -36,37 +36,37 @@ public void subscribeActual(Observer> t) { } static final class TimeIntervalObserver implements Observer, Disposable { - final Observer> actual; + final Observer> downstream; final TimeUnit unit; final Scheduler scheduler; long lastTime; - Disposable s; + Disposable upstream; TimeIntervalObserver(Observer> actual, TimeUnit unit, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.scheduler = scheduler; this.unit = unit; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; lastTime = scheduler.now(unit); - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -76,17 +76,17 @@ public void onNext(T t) { long last = lastTime; lastTime = now; long delta = now - last; - actual.onNext(new Timed(t, delta, unit)); + downstream.onNext(new Timed(t, delta, unit)); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeout.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeout.java index eeacf6d555..2aeb9051a2 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeout.java @@ -65,7 +65,7 @@ static final class TimeoutObserver extends AtomicLong private static final long serialVersionUID = 3764492702657003550L; - final Observer actual; + final Observer downstream; final Function> itemTimeoutIndicator; @@ -74,15 +74,15 @@ static final class TimeoutObserver extends AtomicLong final AtomicReference upstream; TimeoutObserver(Observer actual, Function> itemTimeoutIndicator) { - this.actual = actual; + this.downstream = actual; this.itemTimeoutIndicator = itemTimeoutIndicator; this.task = new SequentialDisposable(); this.upstream = new AtomicReference(); } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(upstream, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(upstream, d); } @Override @@ -97,7 +97,7 @@ public void onNext(T t) { d.dispose(); } - actual.onNext(t); + downstream.onNext(t); ObservableSource itemTimeoutObservableSource; @@ -109,7 +109,7 @@ public void onNext(T t) { Exceptions.throwIfFatal(ex); upstream.get().dispose(); getAndSet(Long.MAX_VALUE); - actual.onError(ex); + downstream.onError(ex); return; } @@ -133,7 +133,7 @@ public void onError(Throwable t) { if (getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -144,7 +144,7 @@ public void onComplete() { if (getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onComplete(); + downstream.onComplete(); } } @@ -153,7 +153,7 @@ public void onTimeout(long idx) { if (compareAndSet(idx, Long.MAX_VALUE)) { DisposableHelper.dispose(upstream); - actual.onError(new TimeoutException()); + downstream.onError(new TimeoutException()); } } @@ -162,7 +162,7 @@ public void onTimeoutError(long idx, Throwable ex) { if (compareAndSet(idx, Long.MAX_VALUE)) { DisposableHelper.dispose(upstream); - actual.onError(ex); + downstream.onError(ex); } else { RxJavaPlugins.onError(ex); } @@ -186,7 +186,7 @@ static final class TimeoutFallbackObserver private static final long serialVersionUID = -7508389464265974549L; - final Observer actual; + final Observer downstream; final Function> itemTimeoutIndicator; @@ -201,7 +201,7 @@ static final class TimeoutFallbackObserver TimeoutFallbackObserver(Observer actual, Function> itemTimeoutIndicator, ObservableSource fallback) { - this.actual = actual; + this.downstream = actual; this.itemTimeoutIndicator = itemTimeoutIndicator; this.task = new SequentialDisposable(); this.fallback = fallback; @@ -210,8 +210,8 @@ static final class TimeoutFallbackObserver } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(upstream, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(upstream, d); } @Override @@ -226,7 +226,7 @@ public void onNext(T t) { d.dispose(); } - actual.onNext(t); + downstream.onNext(t); ObservableSource itemTimeoutObservableSource; @@ -238,7 +238,7 @@ public void onNext(T t) { Exceptions.throwIfFatal(ex); upstream.get().dispose(); index.getAndSet(Long.MAX_VALUE); - actual.onError(ex); + downstream.onError(ex); return; } @@ -262,7 +262,7 @@ public void onError(Throwable t) { if (index.getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onError(t); + downstream.onError(t); task.dispose(); } else { @@ -275,7 +275,7 @@ public void onComplete() { if (index.getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onComplete(); + downstream.onComplete(); task.dispose(); } @@ -289,7 +289,7 @@ public void onTimeout(long idx) { ObservableSource f = fallback; fallback = null; - f.subscribe(new ObservableTimeoutTimed.FallbackObserver(actual, this)); + f.subscribe(new ObservableTimeoutTimed.FallbackObserver(downstream, this)); } } @@ -298,7 +298,7 @@ public void onTimeoutError(long idx, Throwable ex) { if (index.compareAndSet(idx, Long.MAX_VALUE)) { DisposableHelper.dispose(this); - actual.onError(ex); + downstream.onError(ex); } else { RxJavaPlugins.onError(ex); } @@ -332,8 +332,8 @@ static final class TimeoutConsumer extends AtomicReference } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this, d); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java index 45416b9344..7c955939c0 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java @@ -56,7 +56,7 @@ static final class TimeoutObserver extends AtomicLong private static final long serialVersionUID = 3764492702657003550L; - final Observer actual; + final Observer downstream; final long timeout; @@ -69,7 +69,7 @@ static final class TimeoutObserver extends AtomicLong final AtomicReference upstream; TimeoutObserver(Observer actual, long timeout, TimeUnit unit, Scheduler.Worker worker) { - this.actual = actual; + this.downstream = actual; this.timeout = timeout; this.unit = unit; this.worker = worker; @@ -78,8 +78,8 @@ static final class TimeoutObserver extends AtomicLong } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(upstream, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(upstream, d); } @Override @@ -91,7 +91,7 @@ public void onNext(T t) { task.get().dispose(); - actual.onNext(t); + downstream.onNext(t); startTimeout(idx + 1); } @@ -105,7 +105,7 @@ public void onError(Throwable t) { if (getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onError(t); + downstream.onError(t); worker.dispose(); } else { @@ -118,7 +118,7 @@ public void onComplete() { if (getAndSet(Long.MAX_VALUE) != Long.MAX_VALUE) { task.dispose(); - actual.onComplete(); + downstream.onComplete(); worker.dispose(); } @@ -129,7 +129,7 @@ public void onTimeout(long idx) { if (compareAndSet(idx, Long.MAX_VALUE)) { DisposableHelper.dispose(upstream); - actual.onError(new TimeoutException()); + downstream.onError(new TimeoutException()); worker.dispose(); } @@ -170,7 +170,7 @@ static final class TimeoutFallbackObserver extends AtomicReference actual; + final Observer downstream; final long timeout; @@ -188,7 +188,7 @@ static final class TimeoutFallbackObserver extends AtomicReference actual, long timeout, TimeUnit unit, Scheduler.Worker worker, ObservableSource fallback) { - this.actual = actual; + this.downstream = actual; this.timeout = timeout; this.unit = unit; this.worker = worker; @@ -199,8 +199,8 @@ static final class TimeoutFallbackObserver extends AtomicReference f = fallback; fallback = null; - f.subscribe(new FallbackObserver(actual, this)); + f.subscribe(new FallbackObserver(downstream, this)); worker.dispose(); } @@ -274,33 +274,33 @@ public boolean isDisposed() { static final class FallbackObserver implements Observer { - final Observer actual; + final Observer downstream; final AtomicReference arbiter; FallbackObserver(Observer actual, AtomicReference arbiter) { - this.actual = actual; + this.downstream = actual; this.arbiter = arbiter; } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.replace(arbiter, s); + public void onSubscribe(Disposable d) { + DisposableHelper.replace(arbiter, d); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimer.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimer.java index 01a6a52743..c635ccb9db 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimer.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimer.java @@ -45,10 +45,10 @@ static final class TimerObserver extends AtomicReference private static final long serialVersionUID = -2809475196591179431L; - final Observer actual; + final Observer downstream; - TimerObserver(Observer actual) { - this.actual = actual; + TimerObserver(Observer downstream) { + this.downstream = downstream; } @Override @@ -64,9 +64,9 @@ public boolean isDisposed() { @Override public void run() { if (!isDisposed()) { - actual.onNext(0L); + downstream.onNext(0L); lazySet(EmptyDisposable.INSTANCE); - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableToList.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableToList.java index 8181c00563..53dd99fd2b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableToList.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableToList.java @@ -52,33 +52,34 @@ public void subscribeActual(Observer t) { } static final class ToListObserver> implements Observer, Disposable { - U collection; - final Observer actual; + final Observer downstream; + + Disposable upstream; - Disposable s; + U collection; ToListObserver(Observer actual, U collection) { - this.actual = actual; + this.downstream = actual; this.collection = collection; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -90,15 +91,15 @@ public void onNext(T t) { @Override public void onError(Throwable t) { collection = null; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { U c = collection; collection = null; - actual.onNext(c); - actual.onComplete(); + downstream.onNext(c); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableToListSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableToListSingle.java index dc38c76dfd..4358229f53 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableToListSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableToListSingle.java @@ -64,34 +64,34 @@ public Observable fuseToObservable() { } static final class ToListObserver> implements Observer, Disposable { - final SingleObserver actual; + final SingleObserver downstream; U collection; - Disposable s; + Disposable upstream; ToListObserver(SingleObserver actual, U collection) { - this.actual = actual; + this.downstream = actual; this.collection = collection; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -103,14 +103,14 @@ public void onNext(T t) { @Override public void onError(Throwable t) { collection = null; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { U c = collection; collection = null; - actual.onSuccess(c); + downstream.onSuccess(c); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOn.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOn.java index bfcc33308e..5f4ecad8a6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOn.java @@ -36,28 +36,28 @@ static final class UnsubscribeObserver extends AtomicBoolean implements Obser private static final long serialVersionUID = 1015244841293359600L; - final Observer actual; + final Observer downstream; final Scheduler scheduler; - Disposable s; + Disposable upstream; UnsubscribeObserver(Observer actual, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.scheduler = scheduler; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { if (!get()) { - actual.onNext(t); + downstream.onNext(t); } } @@ -67,13 +67,13 @@ public void onError(Throwable t) { RxJavaPlugins.onError(t); return; } - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (!get()) { - actual.onComplete(); + downstream.onComplete(); } } @@ -92,7 +92,7 @@ public boolean isDisposed() { final class DisposeTask implements Runnable { @Override public void run() { - s.dispose(); + upstream.dispose(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableUsing.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableUsing.java index 039da6f67c..46806ae0dc 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableUsing.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableUsing.java @@ -77,31 +77,31 @@ static final class UsingObserver extends AtomicBoolean implements Observer private static final long serialVersionUID = 5904473792286235046L; - final Observer actual; + final Observer downstream; final D resource; final Consumer disposer; final boolean eager; - Disposable s; + Disposable upstream; UsingObserver(Observer actual, D resource, Consumer disposer, boolean eager) { - this.actual = actual; + this.downstream = actual; this.resource = resource; this.disposer = disposer; this.eager = eager; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override @@ -116,11 +116,11 @@ public void onError(Throwable t) { } } - s.dispose(); - actual.onError(t); + upstream.dispose(); + downstream.onError(t); } else { - actual.onError(t); - s.dispose(); + downstream.onError(t); + upstream.dispose(); disposeAfter(); } } @@ -133,16 +133,16 @@ public void onComplete() { disposer.accept(resource); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } } - s.dispose(); - actual.onComplete(); + upstream.dispose(); + downstream.onComplete(); } else { - actual.onComplete(); - s.dispose(); + downstream.onComplete(); + upstream.dispose(); disposeAfter(); } } @@ -150,7 +150,7 @@ public void onComplete() { @Override public void dispose() { disposeAfter(); - s.dispose(); + upstream.dispose(); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindow.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindow.java index dae684bc9a..0c5c50d407 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindow.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindow.java @@ -47,30 +47,30 @@ static final class WindowExactObserver implements Observer, Disposable, Runnable { private static final long serialVersionUID = -7481782523886138128L; - final Observer> actual; + final Observer> downstream; final long count; final int capacityHint; long size; - Disposable s; + Disposable upstream; UnicastSubject window; volatile boolean cancelled; WindowExactObserver(Observer> actual, long count, int capacityHint) { - this.actual = actual; + this.downstream = actual; this.count = count; this.capacityHint = capacityHint; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -80,7 +80,7 @@ public void onNext(T t) { if (w == null && !cancelled) { w = UnicastSubject.create(capacityHint, this); window = w; - actual.onNext(w); + downstream.onNext(w); } if (w != null) { @@ -90,7 +90,7 @@ public void onNext(T t) { window = null; w.onComplete(); if (cancelled) { - s.dispose(); + upstream.dispose(); } } } @@ -103,7 +103,7 @@ public void onError(Throwable t) { window = null; w.onError(t); } - actual.onError(t); + downstream.onError(t); } @Override @@ -113,7 +113,7 @@ public void onComplete() { window = null; w.onComplete(); } - actual.onComplete(); + downstream.onComplete(); } @Override @@ -129,7 +129,7 @@ public boolean isDisposed() { @Override public void run() { if (cancelled) { - s.dispose(); + upstream.dispose(); } } } @@ -138,7 +138,7 @@ static final class WindowSkipObserver extends AtomicBoolean implements Observer, Disposable, Runnable { private static final long serialVersionUID = 3366976432059579510L; - final Observer> actual; + final Observer> downstream; final long count; final long skip; final int capacityHint; @@ -151,12 +151,12 @@ static final class WindowSkipObserver extends AtomicBoolean /** Counts how many elements were emitted to the very first window in windows. */ long firstEmission; - Disposable s; + Disposable upstream; final AtomicInteger wip = new AtomicInteger(); WindowSkipObserver(Observer> actual, long count, long skip, int capacityHint) { - this.actual = actual; + this.downstream = actual; this.count = count; this.skip = skip; this.capacityHint = capacityHint; @@ -164,11 +164,11 @@ static final class WindowSkipObserver extends AtomicBoolean } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -184,7 +184,7 @@ public void onNext(T t) { wip.getAndIncrement(); UnicastSubject w = UnicastSubject.create(capacityHint, this); ws.offer(w); - actual.onNext(w); + downstream.onNext(w); } long c = firstEmission + 1; @@ -196,7 +196,7 @@ public void onNext(T t) { if (c >= count) { ws.poll().onComplete(); if (ws.isEmpty() && cancelled) { - this.s.dispose(); + this.upstream.dispose(); return; } firstEmission = c - s; @@ -213,7 +213,7 @@ public void onError(Throwable t) { while (!ws.isEmpty()) { ws.poll().onError(t); } - actual.onError(t); + downstream.onError(t); } @Override @@ -222,7 +222,7 @@ public void onComplete() { while (!ws.isEmpty()) { ws.poll().onComplete(); } - actual.onComplete(); + downstream.onComplete(); } @Override @@ -239,7 +239,7 @@ public boolean isDisposed() { public void run() { if (wip.decrementAndGet() == 0) { if (cancelled) { - s.dispose(); + upstream.dispose(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java index d0da7e2b0a..b15d4ee140 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java @@ -61,7 +61,7 @@ static final class WindowBoundaryMainObserver final int bufferSize; final CompositeDisposable resources; - Disposable s; + Disposable upstream; final AtomicReference boundary = new AtomicReference(); @@ -81,11 +81,11 @@ static final class WindowBoundaryMainObserver } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); if (cancelled) { return; @@ -135,7 +135,7 @@ public void onError(Throwable t) { resources.dispose(); } - actual.onError(t); + downstream.onError(t); } @Override @@ -153,11 +153,11 @@ public void onComplete() { resources.dispose(); } - actual.onComplete(); + downstream.onComplete(); } void error(Throwable t) { - s.dispose(); + upstream.dispose(); resources.dispose(); onError(t); } @@ -179,7 +179,7 @@ void disposeBoundary() { void drainLoop() { final MpscLinkedQueue q = (MpscLinkedQueue)queue; - final Observer> a = actual; + final Observer> a = downstream; final List> ws = this.ws; int missed = 1; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java index 73676bf698..5b76d067e7 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java @@ -81,7 +81,7 @@ static final class WindowExactUnboundedObserver final Scheduler scheduler; final int bufferSize; - Disposable s; + Disposable upstream; UnicastSubject window; @@ -101,20 +101,20 @@ static final class WindowExactUnboundedObserver } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; window = UnicastSubject.create(bufferSize); - Observer> a = actual; + Observer> a = downstream; a.onSubscribe(this); a.onNext(window); if (!cancelled) { - Disposable d = scheduler.schedulePeriodicallyDirect(this, timespan, timespan, unit); - DisposableHelper.replace(timer, d); + Disposable task = scheduler.schedulePeriodicallyDirect(this, timespan, timespan, unit); + DisposableHelper.replace(timer, task); } } } @@ -147,7 +147,7 @@ public void onError(Throwable t) { } disposeTimer(); - actual.onError(t); + downstream.onError(t); } @Override @@ -158,7 +158,7 @@ public void onComplete() { } disposeTimer(); - actual.onComplete(); + downstream.onComplete(); } @Override @@ -190,7 +190,7 @@ public void run() { void drainLoop() { final MpscLinkedQueue q = (MpscLinkedQueue)queue; - final Observer> a = actual; + final Observer> a = downstream; UnicastSubject w = window; int missed = 1; @@ -228,7 +228,7 @@ void drainLoop() { a.onNext(w); } else { - s.dispose(); + upstream.dispose(); } continue; } @@ -260,7 +260,7 @@ static final class WindowExactBoundedObserver long producerIndex; - Disposable s; + Disposable upstream; UnicastSubject window; @@ -288,11 +288,11 @@ static final class WindowExactBoundedObserver } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - Observer> a = actual; + Observer> a = downstream; a.onSubscribe(this); @@ -305,15 +305,15 @@ public void onSubscribe(Disposable s) { a.onNext(w); - Disposable d; + Disposable task; ConsumerIndexHolder consumerIndexHolder = new ConsumerIndexHolder(producerIndex, this); if (restartTimerOnMaxSize) { - d = worker.schedulePeriodically(consumerIndexHolder, timespan, timespan, unit); + task = worker.schedulePeriodically(consumerIndexHolder, timespan, timespan, unit); } else { - d = scheduler.schedulePeriodicallyDirect(consumerIndexHolder, timespan, timespan, unit); + task = scheduler.schedulePeriodicallyDirect(consumerIndexHolder, timespan, timespan, unit); } - DisposableHelper.replace(timer, d); + DisposableHelper.replace(timer, task); } } @@ -337,7 +337,7 @@ public void onNext(T t) { w = UnicastSubject.create(bufferSize); window = w; - actual.onNext(w); + downstream.onNext(w); if (restartTimerOnMaxSize) { Disposable tm = timer.get(); tm.dispose(); @@ -370,7 +370,7 @@ public void onError(Throwable t) { drainLoop(); } - actual.onError(t); + downstream.onError(t); disposeTimer(); } @@ -381,7 +381,7 @@ public void onComplete() { drainLoop(); } - actual.onComplete(); + downstream.onComplete(); disposeTimer(); } @@ -405,7 +405,7 @@ void disposeTimer() { void drainLoop() { final MpscLinkedQueue q = (MpscLinkedQueue)queue; - final Observer> a = actual; + final Observer> a = downstream; UnicastSubject w = window; int missed = 1; @@ -413,7 +413,7 @@ void drainLoop() { for (;;) { if (terminated) { - s.dispose(); + upstream.dispose(); q.clear(); disposeTimer(); return; @@ -467,7 +467,7 @@ void drainLoop() { w = UnicastSubject.create(bufferSize); window = w; - actual.onNext(w); + downstream.onNext(w); if (restartTimerOnMaxSize) { Disposable tm = timer.get(); @@ -528,7 +528,7 @@ static final class WindowSkipObserver final List> windows; - Disposable s; + Disposable upstream; volatile boolean terminated; @@ -545,11 +545,11 @@ static final class WindowSkipObserver } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); if (cancelled) { return; @@ -558,7 +558,7 @@ public void onSubscribe(Disposable s) { final UnicastSubject w = UnicastSubject.create(bufferSize); windows.add(w); - actual.onNext(w); + downstream.onNext(w); worker.schedule(new CompletionTask(w), timespan, unit); worker.schedulePeriodically(this, timeskip, timeskip, unit); @@ -592,7 +592,7 @@ public void onError(Throwable t) { drainLoop(); } - actual.onError(t); + downstream.onError(t); disposeWorker(); } @@ -603,7 +603,7 @@ public void onComplete() { drainLoop(); } - actual.onComplete(); + downstream.onComplete(); disposeWorker(); } @@ -631,7 +631,7 @@ void complete(UnicastSubject w) { @SuppressWarnings("unchecked") void drainLoop() { final MpscLinkedQueue q = (MpscLinkedQueue)queue; - final Observer> a = actual; + final Observer> a = downstream; final List> ws = windows; int missed = 1; @@ -640,7 +640,7 @@ void drainLoop() { for (;;) { if (terminated) { - s.dispose(); + upstream.dispose(); disposeWorker(); q.clear(); ws.clear(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFrom.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFrom.java index d60a086687..9bc7984dd6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFrom.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFrom.java @@ -40,7 +40,7 @@ public void subscribeActual(Observer t) { serial.onSubscribe(wlf); - other.subscribe(new WithLastFrom(wlf)); + other.subscribe(new WithLatestFromOtherObserver(wlf)); source.subscribe(wlf); } @@ -49,21 +49,21 @@ static final class WithLatestFromObserver extends AtomicReference im private static final long serialVersionUID = -312246233408980075L; - final Observer actual; + final Observer downstream; final BiFunction combiner; - final AtomicReference s = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); final AtomicReference other = new AtomicReference(); WithLatestFromObserver(Observer actual, BiFunction combiner) { - this.actual = actual; + this.downstream = actual; this.combiner = combiner; } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this.s, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this.upstream, d); } @Override @@ -76,34 +76,34 @@ public void onNext(T t) { } catch (Throwable e) { Exceptions.throwIfFatal(e); dispose(); - actual.onError(e); + downstream.onError(e); return; } - actual.onNext(r); + downstream.onNext(r); } } @Override public void onError(Throwable t) { DisposableHelper.dispose(other); - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { DisposableHelper.dispose(other); - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - DisposableHelper.dispose(s); + DisposableHelper.dispose(upstream); DisposableHelper.dispose(other); } @Override public boolean isDisposed() { - return DisposableHelper.isDisposed(s.get()); + return DisposableHelper.isDisposed(upstream.get()); } public boolean setOther(Disposable o) { @@ -111,31 +111,31 @@ public boolean setOther(Disposable o) { } public void otherError(Throwable e) { - DisposableHelper.dispose(s); - actual.onError(e); + DisposableHelper.dispose(upstream); + downstream.onError(e); } } - final class WithLastFrom implements Observer { - private final WithLatestFromObserver wlf; + final class WithLatestFromOtherObserver implements Observer { + private final WithLatestFromObserver parent; - WithLastFrom(WithLatestFromObserver wlf) { - this.wlf = wlf; + WithLatestFromOtherObserver(WithLatestFromObserver parent) { + this.parent = parent; } @Override - public void onSubscribe(Disposable s) { - wlf.setOther(s); + public void onSubscribe(Disposable d) { + parent.setOther(d); } @Override public void onNext(U t) { - wlf.lazySet(t); + parent.lazySet(t); } @Override public void onError(Throwable t) { - wlf.otherError(t); + parent.otherError(t); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromMany.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromMany.java index b460ad58b1..194d33c61c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromMany.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromMany.java @@ -100,7 +100,7 @@ static final class WithLatestFromObserver private static final long serialVersionUID = 1577321883966341961L; - final Observer actual; + final Observer downstream; final Function combiner; @@ -108,14 +108,14 @@ static final class WithLatestFromObserver final AtomicReferenceArray values; - final AtomicReference d; + final AtomicReference upstream; final AtomicThrowable error; volatile boolean done; WithLatestFromObserver(Observer actual, Function combiner, int n) { - this.actual = actual; + this.downstream = actual; this.combiner = combiner; WithLatestInnerObserver[] s = new WithLatestInnerObserver[n]; for (int i = 0; i < n; i++) { @@ -123,15 +123,15 @@ static final class WithLatestFromObserver } this.observers = s; this.values = new AtomicReferenceArray(n); - this.d = new AtomicReference(); + this.upstream = new AtomicReference(); this.error = new AtomicThrowable(); } void subscribe(ObservableSource[] others, int n) { WithLatestInnerObserver[] observers = this.observers; - AtomicReference s = this.d; + AtomicReference upstream = this.upstream; for (int i = 0; i < n; i++) { - if (DisposableHelper.isDisposed(s.get()) || done) { + if (DisposableHelper.isDisposed(upstream.get()) || done) { return; } others[i].subscribe(observers[i]); @@ -140,7 +140,7 @@ void subscribe(ObservableSource[] others, int n) { @Override public void onSubscribe(Disposable d) { - DisposableHelper.setOnce(this.d, d); + DisposableHelper.setOnce(this.upstream, d); } @Override @@ -173,7 +173,7 @@ public void onNext(T t) { return; } - HalfSerializer.onNext(actual, v, this, error); + HalfSerializer.onNext(downstream, v, this, error); } @Override @@ -184,7 +184,7 @@ public void onError(Throwable t) { } done = true; cancelAllBut(-1); - HalfSerializer.onError(actual, t, this, error); + HalfSerializer.onError(downstream, t, this, error); } @Override @@ -192,18 +192,18 @@ public void onComplete() { if (!done) { done = true; cancelAllBut(-1); - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } } @Override public boolean isDisposed() { - return DisposableHelper.isDisposed(d.get()); + return DisposableHelper.isDisposed(upstream.get()); } @Override public void dispose() { - DisposableHelper.dispose(d); + DisposableHelper.dispose(upstream); for (WithLatestInnerObserver observer : observers) { observer.dispose(); } @@ -215,16 +215,16 @@ void innerNext(int index, Object o) { void innerError(int index, Throwable t) { done = true; - DisposableHelper.dispose(d); + DisposableHelper.dispose(upstream); cancelAllBut(index); - HalfSerializer.onError(actual, t, this, error); + HalfSerializer.onError(downstream, t, this, error); } void innerComplete(int index, boolean nonEmpty) { if (!nonEmpty) { done = true; cancelAllBut(index); - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java index 923c1a062d..5ac0027aeb 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java @@ -75,7 +75,7 @@ public void subscribeActual(Observer observer) { static final class ZipCoordinator extends AtomicInteger implements Disposable { private static final long serialVersionUID = 2983708048395377667L; - final Observer actual; + final Observer downstream; final Function zipper; final ZipObserver[] observers; final T[] row; @@ -87,7 +87,7 @@ static final class ZipCoordinator extends AtomicInteger implements Disposa ZipCoordinator(Observer actual, Function zipper, int count, boolean delayError) { - this.actual = actual; + this.downstream = actual; this.zipper = zipper; this.observers = new ZipObserver[count]; this.row = (T[])new Object[count]; @@ -102,7 +102,7 @@ public void subscribe(ObservableSource[] sources, int bufferSize) { } // this makes sure the contents of the observers array is visible this.lazySet(0); - actual.onSubscribe(this); + downstream.onSubscribe(this); for (int i = 0; i < len; i++) { if (cancelled) { return; @@ -152,7 +152,7 @@ public void drain() { int missing = 1; final ZipObserver[] zs = observers; - final Observer a = actual; + final Observer a = downstream; final T[] os = row; final boolean delayError = this.delayError; @@ -259,15 +259,15 @@ static final class ZipObserver implements Observer { volatile boolean done; Throwable error; - final AtomicReference s = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); ZipObserver(ZipCoordinator parent, int bufferSize) { this.parent = parent; this.queue = new SpscLinkedArrayQueue(bufferSize); } @Override - public void onSubscribe(Disposable s) { - DisposableHelper.setOnce(this.s, s); + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(this.upstream, d); } @Override @@ -290,7 +290,7 @@ public void onComplete() { } public void dispose() { - DisposableHelper.dispose(s); + DisposableHelper.dispose(upstream); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableZipIterable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableZipIterable.java index 4e01080759..8db76ed428 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableZipIterable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableZipIterable.java @@ -67,38 +67,38 @@ public void subscribeActual(Observer t) { } static final class ZipIterableObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final Iterator iterator; final BiFunction zipper; - Disposable s; + Disposable upstream; boolean done; ZipIterableObserver(Observer actual, Iterator iterator, BiFunction zipper) { - this.actual = actual; + this.downstream = actual; this.iterator = iterator; this.zipper = zipper; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -127,7 +127,7 @@ public void onNext(T t) { return; } - actual.onNext(v); + downstream.onNext(v); boolean b; @@ -141,15 +141,15 @@ public void onNext(T t) { if (!b) { done = true; - s.dispose(); - actual.onComplete(); + upstream.dispose(); + downstream.onComplete(); } } void error(Throwable e) { done = true; - s.dispose(); - actual.onError(e); + upstream.dispose(); + downstream.onError(e); } @Override @@ -159,7 +159,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -168,7 +168,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObserverResourceWrapper.java b/src/main/java/io/reactivex/internal/operators/observable/ObserverResourceWrapper.java index 6da2c5d377..80034928be 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObserverResourceWrapper.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObserverResourceWrapper.java @@ -23,48 +23,48 @@ public final class ObserverResourceWrapper extends AtomicReference actual; + final Observer downstream; - final AtomicReference subscription = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); - public ObserverResourceWrapper(Observer actual) { - this.actual = actual; + public ObserverResourceWrapper(Observer downstream) { + this.downstream = downstream; } @Override - public void onSubscribe(Disposable s) { - if (DisposableHelper.setOnce(subscription, s)) { - actual.onSubscribe(this); + public void onSubscribe(Disposable d) { + if (DisposableHelper.setOnce(upstream, d)) { + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { dispose(); - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { dispose(); - actual.onComplete(); + downstream.onComplete(); } @Override public void dispose() { - DisposableHelper.dispose(subscription); + DisposableHelper.dispose(upstream); DisposableHelper.dispose(this); } @Override public boolean isDisposed() { - return subscription.get() == DisposableHelper.DISPOSED; + return upstream.get() == DisposableHelper.DISPOSED; } public void setResource(Disposable resource) { diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelCollect.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelCollect.java index 47c55f5d08..4f7b53ed94 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelCollect.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelCollect.java @@ -105,10 +105,10 @@ static final class ParallelCollectSubscriber extends DeferredScalarSubscri @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -137,7 +137,7 @@ public void onError(Throwable t) { } done = true; collection = null; - actual.onError(t); + downstream.onError(t); } @Override @@ -154,7 +154,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelDoOnNextTry.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelDoOnNextTry.java index ae74461419..23fae57a80 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelDoOnNextTry.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelDoOnNextTry.java @@ -74,46 +74,46 @@ public int parallelism() { static final class ParallelDoOnNextSubscriber implements ConditionalSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final Consumer onNext; final BiFunction errorHandler; - Subscription s; + Subscription upstream; boolean done; ParallelDoOnNextSubscriber(Subscriber actual, Consumer onNext, BiFunction errorHandler) { - this.actual = actual; + this.downstream = actual; this.onNext = onNext; this.errorHandler = errorHandler; } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { if (!tryOnNext(t)) { - s.request(1); + upstream.request(1); } } @@ -157,7 +157,7 @@ public boolean tryOnNext(T t) { } } - actual.onNext(t); + downstream.onNext(t); return true; } } @@ -169,7 +169,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -178,52 +178,53 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } static final class ParallelDoOnNextConditionalSubscriber implements ConditionalSubscriber, Subscription { - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; final Consumer onNext; final BiFunction errorHandler; - Subscription s; + + Subscription upstream; boolean done; ParallelDoOnNextConditionalSubscriber(ConditionalSubscriber actual, Consumer onNext, BiFunction errorHandler) { - this.actual = actual; + this.downstream = actual; this.onNext = onNext; this.errorHandler = errorHandler; } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { if (!tryOnNext(t) && !done) { - s.request(1); + upstream.request(1); } } @@ -267,7 +268,7 @@ public boolean tryOnNext(T t) { } } - return actual.tryOnNext(t); + return downstream.tryOnNext(t); } } @@ -278,7 +279,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -287,7 +288,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelFilter.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelFilter.java index 5dab623306..1a775d54ae 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelFilter.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelFilter.java @@ -68,7 +68,7 @@ public int parallelism() { abstract static class BaseFilterSubscriber implements ConditionalSubscriber, Subscription { final Predicate predicate; - Subscription s; + Subscription upstream; boolean done; @@ -78,37 +78,37 @@ abstract static class BaseFilterSubscriber implements ConditionalSubscriber extends BaseFilterSubscriber { - final Subscriber actual; + final Subscriber downstream; ParallelFilterSubscriber(Subscriber actual, Predicate predicate) { super(predicate); - this.actual = actual; + this.downstream = actual; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -127,7 +127,7 @@ public boolean tryOnNext(T t) { } if (b) { - actual.onNext(t); + downstream.onNext(t); return true; } } @@ -141,33 +141,33 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); } } } static final class ParallelFilterConditionalSubscriber extends BaseFilterSubscriber { - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; ParallelFilterConditionalSubscriber(ConditionalSubscriber actual, Predicate predicate) { super(predicate); - this.actual = actual; + this.downstream = actual; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -186,7 +186,7 @@ public boolean tryOnNext(T t) { } if (b) { - return actual.tryOnNext(t); + return downstream.tryOnNext(t); } } return false; @@ -199,14 +199,14 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); } } }} diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelFilterTry.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelFilterTry.java index e6aa32f867..bd0923fb70 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelFilterTry.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelFilterTry.java @@ -75,7 +75,7 @@ abstract static class BaseFilterSubscriber implements ConditionalSubscriber errorHandler; - Subscription s; + Subscription upstream; boolean done; @@ -86,37 +86,37 @@ abstract static class BaseFilterSubscriber implements ConditionalSubscriber extends BaseFilterSubscriber { - final Subscriber actual; + final Subscriber downstream; ParallelFilterSubscriber(Subscriber actual, Predicate predicate, BiFunction errorHandler) { super(predicate, errorHandler); - this.actual = actual; + this.downstream = actual; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -161,7 +161,7 @@ public boolean tryOnNext(T t) { } if (b) { - actual.onNext(t); + downstream.onNext(t); return true; } return false; @@ -177,35 +177,35 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); } } } static final class ParallelFilterConditionalSubscriber extends BaseFilterSubscriber { - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; ParallelFilterConditionalSubscriber(ConditionalSubscriber actual, Predicate predicate, BiFunction errorHandler) { super(predicate, errorHandler); - this.actual = actual; + this.downstream = actual; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -249,7 +249,7 @@ public boolean tryOnNext(T t) { } } - return b && actual.tryOnNext(t); + return b && downstream.tryOnNext(t); } } return false; @@ -262,14 +262,14 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { if (!done) { done = true; - actual.onComplete(); + downstream.onComplete(); } } }} diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelFromPublisher.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelFromPublisher.java index 5eb11d3e4e..fc7288a1a1 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelFromPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelFromPublisher.java @@ -75,7 +75,7 @@ static final class ParallelDispatcher final int limit; - Subscription s; + Subscription upstream; SimpleQueue queue; @@ -109,8 +109,8 @@ static final class ParallelDispatcher @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") @@ -204,7 +204,7 @@ public void cancel() { public void onNext(T t) { if (sourceMode == QueueSubscription.NONE) { if (!queue.offer(t)) { - s.cancel(); + upstream.cancel(); onError(new MissingBackpressureException("Queue is full?")); return; } @@ -228,7 +228,7 @@ public void onComplete() { void cancel(int m) { if (requests.decrementAndGet(m) == 0L) { cancelled = true; - this.s.cancel(); + this.upstream.cancel(); if (getAndIncrement() == 0) { queue.clear(); @@ -292,7 +292,7 @@ void drainAsync() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); for (Subscriber s : a) { s.onError(ex); } @@ -310,7 +310,7 @@ void drainAsync() { int c = ++consumed; if (c == limit) { consumed = 0; - s.request(c); + upstream.request(c); } notReady = 0; } else { @@ -380,7 +380,7 @@ void drainSync() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.cancel(); + upstream.cancel(); for (Subscriber s : a) { s.onError(ex); } diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelJoin.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelJoin.java index 7a29e1bed4..b248cde69f 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelJoin.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelJoin.java @@ -63,7 +63,7 @@ abstract static class JoinSubscriptionBase extends AtomicInteger private static final long serialVersionUID = 3100232009247827843L; - final Subscriber actual; + final Subscriber downstream; final JoinInnerSubscriber[] subscribers; @@ -76,7 +76,7 @@ abstract static class JoinSubscriptionBase extends AtomicInteger final AtomicInteger done = new AtomicInteger(); JoinSubscriptionBase(Subscriber actual, int n, int prefetch) { - this.actual = actual; + this.downstream = actual; @SuppressWarnings("unchecked") JoinInnerSubscriber[] a = new JoinInnerSubscriber[n]; @@ -144,7 +144,7 @@ static final class JoinSubscription extends JoinSubscriptionBase { public void onNext(JoinInnerSubscriber inner, T value) { if (get() == 0 && compareAndSet(0, 1)) { if (requested.get() != 0) { - actual.onNext(value); + downstream.onNext(value); if (requested.get() != Long.MAX_VALUE) { requested.decrementAndGet(); } @@ -156,7 +156,7 @@ public void onNext(JoinInnerSubscriber inner, T value) { cancelAll(); Throwable mbe = new MissingBackpressureException("Queue full?!"); if (errors.compareAndSet(null, mbe)) { - actual.onError(mbe); + downstream.onError(mbe); } else { RxJavaPlugins.onError(mbe); } @@ -215,7 +215,7 @@ void drainLoop() { JoinInnerSubscriber[] s = this.subscribers; int n = s.length; - Subscriber a = this.actual; + Subscriber a = this.downstream; for (;;) { @@ -329,7 +329,7 @@ static final class JoinSubscriptionDelayError extends JoinSubscriptionBase void onNext(JoinInnerSubscriber inner, T value) { if (get() == 0 && compareAndSet(0, 1)) { if (requested.get() != 0) { - actual.onNext(value); + downstream.onNext(value); if (requested.get() != Long.MAX_VALUE) { requested.decrementAndGet(); } @@ -393,7 +393,7 @@ void drainLoop() { JoinInnerSubscriber[] s = this.subscribers; int n = s.length; - Subscriber a = this.actual; + Subscriber a = this.downstream; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelMap.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelMap.java index 6786621f5f..18a627d6ad 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelMap.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelMap.java @@ -70,35 +70,35 @@ public int parallelism() { static final class ParallelMapSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final Function mapper; - Subscription s; + Subscription upstream; boolean done; ParallelMapSubscriber(Subscriber actual, Function mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -118,7 +118,7 @@ public void onNext(T t) { return; } - actual.onNext(v); + downstream.onNext(v); } @Override @@ -128,7 +128,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -137,41 +137,41 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } static final class ParallelMapConditionalSubscriber implements ConditionalSubscriber, Subscription { - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; final Function mapper; - Subscription s; + Subscription upstream; boolean done; ParallelMapConditionalSubscriber(ConditionalSubscriber actual, Function mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -191,7 +191,7 @@ public void onNext(T t) { return; } - actual.onNext(v); + downstream.onNext(v); } @Override @@ -210,7 +210,7 @@ public boolean tryOnNext(T t) { return false; } - return actual.tryOnNext(v); + return downstream.tryOnNext(v); } @Override @@ -220,7 +220,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -229,7 +229,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelMapTry.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelMapTry.java index 493b5f5dc3..73c19733bd 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelMapTry.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelMapTry.java @@ -75,46 +75,46 @@ public int parallelism() { static final class ParallelMapTrySubscriber implements ConditionalSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final Function mapper; final BiFunction errorHandler; - Subscription s; + Subscription upstream; boolean done; ParallelMapTrySubscriber(Subscriber actual, Function mapper, BiFunction errorHandler) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.errorHandler = errorHandler; } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { if (!tryOnNext(t) && !done) { - s.request(1); + upstream.request(1); } } @@ -160,7 +160,7 @@ public boolean tryOnNext(T t) { } } - actual.onNext(v); + downstream.onNext(v); return true; } } @@ -172,7 +172,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -181,52 +181,53 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } static final class ParallelMapTryConditionalSubscriber implements ConditionalSubscriber, Subscription { - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; final Function mapper; final BiFunction errorHandler; - Subscription s; + + Subscription upstream; boolean done; ParallelMapTryConditionalSubscriber(ConditionalSubscriber actual, Function mapper, BiFunction errorHandler) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.errorHandler = errorHandler; } @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onNext(T t) { if (!tryOnNext(t) && !done) { - s.request(1); + upstream.request(1); } } @@ -272,7 +273,7 @@ public boolean tryOnNext(T t) { } } - return actual.tryOnNext(v); + return downstream.tryOnNext(v); } } @@ -283,7 +284,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } @Override @@ -292,7 +293,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelPeek.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelPeek.java index ebcc3c91a4..3e7914c02a 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelPeek.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelPeek.java @@ -87,16 +87,16 @@ public int parallelism() { static final class ParallelPeekSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final ParallelPeek parent; - Subscription s; + Subscription upstream; boolean done; ParallelPeekSubscriber(Subscriber actual, ParallelPeek parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } @@ -108,7 +108,7 @@ public void request(long n) { Exceptions.throwIfFatal(ex); RxJavaPlugins.onError(ex); } - s.request(n); + upstream.request(n); } @Override @@ -119,25 +119,25 @@ public void cancel() { Exceptions.throwIfFatal(ex); RxJavaPlugins.onError(ex); } - s.cancel(); + upstream.cancel(); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; try { parent.onSubscribe.accept(s); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); s.cancel(); - actual.onSubscribe(EmptySubscription.INSTANCE); + downstream.onSubscribe(EmptySubscription.INSTANCE); onError(ex); return; } - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -152,7 +152,7 @@ public void onNext(T t) { return; } - actual.onNext(t); + downstream.onNext(t); try { parent.onAfterNext.accept(t); @@ -177,7 +177,7 @@ public void onError(Throwable t) { Exceptions.throwIfFatal(ex); t = new CompositeException(t, ex); } - actual.onError(t); + downstream.onError(t); try { parent.onAfterTerminated.run(); @@ -195,10 +195,10 @@ public void onComplete() { parent.onComplete.run(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } - actual.onComplete(); + downstream.onComplete(); try { parent.onAfterTerminated.run(); diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduce.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduce.java index f747e8c83c..8e421ef112 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduce.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduce.java @@ -103,10 +103,10 @@ static final class ParallelReduceSubscriber extends DeferredScalarSubscrib @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -138,7 +138,7 @@ public void onError(Throwable t) { } done = true; accumulator = null; - actual.onError(t); + downstream.onError(t); } @Override @@ -155,7 +155,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduceFull.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduceFull.java index 1505ea0ff3..347ce2ead9 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduceFull.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduceFull.java @@ -117,7 +117,7 @@ public void cancel() { void innerError(Throwable ex) { if (error.compareAndSet(null, ex)) { cancel(); - actual.onError(ex); + downstream.onError(ex); } else { if (ex != error.get()) { RxJavaPlugins.onError(ex); @@ -153,7 +153,7 @@ void innerComplete(T value) { if (sp != null) { complete(sp.first); } else { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelRunOn.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelRunOn.java index bf52698359..8643cc6d2b 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelRunOn.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelRunOn.java @@ -120,7 +120,7 @@ abstract static class BaseRunOnSubscriber extends AtomicInteger final Worker worker; - Subscription s; + Subscription upstream; volatile boolean done; @@ -145,7 +145,7 @@ public final void onNext(T t) { return; } if (!queue.offer(t)) { - s.cancel(); + upstream.cancel(); onError(new MissingBackpressureException("Queue is full?!")); return; } @@ -184,7 +184,7 @@ public final void request(long n) { public final void cancel() { if (!cancelled) { cancelled = true; - s.cancel(); + upstream.cancel(); worker.dispose(); if (getAndIncrement() == 0) { @@ -204,19 +204,19 @@ static final class RunOnSubscriber extends BaseRunOnSubscriber { private static final long serialVersionUID = 1075119423897941642L; - final Subscriber actual; + final Subscriber downstream; RunOnSubscriber(Subscriber actual, int prefetch, SpscArrayQueue queue, Worker worker) { super(prefetch, queue, worker); - this.actual = actual; + this.downstream = actual; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(prefetch); } @@ -227,7 +227,7 @@ public void run() { int missed = 1; int c = consumed; SpscArrayQueue q = queue; - Subscriber a = actual; + Subscriber a = downstream; int lim = limit; for (;;) { @@ -277,7 +277,7 @@ public void run() { int p = ++c; if (p == lim) { c = 0; - s.request(p); + upstream.request(p); } } @@ -328,19 +328,19 @@ static final class RunOnConditionalSubscriber extends BaseRunOnSubscriber private static final long serialVersionUID = 1075119423897941642L; - final ConditionalSubscriber actual; + final ConditionalSubscriber downstream; RunOnConditionalSubscriber(ConditionalSubscriber actual, int prefetch, SpscArrayQueue queue, Worker worker) { super(prefetch, queue, worker); - this.actual = actual; + this.downstream = actual; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(prefetch); } @@ -351,7 +351,7 @@ public void run() { int missed = 1; int c = consumed; SpscArrayQueue q = queue; - ConditionalSubscriber a = actual; + ConditionalSubscriber a = downstream; int lim = limit; for (;;) { @@ -401,7 +401,7 @@ public void run() { int p = ++c; if (p == lim) { c = 0; - s.request(p); + upstream.request(p); } } diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelSortedJoin.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelSortedJoin.java index 43ef716d1a..1151716fff 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelSortedJoin.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelSortedJoin.java @@ -58,7 +58,7 @@ static final class SortedJoinSubscription private static final long serialVersionUID = 3481980673745556697L; - final Subscriber actual; + final Subscriber downstream; final SortedJoinInnerSubscriber[] subscribers; @@ -78,7 +78,7 @@ static final class SortedJoinSubscription @SuppressWarnings("unchecked") SortedJoinSubscription(Subscriber actual, int n, Comparator comparator) { - this.actual = actual; + this.downstream = actual; this.comparator = comparator; SortedJoinInnerSubscriber[] s = new SortedJoinInnerSubscriber[n]; @@ -142,7 +142,7 @@ void drain() { } int missed = 1; - Subscriber a = actual; + Subscriber a = downstream; List[] lists = this.lists; int[] indexes = this.indexes; int n = indexes.length; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleCache.java b/src/main/java/io/reactivex/internal/operators/single/SingleCache.java index de237efc84..1752a283b0 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleCache.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleCache.java @@ -131,7 +131,7 @@ public void onSuccess(T value) { for (CacheDisposable d : observers.getAndSet(TERMINATED)) { if (!d.isDisposed()) { - d.actual.onSuccess(value); + d.downstream.onSuccess(value); } } } @@ -143,7 +143,7 @@ public void onError(Throwable e) { for (CacheDisposable d : observers.getAndSet(TERMINATED)) { if (!d.isDisposed()) { - d.actual.onError(e); + d.downstream.onError(e); } } } @@ -154,12 +154,12 @@ static final class CacheDisposable private static final long serialVersionUID = 7514387411091976596L; - final SingleObserver actual; + final SingleObserver downstream; final SingleCache parent; CacheDisposable(SingleObserver actual, SingleCache parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleCreate.java b/src/main/java/io/reactivex/internal/operators/single/SingleCreate.java index fd52840f89..2b0dcfae85 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleCreate.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleCreate.java @@ -47,14 +47,13 @@ static final class Emitter extends AtomicReference implements SingleEmitter, Disposable { - final SingleObserver actual; - - Emitter(SingleObserver actual) { - this.actual = actual; - } + private static final long serialVersionUID = -2467358622224974244L; + final SingleObserver downstream; - private static final long serialVersionUID = -2467358622224974244L; + Emitter(SingleObserver downstream) { + this.downstream = downstream; + } @Override public void onSuccess(T value) { @@ -63,9 +62,9 @@ public void onSuccess(T value) { if (d != DisposableHelper.DISPOSED) { try { if (value == null) { - actual.onError(new NullPointerException("onSuccess called with null. Null values are generally not allowed in 2.x operators and sources.")); + downstream.onError(new NullPointerException("onSuccess called with null. Null values are generally not allowed in 2.x operators and sources.")); } else { - actual.onSuccess(value); + downstream.onSuccess(value); } } finally { if (d != null) { @@ -92,7 +91,7 @@ public boolean tryOnError(Throwable t) { Disposable d = getAndSet(DisposableHelper.DISPOSED); if (d != DisposableHelper.DISPOSED) { try { - actual.onError(t); + downstream.onError(t); } finally { if (d != null) { d.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java index 4307f4197c..ba5beeec9d 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java @@ -43,12 +43,12 @@ static final class OtherObserver private static final long serialVersionUID = -8565274649390031272L; - final SingleObserver actual; + final SingleObserver downstream; final SingleSource source; OtherObserver(SingleObserver actual, SingleSource source) { - this.actual = actual; + this.downstream = actual; this.source = source; } @@ -56,18 +56,18 @@ static final class OtherObserver public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - source.subscribe(new ResumeSingleObserver(this, actual)); + source.subscribe(new ResumeSingleObserver(this, downstream)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java index d9ec740604..0614c091c0 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java @@ -44,14 +44,14 @@ static final class OtherSubscriber private static final long serialVersionUID = -8565274649390031272L; - final SingleObserver actual; + final SingleObserver downstream; final SingleSource source; boolean done; OtherSubscriber(SingleObserver actual, SingleSource source) { - this.actual = actual; + this.downstream = actual; this.source = source; } @@ -59,7 +59,7 @@ static final class OtherSubscriber public void onSubscribe(Disposable d) { if (DisposableHelper.set(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -76,7 +76,7 @@ public void onError(Throwable e) { return; } done = true; - actual.onError(e); + downstream.onError(e); } @Override @@ -85,7 +85,7 @@ public void onComplete() { return; } done = true; - source.subscribe(new ResumeSingleObserver(this, actual)); + source.subscribe(new ResumeSingleObserver(this, downstream)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java index 0928bab13d..bbc8a9e460 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java @@ -47,25 +47,25 @@ static final class OtherSubscriber private static final long serialVersionUID = -8565274649390031272L; - final SingleObserver actual; + final SingleObserver downstream; final SingleSource source; boolean done; - Subscription s; + Subscription upstream; OtherSubscriber(SingleObserver actual, SingleSource source) { - this.actual = actual; + this.downstream = actual; this.source = source; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -73,7 +73,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(U value) { - s.cancel(); + upstream.cancel(); onComplete(); } @@ -84,7 +84,7 @@ public void onError(Throwable e) { return; } done = true; - actual.onError(e); + downstream.onError(e); } @Override @@ -93,12 +93,12 @@ public void onComplete() { return; } done = true; - source.subscribe(new ResumeSingleObserver(this, actual)); + source.subscribe(new ResumeSingleObserver(this, downstream)); } @Override public void dispose() { - s.cancel(); + upstream.cancel(); DisposableHelper.dispose(this); } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java index 3adc4f9333..1c1b4aabe3 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java @@ -43,12 +43,12 @@ static final class OtherObserver private static final long serialVersionUID = -8565274649390031272L; - final SingleObserver actual; + final SingleObserver downstream; final SingleSource source; OtherObserver(SingleObserver actual, SingleSource source) { - this.actual = actual; + this.downstream = actual; this.source = source; } @@ -56,18 +56,18 @@ static final class OtherObserver public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(U value) { - source.subscribe(new ResumeSingleObserver(this, actual)); + source.subscribe(new ResumeSingleObserver(this, downstream)); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDetach.java b/src/main/java/io/reactivex/internal/operators/single/SingleDetach.java index dd077d259e..ad9883a1a2 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDetach.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDetach.java @@ -38,51 +38,51 @@ protected void subscribeActual(SingleObserver observer) { static final class DetachSingleObserver implements SingleObserver, Disposable { - SingleObserver actual; + SingleObserver downstream; - Disposable d; + Disposable upstream; - DetachSingleObserver(SingleObserver actual) { - this.actual = actual; + DetachSingleObserver(SingleObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - actual = null; - d.dispose(); - d = DisposableHelper.DISPOSED; + downstream = null; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; - SingleObserver a = actual; + upstream = DisposableHelper.DISPOSED; + SingleObserver a = downstream; if (a != null) { - actual = null; + downstream = null; a.onSuccess(value); } } @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - SingleObserver a = actual; + upstream = DisposableHelper.DISPOSED; + SingleObserver a = downstream; if (a != null) { - actual = null; + downstream = null; a.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java index bf2e557c36..208bb0ecba 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterSuccess.java @@ -44,29 +44,29 @@ protected void subscribeActual(SingleObserver observer) { static final class DoAfterObserver implements SingleObserver, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final Consumer onAfterSuccess; - Disposable d; + Disposable upstream; DoAfterObserver(SingleObserver actual, Consumer onAfterSuccess) { - this.actual = actual; + this.downstream = actual; this.onAfterSuccess = onAfterSuccess; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T t) { - actual.onSuccess(t); + downstream.onSuccess(t); try { onAfterSuccess.accept(t); @@ -79,17 +79,17 @@ public void onSuccess(T t) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java index 269902cdc7..eed7993231 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoAfterTerminate.java @@ -46,48 +46,48 @@ protected void subscribeActual(SingleObserver observer) { static final class DoAfterTerminateObserver implements SingleObserver, Disposable { - final SingleObserver actual; + final SingleObserver downstream; final Action onAfterTerminate; - Disposable d; + Disposable upstream; DoAfterTerminateObserver(SingleObserver actual, Action onAfterTerminate) { - this.actual = actual; + this.downstream = actual; this.onAfterTerminate = onAfterTerminate; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T t) { - actual.onSuccess(t); + downstream.onSuccess(t); onAfterTerminate(); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); onAfterTerminate(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } private void onAfterTerminate() { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java index f7e6cc3fee..7a6bc67258 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoFinally.java @@ -48,47 +48,47 @@ static final class DoFinallyObserver extends AtomicInteger implements SingleO private static final long serialVersionUID = 4109457741734051389L; - final SingleObserver actual; + final SingleObserver downstream; final Action onFinally; - Disposable d; + Disposable upstream; DoFinallyObserver(SingleObserver actual, Action onFinally) { - this.actual = actual; + this.downstream = actual; this.onFinally = onFinally; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T t) { - actual.onSuccess(t); + downstream.onSuccess(t); runFinally(); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); runFinally(); } @Override public void dispose() { - d.dispose(); + upstream.dispose(); runFinally(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } void runFinally() { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnDispose.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnDispose.java index 8515d99887..29cd86d6b7 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnDispose.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnDispose.java @@ -43,12 +43,12 @@ static final class DoOnDisposeObserver implements SingleObserver, Disposable { private static final long serialVersionUID = -8583764624474935784L; - final SingleObserver actual; + final SingleObserver downstream; - Disposable d; + Disposable upstream; DoOnDisposeObserver(SingleObserver actual, Action onDispose) { - this.actual = actual; + this.downstream = actual; this.lazySet(onDispose); } @@ -62,31 +62,31 @@ public void dispose() { Exceptions.throwIfFatal(ex); RxJavaPlugins.onError(ex); } - d.dispose(); + upstream.dispose(); } } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; - actual.onSubscribe(this); + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSubscribe.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSubscribe.java index c46c2d819b..4103ad6c79 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSubscribe.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnSubscribe.java @@ -43,14 +43,14 @@ protected void subscribeActual(final SingleObserver observer) { static final class DoOnSubscribeSingleObserver implements SingleObserver { - final SingleObserver actual; + final SingleObserver downstream; final Consumer onSubscribe; boolean done; DoOnSubscribeSingleObserver(SingleObserver actual, Consumer onSubscribe) { - this.actual = actual; + this.downstream = actual; this.onSubscribe = onSubscribe; } @@ -62,11 +62,11 @@ public void onSubscribe(Disposable d) { Exceptions.throwIfFatal(ex); done = true; d.dispose(); - EmptyDisposable.error(ex, actual); + EmptyDisposable.error(ex, downstream); return; } - actual.onSubscribe(d); + downstream.onSubscribe(d); } @Override @@ -74,7 +74,7 @@ public void onSuccess(T value) { if (done) { return; } - actual.onSuccess(value); + downstream.onSuccess(value); } @Override @@ -83,7 +83,7 @@ public void onError(Throwable e) { RxJavaPlugins.onError(e); return; } - actual.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMap.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMap.java index 29dc3433e4..2913ff79d7 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMap.java @@ -32,8 +32,8 @@ public SingleFlatMap(SingleSource source, Function actual) { - source.subscribe(new SingleFlatMapCallback(actual, mapper)); + protected void subscribeActual(SingleObserver downstream) { + source.subscribe(new SingleFlatMapCallback(downstream, mapper)); } static final class SingleFlatMapCallback @@ -41,13 +41,13 @@ static final class SingleFlatMapCallback implements SingleObserver, Disposable { private static final long serialVersionUID = 3258103020495908596L; - final SingleObserver actual; + final SingleObserver downstream; final Function> mapper; SingleFlatMapCallback(SingleObserver actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @@ -64,7 +64,7 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -76,29 +76,29 @@ public void onSuccess(T value) { o = ObjectHelper.requireNonNull(mapper.apply(value), "The single returned by the mapper is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } if (!isDisposed()) { - o.subscribe(new FlatMapSingleObserver(this, actual)); + o.subscribe(new FlatMapSingleObserver(this, downstream)); } } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } static final class FlatMapSingleObserver implements SingleObserver { final AtomicReference parent; - final SingleObserver actual; + final SingleObserver downstream; - FlatMapSingleObserver(AtomicReference parent, SingleObserver actual) { + FlatMapSingleObserver(AtomicReference parent, SingleObserver downstream) { this.parent = parent; - this.actual = actual; + this.downstream = downstream; } @Override @@ -108,12 +108,12 @@ public void onSubscribe(final Disposable d) { @Override public void onSuccess(final R value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(final Throwable e) { - actual.onError(e); + downstream.onError(e); } } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapCompletable.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapCompletable.java index 986a831f94..31b9ac2c99 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapCompletable.java @@ -50,13 +50,13 @@ static final class FlatMapCompletableObserver private static final long serialVersionUID = -2177128922851101253L; - final CompletableObserver actual; + final CompletableObserver downstream; final Function mapper; FlatMapCompletableObserver(CompletableObserver actual, Function mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @@ -94,12 +94,12 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowable.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowable.java index 7267fad95c..1243413dff 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowable.java @@ -57,13 +57,13 @@ static final class FlatMapIterableObserver private static final long serialVersionUID = -8938804753851907758L; - final Subscriber actual; + final Subscriber downstream; final Function> mapper; final AtomicLong requested; - Disposable d; + Disposable upstream; volatile Iterator it; @@ -73,17 +73,17 @@ static final class FlatMapIterableObserver FlatMapIterableObserver(Subscriber actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.requested = new AtomicLong(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -97,12 +97,12 @@ public void onSuccess(T value) { has = iterator.hasNext(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } if (!has) { - actual.onComplete(); + downstream.onComplete(); return; } @@ -112,8 +112,8 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override @@ -127,8 +127,8 @@ public void request(long n) { @Override public void cancel() { cancelled = true; - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } void drain() { @@ -136,7 +136,7 @@ void drain() { return; } - Subscriber a = actual; + Subscriber a = downstream; Iterator iterator = this.it; if (outputFused && iterator != null) { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java index 541e5063ed..760a052278 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java @@ -53,11 +53,11 @@ static final class FlatMapIterableObserver private static final long serialVersionUID = -8938804753851907758L; - final Observer actual; + final Observer downstream; final Function> mapper; - Disposable d; + Disposable upstream; volatile Iterator it; @@ -67,22 +67,22 @@ static final class FlatMapIterableObserver FlatMapIterableObserver(Observer actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - Observer a = actual; + Observer a = downstream; Iterator iterator; boolean has; try { @@ -91,7 +91,7 @@ public void onSuccess(T value) { has = iterator.hasNext(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } @@ -147,15 +147,15 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; - actual.onError(e); + upstream = DisposableHelper.DISPOSED; + downstream.onError(e); } @Override public void dispose() { cancelled = true; - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; } @Override diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapMaybe.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapMaybe.java index 2b9030ce19..dfe6b60143 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapMaybe.java @@ -37,8 +37,8 @@ public SingleFlatMapMaybe(SingleSource source, Function actual) { - source.subscribe(new FlatMapSingleObserver(actual, mapper)); + protected void subscribeActual(MaybeObserver downstream) { + source.subscribe(new FlatMapSingleObserver(downstream, mapper)); } static final class FlatMapSingleObserver @@ -47,12 +47,12 @@ static final class FlatMapSingleObserver private static final long serialVersionUID = -5843758257109742742L; - final MaybeObserver actual; + final MaybeObserver downstream; final Function> mapper; FlatMapSingleObserver(MaybeObserver actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; } @@ -69,7 +69,7 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -86,13 +86,13 @@ public void onSuccess(T value) { } if (!isDisposed()) { - ms.subscribe(new FlatMapMaybeObserver(this, actual)); + ms.subscribe(new FlatMapMaybeObserver(this, downstream)); } } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } } @@ -100,11 +100,11 @@ static final class FlatMapMaybeObserver implements MaybeObserver { final AtomicReference parent; - final MaybeObserver actual; + final MaybeObserver downstream; - FlatMapMaybeObserver(AtomicReference parent, MaybeObserver actual) { + FlatMapMaybeObserver(AtomicReference parent, MaybeObserver downstream) { this.parent = parent; - this.actual = actual; + this.downstream = downstream; } @Override @@ -114,17 +114,17 @@ public void onSubscribe(final Disposable d) { @Override public void onSuccess(final R value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(final Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapPublisher.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapPublisher.java index bdb7d166cd..be090bd20b 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapPublisher.java @@ -62,8 +62,8 @@ public SingleFlatMapPublisher(SingleSource source, } @Override - protected void subscribeActual(Subscriber actual) { - source.subscribe(new SingleFlatMapPublisherObserver(actual, mapper)); + protected void subscribeActual(Subscriber downstream) { + source.subscribe(new SingleFlatMapPublisherObserver(downstream, mapper)); } static final class SingleFlatMapPublisherObserver extends AtomicLong @@ -71,14 +71,14 @@ static final class SingleFlatMapPublisherObserver extends AtomicLong private static final long serialVersionUID = 7759721921468635667L; - final Subscriber actual; + final Subscriber downstream; final Function> mapper; final AtomicReference parent; Disposable disposable; SingleFlatMapPublisherObserver(Subscriber actual, Function> mapper) { - this.actual = actual; + this.downstream = actual; this.mapper = mapper; this.parent = new AtomicReference(); } @@ -86,7 +86,7 @@ static final class SingleFlatMapPublisherObserver extends AtomicLong @Override public void onSubscribe(Disposable d) { this.disposable = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } @Override @@ -96,7 +96,7 @@ public void onSuccess(S value) { f = ObjectHelper.requireNonNull(mapper.apply(value), "the mapper returned a null Publisher"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - actual.onError(e); + downstream.onError(e); return; } f.subscribe(this); @@ -109,17 +109,17 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFromPublisher.java b/src/main/java/io/reactivex/internal/operators/single/SingleFromPublisher.java index 9543c494c9..5709f3c6d4 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFromPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFromPublisher.java @@ -36,9 +36,9 @@ protected void subscribeActual(final SingleObserver observer) { } static final class ToSingleObserver implements FlowableSubscriber, Disposable { - final SingleObserver actual; + final SingleObserver downstream; - Subscription s; + Subscription upstream; T value; @@ -46,16 +46,16 @@ static final class ToSingleObserver implements FlowableSubscriber, Disposa volatile boolean disposed; - ToSingleObserver(SingleObserver actual) { - this.actual = actual; + ToSingleObserver(SingleObserver downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -67,10 +67,10 @@ public void onNext(T t) { return; } if (value != null) { - s.cancel(); + upstream.cancel(); done = true; this.value = null; - actual.onError(new IndexOutOfBoundsException("Too many elements in the Publisher")); + downstream.onError(new IndexOutOfBoundsException("Too many elements in the Publisher")); } else { value = t; } @@ -84,7 +84,7 @@ public void onError(Throwable t) { } done = true; this.value = null; - actual.onError(t); + downstream.onError(t); } @Override @@ -96,9 +96,9 @@ public void onComplete() { T v = this.value; this.value = null; if (v == null) { - actual.onError(new NoSuchElementException("The source Publisher is empty")); + downstream.onError(new NoSuchElementException("The source Publisher is empty")); } else { - actual.onSuccess(v); + downstream.onSuccess(v); } } @@ -110,7 +110,7 @@ public boolean isDisposed() { @Override public void dispose() { disposed = true; - s.cancel(); + upstream.cancel(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleHide.java b/src/main/java/io/reactivex/internal/operators/single/SingleHide.java index 27cf6205b2..7ec7390e20 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleHide.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleHide.java @@ -32,40 +32,40 @@ protected void subscribeActual(SingleObserver observer) { static final class HideSingleObserver implements SingleObserver, Disposable { - final SingleObserver actual; + final SingleObserver downstream; - Disposable d; + Disposable upstream; - HideSingleObserver(SingleObserver actual) { - this.actual = actual; + HideSingleObserver(SingleObserver downstream) { + this.downstream = downstream; } @Override public void dispose() { - d.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; - actual.onSubscribe(this); + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleObserveOn.java b/src/main/java/io/reactivex/internal/operators/single/SingleObserveOn.java index 494fa2c896..7c8a6c1977 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleObserveOn.java @@ -39,7 +39,7 @@ static final class ObserveOnSingleObserver extends AtomicReference, Disposable, Runnable { private static final long serialVersionUID = 3528003840217436037L; - final SingleObserver actual; + final SingleObserver downstream; final Scheduler scheduler; @@ -47,14 +47,14 @@ static final class ObserveOnSingleObserver extends AtomicReference actual, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.scheduler = scheduler; } @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -76,9 +76,9 @@ public void onError(Throwable e) { public void run() { Throwable ex = error; if (ex != null) { - actual.onError(ex); + downstream.onError(ex); } else { - actual.onSuccess(value); + downstream.onSuccess(value); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleResumeNext.java b/src/main/java/io/reactivex/internal/operators/single/SingleResumeNext.java index 42133c05f4..325365f8f4 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleResumeNext.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleResumeNext.java @@ -43,26 +43,26 @@ static final class ResumeMainSingleObserver extends AtomicReference, Disposable { private static final long serialVersionUID = -5314538511045349925L; - final SingleObserver actual; + final SingleObserver downstream; final Function> nextFunction; ResumeMainSingleObserver(SingleObserver actual, Function> nextFunction) { - this.actual = actual; + this.downstream = actual; this.nextFunction = nextFunction; } @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override @@ -73,11 +73,11 @@ public void onError(Throwable e) { source = ObjectHelper.requireNonNull(nextFunction.apply(e), "The nextFunction returned a null SingleSource."); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(new CompositeException(e, ex)); + downstream.onError(new CompositeException(e, ex)); return; } - source.subscribe(new ResumeSingleObserver(this, actual)); + source.subscribe(new ResumeSingleObserver(this, downstream)); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/single/SingleSubscribeOn.java index 68299fef2c..9b29e6253f 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleSubscribeOn.java @@ -46,14 +46,14 @@ static final class SubscribeOnObserver private static final long serialVersionUID = 7000911171163930287L; - final SingleObserver actual; + final SingleObserver downstream; final SequentialDisposable task; final SingleSource source; SubscribeOnObserver(SingleObserver actual, SingleSource source) { - this.actual = actual; + this.downstream = actual; this.source = source; this.task = new SequentialDisposable(); } @@ -65,12 +65,12 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleTakeUntil.java b/src/main/java/io/reactivex/internal/operators/single/SingleTakeUntil.java index 2a4bb1b4b7..8db5e40a03 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleTakeUntil.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleTakeUntil.java @@ -57,12 +57,12 @@ static final class TakeUntilMainObserver private static final long serialVersionUID = -622603812305745221L; - final SingleObserver actual; + final SingleObserver downstream; final TakeUntilOtherSubscriber other; - TakeUntilMainObserver(SingleObserver actual) { - this.actual = actual; + TakeUntilMainObserver(SingleObserver downstream) { + this.downstream = downstream; this.other = new TakeUntilOtherSubscriber(this); } @@ -88,7 +88,7 @@ public void onSuccess(T value) { Disposable a = getAndSet(DisposableHelper.DISPOSED); if (a != DisposableHelper.DISPOSED) { - actual.onSuccess(value); + downstream.onSuccess(value); } } @@ -100,7 +100,7 @@ public void onError(Throwable e) { if (a != DisposableHelper.DISPOSED) { a = getAndSet(DisposableHelper.DISPOSED); if (a != DisposableHelper.DISPOSED) { - actual.onError(e); + downstream.onError(e); return; } } @@ -115,7 +115,7 @@ void otherError(Throwable e) { if (a != null) { a.dispose(); } - actual.onError(e); + downstream.onError(e); return; } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java b/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java index 575d47732a..4c97882d62 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java @@ -58,7 +58,7 @@ static final class TimeoutMainObserver extends AtomicReference private static final long serialVersionUID = 37497744973048446L; - final SingleObserver actual; + final SingleObserver downstream; final AtomicReference task; @@ -70,10 +70,10 @@ static final class TimeoutFallbackObserver extends AtomicReference { private static final long serialVersionUID = 2071387740092105509L; - final SingleObserver actual; + final SingleObserver downstream; - TimeoutFallbackObserver(SingleObserver actual) { - this.actual = actual; + TimeoutFallbackObserver(SingleObserver downstream) { + this.downstream = downstream; } @Override @@ -83,17 +83,17 @@ public void onSubscribe(Disposable d) { @Override public void onSuccess(T t) { - actual.onSuccess(t); + downstream.onSuccess(t); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } } TimeoutMainObserver(SingleObserver actual, SingleSource other) { - this.actual = actual; + this.downstream = actual; this.other = other; this.task = new AtomicReference(); if (other != null) { @@ -112,7 +112,7 @@ public void run() { } SingleSource other = this.other; if (other == null) { - actual.onError(new TimeoutException()); + downstream.onError(new TimeoutException()); } else { this.other = null; other.subscribe(fallback); @@ -130,7 +130,7 @@ public void onSuccess(T t) { Disposable d = get(); if (d != DisposableHelper.DISPOSED && compareAndSet(d, DisposableHelper.DISPOSED)) { DisposableHelper.dispose(task); - actual.onSuccess(t); + downstream.onSuccess(t); } } @@ -139,7 +139,7 @@ public void onError(Throwable e) { Disposable d = get(); if (d != DisposableHelper.DISPOSED && compareAndSet(d, DisposableHelper.DISPOSED)) { DisposableHelper.dispose(task); - actual.onError(e); + downstream.onError(e); } else { RxJavaPlugins.onError(e); } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleTimer.java b/src/main/java/io/reactivex/internal/operators/single/SingleTimer.java index 638a8894c5..68b4c9c3b7 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleTimer.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleTimer.java @@ -45,15 +45,15 @@ protected void subscribeActual(final SingleObserver observer) { static final class TimerDisposable extends AtomicReference implements Disposable, Runnable { private static final long serialVersionUID = 8465401857522493082L; - final SingleObserver actual; + final SingleObserver downstream; - TimerDisposable(final SingleObserver actual) { - this.actual = actual; + TimerDisposable(final SingleObserver downstream) { + this.downstream = downstream; } @Override public void run() { - actual.onSuccess(0L); + downstream.onSuccess(0L); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleToFlowable.java b/src/main/java/io/reactivex/internal/operators/single/SingleToFlowable.java index a33d36df98..f48aa4659b 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleToFlowable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleToFlowable.java @@ -43,18 +43,18 @@ static final class SingleToFlowableObserver extends DeferredScalarSubscriptio private static final long serialVersionUID = 187782011903685568L; - Disposable d; + Disposable upstream; - SingleToFlowableObserver(Subscriber actual) { - super(actual); + SingleToFlowableObserver(Subscriber downstream) { + super(downstream); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -65,13 +65,13 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } @Override public void cancel() { super.cancel(); - d.dispose(); + upstream.dispose(); } } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java b/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java index 56d78e0774..2c4126a837 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleToObservable.java @@ -52,18 +52,18 @@ static final class SingleToObservableObserver implements SingleObserver { private static final long serialVersionUID = 3786543492451018833L; - Disposable d; + Disposable upstream; - SingleToObservableObserver(Observer actual) { - super(actual); + SingleToObservableObserver(Observer downstream) { + super(downstream); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @@ -80,7 +80,7 @@ public void onError(Throwable e) { @Override public void dispose() { super.dispose(); - d.dispose(); + upstream.dispose(); } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleUnsubscribeOn.java b/src/main/java/io/reactivex/internal/operators/single/SingleUnsubscribeOn.java index 27c4200d8a..dc7962ba8e 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleUnsubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleUnsubscribeOn.java @@ -45,14 +45,14 @@ static final class UnsubscribeOnSingleObserver extends AtomicReference actual; + final SingleObserver downstream; final Scheduler scheduler; Disposable ds; UnsubscribeOnSingleObserver(SingleObserver actual, Scheduler scheduler) { - this.actual = actual; + this.downstream = actual; this.scheduler = scheduler; } @@ -78,18 +78,18 @@ public boolean isDisposed() { @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void onSuccess(T value) { - actual.onSuccess(value); + downstream.onSuccess(value); } @Override public void onError(Throwable e) { - actual.onError(e); + downstream.onError(e); } } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleUsing.java b/src/main/java/io/reactivex/internal/operators/single/SingleUsing.java index e2f93a9110..0352bddb63 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleUsing.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleUsing.java @@ -89,47 +89,47 @@ static final class UsingSingleObserver extends private static final long serialVersionUID = -5331524057054083935L; - final SingleObserver actual; + final SingleObserver downstream; final Consumer disposer; final boolean eager; - Disposable d; + Disposable upstream; UsingSingleObserver(SingleObserver actual, U resource, boolean eager, Consumer disposer) { super(resource); - this.actual = actual; + this.downstream = actual; this.eager = eager; this.disposer = disposer; } @Override public void dispose() { - d.dispose(); - d = DisposableHelper.DISPOSED; + upstream.dispose(); + upstream = DisposableHelper.DISPOSED; disposeAfter(); } @Override public boolean isDisposed() { - return d.isDisposed(); + return upstream.isDisposed(); } @Override public void onSubscribe(Disposable d) { - if (DisposableHelper.validate(this.d, d)) { - this.d = d; + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @SuppressWarnings("unchecked") @Override public void onSuccess(T value) { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; if (eager) { Object u = getAndSet(this); @@ -138,7 +138,7 @@ public void onSuccess(T value) { disposer.accept((U)u); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } } else { @@ -146,7 +146,7 @@ public void onSuccess(T value) { } } - actual.onSuccess(value); + downstream.onSuccess(value); if (!eager) { disposeAfter(); @@ -156,7 +156,7 @@ public void onSuccess(T value) { @SuppressWarnings("unchecked") @Override public void onError(Throwable e) { - d = DisposableHelper.DISPOSED; + upstream = DisposableHelper.DISPOSED; if (eager) { Object u = getAndSet(this); @@ -172,7 +172,7 @@ public void onError(Throwable e) { } } - actual.onError(e); + downstream.onError(e); if (!eager) { disposeAfter(); diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleZipArray.java b/src/main/java/io/reactivex/internal/operators/single/SingleZipArray.java index e98917b511..e9ba27d755 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleZipArray.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleZipArray.java @@ -70,7 +70,7 @@ static final class ZipCoordinator extends AtomicInteger implements Disposa private static final long serialVersionUID = -5556924161382950569L; - final SingleObserver actual; + final SingleObserver downstream; final Function zipper; @@ -81,7 +81,7 @@ static final class ZipCoordinator extends AtomicInteger implements Disposa @SuppressWarnings("unchecked") ZipCoordinator(SingleObserver observer, int n, Function zipper) { super(n); - this.actual = observer; + this.downstream = observer; this.zipper = zipper; ZipSingleObserver[] o = new ZipSingleObserver[n]; for (int i = 0; i < n; i++) { @@ -114,11 +114,11 @@ void innerSuccess(T value, int index) { v = ObjectHelper.requireNonNull(zipper.apply(values), "The zipper returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - actual.onError(ex); + downstream.onError(ex); return; } - actual.onSuccess(v); + downstream.onSuccess(v); } } @@ -136,7 +136,7 @@ void disposeExcept(int index) { void innerError(Throwable ex, int index) { if (getAndSet(0) > 0) { disposeExcept(index); - actual.onError(ex); + downstream.onError(ex); } else { RxJavaPlugins.onError(ex); } diff --git a/src/main/java/io/reactivex/internal/schedulers/DisposeOnCancel.java b/src/main/java/io/reactivex/internal/schedulers/DisposeOnCancel.java index ef7dfedd02..c79eaeb149 100644 --- a/src/main/java/io/reactivex/internal/schedulers/DisposeOnCancel.java +++ b/src/main/java/io/reactivex/internal/schedulers/DisposeOnCancel.java @@ -22,15 +22,16 @@ * the other methods are not implemented. */ final class DisposeOnCancel implements Future { - final Disposable d; + + final Disposable upstream; DisposeOnCancel(Disposable d) { - this.d = d; + this.upstream = d; } @Override public boolean cancel(boolean mayInterruptIfRunning) { - d.dispose(); + upstream.dispose(); return false; } diff --git a/src/main/java/io/reactivex/internal/subscribers/BasicFuseableConditionalSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/BasicFuseableConditionalSubscriber.java index c9d2f98b46..f665d48a49 100644 --- a/src/main/java/io/reactivex/internal/subscribers/BasicFuseableConditionalSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/BasicFuseableConditionalSubscriber.java @@ -28,10 +28,10 @@ public abstract class BasicFuseableConditionalSubscriber implements ConditionalSubscriber, QueueSubscription { /** The downstream subscriber. */ - protected final ConditionalSubscriber actual; + protected final ConditionalSubscriber downstream; /** The upstream subscription. */ - protected Subscription s; + protected Subscription upstream; /** The upstream's QueueSubscription if not null. */ protected QueueSubscription qs; @@ -44,26 +44,26 @@ public abstract class BasicFuseableConditionalSubscriber implements Condit /** * Construct a BasicFuseableSubscriber by wrapping the given subscriber. - * @param actual the subscriber, not null (not verified) + * @param downstream the subscriber, not null (not verified) */ - public BasicFuseableConditionalSubscriber(ConditionalSubscriber actual) { - this.actual = actual; + public BasicFuseableConditionalSubscriber(ConditionalSubscriber downstream) { + this.downstream = downstream; } // final: fixed protocol steps to support fuseable and non-fuseable upstream @SuppressWarnings("unchecked") @Override public final void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { + if (SubscriptionHelper.validate(this.upstream, s)) { - this.s = s; + this.upstream = s; if (s instanceof QueueSubscription) { this.qs = (QueueSubscription)s; } if (beforeDownstream()) { - actual.onSubscribe(this); + downstream.onSubscribe(this); afterDownstream(); } @@ -97,7 +97,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } /** @@ -106,7 +106,7 @@ public void onError(Throwable t) { */ protected final void fail(Throwable t) { Exceptions.throwIfFatal(t); - s.cancel(); + upstream.cancel(); onError(t); } @@ -116,7 +116,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } /** @@ -149,12 +149,12 @@ protected final int transitiveBoundaryFusion(int mode) { @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override diff --git a/src/main/java/io/reactivex/internal/subscribers/BasicFuseableSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/BasicFuseableSubscriber.java index 6af9b49fc1..945d311b29 100644 --- a/src/main/java/io/reactivex/internal/subscribers/BasicFuseableSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/BasicFuseableSubscriber.java @@ -29,10 +29,10 @@ public abstract class BasicFuseableSubscriber implements FlowableSubscriber, QueueSubscription { /** The downstream subscriber. */ - protected final Subscriber actual; + protected final Subscriber downstream; /** The upstream subscription. */ - protected Subscription s; + protected Subscription upstream; /** The upstream's QueueSubscription if not null. */ protected QueueSubscription qs; @@ -45,26 +45,26 @@ public abstract class BasicFuseableSubscriber implements FlowableSubscribe /** * Construct a BasicFuseableSubscriber by wrapping the given subscriber. - * @param actual the subscriber, not null (not verified) + * @param downstream the subscriber, not null (not verified) */ - public BasicFuseableSubscriber(Subscriber actual) { - this.actual = actual; + public BasicFuseableSubscriber(Subscriber downstream) { + this.downstream = downstream; } // final: fixed protocol steps to support fuseable and non-fuseable upstream @SuppressWarnings("unchecked") @Override public final void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { + if (SubscriptionHelper.validate(this.upstream, s)) { - this.s = s; + this.upstream = s; if (s instanceof QueueSubscription) { this.qs = (QueueSubscription)s; } if (beforeDownstream()) { - actual.onSubscribe(this); + downstream.onSubscribe(this); afterDownstream(); } @@ -98,7 +98,7 @@ public void onError(Throwable t) { return; } done = true; - actual.onError(t); + downstream.onError(t); } /** @@ -107,7 +107,7 @@ public void onError(Throwable t) { */ protected final void fail(Throwable t) { Exceptions.throwIfFatal(t); - s.cancel(); + upstream.cancel(); onError(t); } @@ -117,7 +117,7 @@ public void onComplete() { return; } done = true; - actual.onComplete(); + downstream.onComplete(); } /** @@ -150,12 +150,12 @@ protected final int transitiveBoundaryFusion(int mode) { @Override public void request(long n) { - s.request(n); + upstream.request(n); } @Override public void cancel() { - s.cancel(); + upstream.cancel(); } @Override diff --git a/src/main/java/io/reactivex/internal/subscribers/BlockingBaseSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/BlockingBaseSubscriber.java index 6ab208cc27..72a1374420 100644 --- a/src/main/java/io/reactivex/internal/subscribers/BlockingBaseSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/BlockingBaseSubscriber.java @@ -26,7 +26,7 @@ public abstract class BlockingBaseSubscriber extends CountDownLatch T value; Throwable error; - Subscription s; + Subscription upstream; volatile boolean cancelled; @@ -36,12 +36,12 @@ public BlockingBaseSubscriber() { @Override public final void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; if (!cancelled) { s.request(Long.MAX_VALUE); if (cancelled) { - this.s = SubscriptionHelper.CANCELLED; + this.upstream = SubscriptionHelper.CANCELLED; s.cancel(); } } @@ -64,8 +64,8 @@ public final T blockingGet() { BlockingHelper.verifyNonBlocking(); await(); } catch (InterruptedException ex) { - Subscription s = this.s; - this.s = SubscriptionHelper.CANCELLED; + Subscription s = this.upstream; + this.upstream = SubscriptionHelper.CANCELLED; if (s != null) { s.cancel(); } diff --git a/src/main/java/io/reactivex/internal/subscribers/BlockingFirstSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/BlockingFirstSubscriber.java index 55e8e8c0a2..57fd44623f 100644 --- a/src/main/java/io/reactivex/internal/subscribers/BlockingFirstSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/BlockingFirstSubscriber.java @@ -26,7 +26,7 @@ public final class BlockingFirstSubscriber extends BlockingBaseSubscriber public void onNext(T t) { if (value == null) { value = t; - s.cancel(); + upstream.cancel(); countDown(); } } diff --git a/src/main/java/io/reactivex/internal/subscribers/DeferredScalarSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/DeferredScalarSubscriber.java index 910a898214..701b4a44bc 100644 --- a/src/main/java/io/reactivex/internal/subscribers/DeferredScalarSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/DeferredScalarSubscriber.java @@ -30,25 +30,25 @@ public abstract class DeferredScalarSubscriber extends DeferredScalarSubsc private static final long serialVersionUID = 2984505488220891551L; /** The upstream subscription. */ - protected Subscription s; + protected Subscription upstream; /** Can indicate if there was at least on onNext call. */ protected boolean hasValue; /** * Creates a DeferredScalarSubscriber instance and wraps a downstream Subscriber. - * @param actual the downstream subscriber, not null (not verified) + * @param downstream the downstream subscriber, not null (not verified) */ - public DeferredScalarSubscriber(Subscriber actual) { - super(actual); + public DeferredScalarSubscriber(Subscriber downstream) { + super(downstream); } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } @@ -57,7 +57,7 @@ public void onSubscribe(Subscription s) { @Override public void onError(Throwable t) { value = null; - actual.onError(t); + downstream.onError(t); } @Override @@ -65,13 +65,13 @@ public void onComplete() { if (hasValue) { complete(value); } else { - actual.onComplete(); + downstream.onComplete(); } } @Override public void cancel() { super.cancel(); - s.cancel(); + upstream.cancel(); } } diff --git a/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java index 9537556008..1cc2eb2e09 100644 --- a/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java @@ -36,22 +36,22 @@ public final class FutureSubscriber extends CountDownLatch T value; Throwable error; - final AtomicReference s; + final AtomicReference upstream; public FutureSubscriber() { super(1); - this.s = new AtomicReference(); + this.upstream = new AtomicReference(); } @Override public boolean cancel(boolean mayInterruptIfRunning) { for (;;) { - Subscription a = s.get(); + Subscription a = upstream.get(); if (a == this || a == SubscriptionHelper.CANCELLED) { return false; } - if (s.compareAndSet(a, SubscriptionHelper.CANCELLED)) { + if (upstream.compareAndSet(a, SubscriptionHelper.CANCELLED)) { if (a != null) { a.cancel(); } @@ -63,7 +63,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { @Override public boolean isCancelled() { - return SubscriptionHelper.isCancelled(s.get()); + return SubscriptionHelper.isCancelled(upstream.get()); } @Override @@ -110,13 +110,13 @@ public T get(long timeout, TimeUnit unit) throws InterruptedException, Execution @Override public void onSubscribe(Subscription s) { - SubscriptionHelper.setOnce(this.s, s, Long.MAX_VALUE); + SubscriptionHelper.setOnce(this.upstream, s, Long.MAX_VALUE); } @Override public void onNext(T t) { if (value != null) { - s.get().cancel(); + upstream.get().cancel(); onError(new IndexOutOfBoundsException("More than one element received")); return; } @@ -126,13 +126,13 @@ public void onNext(T t) { @Override public void onError(Throwable t) { for (;;) { - Subscription a = s.get(); + Subscription a = upstream.get(); if (a == this || a == SubscriptionHelper.CANCELLED) { RxJavaPlugins.onError(t); return; } error = t; - if (s.compareAndSet(a, this)) { + if (upstream.compareAndSet(a, this)) { countDown(); return; } @@ -146,11 +146,11 @@ public void onComplete() { return; } for (;;) { - Subscription a = s.get(); + Subscription a = upstream.get(); if (a == this || a == SubscriptionHelper.CANCELLED) { return; } - if (s.compareAndSet(a, this)) { + if (upstream.compareAndSet(a, this)) { countDown(); return; } diff --git a/src/main/java/io/reactivex/internal/subscribers/QueueDrainSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/QueueDrainSubscriber.java index 31d97833c2..d07f748999 100644 --- a/src/main/java/io/reactivex/internal/subscribers/QueueDrainSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/QueueDrainSubscriber.java @@ -33,7 +33,9 @@ * @param the value type the child subscriber accepts */ public abstract class QueueDrainSubscriber extends QueueDrainSubscriberPad4 implements FlowableSubscriber, QueueDrain { - protected final Subscriber actual; + + protected final Subscriber downstream; + protected final SimplePlainQueue queue; protected volatile boolean cancelled; @@ -42,7 +44,7 @@ public abstract class QueueDrainSubscriber extends QueueDrainSubscriber protected Throwable error; public QueueDrainSubscriber(Subscriber actual, SimplePlainQueue queue) { - this.actual = actual; + this.downstream = actual; this.queue = queue; } @@ -66,7 +68,7 @@ public final boolean fastEnter() { } protected final void fastPathEmitMax(U value, boolean delayError, Disposable dispose) { - final Subscriber s = actual; + final Subscriber s = downstream; final SimplePlainQueue q = queue; if (fastEnter()) { @@ -95,7 +97,7 @@ protected final void fastPathEmitMax(U value, boolean delayError, Disposable dis } protected final void fastPathOrderedEmitMax(U value, boolean delayError, Disposable dispose) { - final Subscriber s = actual; + final Subscriber s = downstream; final SimplePlainQueue q = queue; if (fastEnter()) { diff --git a/src/main/java/io/reactivex/internal/subscribers/SinglePostCompleteSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/SinglePostCompleteSubscriber.java index 8d7efc37aa..4ea2ac2368 100644 --- a/src/main/java/io/reactivex/internal/subscribers/SinglePostCompleteSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/SinglePostCompleteSubscriber.java @@ -32,10 +32,10 @@ public abstract class SinglePostCompleteSubscriber extends AtomicLong impl private static final long serialVersionUID = 7917814472626990048L; /** The downstream consumer. */ - protected final Subscriber actual; + protected final Subscriber downstream; /** The upstream subscription. */ - protected Subscription s; + protected Subscription upstream; /** The last value stored in case there is no request for it. */ protected R value; @@ -48,15 +48,15 @@ public abstract class SinglePostCompleteSubscriber extends AtomicLong impl /** Masks out the lower 63 bit holding the current request amount. */ static final long REQUEST_MASK = Long.MAX_VALUE; - public SinglePostCompleteSubscriber(Subscriber actual) { - this.actual = actual; + public SinglePostCompleteSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -78,8 +78,8 @@ protected final void complete(R n) { } if ((r & REQUEST_MASK) != 0) { lazySet(COMPLETE_MASK + 1); - actual.onNext(n); - actual.onComplete(); + downstream.onNext(n); + downstream.onComplete(); return; } value = n; @@ -105,14 +105,14 @@ public final void request(long n) { long r = get(); if ((r & COMPLETE_MASK) != 0) { if (compareAndSet(COMPLETE_MASK, COMPLETE_MASK + 1)) { - actual.onNext(value); - actual.onComplete(); + downstream.onNext(value); + downstream.onComplete(); } break; } long u = BackpressureHelper.addCap(r, n); if (compareAndSet(r, u)) { - s.request(n); + upstream.request(n); break; } } @@ -121,6 +121,6 @@ public final void request(long n) { @Override public void cancel() { - s.cancel(); + upstream.cancel(); } } diff --git a/src/main/java/io/reactivex/internal/subscribers/StrictSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/StrictSubscriber.java index 6d6c7514c2..0fb9d5666c 100644 --- a/src/main/java/io/reactivex/internal/subscribers/StrictSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/StrictSubscriber.java @@ -41,23 +41,23 @@ public class StrictSubscriber private static final long serialVersionUID = -4945028590049415624L; - final Subscriber actual; + final Subscriber downstream; final AtomicThrowable error; final AtomicLong requested; - final AtomicReference s; + final AtomicReference upstream; final AtomicBoolean once; volatile boolean done; - public StrictSubscriber(Subscriber actual) { - this.actual = actual; + public StrictSubscriber(Subscriber downstream) { + this.downstream = downstream; this.error = new AtomicThrowable(); this.requested = new AtomicLong(); - this.s = new AtomicReference(); + this.upstream = new AtomicReference(); this.once = new AtomicBoolean(); } @@ -67,14 +67,14 @@ public void request(long n) { cancel(); onError(new IllegalArgumentException("§3.9 violated: positive request amount required but it was " + n)); } else { - SubscriptionHelper.deferredRequest(s, requested, n); + SubscriptionHelper.deferredRequest(upstream, requested, n); } } @Override public void cancel() { if (!done) { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); } } @@ -82,9 +82,9 @@ public void cancel() { public void onSubscribe(Subscription s) { if (once.compareAndSet(false, true)) { - actual.onSubscribe(this); + downstream.onSubscribe(this); - SubscriptionHelper.deferredSetOnce(this.s, requested, s); + SubscriptionHelper.deferredSetOnce(this.upstream, requested, s); } else { s.cancel(); cancel(); @@ -94,18 +94,18 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { - HalfSerializer.onNext(actual, t, this, error); + HalfSerializer.onNext(downstream, t, this, error); } @Override public void onError(Throwable t) { done = true; - HalfSerializer.onError(actual, t, this, error); + HalfSerializer.onError(downstream, t, this, error); } @Override public void onComplete() { done = true; - HalfSerializer.onComplete(actual, this, error); + HalfSerializer.onComplete(downstream, this, error); } } diff --git a/src/main/java/io/reactivex/internal/subscribers/SubscriberResourceWrapper.java b/src/main/java/io/reactivex/internal/subscribers/SubscriberResourceWrapper.java index bb8061b610..807430bb7b 100644 --- a/src/main/java/io/reactivex/internal/subscribers/SubscriberResourceWrapper.java +++ b/src/main/java/io/reactivex/internal/subscribers/SubscriberResourceWrapper.java @@ -26,55 +26,55 @@ public final class SubscriberResourceWrapper extends AtomicReference actual; + final Subscriber downstream; - final AtomicReference subscription = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); - public SubscriberResourceWrapper(Subscriber actual) { - this.actual = actual; + public SubscriberResourceWrapper(Subscriber downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.setOnce(subscription, s)) { - actual.onSubscribe(this); + if (SubscriptionHelper.setOnce(upstream, s)) { + downstream.onSubscribe(this); } } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { DisposableHelper.dispose(this); - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { DisposableHelper.dispose(this); - actual.onComplete(); + downstream.onComplete(); } @Override public void request(long n) { if (SubscriptionHelper.validate(n)) { - subscription.get().request(n); + upstream.get().request(n); } } @Override public void dispose() { - SubscriptionHelper.cancel(subscription); + SubscriptionHelper.cancel(upstream); DisposableHelper.dispose(this); } @Override public boolean isDisposed() { - return subscription.get() == SubscriptionHelper.CANCELLED; + return upstream.get() == SubscriptionHelper.CANCELLED; } @Override diff --git a/src/main/java/io/reactivex/internal/subscriptions/DeferredScalarSubscription.java b/src/main/java/io/reactivex/internal/subscriptions/DeferredScalarSubscription.java index 3e0406f4fe..536ddf4c00 100644 --- a/src/main/java/io/reactivex/internal/subscriptions/DeferredScalarSubscription.java +++ b/src/main/java/io/reactivex/internal/subscriptions/DeferredScalarSubscription.java @@ -38,7 +38,7 @@ public class DeferredScalarSubscription extends BasicIntQueueSubscription private static final long serialVersionUID = -2151279923272604993L; /** The Subscriber to emit the value to. */ - protected final Subscriber actual; + protected final Subscriber downstream; /** The value is stored here if there is no request yet or in fusion mode. */ protected T value; @@ -64,10 +64,10 @@ public class DeferredScalarSubscription extends BasicIntQueueSubscription /** * Creates a DeferredScalarSubscription by wrapping the given Subscriber. - * @param actual the Subscriber to wrap, not null (not verified) + * @param downstream the Subscriber to wrap, not null (not verified) */ - public DeferredScalarSubscription(Subscriber actual) { - this.actual = actual; + public DeferredScalarSubscription(Subscriber downstream) { + this.downstream = downstream; } @Override @@ -85,7 +85,7 @@ public final void request(long n) { T v = value; if (v != null) { value = null; - Subscriber a = actual; + Subscriber a = downstream; a.onNext(v); if (get() != CANCELLED) { a.onComplete(); @@ -114,7 +114,7 @@ public final void complete(T v) { value = v; lazySet(FUSED_READY); - Subscriber a = actual; + Subscriber a = downstream; a.onNext(v); if (get() != CANCELLED) { a.onComplete(); @@ -129,7 +129,7 @@ public final void complete(T v) { if (state == HAS_REQUEST_NO_VALUE) { lazySet(HAS_REQUEST_HAS_VALUE); - Subscriber a = actual; + Subscriber a = downstream; a.onNext(v); if (get() != CANCELLED) { a.onComplete(); diff --git a/src/main/java/io/reactivex/internal/util/NotificationLite.java b/src/main/java/io/reactivex/internal/util/NotificationLite.java index 68aeb8492e..2359141e5e 100644 --- a/src/main/java/io/reactivex/internal/util/NotificationLite.java +++ b/src/main/java/io/reactivex/internal/util/NotificationLite.java @@ -64,14 +64,14 @@ public boolean equals(Object obj) { static final class SubscriptionNotification implements Serializable { private static final long serialVersionUID = -1322257508628817540L; - final Subscription s; + final Subscription upstream; SubscriptionNotification(Subscription s) { - this.s = s; + this.upstream = s; } @Override public String toString() { - return "NotificationLite.Subscription[" + s + "]"; + return "NotificationLite.Subscription[" + upstream + "]"; } } @@ -81,15 +81,15 @@ public String toString() { static final class DisposableNotification implements Serializable { private static final long serialVersionUID = -7482590109178395495L; - final Disposable d; + final Disposable upstream; DisposableNotification(Disposable d) { - this.d = d; + this.upstream = d; } @Override public String toString() { - return "NotificationLite.Disposable[" + d + "]"; + return "NotificationLite.Disposable[" + upstream + "]"; } } @@ -195,11 +195,11 @@ public static Throwable getError(Object o) { * @return the extracted Subscription */ public static Subscription getSubscription(Object o) { - return ((SubscriptionNotification)o).s; + return ((SubscriptionNotification)o).upstream; } public static Disposable getDisposable(Object o) { - return ((DisposableNotification)o).d; + return ((DisposableNotification)o).upstream; } /** @@ -266,7 +266,7 @@ public static boolean acceptFull(Object o, Subscriber s) { return true; } else if (o instanceof SubscriptionNotification) { - s.onSubscribe(((SubscriptionNotification)o).s); + s.onSubscribe(((SubscriptionNotification)o).upstream); return false; } s.onNext((T)o); @@ -292,7 +292,7 @@ public static boolean acceptFull(Object o, Observer observer) { return true; } else if (o instanceof DisposableNotification) { - observer.onSubscribe(((DisposableNotification)o).d); + observer.onSubscribe(((DisposableNotification)o).upstream); return false; } observer.onNext((T)o); diff --git a/src/main/java/io/reactivex/observers/DefaultObserver.java b/src/main/java/io/reactivex/observers/DefaultObserver.java index b09f8b7e89..144cea72ae 100644 --- a/src/main/java/io/reactivex/observers/DefaultObserver.java +++ b/src/main/java/io/reactivex/observers/DefaultObserver.java @@ -62,11 +62,13 @@ * @param the value type */ public abstract class DefaultObserver implements Observer { - private Disposable s; + + private Disposable upstream; + @Override - public final void onSubscribe(@NonNull Disposable s) { - if (EndConsumerHelper.validate(this.s, s, getClass())) { - this.s = s; + public final void onSubscribe(@NonNull Disposable d) { + if (EndConsumerHelper.validate(this.upstream, d, getClass())) { + this.upstream = d; onStart(); } } @@ -75,9 +77,9 @@ public final void onSubscribe(@NonNull Disposable s) { * Cancels the upstream's disposable. */ protected final void cancel() { - Disposable s = this.s; - this.s = DisposableHelper.DISPOSED; - s.dispose(); + Disposable upstream = this.upstream; + this.upstream = DisposableHelper.DISPOSED; + upstream.dispose(); } /** * Called once the subscription has been set on this observer; override this diff --git a/src/main/java/io/reactivex/observers/DisposableCompletableObserver.java b/src/main/java/io/reactivex/observers/DisposableCompletableObserver.java index e07cb508c7..5ec519492c 100644 --- a/src/main/java/io/reactivex/observers/DisposableCompletableObserver.java +++ b/src/main/java/io/reactivex/observers/DisposableCompletableObserver.java @@ -52,11 +52,12 @@ * */ public abstract class DisposableCompletableObserver implements CompletableObserver, Disposable { - final AtomicReference s = new AtomicReference(); + + final AtomicReference upstream = new AtomicReference(); @Override - public final void onSubscribe(@NonNull Disposable s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + public final void onSubscribe(@NonNull Disposable d) { + if (EndConsumerHelper.setOnce(this.upstream, d, getClass())) { onStart(); } } @@ -69,11 +70,11 @@ protected void onStart() { @Override public final boolean isDisposed() { - return s.get() == DisposableHelper.DISPOSED; + return upstream.get() == DisposableHelper.DISPOSED; } @Override public final void dispose() { - DisposableHelper.dispose(s); + DisposableHelper.dispose(upstream); } } diff --git a/src/main/java/io/reactivex/observers/DisposableMaybeObserver.java b/src/main/java/io/reactivex/observers/DisposableMaybeObserver.java index ebf8a579f2..6cff241c22 100644 --- a/src/main/java/io/reactivex/observers/DisposableMaybeObserver.java +++ b/src/main/java/io/reactivex/observers/DisposableMaybeObserver.java @@ -62,11 +62,11 @@ */ public abstract class DisposableMaybeObserver implements MaybeObserver, Disposable { - final AtomicReference s = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); @Override - public final void onSubscribe(@NonNull Disposable s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + public final void onSubscribe(@NonNull Disposable d) { + if (EndConsumerHelper.setOnce(this.upstream, d, getClass())) { onStart(); } } @@ -79,11 +79,11 @@ protected void onStart() { @Override public final boolean isDisposed() { - return s.get() == DisposableHelper.DISPOSED; + return upstream.get() == DisposableHelper.DISPOSED; } @Override public final void dispose() { - DisposableHelper.dispose(s); + DisposableHelper.dispose(upstream); } } diff --git a/src/main/java/io/reactivex/observers/DisposableObserver.java b/src/main/java/io/reactivex/observers/DisposableObserver.java index c835b853a2..dccd973549 100644 --- a/src/main/java/io/reactivex/observers/DisposableObserver.java +++ b/src/main/java/io/reactivex/observers/DisposableObserver.java @@ -66,11 +66,11 @@ */ public abstract class DisposableObserver implements Observer, Disposable { - final AtomicReference s = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); @Override - public final void onSubscribe(@NonNull Disposable s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + public final void onSubscribe(@NonNull Disposable d) { + if (EndConsumerHelper.setOnce(this.upstream, d, getClass())) { onStart(); } } @@ -83,11 +83,11 @@ protected void onStart() { @Override public final boolean isDisposed() { - return s.get() == DisposableHelper.DISPOSED; + return upstream.get() == DisposableHelper.DISPOSED; } @Override public final void dispose() { - DisposableHelper.dispose(s); + DisposableHelper.dispose(upstream); } } diff --git a/src/main/java/io/reactivex/observers/DisposableSingleObserver.java b/src/main/java/io/reactivex/observers/DisposableSingleObserver.java index 2d339e3400..38224e0668 100644 --- a/src/main/java/io/reactivex/observers/DisposableSingleObserver.java +++ b/src/main/java/io/reactivex/observers/DisposableSingleObserver.java @@ -55,11 +55,11 @@ */ public abstract class DisposableSingleObserver implements SingleObserver, Disposable { - final AtomicReference s = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); @Override - public final void onSubscribe(@NonNull Disposable s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + public final void onSubscribe(@NonNull Disposable d) { + if (EndConsumerHelper.setOnce(this.upstream, d, getClass())) { onStart(); } } @@ -72,11 +72,11 @@ protected void onStart() { @Override public final boolean isDisposed() { - return s.get() == DisposableHelper.DISPOSED; + return upstream.get() == DisposableHelper.DISPOSED; } @Override public final void dispose() { - DisposableHelper.dispose(s); + DisposableHelper.dispose(upstream); } } diff --git a/src/main/java/io/reactivex/observers/ResourceCompletableObserver.java b/src/main/java/io/reactivex/observers/ResourceCompletableObserver.java index f4b4261807..ead4570ff9 100644 --- a/src/main/java/io/reactivex/observers/ResourceCompletableObserver.java +++ b/src/main/java/io/reactivex/observers/ResourceCompletableObserver.java @@ -74,7 +74,7 @@ */ public abstract class ResourceCompletableObserver implements CompletableObserver, Disposable { /** The active subscription. */ - private final AtomicReference s = new AtomicReference(); + private final AtomicReference upstream = new AtomicReference(); /** The resource composite, can never be null. */ private final ListCompositeDisposable resources = new ListCompositeDisposable(); @@ -92,8 +92,8 @@ public final void add(@NonNull Disposable resource) { } @Override - public final void onSubscribe(@NonNull Disposable s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + public final void onSubscribe(@NonNull Disposable d) { + if (EndConsumerHelper.setOnce(this.upstream, d, getClass())) { onStart(); } } @@ -116,7 +116,7 @@ protected void onStart() { */ @Override public final void dispose() { - if (DisposableHelper.dispose(s)) { + if (DisposableHelper.dispose(upstream)) { resources.dispose(); } } @@ -127,6 +127,6 @@ public final void dispose() { */ @Override public final boolean isDisposed() { - return DisposableHelper.isDisposed(s.get()); + return DisposableHelper.isDisposed(upstream.get()); } } diff --git a/src/main/java/io/reactivex/observers/ResourceMaybeObserver.java b/src/main/java/io/reactivex/observers/ResourceMaybeObserver.java index a48fb06872..ca603cf3b0 100644 --- a/src/main/java/io/reactivex/observers/ResourceMaybeObserver.java +++ b/src/main/java/io/reactivex/observers/ResourceMaybeObserver.java @@ -84,7 +84,7 @@ */ public abstract class ResourceMaybeObserver implements MaybeObserver, Disposable { /** The active subscription. */ - private final AtomicReference s = new AtomicReference(); + private final AtomicReference upstream = new AtomicReference(); /** The resource composite, can never be null. */ private final ListCompositeDisposable resources = new ListCompositeDisposable(); @@ -102,8 +102,8 @@ public final void add(@NonNull Disposable resource) { } @Override - public final void onSubscribe(@NonNull Disposable s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + public final void onSubscribe(@NonNull Disposable d) { + if (EndConsumerHelper.setOnce(this.upstream, d, getClass())) { onStart(); } } @@ -126,7 +126,7 @@ protected void onStart() { */ @Override public final void dispose() { - if (DisposableHelper.dispose(s)) { + if (DisposableHelper.dispose(upstream)) { resources.dispose(); } } @@ -137,6 +137,6 @@ public final void dispose() { */ @Override public final boolean isDisposed() { - return DisposableHelper.isDisposed(s.get()); + return DisposableHelper.isDisposed(upstream.get()); } } diff --git a/src/main/java/io/reactivex/observers/ResourceObserver.java b/src/main/java/io/reactivex/observers/ResourceObserver.java index f42353db13..f30d4475df 100644 --- a/src/main/java/io/reactivex/observers/ResourceObserver.java +++ b/src/main/java/io/reactivex/observers/ResourceObserver.java @@ -82,7 +82,7 @@ */ public abstract class ResourceObserver implements Observer, Disposable { /** The active subscription. */ - private final AtomicReference s = new AtomicReference(); + private final AtomicReference upstream = new AtomicReference(); /** The resource composite, can never be null. */ private final ListCompositeDisposable resources = new ListCompositeDisposable(); @@ -100,8 +100,8 @@ public final void add(@NonNull Disposable resource) { } @Override - public final void onSubscribe(Disposable s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + public final void onSubscribe(Disposable d) { + if (EndConsumerHelper.setOnce(this.upstream, d, getClass())) { onStart(); } } @@ -124,7 +124,7 @@ protected void onStart() { */ @Override public final void dispose() { - if (DisposableHelper.dispose(s)) { + if (DisposableHelper.dispose(upstream)) { resources.dispose(); } } @@ -135,6 +135,6 @@ public final void dispose() { */ @Override public final boolean isDisposed() { - return DisposableHelper.isDisposed(s.get()); + return DisposableHelper.isDisposed(upstream.get()); } } diff --git a/src/main/java/io/reactivex/observers/ResourceSingleObserver.java b/src/main/java/io/reactivex/observers/ResourceSingleObserver.java index 9f28fd0791..2f533b8d99 100644 --- a/src/main/java/io/reactivex/observers/ResourceSingleObserver.java +++ b/src/main/java/io/reactivex/observers/ResourceSingleObserver.java @@ -77,7 +77,7 @@ */ public abstract class ResourceSingleObserver implements SingleObserver, Disposable { /** The active subscription. */ - private final AtomicReference s = new AtomicReference(); + private final AtomicReference upstream = new AtomicReference(); /** The resource composite, can never be null. */ private final ListCompositeDisposable resources = new ListCompositeDisposable(); @@ -95,8 +95,8 @@ public final void add(@NonNull Disposable resource) { } @Override - public final void onSubscribe(@NonNull Disposable s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + public final void onSubscribe(@NonNull Disposable d) { + if (EndConsumerHelper.setOnce(this.upstream, d, getClass())) { onStart(); } } @@ -119,7 +119,7 @@ protected void onStart() { */ @Override public final void dispose() { - if (DisposableHelper.dispose(s)) { + if (DisposableHelper.dispose(upstream)) { resources.dispose(); } } @@ -130,6 +130,6 @@ public final void dispose() { */ @Override public final boolean isDisposed() { - return DisposableHelper.isDisposed(s.get()); + return DisposableHelper.isDisposed(upstream.get()); } } diff --git a/src/main/java/io/reactivex/observers/SafeObserver.java b/src/main/java/io/reactivex/observers/SafeObserver.java index a370f3799b..8dddcf1d9e 100644 --- a/src/main/java/io/reactivex/observers/SafeObserver.java +++ b/src/main/java/io/reactivex/observers/SafeObserver.java @@ -27,32 +27,32 @@ */ public final class SafeObserver implements Observer, Disposable { /** The actual Subscriber. */ - final Observer actual; + final Observer downstream; /** The subscription. */ - Disposable s; + Disposable upstream; /** Indicates a terminal state. */ boolean done; /** * Constructs a SafeObserver by wrapping the given actual Observer. - * @param actual the actual Observer to wrap, not null (not validated) + * @param downstream the actual Observer to wrap, not null (not validated) */ - public SafeObserver(@NonNull Observer actual) { - this.actual = actual; + public SafeObserver(@NonNull Observer downstream) { + this.downstream = downstream; } @Override - public void onSubscribe(@NonNull Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(@NonNull Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; try { - actual.onSubscribe(this); + downstream.onSubscribe(this); } catch (Throwable e) { Exceptions.throwIfFatal(e); done = true; // can't call onError because the actual's state may be corrupt at this point try { - s.dispose(); + d.dispose(); } catch (Throwable e1) { Exceptions.throwIfFatal(e1); RxJavaPlugins.onError(new CompositeException(e, e1)); @@ -66,12 +66,12 @@ public void onSubscribe(@NonNull Disposable s) { @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @Override @@ -79,7 +79,7 @@ public void onNext(@NonNull T t) { if (done) { return; } - if (s == null) { + if (upstream == null) { onNextNoSubscription(); return; } @@ -87,7 +87,7 @@ public void onNext(@NonNull T t) { if (t == null) { Throwable ex = new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."); try { - s.dispose(); + upstream.dispose(); } catch (Throwable e1) { Exceptions.throwIfFatal(e1); onError(new CompositeException(ex, e1)); @@ -98,11 +98,11 @@ public void onNext(@NonNull T t) { } try { - actual.onNext(t); + downstream.onNext(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); try { - s.dispose(); + upstream.dispose(); } catch (Throwable e1) { Exceptions.throwIfFatal(e1); onError(new CompositeException(e, e1)); @@ -118,7 +118,7 @@ void onNextNoSubscription() { Throwable ex = new NullPointerException("Subscription not set!"); try { - actual.onSubscribe(EmptyDisposable.INSTANCE); + downstream.onSubscribe(EmptyDisposable.INSTANCE); } catch (Throwable e) { Exceptions.throwIfFatal(e); // can't call onError because the actual's state may be corrupt at this point @@ -126,7 +126,7 @@ void onNextNoSubscription() { return; } try { - actual.onError(ex); + downstream.onError(ex); } catch (Throwable e) { Exceptions.throwIfFatal(e); // if onError failed, all that's left is to report the error to plugins @@ -142,11 +142,11 @@ public void onError(@NonNull Throwable t) { } done = true; - if (s == null) { + if (upstream == null) { Throwable npe = new NullPointerException("Subscription not set!"); try { - actual.onSubscribe(EmptyDisposable.INSTANCE); + downstream.onSubscribe(EmptyDisposable.INSTANCE); } catch (Throwable e) { Exceptions.throwIfFatal(e); // can't call onError because the actual's state may be corrupt at this point @@ -154,7 +154,7 @@ public void onError(@NonNull Throwable t) { return; } try { - actual.onError(new CompositeException(t, npe)); + downstream.onError(new CompositeException(t, npe)); } catch (Throwable e) { Exceptions.throwIfFatal(e); // if onError failed, all that's left is to report the error to plugins @@ -168,7 +168,7 @@ public void onError(@NonNull Throwable t) { } try { - actual.onError(t); + downstream.onError(t); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); @@ -184,13 +184,13 @@ public void onComplete() { done = true; - if (s == null) { + if (upstream == null) { onCompleteNoSubscription(); return; } try { - actual.onComplete(); + downstream.onComplete(); } catch (Throwable e) { Exceptions.throwIfFatal(e); RxJavaPlugins.onError(e); @@ -202,7 +202,7 @@ void onCompleteNoSubscription() { Throwable ex = new NullPointerException("Subscription not set!"); try { - actual.onSubscribe(EmptyDisposable.INSTANCE); + downstream.onSubscribe(EmptyDisposable.INSTANCE); } catch (Throwable e) { Exceptions.throwIfFatal(e); // can't call onError because the actual's state may be corrupt at this point @@ -210,7 +210,7 @@ void onCompleteNoSubscription() { return; } try { - actual.onError(ex); + downstream.onError(ex); } catch (Throwable e) { Exceptions.throwIfFatal(e); // if onError failed, all that's left is to report the error to plugins diff --git a/src/main/java/io/reactivex/observers/SerializedObserver.java b/src/main/java/io/reactivex/observers/SerializedObserver.java index ec2061ba97..d0cdd4eeab 100644 --- a/src/main/java/io/reactivex/observers/SerializedObserver.java +++ b/src/main/java/io/reactivex/observers/SerializedObserver.java @@ -31,12 +31,12 @@ * @param the value type */ public final class SerializedObserver implements Observer, Disposable { - final Observer actual; + final Observer downstream; final boolean delayError; static final int QUEUE_LINK_SIZE = 4; - Disposable s; + Disposable upstream; boolean emitting; AppendOnlyLinkedArrayList queue; @@ -45,10 +45,10 @@ public final class SerializedObserver implements Observer, Disposable { /** * Construct a SerializedObserver by wrapping the given actual Observer. - * @param actual the actual Observer, not null (not verified) + * @param downstream the actual Observer, not null (not verified) */ - public SerializedObserver(@NonNull Observer actual) { - this(actual, false); + public SerializedObserver(@NonNull Observer downstream) { + this(downstream, false); } /** @@ -59,28 +59,28 @@ public SerializedObserver(@NonNull Observer actual) { * @param delayError if true, errors are emitted after regular values have been emitted */ public SerializedObserver(@NonNull Observer actual, boolean delayError) { - this.actual = actual; + this.downstream = actual; this.delayError = delayError; } @Override - public void onSubscribe(@NonNull Disposable s) { - if (DisposableHelper.validate(this.s, s)) { - this.s = s; + public void onSubscribe(@NonNull Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; - actual.onSubscribe(this); + downstream.onSubscribe(this); } } @Override public void dispose() { - s.dispose(); + upstream.dispose(); } @Override public boolean isDisposed() { - return s.isDisposed(); + return upstream.isDisposed(); } @@ -90,7 +90,7 @@ public void onNext(@NonNull T t) { return; } if (t == null) { - s.dispose(); + upstream.dispose(); onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } @@ -110,7 +110,7 @@ public void onNext(@NonNull T t) { emitting = true; } - actual.onNext(t); + downstream.onNext(t); emitLoop(); } @@ -152,7 +152,7 @@ public void onError(@NonNull Throwable t) { return; } - actual.onError(t); + downstream.onError(t); // no need to loop because this onError is the last event } @@ -178,7 +178,7 @@ public void onComplete() { emitting = true; } - actual.onComplete(); + downstream.onComplete(); // no need to loop because this onComplete is the last event } @@ -194,7 +194,7 @@ void emitLoop() { queue = null; } - if (q.accept(actual)) { + if (q.accept(downstream)) { return; } } diff --git a/src/main/java/io/reactivex/observers/TestObserver.java b/src/main/java/io/reactivex/observers/TestObserver.java index 18d9b41faf..3909059b27 100644 --- a/src/main/java/io/reactivex/observers/TestObserver.java +++ b/src/main/java/io/reactivex/observers/TestObserver.java @@ -35,12 +35,12 @@ public class TestObserver extends BaseTestConsumer> implements Observer, Disposable, MaybeObserver, SingleObserver, CompletableObserver { /** The actual observer to forward events to. */ - private final Observer actual; + private final Observer downstream; /** Holds the current subscription if any. */ - private final AtomicReference subscription = new AtomicReference(); + private final AtomicReference upstream = new AtomicReference(); - private QueueDisposable qs; + private QueueDisposable qd; /** * Constructs a non-forwarding TestObserver. @@ -70,34 +70,34 @@ public TestObserver() { /** * Constructs a forwarding TestObserver. - * @param actual the actual Observer to forward events to + * @param downstream the actual Observer to forward events to */ - public TestObserver(Observer actual) { - this.actual = actual; + public TestObserver(Observer downstream) { + this.downstream = downstream; } @SuppressWarnings("unchecked") @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { lastThread = Thread.currentThread(); - if (s == null) { + if (d == null) { errors.add(new NullPointerException("onSubscribe received a null Subscription")); return; } - if (!subscription.compareAndSet(null, s)) { - s.dispose(); - if (subscription.get() != DisposableHelper.DISPOSED) { - errors.add(new IllegalStateException("onSubscribe received multiple subscriptions: " + s)); + if (!upstream.compareAndSet(null, d)) { + d.dispose(); + if (upstream.get() != DisposableHelper.DISPOSED) { + errors.add(new IllegalStateException("onSubscribe received multiple subscriptions: " + d)); } return; } if (initialFusionMode != 0) { - if (s instanceof QueueDisposable) { - qs = (QueueDisposable)s; + if (d instanceof QueueDisposable) { + qd = (QueueDisposable)d; - int m = qs.requestFusion(initialFusionMode); + int m = qd.requestFusion(initialFusionMode); establishedFusionMode = m; if (m == QueueDisposable.SYNC) { @@ -105,12 +105,12 @@ public void onSubscribe(Disposable s) { lastThread = Thread.currentThread(); try { T t; - while ((t = qs.poll()) != null) { + while ((t = qd.poll()) != null) { values.add(t); } completions++; - subscription.lazySet(DisposableHelper.DISPOSED); + upstream.lazySet(DisposableHelper.DISPOSED); } catch (Throwable ex) { // Exceptions.throwIfFatal(e); TODO add fatal exceptions? errors.add(ex); @@ -120,14 +120,14 @@ public void onSubscribe(Disposable s) { } } - actual.onSubscribe(s); + downstream.onSubscribe(d); } @Override public void onNext(T t) { if (!checkSubscriptionOnce) { checkSubscriptionOnce = true; - if (subscription.get() == null) { + if (upstream.get() == null) { errors.add(new IllegalStateException("onSubscribe not called in proper order")); } } @@ -136,13 +136,13 @@ public void onNext(T t) { if (establishedFusionMode == QueueDisposable.ASYNC) { try { - while ((t = qs.poll()) != null) { + while ((t = qd.poll()) != null) { values.add(t); } } catch (Throwable ex) { // Exceptions.throwIfFatal(e); TODO add fatal exceptions? errors.add(ex); - qs.dispose(); + qd.dispose(); } return; } @@ -153,14 +153,14 @@ public void onNext(T t) { errors.add(new NullPointerException("onNext received a null value")); } - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { if (!checkSubscriptionOnce) { checkSubscriptionOnce = true; - if (subscription.get() == null) { + if (upstream.get() == null) { errors.add(new IllegalStateException("onSubscribe not called in proper order")); } } @@ -173,7 +173,7 @@ public void onError(Throwable t) { errors.add(t); } - actual.onError(t); + downstream.onError(t); } finally { done.countDown(); } @@ -183,7 +183,7 @@ public void onError(Throwable t) { public void onComplete() { if (!checkSubscriptionOnce) { checkSubscriptionOnce = true; - if (subscription.get() == null) { + if (upstream.get() == null) { errors.add(new IllegalStateException("onSubscribe not called in proper order")); } } @@ -192,7 +192,7 @@ public void onComplete() { lastThread = Thread.currentThread(); completions++; - actual.onComplete(); + downstream.onComplete(); } finally { done.countDown(); } @@ -217,12 +217,12 @@ public final void cancel() { @Override public final void dispose() { - DisposableHelper.dispose(subscription); + DisposableHelper.dispose(upstream); } @Override public final boolean isDisposed() { - return DisposableHelper.isDisposed(subscription.get()); + return DisposableHelper.isDisposed(upstream.get()); } // state retrieval methods @@ -231,7 +231,7 @@ public final boolean isDisposed() { * @return true if this TestObserver received a subscription */ public final boolean hasSubscription() { - return subscription.get() != null; + return upstream.get() != null; } /** @@ -240,7 +240,7 @@ public final boolean hasSubscription() { */ @Override public final TestObserver assertSubscribed() { - if (subscription.get() == null) { + if (upstream.get() == null) { throw fail("Not subscribed!"); } return this; @@ -252,7 +252,7 @@ public final TestObserver assertSubscribed() { */ @Override public final TestObserver assertNotSubscribed() { - if (subscription.get() != null) { + if (upstream.get() != null) { throw fail("Subscribed!"); } else if (!errors.isEmpty()) { @@ -297,7 +297,7 @@ final TestObserver setInitialFusionMode(int mode) { final TestObserver assertFusionMode(int mode) { int m = establishedFusionMode; if (m != mode) { - if (qs != null) { + if (qd != null) { throw new AssertionError("Fusion mode different. Expected: " + fusionModeToString(mode) + ", actual: " + fusionModeToString(m)); } else { @@ -323,7 +323,7 @@ static String fusionModeToString(int mode) { * @return this */ final TestObserver assertFuseable() { - if (qs == null) { + if (qd == null) { throw new AssertionError("Upstream is not fuseable."); } return this; @@ -336,7 +336,7 @@ final TestObserver assertFuseable() { * @return this */ final TestObserver assertNotFuseable() { - if (qs != null) { + if (qd != null) { throw new AssertionError("Upstream is fuseable."); } return this; diff --git a/src/main/java/io/reactivex/processors/AsyncProcessor.java b/src/main/java/io/reactivex/processors/AsyncProcessor.java index 6ef3044d6d..e360d17eb3 100644 --- a/src/main/java/io/reactivex/processors/AsyncProcessor.java +++ b/src/main/java/io/reactivex/processors/AsyncProcessor.java @@ -390,7 +390,7 @@ public void cancel() { void onComplete() { if (!isCancelled()) { - actual.onComplete(); + downstream.onComplete(); } } @@ -398,7 +398,7 @@ void onError(Throwable t) { if (isCancelled()) { RxJavaPlugins.onError(t); } else { - actual.onError(t); + downstream.onError(t); } } } diff --git a/src/main/java/io/reactivex/processors/BehaviorProcessor.java b/src/main/java/io/reactivex/processors/BehaviorProcessor.java index 0c4af463e0..ff69ef4273 100644 --- a/src/main/java/io/reactivex/processors/BehaviorProcessor.java +++ b/src/main/java/io/reactivex/processors/BehaviorProcessor.java @@ -525,7 +525,7 @@ static final class BehaviorSubscription extends AtomicLong implements Subscri private static final long serialVersionUID = 3293175281126227086L; - final Subscriber actual; + final Subscriber downstream; final BehaviorProcessor state; boolean next; @@ -539,7 +539,7 @@ static final class BehaviorSubscription extends AtomicLong implements Subscri long index; BehaviorSubscription(Subscriber actual, BehaviorProcessor state) { - this.actual = actual; + this.downstream = actual; this.state = state; } @@ -629,24 +629,24 @@ public boolean test(Object o) { } if (NotificationLite.isComplete(o)) { - actual.onComplete(); + downstream.onComplete(); return true; } else if (NotificationLite.isError(o)) { - actual.onError(NotificationLite.getError(o)); + downstream.onError(NotificationLite.getError(o)); return true; } long r = get(); if (r != 0L) { - actual.onNext(NotificationLite.getValue(o)); + downstream.onNext(NotificationLite.getValue(o)); if (r != Long.MAX_VALUE) { decrementAndGet(); } return false; } cancel(); - actual.onError(new MissingBackpressureException("Could not deliver value due to lack of requests")); + downstream.onError(new MissingBackpressureException("Could not deliver value due to lack of requests")); return true; } diff --git a/src/main/java/io/reactivex/processors/MulticastProcessor.java b/src/main/java/io/reactivex/processors/MulticastProcessor.java index 3d0923a8ab..317244313f 100644 --- a/src/main/java/io/reactivex/processors/MulticastProcessor.java +++ b/src/main/java/io/reactivex/processors/MulticastProcessor.java @@ -580,14 +580,14 @@ static final class MulticastSubscription extends AtomicLong implements Subscr private static final long serialVersionUID = -363282618957264509L; - final Subscriber actual; + final Subscriber downstream; final MulticastProcessor parent; long emitted; MulticastSubscription(Subscriber actual, MulticastProcessor parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } @@ -621,19 +621,19 @@ public void cancel() { void onNext(T t) { if (get() != Long.MIN_VALUE) { emitted++; - actual.onNext(t); + downstream.onNext(t); } } void onError(Throwable t) { if (get() != Long.MIN_VALUE) { - actual.onError(t); + downstream.onError(t); } } void onComplete() { if (get() != Long.MIN_VALUE) { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/main/java/io/reactivex/processors/PublishProcessor.java b/src/main/java/io/reactivex/processors/PublishProcessor.java index 38f0aa874c..713fc4190f 100644 --- a/src/main/java/io/reactivex/processors/PublishProcessor.java +++ b/src/main/java/io/reactivex/processors/PublishProcessor.java @@ -338,7 +338,7 @@ static final class PublishSubscription extends AtomicLong implements Subscrip private static final long serialVersionUID = 3562861878281475070L; /** The actual subscriber. */ - final Subscriber actual; + final Subscriber downstream; /** The parent processor servicing this subscriber. */ final PublishProcessor parent; @@ -348,7 +348,7 @@ static final class PublishSubscription extends AtomicLong implements Subscrip * @param parent the parent PublishProcessor */ PublishSubscription(Subscriber actual, PublishProcessor parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } @@ -358,17 +358,17 @@ public void onNext(T t) { return; } if (r != 0L) { - actual.onNext(t); + downstream.onNext(t); BackpressureHelper.producedCancel(this, 1); } else { cancel(); - actual.onError(new MissingBackpressureException("Could not emit value due to lack of requests")); + downstream.onError(new MissingBackpressureException("Could not emit value due to lack of requests")); } } public void onError(Throwable t) { if (get() != Long.MIN_VALUE) { - actual.onError(t); + downstream.onError(t); } else { RxJavaPlugins.onError(t); } @@ -376,7 +376,7 @@ public void onError(Throwable t) { public void onComplete() { if (get() != Long.MIN_VALUE) { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/processors/ReplayProcessor.java b/src/main/java/io/reactivex/processors/ReplayProcessor.java index 95bcf5d263..868d465748 100644 --- a/src/main/java/io/reactivex/processors/ReplayProcessor.java +++ b/src/main/java/io/reactivex/processors/ReplayProcessor.java @@ -589,7 +589,7 @@ interface ReplayBuffer { static final class ReplaySubscription extends AtomicInteger implements Subscription { private static final long serialVersionUID = 466549804534799122L; - final Subscriber actual; + final Subscriber downstream; final ReplayProcessor state; Object index; @@ -601,7 +601,7 @@ static final class ReplaySubscription extends AtomicInteger implements Subscr long emitted; ReplaySubscription(Subscriber actual, ReplayProcessor state) { - this.actual = actual; + this.downstream = actual; this.state = state; this.requested = new AtomicLong(); } @@ -701,7 +701,7 @@ public void replay(ReplaySubscription rs) { int missed = 1; final List b = buffer; - final Subscriber a = rs.actual; + final Subscriber a = rs.downstream; Integer indexObject = (Integer)rs.index; int index; @@ -940,7 +940,7 @@ public void replay(ReplaySubscription rs) { } int missed = 1; - final Subscriber a = rs.actual; + final Subscriber a = rs.downstream; Node index = (Node)rs.index; if (index == null) { @@ -1227,7 +1227,7 @@ public void replay(ReplaySubscription rs) { } int missed = 1; - final Subscriber a = rs.actual; + final Subscriber a = rs.downstream; TimedNode index = (TimedNode)rs.index; if (index == null) { diff --git a/src/main/java/io/reactivex/processors/UnicastProcessor.java b/src/main/java/io/reactivex/processors/UnicastProcessor.java index c9fb44f7eb..c754629374 100644 --- a/src/main/java/io/reactivex/processors/UnicastProcessor.java +++ b/src/main/java/io/reactivex/processors/UnicastProcessor.java @@ -160,7 +160,7 @@ public final class UnicastProcessor extends FlowableProcessor { Throwable error; - final AtomicReference> actual; + final AtomicReference> downstream; volatile boolean cancelled; @@ -282,7 +282,7 @@ public static UnicastProcessor create(int capacityHint, Runnable onCancel this.queue = new SpscLinkedArrayQueue(ObjectHelper.verifyPositive(capacityHint, "capacityHint")); this.onTerminate = new AtomicReference(onTerminate); this.delayError = delayError; - this.actual = new AtomicReference>(); + this.downstream = new AtomicReference>(); this.once = new AtomicBoolean(); this.wip = new UnicastQueueSubscription(); this.requested = new AtomicLong(); @@ -348,7 +348,7 @@ void drainFused(Subscriber a) { if (cancelled) { q.clear(); - actual.lazySet(null); + downstream.lazySet(null); return; } @@ -356,14 +356,14 @@ void drainFused(Subscriber a) { if (failFast && d && error != null) { q.clear(); - actual.lazySet(null); + downstream.lazySet(null); a.onError(error); return; } a.onNext(null); if (d) { - actual.lazySet(null); + downstream.lazySet(null); Throwable ex = error; if (ex != null) { @@ -388,7 +388,7 @@ void drain() { int missed = 1; - Subscriber a = actual.get(); + Subscriber a = downstream.get(); for (;;) { if (a != null) { @@ -404,27 +404,27 @@ void drain() { if (missed == 0) { break; } - a = actual.get(); + a = downstream.get(); } } boolean checkTerminated(boolean failFast, boolean d, boolean empty, Subscriber a, SpscLinkedArrayQueue q) { if (cancelled) { q.clear(); - actual.lazySet(null); + downstream.lazySet(null); return true; } if (d) { if (failFast && error != null) { q.clear(); - actual.lazySet(null); + downstream.lazySet(null); a.onError(error); return true; } if (empty) { Throwable e = error; - actual.lazySet(null); + downstream.lazySet(null); if (e != null) { a.onError(e); } else { @@ -493,9 +493,9 @@ protected void subscribeActual(Subscriber s) { if (!once.get() && once.compareAndSet(false, true)) { s.onSubscribe(wip); - actual.set(s); + downstream.set(s); if (cancelled) { - actual.lazySet(null); + downstream.lazySet(null); } else { drain(); } @@ -554,7 +554,7 @@ public void cancel() { if (!enableOperatorFusion) { if (wip.getAndIncrement() == 0) { queue.clear(); - actual.lazySet(null); + downstream.lazySet(null); } } } @@ -562,7 +562,7 @@ public void cancel() { @Override public boolean hasSubscribers() { - return actual.get() != null; + return downstream.get() != null; } @Override diff --git a/src/main/java/io/reactivex/subjects/AsyncSubject.java b/src/main/java/io/reactivex/subjects/AsyncSubject.java index 335b183e1a..ce9b2dcedb 100644 --- a/src/main/java/io/reactivex/subjects/AsyncSubject.java +++ b/src/main/java/io/reactivex/subjects/AsyncSubject.java @@ -145,9 +145,9 @@ public static AsyncSubject create() { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { if (subscribers.get() == TERMINATED) { - s.dispose(); + d.dispose(); } } @@ -380,7 +380,7 @@ public void dispose() { void onComplete() { if (!isDisposed()) { - actual.onComplete(); + downstream.onComplete(); } } @@ -388,7 +388,7 @@ void onError(Throwable t) { if (isDisposed()) { RxJavaPlugins.onError(t); } else { - actual.onError(t); + downstream.onError(t); } } } diff --git a/src/main/java/io/reactivex/subjects/BehaviorSubject.java b/src/main/java/io/reactivex/subjects/BehaviorSubject.java index d147f24b85..7f13dfb432 100644 --- a/src/main/java/io/reactivex/subjects/BehaviorSubject.java +++ b/src/main/java/io/reactivex/subjects/BehaviorSubject.java @@ -249,9 +249,9 @@ protected void subscribeActual(Observer observer) { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { if (terminalEvent.get() != null) { - s.dispose(); + d.dispose(); } } @@ -470,7 +470,7 @@ void setCurrent(Object o) { static final class BehaviorDisposable implements Disposable, NonThrowingPredicate { - final Observer actual; + final Observer downstream; final BehaviorSubject state; boolean next; @@ -484,7 +484,7 @@ static final class BehaviorDisposable implements Disposable, NonThrowingPredi long index; BehaviorDisposable(Observer actual, BehaviorSubject state) { - this.actual = actual; + this.downstream = actual; this.state = state; } @@ -567,7 +567,7 @@ void emitNext(Object value, long stateIndex) { @Override public boolean test(Object o) { - return cancelled || NotificationLite.accept(o, actual); + return cancelled || NotificationLite.accept(o, downstream); } void emitLoop() { diff --git a/src/main/java/io/reactivex/subjects/CompletableSubject.java b/src/main/java/io/reactivex/subjects/CompletableSubject.java index 2e1b72ec9c..328e35175f 100644 --- a/src/main/java/io/reactivex/subjects/CompletableSubject.java +++ b/src/main/java/io/reactivex/subjects/CompletableSubject.java @@ -125,7 +125,7 @@ public void onError(Throwable e) { if (once.compareAndSet(false, true)) { this.error = e; for (CompletableDisposable md : observers.getAndSet(TERMINATED)) { - md.actual.onError(e); + md.downstream.onError(e); } } else { RxJavaPlugins.onError(e); @@ -136,7 +136,7 @@ public void onError(Throwable e) { public void onComplete() { if (once.compareAndSet(false, true)) { for (CompletableDisposable md : observers.getAndSet(TERMINATED)) { - md.actual.onComplete(); + md.downstream.onComplete(); } } } @@ -260,10 +260,10 @@ static final class CompletableDisposable extends AtomicReference implements Disposable { private static final long serialVersionUID = -7650903191002190468L; - final CompletableObserver actual; + final CompletableObserver downstream; CompletableDisposable(CompletableObserver actual, CompletableSubject parent) { - this.actual = actual; + this.downstream = actual; lazySet(parent); } diff --git a/src/main/java/io/reactivex/subjects/MaybeSubject.java b/src/main/java/io/reactivex/subjects/MaybeSubject.java index 61b80445af..ef9128c4f6 100644 --- a/src/main/java/io/reactivex/subjects/MaybeSubject.java +++ b/src/main/java/io/reactivex/subjects/MaybeSubject.java @@ -154,7 +154,7 @@ public void onSuccess(T value) { if (once.compareAndSet(false, true)) { this.value = value; for (MaybeDisposable md : observers.getAndSet(TERMINATED)) { - md.actual.onSuccess(value); + md.downstream.onSuccess(value); } } } @@ -166,7 +166,7 @@ public void onError(Throwable e) { if (once.compareAndSet(false, true)) { this.error = e; for (MaybeDisposable md : observers.getAndSet(TERMINATED)) { - md.actual.onError(e); + md.downstream.onError(e); } } else { RxJavaPlugins.onError(e); @@ -178,7 +178,7 @@ public void onError(Throwable e) { public void onComplete() { if (once.compareAndSet(false, true)) { for (MaybeDisposable md : observers.getAndSet(TERMINATED)) { - md.actual.onComplete(); + md.downstream.onComplete(); } } } @@ -328,10 +328,10 @@ static final class MaybeDisposable extends AtomicReference> implements Disposable { private static final long serialVersionUID = -7650903191002190468L; - final MaybeObserver actual; + final MaybeObserver downstream; MaybeDisposable(MaybeObserver actual, MaybeSubject parent) { - this.actual = actual; + this.downstream = actual; lazySet(parent); } diff --git a/src/main/java/io/reactivex/subjects/PublishSubject.java b/src/main/java/io/reactivex/subjects/PublishSubject.java index b99fe9f6cc..b97af134ca 100644 --- a/src/main/java/io/reactivex/subjects/PublishSubject.java +++ b/src/main/java/io/reactivex/subjects/PublishSubject.java @@ -216,17 +216,17 @@ void remove(PublishDisposable ps) { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { if (subscribers.get() == TERMINATED) { - s.dispose(); + d.dispose(); } } @Override public void onNext(T t) { ObjectHelper.requireNonNull(t, "onNext called with null. Null values are generally not allowed in 2.x operators and sources."); - for (PublishDisposable s : subscribers.get()) { - s.onNext(t); + for (PublishDisposable pd : subscribers.get()) { + pd.onNext(t); } } @@ -240,8 +240,8 @@ public void onError(Throwable t) { } error = t; - for (PublishDisposable s : subscribers.getAndSet(TERMINATED)) { - s.onError(t); + for (PublishDisposable pd : subscribers.getAndSet(TERMINATED)) { + pd.onError(t); } } @@ -251,8 +251,8 @@ public void onComplete() { if (subscribers.get() == TERMINATED) { return; } - for (PublishDisposable s : subscribers.getAndSet(TERMINATED)) { - s.onComplete(); + for (PublishDisposable pd : subscribers.getAndSet(TERMINATED)) { + pd.onComplete(); } } @@ -290,7 +290,7 @@ static final class PublishDisposable extends AtomicBoolean implements Disposa private static final long serialVersionUID = 3562861878281475070L; /** The actual subscriber. */ - final Observer actual; + final Observer downstream; /** The subject state. */ final PublishSubject parent; @@ -300,13 +300,13 @@ static final class PublishDisposable extends AtomicBoolean implements Disposa * @param parent the parent PublishProcessor */ PublishDisposable(Observer actual, PublishSubject parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } public void onNext(T t) { if (!get()) { - actual.onNext(t); + downstream.onNext(t); } } @@ -314,13 +314,13 @@ public void onError(Throwable t) { if (get()) { RxJavaPlugins.onError(t); } else { - actual.onError(t); + downstream.onError(t); } } public void onComplete() { if (!get()) { - actual.onComplete(); + downstream.onComplete(); } } diff --git a/src/main/java/io/reactivex/subjects/ReplaySubject.java b/src/main/java/io/reactivex/subjects/ReplaySubject.java index 9454de50d0..344ef99fee 100644 --- a/src/main/java/io/reactivex/subjects/ReplaySubject.java +++ b/src/main/java/io/reactivex/subjects/ReplaySubject.java @@ -332,9 +332,9 @@ protected void subscribeActual(Observer observer) { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { if (done) { - s.dispose(); + d.dispose(); } } @@ -597,7 +597,7 @@ interface ReplayBuffer { static final class ReplayDisposable extends AtomicInteger implements Disposable { private static final long serialVersionUID = 466549804534799122L; - final Observer actual; + final Observer downstream; final ReplaySubject state; Object index; @@ -605,7 +605,7 @@ static final class ReplayDisposable extends AtomicInteger implements Disposab volatile boolean cancelled; ReplayDisposable(Observer actual, ReplaySubject state) { - this.actual = actual; + this.downstream = actual; this.state = state; } @@ -723,7 +723,7 @@ public void replay(ReplayDisposable rs) { int missed = 1; final List b = buffer; - final Observer a = rs.actual; + final Observer a = rs.downstream; Integer indexObject = (Integer)rs.index; int index; @@ -957,7 +957,7 @@ public void replay(ReplayDisposable rs) { } int missed = 1; - final Observer a = rs.actual; + final Observer a = rs.downstream; Node index = (Node)rs.index; if (index == null) { @@ -1247,7 +1247,7 @@ public void replay(ReplayDisposable rs) { } int missed = 1; - final Observer a = rs.actual; + final Observer a = rs.downstream; TimedNode index = (TimedNode)rs.index; if (index == null) { diff --git a/src/main/java/io/reactivex/subjects/SerializedSubject.java b/src/main/java/io/reactivex/subjects/SerializedSubject.java index 54ffb596a5..5b8bc16204 100644 --- a/src/main/java/io/reactivex/subjects/SerializedSubject.java +++ b/src/main/java/io/reactivex/subjects/SerializedSubject.java @@ -51,7 +51,7 @@ protected void subscribeActual(Observer observer) { @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { boolean cancel; if (!done) { synchronized (this) { @@ -64,7 +64,7 @@ public void onSubscribe(Disposable s) { q = new AppendOnlyLinkedArrayList(4); queue = q; } - q.add(NotificationLite.disposable(s)); + q.add(NotificationLite.disposable(d)); return; } emitting = true; @@ -75,9 +75,9 @@ public void onSubscribe(Disposable s) { cancel = true; } if (cancel) { - s.dispose(); + d.dispose(); } else { - actual.onSubscribe(s); + actual.onSubscribe(d); emitLoop(); } } diff --git a/src/main/java/io/reactivex/subjects/SingleSubject.java b/src/main/java/io/reactivex/subjects/SingleSubject.java index ff07b75845..cd9e3a2cd4 100644 --- a/src/main/java/io/reactivex/subjects/SingleSubject.java +++ b/src/main/java/io/reactivex/subjects/SingleSubject.java @@ -138,7 +138,7 @@ public void onSuccess(@NonNull T value) { if (once.compareAndSet(false, true)) { this.value = value; for (SingleDisposable md : observers.getAndSet(TERMINATED)) { - md.actual.onSuccess(value); + md.downstream.onSuccess(value); } } } @@ -150,7 +150,7 @@ public void onError(@NonNull Throwable e) { if (once.compareAndSet(false, true)) { this.error = e; for (SingleDisposable md : observers.getAndSet(TERMINATED)) { - md.actual.onError(e); + md.downstream.onError(e); } } else { RxJavaPlugins.onError(e); @@ -289,10 +289,10 @@ static final class SingleDisposable extends AtomicReference> implements Disposable { private static final long serialVersionUID = -7650903191002190468L; - final SingleObserver actual; + final SingleObserver downstream; SingleDisposable(SingleObserver actual, SingleSubject parent) { - this.actual = actual; + this.downstream = actual; lazySet(parent); } diff --git a/src/main/java/io/reactivex/subjects/UnicastSubject.java b/src/main/java/io/reactivex/subjects/UnicastSubject.java index e6cc271073..72f0563637 100644 --- a/src/main/java/io/reactivex/subjects/UnicastSubject.java +++ b/src/main/java/io/reactivex/subjects/UnicastSubject.java @@ -146,7 +146,7 @@ public final class UnicastSubject extends Subject { final SpscLinkedArrayQueue queue; /** The single Observer. */ - final AtomicReference> actual; + final AtomicReference> downstream; /** The optional callback when the Subject gets cancelled or terminates. */ final AtomicReference onTerminate; @@ -263,7 +263,7 @@ public static UnicastSubject create(boolean delayError) { this.queue = new SpscLinkedArrayQueue(ObjectHelper.verifyPositive(capacityHint, "capacityHint")); this.onTerminate = new AtomicReference(); this.delayError = delayError; - this.actual = new AtomicReference>(); + this.downstream = new AtomicReference>(); this.once = new AtomicBoolean(); this.wip = new UnicastQueueDisposable(); } @@ -293,7 +293,7 @@ public static UnicastSubject create(boolean delayError) { this.queue = new SpscLinkedArrayQueue(ObjectHelper.verifyPositive(capacityHint, "capacityHint")); this.onTerminate = new AtomicReference(ObjectHelper.requireNonNull(onTerminate, "onTerminate")); this.delayError = delayError; - this.actual = new AtomicReference>(); + this.downstream = new AtomicReference>(); this.once = new AtomicBoolean(); this.wip = new UnicastQueueDisposable(); } @@ -302,9 +302,9 @@ public static UnicastSubject create(boolean delayError) { protected void subscribeActual(Observer observer) { if (!once.get() && once.compareAndSet(false, true)) { observer.onSubscribe(wip); - actual.lazySet(observer); // full barrier in drain + downstream.lazySet(observer); // full barrier in drain if (disposed) { - actual.lazySet(null); + downstream.lazySet(null); return; } drain(); @@ -321,9 +321,9 @@ void doTerminate() { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { if (done || disposed) { - s.dispose(); + d.dispose(); } } @@ -373,7 +373,7 @@ void drainNormal(Observer a) { for (;;) { if (disposed) { - actual.lazySet(null); + downstream.lazySet(null); q.clear(); return; } @@ -420,7 +420,7 @@ void drainFused(Observer a) { for (;;) { if (disposed) { - actual.lazySet(null); + downstream.lazySet(null); q.clear(); return; } @@ -447,7 +447,7 @@ void drainFused(Observer a) { } void errorOrComplete(Observer a) { - actual.lazySet(null); + downstream.lazySet(null); Throwable ex = error; if (ex != null) { a.onError(ex); @@ -459,7 +459,7 @@ void errorOrComplete(Observer a) { boolean failedFast(final SimpleQueue q, Observer a) { Throwable ex = error; if (ex != null) { - actual.lazySet(null); + downstream.lazySet(null); q.clear(); a.onError(ex); return true; @@ -473,7 +473,7 @@ void drain() { return; } - Observer a = actual.get(); + Observer a = downstream.get(); int missed = 1; for (;;) { @@ -492,13 +492,13 @@ void drain() { break; } - a = actual.get(); + a = downstream.get(); } } @Override public boolean hasObservers() { - return actual.get() != null; + return downstream.get() != null; } @Override @@ -557,9 +557,9 @@ public void dispose() { doTerminate(); - actual.lazySet(null); + downstream.lazySet(null); if (wip.getAndIncrement() == 0) { - actual.lazySet(null); + downstream.lazySet(null); queue.clear(); } } diff --git a/src/main/java/io/reactivex/subscribers/DefaultSubscriber.java b/src/main/java/io/reactivex/subscribers/DefaultSubscriber.java index 0b6c538cf9..3038a955fd 100644 --- a/src/main/java/io/reactivex/subscribers/DefaultSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/DefaultSubscriber.java @@ -73,11 +73,13 @@ * */ public abstract class DefaultSubscriber implements FlowableSubscriber { - private Subscription s; + + Subscription upstream; + @Override public final void onSubscribe(Subscription s) { - if (EndConsumerHelper.validate(this.s, s, getClass())) { - this.s = s; + if (EndConsumerHelper.validate(this.upstream, s, getClass())) { + this.upstream = s; onStart(); } } @@ -87,7 +89,7 @@ public final void onSubscribe(Subscription s) { * @param n the request amount, positive */ protected final void request(long n) { - Subscription s = this.s; + Subscription s = this.upstream; if (s != null) { s.request(n); } @@ -97,8 +99,8 @@ protected final void request(long n) { * Cancels the upstream's Subscription. */ protected final void cancel() { - Subscription s = this.s; - this.s = SubscriptionHelper.CANCELLED; + Subscription s = this.upstream; + this.upstream = SubscriptionHelper.CANCELLED; s.cancel(); } /** diff --git a/src/main/java/io/reactivex/subscribers/SafeSubscriber.java b/src/main/java/io/reactivex/subscribers/SafeSubscriber.java index 7c17a472d2..a7c1fb3ad6 100644 --- a/src/main/java/io/reactivex/subscribers/SafeSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/SafeSubscriber.java @@ -27,26 +27,26 @@ */ public final class SafeSubscriber implements FlowableSubscriber, Subscription { /** The actual Subscriber. */ - final Subscriber actual; + final Subscriber downstream; /** The subscription. */ - Subscription s; + Subscription upstream; /** Indicates a terminal state. */ boolean done; /** * Constructs a SafeSubscriber by wrapping the given actual Subscriber. - * @param actual the actual Subscriber to wrap, not null (not validated) + * @param downstream the actual Subscriber to wrap, not null (not validated) */ - public SafeSubscriber(Subscriber actual) { - this.actual = actual; + public SafeSubscriber(Subscriber downstream) { + this.downstream = downstream; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.s, s)) { - this.s = s; + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; try { - actual.onSubscribe(this); + downstream.onSubscribe(this); } catch (Throwable e) { Exceptions.throwIfFatal(e); done = true; @@ -68,7 +68,7 @@ public void onNext(T t) { if (done) { return; } - if (s == null) { + if (upstream == null) { onNextNoSubscription(); return; } @@ -76,7 +76,7 @@ public void onNext(T t) { if (t == null) { Throwable ex = new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."); try { - s.cancel(); + upstream.cancel(); } catch (Throwable e1) { Exceptions.throwIfFatal(e1); onError(new CompositeException(ex, e1)); @@ -87,11 +87,11 @@ public void onNext(T t) { } try { - actual.onNext(t); + downstream.onNext(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); try { - s.cancel(); + upstream.cancel(); } catch (Throwable e1) { Exceptions.throwIfFatal(e1); onError(new CompositeException(e, e1)); @@ -106,7 +106,7 @@ void onNextNoSubscription() { Throwable ex = new NullPointerException("Subscription not set!"); try { - actual.onSubscribe(EmptySubscription.INSTANCE); + downstream.onSubscribe(EmptySubscription.INSTANCE); } catch (Throwable e) { Exceptions.throwIfFatal(e); // can't call onError because the actual's state may be corrupt at this point @@ -114,7 +114,7 @@ void onNextNoSubscription() { return; } try { - actual.onError(ex); + downstream.onError(ex); } catch (Throwable e) { Exceptions.throwIfFatal(e); // if onError failed, all that's left is to report the error to plugins @@ -130,11 +130,11 @@ public void onError(Throwable t) { } done = true; - if (s == null) { + if (upstream == null) { Throwable npe = new NullPointerException("Subscription not set!"); try { - actual.onSubscribe(EmptySubscription.INSTANCE); + downstream.onSubscribe(EmptySubscription.INSTANCE); } catch (Throwable e) { Exceptions.throwIfFatal(e); // can't call onError because the actual's state may be corrupt at this point @@ -142,7 +142,7 @@ public void onError(Throwable t) { return; } try { - actual.onError(new CompositeException(t, npe)); + downstream.onError(new CompositeException(t, npe)); } catch (Throwable e) { Exceptions.throwIfFatal(e); // if onError failed, all that's left is to report the error to plugins @@ -156,7 +156,7 @@ public void onError(Throwable t) { } try { - actual.onError(t); + downstream.onError(t); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); @@ -171,14 +171,14 @@ public void onComplete() { } done = true; - if (s == null) { + if (upstream == null) { onCompleteNoSubscription(); return; } try { - actual.onComplete(); + downstream.onComplete(); } catch (Throwable e) { Exceptions.throwIfFatal(e); RxJavaPlugins.onError(e); @@ -190,7 +190,7 @@ void onCompleteNoSubscription() { Throwable ex = new NullPointerException("Subscription not set!"); try { - actual.onSubscribe(EmptySubscription.INSTANCE); + downstream.onSubscribe(EmptySubscription.INSTANCE); } catch (Throwable e) { Exceptions.throwIfFatal(e); // can't call onError because the actual's state may be corrupt at this point @@ -198,7 +198,7 @@ void onCompleteNoSubscription() { return; } try { - actual.onError(ex); + downstream.onError(ex); } catch (Throwable e) { Exceptions.throwIfFatal(e); // if onError failed, all that's left is to report the error to plugins @@ -209,11 +209,11 @@ void onCompleteNoSubscription() { @Override public void request(long n) { try { - s.request(n); + upstream.request(n); } catch (Throwable e) { Exceptions.throwIfFatal(e); try { - s.cancel(); + upstream.cancel(); } catch (Throwable e1) { Exceptions.throwIfFatal(e1); RxJavaPlugins.onError(new CompositeException(e, e1)); @@ -226,7 +226,7 @@ public void request(long n) { @Override public void cancel() { try { - s.cancel(); + upstream.cancel(); } catch (Throwable e1) { Exceptions.throwIfFatal(e1); RxJavaPlugins.onError(e1); diff --git a/src/main/java/io/reactivex/subscribers/SerializedSubscriber.java b/src/main/java/io/reactivex/subscribers/SerializedSubscriber.java index 9743518eea..4e1b147d8e 100644 --- a/src/main/java/io/reactivex/subscribers/SerializedSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/SerializedSubscriber.java @@ -31,12 +31,12 @@ * @param the value type */ public final class SerializedSubscriber implements FlowableSubscriber, Subscription { - final Subscriber actual; + final Subscriber downstream; final boolean delayError; static final int QUEUE_LINK_SIZE = 4; - Subscription subscription; + Subscription upstream; boolean emitting; AppendOnlyLinkedArrayList queue; @@ -45,10 +45,10 @@ public final class SerializedSubscriber implements FlowableSubscriber, Sub /** * Construct a SerializedSubscriber by wrapping the given actual Subscriber. - * @param actual the actual Subscriber, not null (not verified) + * @param downstream the actual Subscriber, not null (not verified) */ - public SerializedSubscriber(Subscriber actual) { - this(actual, false); + public SerializedSubscriber(Subscriber downstream) { + this(downstream, false); } /** @@ -59,15 +59,15 @@ public SerializedSubscriber(Subscriber actual) { * @param delayError if true, errors are emitted after regular values have been emitted */ public SerializedSubscriber(Subscriber actual, boolean delayError) { - this.actual = actual; + this.downstream = actual; this.delayError = delayError; } @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.validate(this.subscription, s)) { - this.subscription = s; - actual.onSubscribe(this); + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); } } @@ -77,7 +77,7 @@ public void onNext(T t) { return; } if (t == null) { - subscription.cancel(); + upstream.cancel(); onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } @@ -97,7 +97,7 @@ public void onNext(T t) { emitting = true; } - actual.onNext(t); + downstream.onNext(t); emitLoop(); } @@ -139,7 +139,7 @@ public void onError(Throwable t) { return; } - actual.onError(t); + downstream.onError(t); // no need to loop because this onError is the last event } @@ -165,7 +165,7 @@ public void onComplete() { emitting = true; } - actual.onComplete(); + downstream.onComplete(); // no need to loop because this onComplete is the last event } @@ -181,7 +181,7 @@ void emitLoop() { queue = null; } - if (q.accept(actual)) { + if (q.accept(downstream)) { return; } } @@ -189,11 +189,11 @@ void emitLoop() { @Override public void request(long n) { - subscription.request(n); + upstream.request(n); } @Override public void cancel() { - subscription.cancel(); + upstream.cancel(); } } diff --git a/src/main/java/io/reactivex/subscribers/TestSubscriber.java b/src/main/java/io/reactivex/subscribers/TestSubscriber.java index 07a63a4753..30c1a22b03 100644 --- a/src/main/java/io/reactivex/subscribers/TestSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/TestSubscriber.java @@ -41,13 +41,13 @@ public class TestSubscriber extends BaseTestConsumer> implements FlowableSubscriber, Subscription, Disposable { /** The actual subscriber to forward events to. */ - private final Subscriber actual; + private final Subscriber downstream; /** Makes sure the incoming Subscriptions get cancelled immediately. */ private volatile boolean cancelled; /** Holds the current subscription if any. */ - private final AtomicReference subscription; + private final AtomicReference upstream; /** Holds the requested amount until a subscription arrives. */ private final AtomicLong missedRequested; @@ -102,10 +102,10 @@ public TestSubscriber(long initialRequest) { /** * Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped subscriber. - * @param actual the actual Subscriber to forward events to + * @param downstream the actual Subscriber to forward events to */ - public TestSubscriber(Subscriber actual) { - this(actual, Long.MAX_VALUE); + public TestSubscriber(Subscriber downstream) { + this(downstream, Long.MAX_VALUE); } /** @@ -120,8 +120,8 @@ public TestSubscriber(Subscriber actual, long initialRequest) { if (initialRequest < 0) { throw new IllegalArgumentException("Negative initial request not allowed"); } - this.actual = actual; - this.subscription = new AtomicReference(); + this.downstream = actual; + this.upstream = new AtomicReference(); this.missedRequested = new AtomicLong(initialRequest); } @@ -134,9 +134,9 @@ public void onSubscribe(Subscription s) { errors.add(new NullPointerException("onSubscribe received a null Subscription")); return; } - if (!subscription.compareAndSet(null, s)) { + if (!upstream.compareAndSet(null, s)) { s.cancel(); - if (subscription.get() != SubscriptionHelper.CANCELLED) { + if (upstream.get() != SubscriptionHelper.CANCELLED) { errors.add(new IllegalStateException("onSubscribe received multiple subscriptions: " + s)); } return; @@ -168,7 +168,7 @@ public void onSubscribe(Subscription s) { } - actual.onSubscribe(s); + downstream.onSubscribe(s); long mr = missedRequested.getAndSet(0L); if (mr != 0L) { @@ -189,7 +189,7 @@ protected void onStart() { public void onNext(T t) { if (!checkSubscriptionOnce) { checkSubscriptionOnce = true; - if (subscription.get() == null) { + if (upstream.get() == null) { errors.add(new IllegalStateException("onSubscribe not called in proper order")); } } @@ -214,14 +214,14 @@ public void onNext(T t) { errors.add(new NullPointerException("onNext received a null value")); } - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { if (!checkSubscriptionOnce) { checkSubscriptionOnce = true; - if (subscription.get() == null) { + if (upstream.get() == null) { errors.add(new NullPointerException("onSubscribe not called in proper order")); } } @@ -233,7 +233,7 @@ public void onError(Throwable t) { errors.add(new IllegalStateException("onError received a null Throwable")); } - actual.onError(t); + downstream.onError(t); } finally { done.countDown(); } @@ -243,7 +243,7 @@ public void onError(Throwable t) { public void onComplete() { if (!checkSubscriptionOnce) { checkSubscriptionOnce = true; - if (subscription.get() == null) { + if (upstream.get() == null) { errors.add(new IllegalStateException("onSubscribe not called in proper order")); } } @@ -251,7 +251,7 @@ public void onComplete() { lastThread = Thread.currentThread(); completions++; - actual.onComplete(); + downstream.onComplete(); } finally { done.countDown(); } @@ -259,14 +259,14 @@ public void onComplete() { @Override public final void request(long n) { - SubscriptionHelper.deferredRequest(subscription, missedRequested, n); + SubscriptionHelper.deferredRequest(upstream, missedRequested, n); } @Override public final void cancel() { if (!cancelled) { cancelled = true; - SubscriptionHelper.cancel(subscription); + SubscriptionHelper.cancel(upstream); } } @@ -295,7 +295,7 @@ public final boolean isDisposed() { * @return true if this TestSubscriber received a subscription */ public final boolean hasSubscription() { - return subscription.get() != null; + return upstream.get() != null; } // assertion methods @@ -306,7 +306,7 @@ public final boolean hasSubscription() { */ @Override public final TestSubscriber assertSubscribed() { - if (subscription.get() == null) { + if (upstream.get() == null) { throw fail("Not subscribed!"); } return this; @@ -318,7 +318,7 @@ public final TestSubscriber assertSubscribed() { */ @Override public final TestSubscriber assertNotSubscribed() { - if (subscription.get() != null) { + if (upstream.get() != null) { throw fail("Subscribed!"); } else if (!errors.isEmpty()) { diff --git a/src/test/java/io/reactivex/TestHelper.java b/src/test/java/io/reactivex/TestHelper.java index cba835fcbd..7d19b95b35 100644 --- a/src/test/java/io/reactivex/TestHelper.java +++ b/src/test/java/io/reactivex/TestHelper.java @@ -1425,16 +1425,16 @@ public static void checkDoubleOnSubscribeFlowable(Function, ? @Override protected void subscribeActual(Subscriber subscriber) { try { - BooleanSubscription d1 = new BooleanSubscription(); + BooleanSubscription bs1 = new BooleanSubscription(); - subscriber.onSubscribe(d1); + subscriber.onSubscribe(bs1); - BooleanSubscription d2 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); - subscriber.onSubscribe(d2); + subscriber.onSubscribe(bs2); - b[0] = d1.isCancelled(); - b[1] = d2.isCancelled(); + b[0] = bs1.isCancelled(); + b[1] = bs2.isCancelled(); } finally { cdl.countDown(); } @@ -1694,16 +1694,16 @@ public static void checkDoubleOnSubscribeFlowableToObservable(Function subscriber) { try { - BooleanSubscription d1 = new BooleanSubscription(); + BooleanSubscription bs1 = new BooleanSubscription(); - subscriber.onSubscribe(d1); + subscriber.onSubscribe(bs1); - BooleanSubscription d2 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); - subscriber.onSubscribe(d2); + subscriber.onSubscribe(bs2); - b[0] = d1.isCancelled(); - b[1] = d2.isCancelled(); + b[0] = bs1.isCancelled(); + b[1] = bs2.isCancelled(); } finally { cdl.countDown(); } @@ -1748,16 +1748,16 @@ public static void checkDoubleOnSubscribeFlowableToSingle(Function subscriber) { try { - BooleanSubscription d1 = new BooleanSubscription(); + BooleanSubscription bs1 = new BooleanSubscription(); - subscriber.onSubscribe(d1); + subscriber.onSubscribe(bs1); - BooleanSubscription d2 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); - subscriber.onSubscribe(d2); + subscriber.onSubscribe(bs2); - b[0] = d1.isCancelled(); - b[1] = d2.isCancelled(); + b[0] = bs1.isCancelled(); + b[1] = bs2.isCancelled(); } finally { cdl.countDown(); } @@ -1802,16 +1802,16 @@ public static void checkDoubleOnSubscribeFlowableToMaybe(Function subscriber) { try { - BooleanSubscription d1 = new BooleanSubscription(); + BooleanSubscription bs1 = new BooleanSubscription(); - subscriber.onSubscribe(d1); + subscriber.onSubscribe(bs1); - BooleanSubscription d2 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); - subscriber.onSubscribe(d2); + subscriber.onSubscribe(bs2); - b[0] = d1.isCancelled(); - b[1] = d2.isCancelled(); + b[0] = bs1.isCancelled(); + b[1] = bs2.isCancelled(); } finally { cdl.countDown(); } @@ -1855,16 +1855,16 @@ public static void checkDoubleOnSubscribeFlowableToCompletable(Function subscriber) { try { - BooleanSubscription d1 = new BooleanSubscription(); + BooleanSubscription bs1 = new BooleanSubscription(); - subscriber.onSubscribe(d1); + subscriber.onSubscribe(bs1); - BooleanSubscription d2 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); - subscriber.onSubscribe(d2); + subscriber.onSubscribe(bs2); - b[0] = d1.isCancelled(); - b[1] = d2.isCancelled(); + b[0] = bs1.isCancelled(); + b[1] = bs2.isCancelled(); } finally { cdl.countDown(); } @@ -2416,28 +2416,28 @@ public static void checkFusedIsEmptyClear(Flowable source) { source.subscribe(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { + public void onSubscribe(Subscription s) { try { - if (d instanceof QueueSubscription) { + if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") - QueueSubscription qd = (QueueSubscription) d; + QueueSubscription qs = (QueueSubscription) s; state[0] = true; - int m = qd.requestFusion(QueueFuseable.ANY); + int m = qs.requestFusion(QueueFuseable.ANY); if (m != QueueFuseable.NONE) { state[1] = true; - state[2] = qd.isEmpty(); + state[2] = qs.isEmpty(); - qd.clear(); + qs.clear(); - state[3] = qd.isEmpty(); + state[3] = qs.isEmpty(); } } cdl.countDown(); } finally { - d.cancel(); + s.cancel(); } } @@ -2943,14 +2943,14 @@ protected void subscribeActual(Subscriber s) { static final class StripBoundarySubscriber implements FlowableSubscriber, QueueSubscription { - final Subscriber actual; + final Subscriber downstream; Subscription upstream; QueueSubscription qs; - StripBoundarySubscriber(Subscriber actual) { - this.actual = actual; + StripBoundarySubscriber(Subscriber downstream) { + this.downstream = downstream; } @SuppressWarnings("unchecked") @@ -2960,22 +2960,22 @@ public void onSubscribe(Subscription subscription) { if (subscription instanceof QueueSubscription) { qs = (QueueSubscription)subscription; } - actual.onSubscribe(this); + downstream.onSubscribe(this); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable throwable) { - actual.onError(throwable); + downstream.onError(throwable); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override @@ -3048,14 +3048,14 @@ protected void subscribeActual(Observer observer) { static final class StripBoundaryObserver implements Observer, QueueDisposable { - final Observer actual; + final Observer downstream; Disposable upstream; QueueDisposable qd; - StripBoundaryObserver(Observer actual) { - this.actual = actual; + StripBoundaryObserver(Observer downstream) { + this.downstream = downstream; } @SuppressWarnings("unchecked") @@ -3065,22 +3065,22 @@ public void onSubscribe(Disposable d) { if (d instanceof QueueDisposable) { qd = (QueueDisposable)d; } - actual.onSubscribe(this); + downstream.onSubscribe(this); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable throwable) { - actual.onError(throwable); + downstream.onError(throwable); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } @Override diff --git a/src/test/java/io/reactivex/completable/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java index dd4bdfc9e3..32461d5d41 100644 --- a/src/test/java/io/reactivex/completable/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -1899,7 +1899,7 @@ public void doOnSubscribeNormal() { Completable c = normal.completable.doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { calls.getAndIncrement(); } }); @@ -3651,21 +3651,21 @@ public void subscribeActionReportsUnsubscribedAfter() { PublishSubject stringSubject = PublishSubject.create(); Completable completable = stringSubject.ignoreElements(); - final AtomicReference subscriptionRef = new AtomicReference(); + final AtomicReference disposableRef = new AtomicReference(); Disposable completableSubscription = completable.subscribe(new Action() { @Override public void run() { - if (subscriptionRef.get().isDisposed()) { - subscriptionRef.set(null); + if (disposableRef.get().isDisposed()) { + disposableRef.set(null); } } }); - subscriptionRef.set(completableSubscription); + disposableRef.set(completableSubscription); stringSubject.onComplete(); assertTrue("Not unsubscribed?", completableSubscription.isDisposed()); - assertNotNull("Unsubscribed before the call to onComplete", subscriptionRef.get()); + assertNotNull("Unsubscribed before the call to onComplete", disposableRef.get()); } @Test @@ -4180,7 +4180,7 @@ public void onError(Throwable e) { } @Override - public void onSubscribe(Subscription d) { + public void onSubscribe(Subscription s) { } @@ -4212,7 +4212,7 @@ public void onError(Throwable e) { } @Override - public void onSubscribe(Subscription d) { + public void onSubscribe(Subscription s) { } @@ -4333,21 +4333,21 @@ public void subscribeAction2ReportsUnsubscribedAfter() { PublishSubject stringSubject = PublishSubject.create(); Completable completable = stringSubject.ignoreElements(); - final AtomicReference subscriptionRef = new AtomicReference(); + final AtomicReference disposableRef = new AtomicReference(); Disposable completableSubscription = completable.subscribe(new Action() { @Override public void run() { - if (subscriptionRef.get().isDisposed()) { - subscriptionRef.set(null); + if (disposableRef.get().isDisposed()) { + disposableRef.set(null); } } }, Functions.emptyConsumer()); - subscriptionRef.set(completableSubscription); + disposableRef.set(completableSubscription); stringSubject.onComplete(); assertTrue("Not unsubscribed?", completableSubscription.isDisposed()); - assertNotNull("Unsubscribed before the call to onComplete", subscriptionRef.get()); + assertNotNull("Unsubscribed before the call to onComplete", disposableRef.get()); } @Test @@ -4355,22 +4355,22 @@ public void subscribeAction2ReportsUnsubscribedOnErrorAfter() { PublishSubject stringSubject = PublishSubject.create(); Completable completable = stringSubject.ignoreElements(); - final AtomicReference subscriptionRef = new AtomicReference(); + final AtomicReference disposableRef = new AtomicReference(); Disposable completableSubscription = completable.subscribe(Functions.EMPTY_ACTION, new Consumer() { @Override public void accept(Throwable e) { - if (subscriptionRef.get().isDisposed()) { - subscriptionRef.set(null); + if (disposableRef.get().isDisposed()) { + disposableRef.set(null); } } }); - subscriptionRef.set(completableSubscription); + disposableRef.set(completableSubscription); stringSubject.onError(new TestException()); assertTrue("Not unsubscribed?", completableSubscription.isDisposed()); - assertNotNull("Unsubscribed before the call to onError", subscriptionRef.get()); + assertNotNull("Unsubscribed before the call to onError", disposableRef.get()); } @Ignore("onXXX methods are not allowed to throw") @@ -4478,9 +4478,9 @@ public void andThenError() { final Exception e = new Exception(); Completable.unsafeCreate(new CompletableSource() { @Override - public void subscribe(CompletableObserver cs) { - cs.onSubscribe(Disposables.empty()); - cs.onError(e); + public void subscribe(CompletableObserver co) { + co.onSubscribe(Disposables.empty()); + co.onError(e); } }) .andThen(Flowable.unsafeCreate(new Publisher() { diff --git a/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java b/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java index 78e73bf047..ce8cd412b2 100644 --- a/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java +++ b/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java @@ -31,8 +31,8 @@ public class CompositeDisposableTest { @Test public void testSuccess() { final AtomicInteger counter = new AtomicInteger(); - CompositeDisposable s = new CompositeDisposable(); - s.add(Disposables.fromRunnable(new Runnable() { + CompositeDisposable cd = new CompositeDisposable(); + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -41,7 +41,7 @@ public void run() { })); - s.add(Disposables.fromRunnable(new Runnable() { + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -49,7 +49,7 @@ public void run() { } })); - s.dispose(); + cd.dispose(); assertEquals(2, counter.get()); } @@ -57,12 +57,12 @@ public void run() { @Test(timeout = 1000) public void shouldUnsubscribeAll() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - final CompositeDisposable s = new CompositeDisposable(); + final CompositeDisposable cd = new CompositeDisposable(); final int count = 10; final CountDownLatch start = new CountDownLatch(1); for (int i = 0; i < count; i++) { - s.add(Disposables.fromRunnable(new Runnable() { + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -78,7 +78,7 @@ public void run() { public void run() { try { start.await(); - s.dispose(); + cd.dispose(); } catch (final InterruptedException e) { fail(e.getMessage()); } @@ -99,8 +99,8 @@ public void run() { @Test public void testException() { final AtomicInteger counter = new AtomicInteger(); - CompositeDisposable s = new CompositeDisposable(); - s.add(Disposables.fromRunnable(new Runnable() { + CompositeDisposable cd = new CompositeDisposable(); + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -109,7 +109,7 @@ public void run() { })); - s.add(Disposables.fromRunnable(new Runnable() { + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -119,7 +119,7 @@ public void run() { })); try { - s.dispose(); + cd.dispose(); fail("Expecting an exception"); } catch (RuntimeException e) { // we expect this @@ -133,8 +133,8 @@ public void run() { @Test public void testCompositeException() { final AtomicInteger counter = new AtomicInteger(); - CompositeDisposable s = new CompositeDisposable(); - s.add(Disposables.fromRunnable(new Runnable() { + CompositeDisposable cd = new CompositeDisposable(); + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -143,7 +143,7 @@ public void run() { })); - s.add(Disposables.fromRunnable(new Runnable() { + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -151,7 +151,7 @@ public void run() { } })); - s.add(Disposables.fromRunnable(new Runnable() { + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -161,7 +161,7 @@ public void run() { })); try { - s.dispose(); + cd.dispose(); fail("Expecting an exception"); } catch (CompositeException e) { // we expect this @@ -174,51 +174,51 @@ public void run() { @Test public void testRemoveUnsubscribes() { - Disposable s1 = Disposables.empty(); - Disposable s2 = Disposables.empty(); + Disposable d1 = Disposables.empty(); + Disposable d2 = Disposables.empty(); - CompositeDisposable s = new CompositeDisposable(); - s.add(s1); - s.add(s2); + CompositeDisposable cd = new CompositeDisposable(); + cd.add(d1); + cd.add(d2); - s.remove(s1); + cd.remove(d1); - assertTrue(s1.isDisposed()); - assertFalse(s2.isDisposed()); + assertTrue(d1.isDisposed()); + assertFalse(d2.isDisposed()); } @Test public void testClear() { - Disposable s1 = Disposables.empty(); - Disposable s2 = Disposables.empty(); + Disposable d1 = Disposables.empty(); + Disposable d2 = Disposables.empty(); - CompositeDisposable s = new CompositeDisposable(); - s.add(s1); - s.add(s2); + CompositeDisposable cd = new CompositeDisposable(); + cd.add(d1); + cd.add(d2); - assertFalse(s1.isDisposed()); - assertFalse(s2.isDisposed()); + assertFalse(d1.isDisposed()); + assertFalse(d2.isDisposed()); - s.clear(); + cd.clear(); - assertTrue(s1.isDisposed()); - assertTrue(s2.isDisposed()); - assertFalse(s.isDisposed()); + assertTrue(d1.isDisposed()); + assertTrue(d2.isDisposed()); + assertFalse(cd.isDisposed()); - Disposable s3 = Disposables.empty(); + Disposable d3 = Disposables.empty(); - s.add(s3); - s.dispose(); + cd.add(d3); + cd.dispose(); - assertTrue(s3.isDisposed()); - assertTrue(s.isDisposed()); + assertTrue(d3.isDisposed()); + assertTrue(cd.isDisposed()); } @Test public void testUnsubscribeIdempotence() { final AtomicInteger counter = new AtomicInteger(); - CompositeDisposable s = new CompositeDisposable(); - s.add(Disposables.fromRunnable(new Runnable() { + CompositeDisposable cd = new CompositeDisposable(); + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -227,9 +227,9 @@ public void run() { })); - s.dispose(); - s.dispose(); - s.dispose(); + cd.dispose(); + cd.dispose(); + cd.dispose(); // we should have only disposed once assertEquals(1, counter.get()); @@ -239,11 +239,11 @@ public void run() { public void testUnsubscribeIdempotenceConcurrently() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - final CompositeDisposable s = new CompositeDisposable(); + final CompositeDisposable cd = new CompositeDisposable(); final int count = 10; final CountDownLatch start = new CountDownLatch(1); - s.add(Disposables.fromRunnable(new Runnable() { + cd.add(Disposables.fromRunnable(new Runnable() { @Override public void run() { @@ -259,7 +259,7 @@ public void run() { public void run() { try { start.await(); - s.dispose(); + cd.dispose(); } catch (final InterruptedException e) { fail(e.getMessage()); } @@ -279,22 +279,22 @@ public void run() { } @Test public void testTryRemoveIfNotIn() { - CompositeDisposable csub = new CompositeDisposable(); + CompositeDisposable cd = new CompositeDisposable(); - CompositeDisposable csub1 = new CompositeDisposable(); - CompositeDisposable csub2 = new CompositeDisposable(); + CompositeDisposable cd1 = new CompositeDisposable(); + CompositeDisposable cd2 = new CompositeDisposable(); - csub.add(csub1); - csub.remove(csub1); - csub.add(csub2); + cd.add(cd1); + cd.remove(cd1); + cd.add(cd2); - csub.remove(csub1); // try removing agian + cd.remove(cd1); // try removing agian } @Test(expected = NullPointerException.class) public void testAddingNullDisposableIllegal() { - CompositeDisposable csub = new CompositeDisposable(); - csub.add(null); + CompositeDisposable cd = new CompositeDisposable(); + cd.add(null); } @Test diff --git a/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java b/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java index 9ad78fd1e4..9db71ac805 100644 --- a/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java @@ -36,13 +36,13 @@ public class FlowableBackpressureTests { static final class FirehoseNoBackpressure extends AtomicBoolean implements Subscription { private static final long serialVersionUID = -669931580197884015L; - final Subscriber s; - private final AtomicInteger counter; + final Subscriber downstream; + final AtomicInteger counter; volatile boolean cancelled; private FirehoseNoBackpressure(AtomicInteger counter, Subscriber s) { this.counter = counter; - this.s = s; + this.downstream = s; } @Override @@ -52,7 +52,7 @@ public void request(long n) { } if (compareAndSet(false, true)) { int i = 0; - final Subscriber a = s; + final Subscriber a = downstream; final AtomicInteger c = counter; while (!cancelled) { diff --git a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java index b01c2886ac..b72df7a98c 100644 --- a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java @@ -589,10 +589,10 @@ public boolean test(Integer v) throws Exception { try { s.onSubscribe(new BooleanSubscription()); - BooleanSubscription d = new BooleanSubscription(); - s.onSubscribe(d); + BooleanSubscription bs = new BooleanSubscription(); + s.onSubscribe(bs); - assertTrue(d.isCancelled()); + assertTrue(bs.isCancelled()); TestHelper.assertError(list, 0, IllegalStateException.class, "Subscription already set!"); } finally { diff --git a/src/test/java/io/reactivex/flowable/FlowableTests.java b/src/test/java/io/reactivex/flowable/FlowableTests.java index 8f45ce3689..f3b7d2b371 100644 --- a/src/test/java/io/reactivex/flowable/FlowableTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableTests.java @@ -549,7 +549,7 @@ public void run() { }).replay(); // we connect immediately and it will emit the value - Disposable s = f.connect(); + Disposable connection = f.connect(); try { // we then expect the following 2 subscriptions to get that same value @@ -578,7 +578,7 @@ public void accept(String v) { } assertEquals(1, counter.get()); } finally { - s.dispose(); + connection.dispose(); } } diff --git a/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java b/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java index 07d279d162..8defb098ef 100644 --- a/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java @@ -32,13 +32,13 @@ static final class TakeFirst extends DeferredScalarObserver { private static final long serialVersionUID = -2793723002312330530L; - TakeFirst(Observer actual) { - super(actual); + TakeFirst(Observer downstream) { + super(downstream); } @Override public void onNext(Integer value) { - s.dispose(); + upstream.dispose(); complete(value); complete(value); } @@ -177,8 +177,8 @@ static final class TakeLast extends DeferredScalarObserver { private static final long serialVersionUID = -2793723002312330530L; - TakeLast(Observer actual) { - super(actual); + TakeLast(Observer downstream) { + super(downstream); } @@ -312,18 +312,18 @@ public void disposedAfterOnNext() { final TestObserver to = new TestObserver(); TakeLast source = new TakeLast(new Observer() { - Disposable d; + Disposable upstream; @Override public void onSubscribe(Disposable d) { - this.d = d; + this.upstream = d; to.onSubscribe(d); } @Override public void onNext(Integer value) { to.onNext(value); - d.dispose(); + upstream.dispose(); } @Override diff --git a/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java b/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java index 90fe6c3910..bf91a78a4e 100644 --- a/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java @@ -135,16 +135,16 @@ public void onSubscribe() throws Exception { try { - Disposable s = Disposables.empty(); + Disposable d1 = Disposables.empty(); - fo.onSubscribe(s); + fo.onSubscribe(d1); - Disposable s2 = Disposables.empty(); + Disposable d2 = Disposables.empty(); - fo.onSubscribe(s2); + fo.onSubscribe(d2); - assertFalse(s.isDisposed()); - assertTrue(s2.isDisposed()); + assertFalse(d1.isDisposed()); + assertTrue(d2.isDisposed()); TestHelper.assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } finally { diff --git a/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java b/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java index 3171f8e8df..8e520fd402 100644 --- a/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java @@ -54,7 +54,7 @@ public void run() throws Exception { } }, new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException(); } }); @@ -91,7 +91,7 @@ public void run() throws Exception { } }, new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { } }); @@ -130,7 +130,7 @@ public void run() throws Exception { } }, new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { } }); @@ -176,7 +176,7 @@ public void run() throws Exception { } }, new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { } }); @@ -201,13 +201,13 @@ public void badSourceOnSubscribe() { Observable source = new Observable() { @Override public void subscribeActual(Observer observer) { - Disposable s1 = Disposables.empty(); - observer.onSubscribe(s1); - Disposable s2 = Disposables.empty(); - observer.onSubscribe(s2); + Disposable d1 = Disposables.empty(); + observer.onSubscribe(d1); + Disposable d2 = Disposables.empty(); + observer.onSubscribe(d2); - assertFalse(s1.isDisposed()); - assertTrue(s2.isDisposed()); + assertFalse(d1.isDisposed()); + assertTrue(d2.isDisposed()); observer.onNext(1); observer.onComplete(); @@ -234,7 +234,7 @@ public void run() throws Exception { } }, new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { } }); @@ -284,7 +284,7 @@ public void run() throws Exception { } }, new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { } }); @@ -348,7 +348,7 @@ public void run() throws Exception { } }, new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException(); } }); diff --git a/src/test/java/io/reactivex/internal/observers/QueueDrainObserverTest.java b/src/test/java/io/reactivex/internal/observers/QueueDrainObserverTest.java index 12959cb898..1f9fffd356 100644 --- a/src/test/java/io/reactivex/internal/observers/QueueDrainObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/QueueDrainObserverTest.java @@ -38,7 +38,7 @@ public void onComplete() { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { } @Override @@ -65,7 +65,7 @@ public void onComplete() { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { } @Override diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java index 91f904ce56..5d38ba126f 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java @@ -93,7 +93,7 @@ protected void subscribeActual(CompletableObserver observer) { } .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException("First"); } }) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java index 2ed817df9a..636d7bcd28 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java @@ -289,8 +289,8 @@ public void blockingSubscribeObserver() { .blockingSubscribe(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { - d.request(Long.MAX_VALUE); + public void onSubscribe(Subscription s) { + s.request(Long.MAX_VALUE); } @Override @@ -324,8 +324,8 @@ public void blockingSubscribeObserverError() { .blockingSubscribe(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { - d.request(Long.MAX_VALUE); + public void onSubscribe(Subscription s) { + s.request(Long.MAX_VALUE); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java index 0599234015..2934084b0d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java @@ -1382,7 +1382,7 @@ public void dontSubscribeIfDone() { Flowable.error(new TestException()) .doOnSubscribe(new Consumer() { @Override - public void accept(Subscription d) throws Exception { + public void accept(Subscription s) throws Exception { count[0]++; } }), @@ -1415,7 +1415,7 @@ public void dontSubscribeIfDone2() { Flowable.error(new TestException()) .doOnSubscribe(new Consumer() { @Override - public void accept(Subscription d) throws Exception { + public void accept(Subscription s) throws Exception { count[0]++; } }) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java index ba4c9933a9..8aeef598c8 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java @@ -792,7 +792,7 @@ public void subscribe(FlowableEmitter e) throws Exception { }, m) .subscribe(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { + public void onSubscribe(Subscription s) { } @Override @@ -830,7 +830,7 @@ public void subscribe(FlowableEmitter e) throws Exception { }, m) .subscribe(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { + public void onSubscribe(Subscription s) { } @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java index fd79f56b9c..448e963d49 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java @@ -175,14 +175,14 @@ public void fusedClear() { .distinct() .subscribe(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { - QueueSubscription qd = (QueueSubscription)d; + public void onSubscribe(Subscription s) { + QueueSubscription qs = (QueueSubscription)s; - assertFalse(qd.isEmpty()); + assertFalse(qs.isEmpty()); - qd.clear(); + qs.clear(); - assertTrue(qd.isEmpty()); + assertTrue(qs.isEmpty()); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java index c0ddc1f302..01309ff55c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java @@ -422,15 +422,15 @@ public CompletableSource apply(Integer v) throws Exception { .toFlowable() .subscribe(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { - QueueSubscription qd = (QueueSubscription)d; + public void onSubscribe(Subscription s) { + QueueSubscription qs = (QueueSubscription)s; try { - assertNull(qd.poll()); + assertNull(qs.poll()); } catch (Throwable ex) { throw new RuntimeException(ex); } - assertTrue(qd.isEmpty()); - qd.clear(); + assertTrue(qs.isEmpty()); + qs.clear(); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java index 421cd9e4c7..fdedc6577c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java @@ -882,21 +882,21 @@ public void fusionClear() { Flowable.fromIterable(Arrays.asList(1, 2, 3)) .subscribe(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { + public void onSubscribe(Subscription s) { @SuppressWarnings("unchecked") - QueueSubscription qd = (QueueSubscription)d; + QueueSubscription qs = (QueueSubscription)s; - qd.requestFusion(QueueFuseable.ANY); + qs.requestFusion(QueueFuseable.ANY); try { - assertEquals(1, qd.poll().intValue()); + assertEquals(1, qs.poll().intValue()); } catch (Throwable ex) { fail(ex.toString()); } - qd.clear(); + qs.clear(); try { - assertNull(qd.poll()); + assertNull(qs.poll()); } catch (Throwable ex) { fail(ex.toString()); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java index 10c6f5bd47..10c1facc16 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java @@ -1306,19 +1306,19 @@ public void outputFusedCancelReentrant() throws Exception { us.observeOn(Schedulers.single()) .subscribe(new FlowableSubscriber() { - Subscription d; + Subscription upstream; int count; @Override - public void onSubscribe(Subscription d) { - this.d = d; - ((QueueSubscription)d).requestFusion(QueueFuseable.ANY); + public void onSubscribe(Subscription s) { + this.upstream = s; + ((QueueSubscription)s).requestFusion(QueueFuseable.ANY); } @Override public void onNext(Integer value) { if (++count == 1) { us.onNext(2); - d.cancel(); + upstream.cancel(); cdl.countDown(); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java index ed8b3b6aba..140ca333ac 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java @@ -148,19 +148,19 @@ public void subscribe(Subscriber t1) { static final class TestObservable implements Publisher { - final Subscription s; + final Subscription upstream; final String[] values; Thread t; TestObservable(Subscription s, String... values) { - this.s = s; + this.upstream = s; this.values = values; } @Override public void subscribe(final Subscriber subscriber) { System.out.println("TestObservable subscribed to ..."); - subscriber.onSubscribe(s); + subscriber.onSubscribe(upstream); t = new Thread(new Runnable() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java index 32c906a692..bf8b269196 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java @@ -81,14 +81,14 @@ public void accept(String v) { } }); - Disposable s = f.connect(); + Disposable connection = f.connect(); try { if (!latch.await(1000, TimeUnit.MILLISECONDS)) { fail("subscriptions did not receive values"); } assertEquals(1, counter.get()); } finally { - s.dispose(); + connection.dispose(); } } @@ -275,7 +275,7 @@ public void testSubscribeAfterDisconnectThenConnect() { source.subscribe(ts1); - Disposable s = source.connect(); + Disposable connection = source.connect(); ts1.assertValue(1); ts1.assertNoErrors(); @@ -285,14 +285,14 @@ public void testSubscribeAfterDisconnectThenConnect() { source.subscribe(ts2); - Disposable s2 = source.connect(); + Disposable connection2 = source.connect(); ts2.assertValue(1); ts2.assertNoErrors(); ts2.assertTerminated(); - System.out.println(s); - System.out.println(s2); + System.out.println(connection); + System.out.println(connection2); } @Test @@ -328,18 +328,18 @@ public void testNonNullConnection() { public void testNoDisconnectSomeoneElse() { ConnectableFlowable source = Flowable.never().publish(); - Disposable s1 = source.connect(); - Disposable s2 = source.connect(); + Disposable connection1 = source.connect(); + Disposable connection2 = source.connect(); - s1.dispose(); + connection1.dispose(); - Disposable s3 = source.connect(); + Disposable connection3 = source.connect(); - s2.dispose(); + connection2.dispose(); - assertTrue(checkPublishDisposed(s1)); - assertTrue(checkPublishDisposed(s2)); - assertFalse(checkPublishDisposed(s3)); + assertTrue(checkPublishDisposed(connection1)); + assertTrue(checkPublishDisposed(connection2)); + assertFalse(checkPublishDisposed(connection3)); } @SuppressWarnings("unchecked") @@ -412,7 +412,7 @@ public void syncFusedObserveOn() { obs.subscribe(ts); } - Disposable s = cf.connect(); + Disposable connection = cf.connect(); for (TestSubscriber ts : tss) { ts.awaitDone(5, TimeUnit.SECONDS) @@ -421,7 +421,7 @@ public void syncFusedObserveOn() { .assertNoErrors() .assertComplete(); } - s.dispose(); + connection.dispose(); } } } @@ -439,7 +439,7 @@ public void syncFusedObserveOn2() { obs.subscribe(ts); } - Disposable s = cf.connect(); + Disposable connection = cf.connect(); for (TestSubscriber ts : tss) { ts.awaitDone(5, TimeUnit.SECONDS) @@ -448,7 +448,7 @@ public void syncFusedObserveOn2() { .assertNoErrors() .assertComplete(); } - s.dispose(); + connection.dispose(); } } } @@ -465,7 +465,7 @@ public void asyncFusedObserveOn() { cf.subscribe(ts); } - Disposable s = cf.connect(); + Disposable connection = cf.connect(); for (TestSubscriber ts : tss) { ts.awaitDone(5, TimeUnit.SECONDS) @@ -474,7 +474,7 @@ public void asyncFusedObserveOn() { .assertNoErrors() .assertComplete(); } - s.dispose(); + connection.dispose(); } } } @@ -492,7 +492,7 @@ public void testObserveOn() { obs.subscribe(ts); } - Disposable s = cf.connect(); + Disposable connection = cf.connect(); for (TestSubscriber ts : tss) { ts.awaitDone(5, TimeUnit.SECONDS) @@ -501,7 +501,7 @@ public void testObserveOn() { .assertNoErrors() .assertComplete(); } - s.dispose(); + connection.dispose(); } } } @@ -519,7 +519,7 @@ public void connectThrows() { try { cf.connect(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException(); } }); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java index acb93684d6..8eefc701e3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java @@ -63,14 +63,14 @@ public void accept(Long l) { .publish().refCount(); final AtomicInteger receivedCount = new AtomicInteger(); - Disposable s1 = r.subscribe(new Consumer() { + Disposable d1 = r.subscribe(new Consumer() { @Override public void accept(Long l) { receivedCount.incrementAndGet(); } }); - Disposable s2 = r.subscribe(); + Disposable d2 = r.subscribe(); try { Thread.sleep(10); @@ -94,8 +94,8 @@ public void accept(Long l) { // give time to emit // now unsubscribe - s2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one subscriber getting a value but not the other - s1.dispose(); + d2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one subscriber getting a value but not the other + d1.dispose(); System.out.println("onNext: " + nextCount.get()); @@ -125,14 +125,14 @@ public void accept(Integer l) { .publish().refCount(); final AtomicInteger receivedCount = new AtomicInteger(); - Disposable s1 = r.subscribe(new Consumer() { + Disposable d1 = r.subscribe(new Consumer() { @Override public void accept(Integer l) { receivedCount.incrementAndGet(); } }); - Disposable s2 = r.subscribe(); + Disposable d2 = r.subscribe(); // give time to emit try { @@ -141,8 +141,8 @@ public void accept(Integer l) { } // now unsubscribe - s2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one subscriber getting a value but not the other - s1.dispose(); + d2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one subscriber getting a value but not the other + d1.dispose(); System.out.println("onNext Count: " + nextCount.get()); @@ -386,7 +386,7 @@ public void testRefCount() { // subscribe list1 final List list1 = new ArrayList(); - Disposable s1 = interval.subscribe(new Consumer() { + Disposable d1 = interval.subscribe(new Consumer() { @Override public void accept(Long t1) { list1.add(t1); @@ -401,7 +401,7 @@ public void accept(Long t1) { // subscribe list2 final List list2 = new ArrayList(); - Disposable s2 = interval.subscribe(new Consumer() { + Disposable d2 = interval.subscribe(new Consumer() { @Override public void accept(Long t1) { list2.add(t1); @@ -423,7 +423,7 @@ public void accept(Long t1) { assertEquals(4L, list2.get(2).longValue()); // unsubscribe list1 - s1.dispose(); + d1.dispose(); // advance further s.advanceTimeBy(300, TimeUnit.MILLISECONDS); @@ -438,7 +438,7 @@ public void accept(Long t1) { assertEquals(7L, list2.get(5).longValue()); // unsubscribe list2 - s2.dispose(); + d2.dispose(); // advance further s.advanceTimeBy(1000, TimeUnit.MILLISECONDS); @@ -694,14 +694,14 @@ public Object call() throws Exception { .replay(1) .refCount(); - Disposable s1 = source.subscribe(); - Disposable s2 = source.subscribe(); + Disposable d1 = source.subscribe(); + Disposable d2 = source.subscribe(); - s1.dispose(); - s2.dispose(); + d1.dispose(); + d2.dispose(); - s1 = null; - s2 = null; + d1 = null; + d2 = null; System.gc(); Thread.sleep(100); @@ -765,14 +765,14 @@ public Object call() throws Exception { .publish() .refCount(); - Disposable s1 = source.test(); - Disposable s2 = source.test(); + Disposable d1 = source.test(); + Disposable d2 = source.test(); - s1.dispose(); - s2.dispose(); + d1.dispose(); + d2.dispose(); - s1 = null; - s2 = null; + d1 = null; + d2 = null; System.gc(); Thread.sleep(100); @@ -790,11 +790,11 @@ public void replayIsUnsubscribed() { assertTrue(((Disposable)cf).isDisposed()); - Disposable s = cf.connect(); + Disposable connection = cf.connect(); assertFalse(((Disposable)cf).isDisposed()); - s.dispose(); + connection.dispose(); assertTrue(((Disposable)cf).isDisposed()); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java index 428eefa467..702f4660e1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java @@ -156,10 +156,10 @@ public void testTakeUntilOtherCompleted() { private static class TestObservable implements Publisher { Subscriber subscriber; - Subscription s; + Subscription upstream; TestObservable(Subscription s) { - this.s = s; + this.upstream = s; } /* used to simulate subscription */ @@ -180,7 +180,7 @@ public void sendOnError(Throwable e) { @Override public void subscribe(Subscriber subscriber) { this.subscriber = subscriber; - subscriber.onSubscribe(s); + subscriber.onSubscribe(upstream); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java index f05b8e9fae..97eac27982 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java @@ -191,19 +191,19 @@ public boolean test(String s) { private static class TestFlowable implements Publisher { - final Subscription s; + final Subscription upstream; final String[] values; Thread t; TestFlowable(Subscription s, String... values) { - this.s = s; + this.upstream = s; this.values = values; } @Override public void subscribe(final Subscriber subscriber) { System.out.println("TestFlowable subscribed to ..."); - subscriber.onSubscribe(s); + subscriber.onSubscribe(upstream); t = new Thread(new Runnable() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java index ad3869f4ac..b67437e7a9 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java @@ -53,8 +53,8 @@ public void accept(Resource r) { private final Consumer disposeSubscription = new Consumer() { @Override - public void accept(Disposable s) { - s.dispose(); + public void accept(Disposable d) { + d.dispose(); } }; @@ -186,7 +186,7 @@ public Disposable call() { Function> observableFactory = new Function>() { @Override - public Flowable apply(Disposable s) { + public Flowable apply(Disposable d) { return Flowable.empty(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java index 81930eb12c..19389db622 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java @@ -70,7 +70,7 @@ protected void subscribeActual(MaybeObserver observer) { } .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException("First"); } }) diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java index c44782fa3c..450129d175 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java @@ -299,24 +299,24 @@ public Iterable apply(Object v) throws Exception { return Arrays.asList(1, 2, 3); } }).subscribe(new FlowableSubscriber() { - QueueSubscription qd; + QueueSubscription qs; @SuppressWarnings("unchecked") @Override - public void onSubscribe(Subscription d) { - qd = (QueueSubscription)d; + public void onSubscribe(Subscription s) { + qs = (QueueSubscription)s; - assertEquals(QueueFuseable.ASYNC, qd.requestFusion(QueueFuseable.ANY)); + assertEquals(QueueFuseable.ASYNC, qs.requestFusion(QueueFuseable.ANY)); } @Override public void onNext(Integer value) { - assertFalse(qd.isEmpty()); + assertFalse(qs.isEmpty()); - qd.clear(); + qs.clear(); - assertTrue(qd.isEmpty()); + assertTrue(qs.isEmpty()); - qd.cancel(); + qs.cancel(); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeArrayTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeArrayTest.java index b5833c1941..38ce04fdf0 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeArrayTest.java @@ -62,23 +62,23 @@ public void fusedPollMixed() { public void fusedEmptyCheck() { Maybe.mergeArray(Maybe.just(1), Maybe.empty(), Maybe.just(2)) .subscribe(new FlowableSubscriber() { - QueueSubscription qd; + QueueSubscription qs; @Override - public void onSubscribe(Subscription d) { - qd = (QueueSubscription)d; + public void onSubscribe(Subscription s) { + qs = (QueueSubscription)s; - assertEquals(QueueFuseable.ASYNC, qd.requestFusion(QueueFuseable.ANY)); + assertEquals(QueueFuseable.ASYNC, qs.requestFusion(QueueFuseable.ANY)); } @Override public void onNext(Integer value) { - assertFalse(qd.isEmpty()); + assertFalse(qs.isEmpty()); - qd.clear(); + qs.clear(); - assertTrue(qd.isEmpty()); + assertTrue(qs.isEmpty()); - qd.cancel(); + qs.cancel(); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java index 497b2894d9..ee4d58adf5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java @@ -165,7 +165,7 @@ public void testSubscriptionOnlyHappensOnce() throws InterruptedException { final AtomicLong count = new AtomicLong(); Consumer incrementer = new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { count.incrementAndGet(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java index f074441875..a9b6dc6faa 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java @@ -471,7 +471,7 @@ public void testConcatUnsubscribeConcurrent() { static class TestObservable implements ObservableSource { - private final Disposable s = new Disposable() { + private final Disposable upstream = new Disposable() { @Override public void dispose() { subscribed = false; @@ -514,7 +514,7 @@ public boolean isDisposed() { @Override public void subscribe(final Observer observer) { - observer.onSubscribe(s); + observer.onSubscribe(upstream); t = new Thread(new Runnable() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java index 5cdb2bed8b..82738bd4de 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java @@ -355,27 +355,27 @@ public void clearIsEmpty() { .subscribe(new Observer() { @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { @SuppressWarnings("unchecked") - QueueDisposable qs = (QueueDisposable)s; + QueueDisposable qd = (QueueDisposable)d; - qs.requestFusion(QueueFuseable.ANY); + qd.requestFusion(QueueFuseable.ANY); - assertFalse(qs.isEmpty()); + assertFalse(qd.isEmpty()); try { - assertEquals(1, qs.poll().intValue()); + assertEquals(1, qd.poll().intValue()); } catch (Throwable ex) { throw new RuntimeException(ex); } - assertFalse(qs.isEmpty()); + assertFalse(qd.isEmpty()); - qs.clear(); + qd.clear(); - assertTrue(qs.isEmpty()); + assertTrue(qd.isEmpty()); - qs.dispose(); + qd.dispose(); } @Override @@ -402,31 +402,31 @@ public void clearIsEmptyConditional() { .subscribe(new Observer() { @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { @SuppressWarnings("unchecked") - QueueDisposable qs = (QueueDisposable)s; + QueueDisposable qd = (QueueDisposable)d; - qs.requestFusion(QueueFuseable.ANY); + qd.requestFusion(QueueFuseable.ANY); - assertFalse(qs.isEmpty()); + assertFalse(qd.isEmpty()); - assertFalse(qs.isDisposed()); + assertFalse(qd.isDisposed()); try { - assertEquals(1, qs.poll().intValue()); + assertEquals(1, qd.poll().intValue()); } catch (Throwable ex) { throw new RuntimeException(ex); } - assertFalse(qs.isEmpty()); + assertFalse(qd.isEmpty()); - qs.clear(); + qd.clear(); - assertTrue(qs.isEmpty()); + assertTrue(qd.isEmpty()); - qs.dispose(); + qd.dispose(); - assertTrue(qs.isDisposed()); + assertTrue(qd.isDisposed()); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java index 93143efe77..76b9737959 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java @@ -33,7 +33,7 @@ public void testDoOnSubscribe() throws Exception { final AtomicInteger count = new AtomicInteger(); Observable o = Observable.just(1).doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { count.incrementAndGet(); } }); @@ -49,12 +49,12 @@ public void testDoOnSubscribe2() throws Exception { final AtomicInteger count = new AtomicInteger(); Observable o = Observable.just(1).doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { count.incrementAndGet(); } }).take(1).doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { count.incrementAndGet(); } }); @@ -80,13 +80,13 @@ public void subscribe(Observer observer) { }).doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { countBefore.incrementAndGet(); } }).publish().refCount() .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { countAfter.incrementAndGet(); } }); @@ -122,7 +122,7 @@ protected void subscribeActual(Observer observer) { } .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException("First"); } }) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index 9e40bd1925..17382f4dad 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -308,7 +308,7 @@ public void testFlatMapTransformsMergeException() { private static Observable composer(Observable source, final AtomicInteger subscriptionCount, final int m) { return source.doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { int n = subscriptionCount.getAndIncrement(); if (n >= m) { Assert.fail("Too many subscriptions! " + (n + 1)); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java index 95c892da87..42f441bd10 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java @@ -1370,12 +1370,12 @@ public void accept(String s) { @Test public void testGroupByUnsubscribe() { - final Disposable s = mock(Disposable.class); + final Disposable upstream = mock(Disposable.class); Observable o = Observable.unsafeCreate( new ObservableSource() { @Override public void subscribe(Observer observer) { - observer.onSubscribe(s); + observer.onSubscribe(upstream); } } ); @@ -1391,7 +1391,7 @@ public Integer apply(Integer integer) { to.dispose(); - verify(s).dispose(); + verify(upstream).dispose(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java index 53f3bff298..3f902cb4a4 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java @@ -202,7 +202,7 @@ public void onComplete() { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Disposable d) { } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java index bd6d291d33..c178b3bddc 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java @@ -133,14 +133,14 @@ public void testUnSubscribeObservableOfObservables() throws InterruptedException @Override public void subscribe(final Observer> observer) { // verbose on purpose so I can track the inside of it - final Disposable s = Disposables.fromRunnable(new Runnable() { + final Disposable upstream = Disposables.fromRunnable(new Runnable() { @Override public void run() { System.out.println("*** unsubscribed"); unsubscribed.set(true); } }); - observer.onSubscribe(s); + observer.onSubscribe(upstream); new Thread(new Runnable() { @@ -502,12 +502,12 @@ public void subscribe(final Observer child) { .take(5) .subscribe(new Observer() { @Override - public void onSubscribe(final Disposable s) { + public void onSubscribe(final Disposable d) { child.onSubscribe(Disposables.fromRunnable(new Runnable() { @Override public void run() { unsubscribed.set(true); - s.dispose(); + d.dispose(); } })); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java index 3330d8cd85..1ac99fcb5e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java @@ -635,11 +635,11 @@ public void outputFusedCancelReentrant() throws Exception { us.observeOn(Schedulers.single()) .subscribe(new Observer() { - Disposable d; + Disposable upstream; int count; @Override public void onSubscribe(Disposable d) { - this.d = d; + this.upstream = d; ((QueueDisposable)d).requestFusion(QueueFuseable.ANY); } @@ -647,7 +647,7 @@ public void onSubscribe(Disposable d) { public void onNext(Integer value) { if (++count == 1) { us.onNext(2); - d.dispose(); + upstream.dispose(); cdl.countDown(); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java index 9ba3738ce6..b8b3f67f1e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java @@ -191,8 +191,8 @@ public Observer apply(final Observer t1) { return new Observer() { @Override - public void onSubscribe(Disposable s) { - t1.onSubscribe(s); + public void onSubscribe(Disposable d) { + t1.onSubscribe(d); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java index 71f9a809fe..3dab17f83f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java @@ -29,9 +29,9 @@ public class ObservableOnErrorResumeNextViaObservableTest { @Test public void testResumeNext() { - Disposable s = mock(Disposable.class); + Disposable upstream = mock(Disposable.class); // Trigger failure on second element - TestObservable f = new TestObservable(s, "one", "fail", "two", "three"); + TestObservable f = new TestObservable(upstream, "one", "fail", "two", "three"); Observable w = Observable.unsafeCreate(f); Observable resume = Observable.just("twoResume", "threeResume"); Observable observable = w.onErrorResumeNext(resume); @@ -146,19 +146,19 @@ public void subscribe(Observer t1) { static class TestObservable implements ObservableSource { - final Disposable s; + final Disposable upstream; final String[] values; Thread t; - TestObservable(Disposable s, String... values) { - this.s = s; + TestObservable(Disposable upstream, String... values) { + this.upstream = upstream; this.values = values; } @Override public void subscribe(final Observer observer) { System.out.println("TestObservable subscribed to ..."); - observer.onSubscribe(s); + observer.onSubscribe(upstream); t = new Thread(new Runnable() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java index 86194a7bf7..18251f8f78 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java @@ -79,14 +79,14 @@ public void accept(String v) { } }); - Disposable s = o.connect(); + Disposable connection = o.connect(); try { if (!latch.await(1000, TimeUnit.MILLISECONDS)) { fail("subscriptions did not receive values"); } assertEquals(1, counter.get()); } finally { - s.dispose(); + connection.dispose(); } } @@ -273,7 +273,7 @@ public void testSubscribeAfterDisconnectThenConnect() { source.subscribe(to1); - Disposable s = source.connect(); + Disposable connection = source.connect(); to1.assertValue(1); to1.assertNoErrors(); @@ -283,14 +283,14 @@ public void testSubscribeAfterDisconnectThenConnect() { source.subscribe(to2); - Disposable s2 = source.connect(); + Disposable connection2 = source.connect(); to2.assertValue(1); to2.assertNoErrors(); to2.assertTerminated(); - System.out.println(s); - System.out.println(s2); + System.out.println(connection); + System.out.println(connection2); } @Test @@ -326,18 +326,18 @@ public void testNonNullConnection() { public void testNoDisconnectSomeoneElse() { ConnectableObservable source = Observable.never().publish(); - Disposable s1 = source.connect(); - Disposable s2 = source.connect(); + Disposable connection1 = source.connect(); + Disposable connection2 = source.connect(); - s1.dispose(); + connection1.dispose(); - Disposable s3 = source.connect(); + Disposable connection3 = source.connect(); - s2.dispose(); + connection2.dispose(); - assertTrue(checkPublishDisposed(s1)); - assertTrue(checkPublishDisposed(s2)); - assertFalse(checkPublishDisposed(s3)); + assertTrue(checkPublishDisposed(connection1)); + assertTrue(checkPublishDisposed(connection2)); + assertFalse(checkPublishDisposed(connection3)); } @SuppressWarnings("unchecked") @@ -385,7 +385,7 @@ public void testObserveOn() { obs.subscribe(to); } - Disposable s = co.connect(); + Disposable connection = co.connect(); for (TestObserver to : tos) { to.awaitTerminalEvent(2, TimeUnit.SECONDS); @@ -393,7 +393,7 @@ public void testObserveOn() { to.assertNoErrors(); assertEquals(1000, to.valueCount()); } - s.dispose(); + connection.dispose(); } } } @@ -459,7 +459,7 @@ public void connectThrows() { try { co.connect(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException(); } }); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index 381b2b964b..37efa77570 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -50,7 +50,7 @@ public void testRefCountAsync() { Observable r = Observable.interval(0, 25, TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { subscribeCount.incrementAndGet(); } }) @@ -63,14 +63,14 @@ public void accept(Long l) { .publish().refCount(); final AtomicInteger receivedCount = new AtomicInteger(); - Disposable s1 = r.subscribe(new Consumer() { + Disposable d1 = r.subscribe(new Consumer() { @Override public void accept(Long l) { receivedCount.incrementAndGet(); } }); - Disposable s2 = r.subscribe(); + Disposable d2 = r.subscribe(); // give time to emit try { @@ -79,8 +79,8 @@ public void accept(Long l) { } // now unsubscribe - s2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one Observer getting a value but not the other - s1.dispose(); + d2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one Observer getting a value but not the other + d1.dispose(); System.out.println("onNext: " + nextCount.get()); @@ -97,7 +97,7 @@ public void testRefCountSynchronous() { Observable r = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { subscribeCount.incrementAndGet(); } }) @@ -110,14 +110,14 @@ public void accept(Integer l) { .publish().refCount(); final AtomicInteger receivedCount = new AtomicInteger(); - Disposable s1 = r.subscribe(new Consumer() { + Disposable d1 = r.subscribe(new Consumer() { @Override public void accept(Integer l) { receivedCount.incrementAndGet(); } }); - Disposable s2 = r.subscribe(); + Disposable d2 = r.subscribe(); // give time to emit try { @@ -126,8 +126,8 @@ public void accept(Integer l) { } // now unsubscribe - s2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one Observer getting a value but not the other - s1.dispose(); + d2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one Observer getting a value but not the other + d1.dispose(); System.out.println("onNext Count: " + nextCount.get()); @@ -172,7 +172,7 @@ public void testRepeat() { Observable r = Observable.interval(0, 1, TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { System.out.println("******************************* Subscribe received"); // when we are subscribed subscribeCount.incrementAndGet(); @@ -217,7 +217,7 @@ public void testConnectUnsubscribe() throws InterruptedException { Observable o = synchronousInterval() .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { System.out.println("******************************* Subscribe received"); // when we are subscribed subscribeLatch.countDown(); @@ -271,7 +271,7 @@ public void run() { }) .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { System.out.println("******************************* SUBSCRIBE received"); subUnsubCount.incrementAndGet(); } @@ -367,7 +367,7 @@ public void testRefCount() { // subscribe list1 final List list1 = new ArrayList(); - Disposable s1 = interval.subscribe(new Consumer() { + Disposable d1 = interval.subscribe(new Consumer() { @Override public void accept(Long t1) { list1.add(t1); @@ -382,7 +382,7 @@ public void accept(Long t1) { // subscribe list2 final List list2 = new ArrayList(); - Disposable s2 = interval.subscribe(new Consumer() { + Disposable d2 = interval.subscribe(new Consumer() { @Override public void accept(Long t1) { list2.add(t1); @@ -404,7 +404,7 @@ public void accept(Long t1) { assertEquals(4L, list2.get(2).longValue()); // unsubscribe list1 - s1.dispose(); + d1.dispose(); // advance further s.advanceTimeBy(300, TimeUnit.MILLISECONDS); @@ -419,7 +419,7 @@ public void accept(Long t1) { assertEquals(7L, list2.get(5).longValue()); // unsubscribe list2 - s2.dispose(); + d2.dispose(); // advance further s.advanceTimeBy(1000, TimeUnit.MILLISECONDS); @@ -519,7 +519,7 @@ public void testUpstreamErrorAllowsRetry() throws InterruptedException { Observable.interval(200,TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { System.out.println("Subscribing to interval " + intervalSubscribed.incrementAndGet()); } } @@ -671,14 +671,14 @@ public Object call() throws Exception { .replay(1) .refCount(); - Disposable s1 = source.subscribe(); - Disposable s2 = source.subscribe(); + Disposable d1 = source.subscribe(); + Disposable d2 = source.subscribe(); - s1.dispose(); - s2.dispose(); + d1.dispose(); + d2.dispose(); - s1 = null; - s2 = null; + d1 = null; + d2 = null; System.gc(); Thread.sleep(100); @@ -742,14 +742,14 @@ public Object call() throws Exception { .publish() .refCount(); - Disposable s1 = source.test(); - Disposable s2 = source.test(); + Disposable d1 = source.test(); + Disposable d2 = source.test(); - s1.dispose(); - s2.dispose(); + d1.dispose(); + d2.dispose(); - s1 = null; - s2 = null; + d1 = null; + d2 = null; System.gc(); Thread.sleep(100); @@ -767,11 +767,11 @@ public void replayIsUnsubscribed() { assertTrue(((Disposable)co).isDisposed()); - Disposable s = co.connect(); + Disposable connection = co.connect(); assertFalse(((Disposable)co).isDisposed()); - s.dispose(); + connection.dispose(); assertTrue(((Disposable)co).isDisposed()); } @@ -992,7 +992,7 @@ public void byCount() { Observable source = Observable.range(1, 5) .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { subscriptions[0]++; } }) @@ -1022,7 +1022,7 @@ public void resubscribeBeforeTimeout() throws Exception { Observable source = ps .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { subscriptions[0]++; } }) @@ -1065,7 +1065,7 @@ public void letitTimeout() throws Exception { Observable source = ps .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { subscriptions[0]++; } }) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java index 3ad79160a0..01f04653f2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java @@ -266,17 +266,17 @@ public void sampleWithSamplerThrows() { @Test public void testSampleUnsubscribe() { - final Disposable s = mock(Disposable.class); + final Disposable upstream = mock(Disposable.class); Observable o = Observable.unsafeCreate( new ObservableSource() { @Override public void subscribe(Observer observer) { - observer.onSubscribe(s); + observer.onSubscribe(upstream); } } ); o.throttleLast(1, TimeUnit.MILLISECONDS).subscribe().dispose(); - verify(s).dispose(); + verify(upstream).dispose(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmptyTest.java index 482c6f84d6..20c5018d01 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmptyTest.java @@ -35,7 +35,7 @@ public void testSwitchWhenNotEmpty() throws Exception { .switchIfEmpty(Observable.just(2) .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) { + public void accept(Disposable d) { subscribed.set(true); } })); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java index 4251fcc108..d78129e2ea 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java @@ -156,10 +156,10 @@ public void testTakeUntilOtherCompleted() { private static class TestObservable implements ObservableSource { Observer observer; - Disposable s; + Disposable upstream; - TestObservable(Disposable s) { - this.s = s; + TestObservable(Disposable d) { + this.upstream = d; } /* used to simulate subscription */ @@ -180,7 +180,7 @@ public void sendOnError(Throwable e) { @Override public void subscribe(Observer observer) { this.observer = observer; - observer.onSubscribe(s); + observer.onSubscribe(upstream); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeWhileTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeWhileTest.java index 4b615de665..6a92491a87 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeWhileTest.java @@ -145,8 +145,8 @@ public boolean test(String s) { @Test public void testUnsubscribeAfterTake() { - Disposable s = mock(Disposable.class); - TestObservable w = new TestObservable(s, "one", "two", "three"); + Disposable upstream = mock(Disposable.class); + TestObservable w = new TestObservable(upstream, "one", "two", "three"); Observer observer = TestHelper.mockObserver(); Observable take = Observable.unsafeCreate(w) @@ -172,24 +172,24 @@ public boolean test(String s) { verify(observer, times(1)).onNext("one"); verify(observer, never()).onNext("two"); verify(observer, never()).onNext("three"); - verify(s, times(1)).dispose(); + verify(upstream, times(1)).dispose(); } private static class TestObservable implements ObservableSource { - final Disposable s; + final Disposable upstream; final String[] values; Thread t; - TestObservable(Disposable s, String... values) { - this.s = s; + TestObservable(Disposable upstream, String... values) { + this.upstream = upstream; this.values = values; } @Override public void subscribe(final Observer observer) { System.out.println("TestObservable subscribed to ..."); - observer.onSubscribe(s); + observer.onSubscribe(upstream); t = new Thread(new Runnable() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java index 07e7c4c39b..21e8caea84 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java @@ -274,12 +274,12 @@ public void subscribe(Observer observer) { @Test public void shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout() throws InterruptedException { // From https://github.com/ReactiveX/RxJava/pull/951 - final Disposable s = mock(Disposable.class); + final Disposable upstream = mock(Disposable.class); Observable never = Observable.unsafeCreate(new ObservableSource() { @Override public void subscribe(Observer observer) { - observer.onSubscribe(s); + observer.onSubscribe(upstream); } }); @@ -296,19 +296,19 @@ public void subscribe(Observer observer) { inOrder.verify(observer).onError(isA(TimeoutException.class)); inOrder.verifyNoMoreInteractions(); - verify(s, times(1)).dispose(); + verify(upstream, times(1)).dispose(); } @Test @Ignore("s should be considered cancelled upon executing onComplete and not expect downstream to call cancel") public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyComplete() { // From https://github.com/ReactiveX/RxJava/pull/951 - final Disposable s = mock(Disposable.class); + final Disposable upstream = mock(Disposable.class); Observable immediatelyComplete = Observable.unsafeCreate(new ObservableSource() { @Override public void subscribe(Observer observer) { - observer.onSubscribe(s); + observer.onSubscribe(upstream); observer.onComplete(); } }); @@ -327,19 +327,19 @@ public void subscribe(Observer observer) { inOrder.verify(observer).onComplete(); inOrder.verifyNoMoreInteractions(); - verify(s, times(1)).dispose(); + verify(upstream, times(1)).dispose(); } @Test @Ignore("s should be considered cancelled upon executing onError and not expect downstream to call cancel") public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyErrored() throws InterruptedException { // From https://github.com/ReactiveX/RxJava/pull/951 - final Disposable s = mock(Disposable.class); + final Disposable upstream = mock(Disposable.class); Observable immediatelyError = Observable.unsafeCreate(new ObservableSource() { @Override public void subscribe(Observer observer) { - observer.onSubscribe(s); + observer.onSubscribe(upstream); observer.onError(new IOException("Error")); } }); @@ -358,7 +358,7 @@ public void subscribe(Observer observer) { inOrder.verify(observer).onError(isA(IOException.class)); inOrder.verifyNoMoreInteractions(); - verify(s, times(1)).dispose(); + verify(upstream, times(1)).dispose(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java index 4d38f049e7..3dad40f34a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java @@ -824,7 +824,7 @@ public void disposedUpfront() { Observable timeoutAndFallback = Observable.never().doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { counter.incrementAndGet(); } }); @@ -844,7 +844,7 @@ public void disposedUpfrontFallback() { Observable timeoutAndFallback = Observable.never().doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { counter.incrementAndGet(); } }); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java index 4276e3bc95..286bb7d4a9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java @@ -52,8 +52,8 @@ public void accept(Resource r) { private final Consumer disposeSubscription = new Consumer() { @Override - public void accept(Disposable s) { - s.dispose(); + public void accept(Disposable d) { + d.dispose(); } }; @@ -185,7 +185,7 @@ public Disposable call() { Function> observableFactory = new Function>() { @Override - public Observable apply(Disposable s) { + public Observable apply(Disposable d) { return Observable.empty(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java index 8422a44c12..ff524df77a 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java @@ -94,7 +94,7 @@ public void doOnSubscribeNormal() { Single.just(1).doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { count[0]++; } }) @@ -110,7 +110,7 @@ public void doOnSubscribeError() { Single.error(new TestException()).doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { count[0]++; } }) @@ -125,7 +125,7 @@ public void doOnSubscribeJustCrash() { Single.just(1).doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException(); } }) @@ -140,7 +140,7 @@ public void doOnSubscribeErrorCrash() { try { Single.error(new TestException("Outer")).doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException("Inner"); } }) @@ -344,7 +344,7 @@ protected void subscribeActual(SingleObserver observer) { } .doOnSubscribe(new Consumer() { @Override - public void accept(Disposable s) throws Exception { + public void accept(Disposable d) throws Exception { throw new TestException("First"); } }) diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowableTest.java index 086f72f838..1839772b67 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowableTest.java @@ -286,24 +286,24 @@ public Iterable apply(Object v) throws Exception { return Arrays.asList(1, 2, 3); } }).subscribe(new FlowableSubscriber() { - QueueSubscription qd; + QueueSubscription qs; @SuppressWarnings("unchecked") @Override - public void onSubscribe(Subscription d) { - qd = (QueueSubscription)d; + public void onSubscribe(Subscription s) { + qs = (QueueSubscription)s; - assertEquals(QueueFuseable.ASYNC, qd.requestFusion(QueueFuseable.ANY)); + assertEquals(QueueFuseable.ASYNC, qs.requestFusion(QueueFuseable.ANY)); } @Override public void onNext(Integer value) { - assertFalse(qd.isEmpty()); + assertFalse(qs.isEmpty()); - qd.clear(); + qs.clear(); - assertTrue(qd.isEmpty()); + assertTrue(qs.isEmpty()); - qd.cancel(); + qs.cancel(); } @Override diff --git a/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java index c6ec1c24ee..8643924bad 100644 --- a/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java @@ -401,8 +401,8 @@ static final class TestingDeferredScalarSubscriber extends DeferredScalarSubscri private static final long serialVersionUID = 6285096158319517837L; - TestingDeferredScalarSubscriber(Subscriber actual) { - super(actual); + TestingDeferredScalarSubscriber(Subscriber downstream) { + super(downstream); } @Override diff --git a/src/test/java/io/reactivex/internal/subscribers/StrictSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/StrictSubscriberTest.java index 0850149811..f8a3ccdb21 100644 --- a/src/test/java/io/reactivex/internal/subscribers/StrictSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/StrictSubscriberTest.java @@ -230,10 +230,10 @@ public void cancelAfterOnComplete() { final List list = new ArrayList(); Subscriber sub = new Subscriber() { - Subscription s; + Subscription upstream; @Override public void onSubscribe(Subscription s) { - this.s = s; + this.upstream = s; } @Override @@ -243,13 +243,13 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { - s.cancel(); + upstream.cancel(); list.add(t); } @Override public void onComplete() { - s.cancel(); + upstream.cancel(); list.add("Done"); } }; @@ -272,10 +272,10 @@ public void cancelAfterOnError() { final List list = new ArrayList(); Subscriber sub = new Subscriber() { - Subscription s; + Subscription upstream; @Override public void onSubscribe(Subscription s) { - this.s = s; + this.upstream = s; } @Override @@ -285,13 +285,13 @@ public void onNext(Object t) { @Override public void onError(Throwable t) { - s.cancel(); + upstream.cancel(); list.add(t.getMessage()); } @Override public void onComplete() { - s.cancel(); + upstream.cancel(); list.add("Done"); } }; diff --git a/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java b/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java index fa07598d30..9fbddd4279 100644 --- a/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java +++ b/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java @@ -482,11 +482,11 @@ public void validateDisposable() { @Test public void validateSubscription() { - BooleanSubscription d1 = new BooleanSubscription(); + BooleanSubscription bs1 = new BooleanSubscription(); - assertFalse(EndConsumerHelper.validate(SubscriptionHelper.CANCELLED, d1, getClass())); + assertFalse(EndConsumerHelper.validate(SubscriptionHelper.CANCELLED, bs1, getClass())); - assertTrue(d1.isCancelled()); + assertTrue(bs1.isCancelled()); assertTrue(errors.toString(), errors.isEmpty()); } diff --git a/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java b/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java index b66f5d5671..dcf4981856 100644 --- a/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java +++ b/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java @@ -34,12 +34,12 @@ public void reentrantOnNextOnNext() { final Observer[] a = { null }; - final TestObserver ts = new TestObserver(); + final TestObserver to = new TestObserver(); Observer observer = new Observer() { @Override - public void onSubscribe(Disposable s) { - ts.onSubscribe(s); + public void onSubscribe(Disposable d) { + to.onSubscribe(d); } @Override @@ -47,17 +47,17 @@ public void onNext(Object t) { if (t.equals(1)) { HalfSerializer.onNext(a[0], 2, wip, error); } - ts.onNext(t); + to.onNext(t); } @Override public void onError(Throwable t) { - ts.onError(t); + to.onError(t); } @Override public void onComplete() { - ts.onComplete(); + to.onComplete(); } }; @@ -67,7 +67,7 @@ public void onComplete() { HalfSerializer.onNext(observer, 1, wip, error); - ts.assertValue(1).assertNoErrors().assertNotComplete(); + to.assertValue(1).assertNoErrors().assertNotComplete(); } @Test @@ -78,12 +78,12 @@ public void reentrantOnNextOnError() { final Observer[] a = { null }; - final TestObserver ts = new TestObserver(); + final TestObserver to = new TestObserver(); Observer observer = new Observer() { @Override - public void onSubscribe(Disposable s) { - ts.onSubscribe(s); + public void onSubscribe(Disposable d) { + to.onSubscribe(d); } @Override @@ -91,17 +91,17 @@ public void onNext(Object t) { if (t.equals(1)) { HalfSerializer.onError(a[0], new TestException(), wip, error); } - ts.onNext(t); + to.onNext(t); } @Override public void onError(Throwable t) { - ts.onError(t); + to.onError(t); } @Override public void onComplete() { - ts.onComplete(); + to.onComplete(); } }; @@ -111,7 +111,7 @@ public void onComplete() { HalfSerializer.onNext(observer, 1, wip, error); - ts.assertFailure(TestException.class, 1); + to.assertFailure(TestException.class, 1); } @Test @@ -122,12 +122,12 @@ public void reentrantOnNextOnComplete() { final Observer[] a = { null }; - final TestObserver ts = new TestObserver(); + final TestObserver to = new TestObserver(); Observer observer = new Observer() { @Override - public void onSubscribe(Disposable s) { - ts.onSubscribe(s); + public void onSubscribe(Disposable d) { + to.onSubscribe(d); } @Override @@ -135,17 +135,17 @@ public void onNext(Object t) { if (t.equals(1)) { HalfSerializer.onComplete(a[0], wip, error); } - ts.onNext(t); + to.onNext(t); } @Override public void onError(Throwable t) { - ts.onError(t); + to.onError(t); } @Override public void onComplete() { - ts.onComplete(); + to.onComplete(); } }; @@ -155,7 +155,7 @@ public void onComplete() { HalfSerializer.onNext(observer, 1, wip, error); - ts.assertResult(1); + to.assertResult(1); } @Test @@ -166,28 +166,28 @@ public void reentrantErrorOnError() { final Observer[] a = { null }; - final TestObserver ts = new TestObserver(); + final TestObserver to = new TestObserver(); Observer observer = new Observer() { @Override - public void onSubscribe(Disposable s) { - ts.onSubscribe(s); + public void onSubscribe(Disposable d) { + to.onSubscribe(d); } @Override public void onNext(Object t) { - ts.onNext(t); + to.onNext(t); } @Override public void onError(Throwable t) { - ts.onError(t); + to.onError(t); HalfSerializer.onError(a[0], new IOException(), wip, error); } @Override public void onComplete() { - ts.onComplete(); + to.onComplete(); } }; @@ -197,7 +197,7 @@ public void onComplete() { HalfSerializer.onError(observer, new TestException(), wip, error); - ts.assertFailure(TestException.class); + to.assertFailure(TestException.class); } @Test diff --git a/src/test/java/io/reactivex/observable/ObservableNullTests.java b/src/test/java/io/reactivex/observable/ObservableNullTests.java index d04c324dfe..7a429c4555 100644 --- a/src/test/java/io/reactivex/observable/ObservableNullTests.java +++ b/src/test/java/io/reactivex/observable/ObservableNullTests.java @@ -1301,7 +1301,7 @@ public void doOnLifecycleOnSubscribeNull() { public void doOnLifecycleOnDisposeNull() { just1.doOnLifecycle(new Consumer() { @Override - public void accept(Disposable s) { } + public void accept(Disposable d) { } }, null); } diff --git a/src/test/java/io/reactivex/observable/ObservableTest.java b/src/test/java/io/reactivex/observable/ObservableTest.java index 64c5059bf8..fbe071714b 100644 --- a/src/test/java/io/reactivex/observable/ObservableTest.java +++ b/src/test/java/io/reactivex/observable/ObservableTest.java @@ -566,7 +566,7 @@ public void run() { }).replay(); // we connect immediately and it will emit the value - Disposable s = o.connect(); + Disposable connection = o.connect(); try { // we then expect the following 2 subscriptions to get that same value @@ -595,7 +595,7 @@ public void accept(String v) { } assertEquals(1, counter.get()); } finally { - s.dispose(); + connection.dispose(); } } diff --git a/src/test/java/io/reactivex/observers/SafeObserverTest.java b/src/test/java/io/reactivex/observers/SafeObserverTest.java index 54d1269138..12c355905f 100644 --- a/src/test/java/io/reactivex/observers/SafeObserverTest.java +++ b/src/test/java/io/reactivex/observers/SafeObserverTest.java @@ -485,7 +485,7 @@ public void onComplete() { }; SafeObserver observer = new SafeObserver(actual); - assertSame(actual, observer.actual); + assertSame(actual, observer.downstream); } @Test diff --git a/src/test/java/io/reactivex/parallel/ParallelFromPublisherTest.java b/src/test/java/io/reactivex/parallel/ParallelFromPublisherTest.java index baa37e3fee..48da2c566f 100644 --- a/src/test/java/io/reactivex/parallel/ParallelFromPublisherTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelFromPublisherTest.java @@ -80,13 +80,13 @@ protected void subscribeActual(Subscriber s) { static final class StripBoundarySubscriber extends BasicFuseableSubscriber { - StripBoundarySubscriber(Subscriber actual) { - super(actual); + StripBoundarySubscriber(Subscriber downstream) { + super(downstream); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override diff --git a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java index 9fa9cc92d0..a8c9668731 100644 --- a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java +++ b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java @@ -712,8 +712,8 @@ public Subscriber apply(Flowable f, final Subscriber t) { return new Subscriber() { @Override - public void onSubscribe(Subscription d) { - t.onSubscribe(d); + public void onSubscribe(Subscription s) { + t.onSubscribe(s); } @SuppressWarnings("unchecked") diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java index 75c013d996..fc5635d975 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java @@ -354,11 +354,11 @@ public void onNext(String v) { public void testSubscriptionLeak() { ReplayProcessor replaySubject = ReplayProcessor.create(); - Disposable s = replaySubject.subscribe(); + Disposable connection = replaySubject.subscribe(); assertEquals(1, replaySubject.subscriberCount()); - s.dispose(); + connection.dispose(); assertEquals(0, replaySubject.subscriberCount()); } diff --git a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java index 4e53fbcf42..954981a91e 100644 --- a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java @@ -189,13 +189,13 @@ public void run() { Scheduler custom = Schedulers.from(exec); Worker w = custom.createWorker(); try { - Disposable s1 = w.schedule(task); - Disposable s2 = w.schedule(task); - Disposable s3 = w.schedule(task); + Disposable d1 = w.schedule(task); + Disposable d2 = w.schedule(task); + Disposable d3 = w.schedule(task); - s1.dispose(); - s2.dispose(); - s3.dispose(); + d1.dispose(); + d2.dispose(); + d3.dispose(); exec.executeAll(); @@ -258,11 +258,11 @@ public void run() { // }; // ExecutorWorker w = (ExecutorWorker)Schedulers.from(e).createWorker(); // -// Disposable s = w.schedule(Functions.emptyRunnable(), 1, TimeUnit.DAYS); +// Disposable task = w.schedule(Functions.emptyRunnable(), 1, TimeUnit.DAYS); // // assertTrue(w.tasks.hasSubscriptions()); // -// s.dispose(); +// task.dispose(); // // assertFalse(w.tasks.hasSubscriptions()); // } @@ -285,13 +285,13 @@ public void run() { // } // }; // -// Disposable s = w.schedulePeriodically(action, 0, 1, TimeUnit.DAYS); +// Disposable task = w.schedulePeriodically(action, 0, 1, TimeUnit.DAYS); // // assertTrue(w.tasks.hasSubscriptions()); // // cdl.await(); // -// s.dispose(); +// task.dispose(); // // assertFalse(w.tasks.hasSubscriptions()); // } diff --git a/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java b/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java index 66ed876967..7f3098ef90 100644 --- a/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java +++ b/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java @@ -73,23 +73,23 @@ public void run() { } }; - CompositeDisposable csub = new CompositeDisposable(); + CompositeDisposable cd = new CompositeDisposable(); try { Worker w1 = Schedulers.computation().createWorker(); - csub.add(w1); + cd.add(w1); w1.schedule(countAction); Worker w2 = Schedulers.io().createWorker(); - csub.add(w2); + cd.add(w2); w2.schedule(countAction); Worker w3 = Schedulers.newThread().createWorker(); - csub.add(w3); + cd.add(w3); w3.schedule(countAction); Worker w4 = Schedulers.single().createWorker(); - csub.add(w4); + cd.add(w4); w4.schedule(countAction); @@ -97,7 +97,7 @@ public void run() { fail("countAction was not run by every worker"); } } finally { - csub.dispose(); + cd.dispose(); } } diff --git a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java index 3d93324d94..12f4116814 100644 --- a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java @@ -533,9 +533,9 @@ public void onSubscribeCancelsImmediately() { ps.subscribe(new Observer() { @Override - public void onSubscribe(Disposable s) { - s.dispose(); - s.dispose(); + public void onSubscribe(Disposable d) { + d.dispose(); + d.dispose(); } @Override diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java index 870b53e2d9..24d9704b8a 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java @@ -352,11 +352,11 @@ public void onNext(String v) { public void testSubscriptionLeak() { ReplaySubject subject = ReplaySubject.create(); - Disposable s = subject.subscribe(); + Disposable d = subject.subscribe(); assertEquals(1, subject.observerCount()); - s.dispose(); + d.dispose(); assertEquals(0, subject.observerCount()); } diff --git a/src/test/java/io/reactivex/subscribers/DisposableSubscriberTest.java b/src/test/java/io/reactivex/subscribers/DisposableSubscriberTest.java index 8e49bdea3d..d6ec19dd7c 100644 --- a/src/test/java/io/reactivex/subscribers/DisposableSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/DisposableSubscriberTest.java @@ -86,11 +86,11 @@ public void startOnce() { tc.onSubscribe(new BooleanSubscription()); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - tc.onSubscribe(d); + tc.onSubscribe(bs); - assertTrue(d.isCancelled()); + assertTrue(bs.isCancelled()); assertEquals(1, tc.start); @@ -110,11 +110,11 @@ public void dispose() { assertTrue(tc.isDisposed()); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - tc.onSubscribe(d); + tc.onSubscribe(bs); - assertTrue(d.isCancelled()); + assertTrue(bs.isCancelled()); assertEquals(0, tc.start); } diff --git a/src/test/java/io/reactivex/subscribers/ResourceSubscriberTest.java b/src/test/java/io/reactivex/subscribers/ResourceSubscriberTest.java index 1623765865..bcaf51acf1 100644 --- a/src/test/java/io/reactivex/subscribers/ResourceSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/ResourceSubscriberTest.java @@ -164,11 +164,11 @@ public void startOnce() { tc.onSubscribe(new BooleanSubscription()); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - tc.onSubscribe(d); + tc.onSubscribe(bs); - assertTrue(d.isCancelled()); + assertTrue(bs.isCancelled()); assertEquals(1, tc.start); @@ -183,11 +183,11 @@ public void dispose() { TestResourceSubscriber tc = new TestResourceSubscriber(); tc.dispose(); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - tc.onSubscribe(d); + tc.onSubscribe(bs); - assertTrue(d.isCancelled()); + assertTrue(bs.isCancelled()); assertEquals(0, tc.start); } diff --git a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java index 2e1893d2f8..d66a1ceecf 100644 --- a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java @@ -612,7 +612,7 @@ public void onComplete() { }; SafeSubscriber s = new SafeSubscriber(actual); - assertSame(actual, s.actual); + assertSame(actual, s.downstream); } @Test @@ -621,13 +621,13 @@ public void dispose() { SafeSubscriber so = new SafeSubscriber(ts); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); ts.dispose(); - assertTrue(d.isCancelled()); + assertTrue(bs.isCancelled()); // assertTrue(so.isDisposed()); } @@ -638,9 +638,9 @@ public void onNextAfterComplete() { SafeSubscriber so = new SafeSubscriber(ts); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); so.onComplete(); @@ -659,9 +659,9 @@ public void onNextNull() { SafeSubscriber so = new SafeSubscriber(ts); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); so.onNext(null); @@ -710,9 +710,9 @@ public void onNextNormal() { SafeSubscriber so = new SafeSubscriber(ts); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); so.onNext(1); so.onComplete(); diff --git a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java index 44d2920699..a6d4d4411f 100644 --- a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java @@ -1005,13 +1005,13 @@ public void dispose() { SerializedSubscriber so = new SerializedSubscriber(ts); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); ts.cancel(); - assertTrue(d.isCancelled()); + assertTrue(bs.isCancelled()); } @Test @@ -1021,9 +1021,9 @@ public void onCompleteRace() { final SerializedSubscriber so = new SerializedSubscriber(ts); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); Runnable r = new Runnable() { @Override @@ -1047,9 +1047,9 @@ public void onNextOnCompleteRace() { final SerializedSubscriber so = new SerializedSubscriber(ts); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); Runnable r1 = new Runnable() { @Override @@ -1083,9 +1083,9 @@ public void onNextOnErrorRace() { final SerializedSubscriber so = new SerializedSubscriber(ts); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); final Throwable ex = new TestException(); @@ -1121,9 +1121,9 @@ public void onNextOnErrorRaceDelayError() { final SerializedSubscriber so = new SerializedSubscriber(ts, true); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); final Throwable ex = new TestException(); @@ -1164,11 +1164,11 @@ public void startOnce() { so.onSubscribe(new BooleanSubscription()); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); - assertTrue(d.isCancelled()); + assertTrue(bs.isCancelled()); TestHelper.assertError(error, 0, IllegalStateException.class, "Subscription already set!"); } finally { @@ -1183,9 +1183,9 @@ public void onCompleteOnErrorRace() { final SerializedSubscriber so = new SerializedSubscriber(ts); - BooleanSubscription d = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(d); + so.onSubscribe(bs); final Throwable ex = new TestException(); diff --git a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java index a720be050c..85cd58baad 100644 --- a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java @@ -1369,22 +1369,22 @@ public void onSubscribe() { ts.onSubscribe(new BooleanSubscription()); - BooleanSubscription d1 = new BooleanSubscription(); + BooleanSubscription bs1 = new BooleanSubscription(); - ts.onSubscribe(d1); + ts.onSubscribe(bs1); - assertTrue(d1.isCancelled()); + assertTrue(bs1.isCancelled()); ts.assertError(IllegalStateException.class); ts = TestSubscriber.create(); ts.dispose(); - d1 = new BooleanSubscription(); + bs1 = new BooleanSubscription(); - ts.onSubscribe(d1); + ts.onSubscribe(bs1); - assertTrue(d1.isCancelled()); + assertTrue(bs1.isCancelled()); } @@ -1544,7 +1544,7 @@ public void completeDelegateThrows() { TestSubscriber ts = new TestSubscriber(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { + public void onSubscribe(Subscription s) { } @@ -1580,7 +1580,7 @@ public void errorDelegateThrows() { TestSubscriber ts = new TestSubscriber(new FlowableSubscriber() { @Override - public void onSubscribe(Subscription d) { + public void onSubscribe(Subscription s) { } diff --git a/src/test/java/io/reactivex/tck/RefCountProcessor.java b/src/test/java/io/reactivex/tck/RefCountProcessor.java index 43fc5d4064..de0538064b 100644 --- a/src/test/java/io/reactivex/tck/RefCountProcessor.java +++ b/src/test/java/io/reactivex/tck/RefCountProcessor.java @@ -172,14 +172,14 @@ static final class RefCountSubscriber extends AtomicBoolean implements Flowab private static final long serialVersionUID = -4317488092687530631L; - final Subscriber actual; + final Subscriber downstream; final RefCountProcessor parent; Subscription upstream; RefCountSubscriber(Subscriber actual, RefCountProcessor parent) { - this.actual = actual; + this.downstream = actual; this.parent = parent; } @@ -198,22 +198,22 @@ public void cancel() { @Override public void onSubscribe(Subscription s) { this.upstream = s; - actual.onSubscribe(this); + downstream.onSubscribe(this); } @Override public void onNext(T t) { - actual.onNext(t); + downstream.onNext(t); } @Override public void onError(Throwable t) { - actual.onError(t); + downstream.onError(t); } @Override public void onComplete() { - actual.onComplete(); + downstream.onComplete(); } } } diff --git a/src/test/java/io/reactivex/BaseTypeAnnotations.java b/src/test/java/io/reactivex/validators/BaseTypeAnnotations.java similarity index 99% rename from src/test/java/io/reactivex/BaseTypeAnnotations.java rename to src/test/java/io/reactivex/validators/BaseTypeAnnotations.java index 609da2b15a..5445115b44 100644 --- a/src/test/java/io/reactivex/BaseTypeAnnotations.java +++ b/src/test/java/io/reactivex/validators/BaseTypeAnnotations.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import static org.junit.Assert.fail; @@ -20,6 +20,7 @@ import org.junit.Test; import org.reactivestreams.Publisher; +import io.reactivex.*; import io.reactivex.annotations.*; /** diff --git a/src/test/java/io/reactivex/BaseTypeParser.java b/src/test/java/io/reactivex/validators/BaseTypeParser.java similarity index 99% rename from src/test/java/io/reactivex/BaseTypeParser.java rename to src/test/java/io/reactivex/validators/BaseTypeParser.java index 55067f74ce..42903ee386 100644 --- a/src/test/java/io/reactivex/BaseTypeParser.java +++ b/src/test/java/io/reactivex/validators/BaseTypeParser.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.io.File; import java.util.*; diff --git a/src/test/java/io/reactivex/CheckLocalVariablesInTests.java b/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java similarity index 65% rename from src/test/java/io/reactivex/CheckLocalVariablesInTests.java rename to src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java index 864dfe4362..9877a66cc1 100644 --- a/src/test/java/io/reactivex/CheckLocalVariablesInTests.java +++ b/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.io.*; import java.util.*; @@ -26,11 +26,21 @@ *
  • {@code TestObserver} named as {@code ts*}
  • *
  • {@code PublishProcessor} named as {@code ps*}
  • *
  • {@code PublishSubject} named as {@code pp*}
  • + *
  • {@code Subscription} with single letter name such as "s" or "d"
  • + *
  • {@code Disposable} with single letter name such as "s" or "d"
  • + *
  • {@code Flowable} named as {@code o|observable} + number
  • + *
  • {@code Observable} named as {@code f|flowable} + number
  • + *
  • {@code Subscriber} named as "o" or "observer"
  • + *
  • {@code Observer} named as "s" or "subscriber"
  • * */ public class CheckLocalVariablesInTests { static void findPattern(String pattern) throws Exception { + findPattern(pattern, false); + } + + static void findPattern(String pattern, boolean checkMain) throws Exception { File f = MaybeNo2Dot0Since.findSource("Flowable"); if (f == null) { System.out.println("Unable to find sources of RxJava"); @@ -44,6 +54,9 @@ static void findPattern(String pattern) throws Exception { File parent = f.getParentFile(); + if (checkMain) { + dirs.offer(new File(parent.getAbsolutePath().replace('\\', '/'))); + } dirs.offer(new File(parent.getAbsolutePath().replace('\\', '/').replace("src/main/java", "src/test/java"))); Pattern p = Pattern.compile(pattern); @@ -114,6 +127,16 @@ public void testObserverAsTs() throws Exception { findPattern("TestObserver<.*>\\s+ts"); } + @Test + public void testSubscriberNoArgAsTo() throws Exception { + findPattern("TestSubscriber\\s+to"); + } + + @Test + public void testObserverNoArgAsTs() throws Exception { + findPattern("TestObserver\\s+ts"); + } + @Test public void publishSubjectAsPp() throws Exception { findPattern("PublishSubject<.*>\\s+pp"); @@ -273,4 +296,126 @@ public void completableAsObservable() throws Exception { public void completableAsFlowable() throws Exception { findPattern("Completable\\s+flowable\\b"); } + + @Test + public void subscriptionAsFieldS() throws Exception { + findPattern("Subscription\\s+s[0-9]?;", true); + } + + @Test + public void subscriptionAsD() throws Exception { + findPattern("Subscription\\s+d[0-9]?", true); + } + + @Test + public void subscriptionAsSubscription() throws Exception { + findPattern("Subscription\\s+subscription[0-9]?;", true); + } + + @Test + public void subscriptionAsDParenthesis() throws Exception { + findPattern("Subscription\\s+d[0-9]?\\)", true); + } + + @Test + public void queueSubscriptionAsD() throws Exception { + findPattern("Subscription<.*>\\s+q?d[0-9]?\\b", true); + } + + @Test + public void booleanSubscriptionAsbd() throws Exception { + findPattern("BooleanSubscription\\s+bd[0-9]?;", true); + } + + @Test + public void atomicSubscriptionAsS() throws Exception { + findPattern("AtomicReference\\s+s[0-9]?;", true); + } + + @Test + public void atomicSubscriptionAsSubscription() throws Exception { + findPattern("AtomicReference\\s+subscription[0-9]?", true); + } + + @Test + public void atomicSubscriptionAsD() throws Exception { + findPattern("AtomicReference\\s+d[0-9]?", true); + } + + @Test + public void disposableAsS() throws Exception { + // the space before makes sure it doesn't match onSubscribe(Subscription) unnecessarily + findPattern("Disposable\\s+s[0-9]?\\b", true); + } + + @Test + public void disposableAsFieldD() throws Exception { + findPattern("Disposable\\s+d[0-9]?;", true); + } + + @Test + public void atomicDisposableAsS() throws Exception { + findPattern("AtomicReference\\s+s[0-9]?", true); + } + + @Test + public void atomicDisposableAsD() throws Exception { + findPattern("AtomicReference\\s+d[0-9]?;", true); + } + + @Test + public void subscriberAsFieldActual() throws Exception { + findPattern("Subscriber<.*>\\s+actual[;\\)]", true); + } + + @Test + public void subscriberNoArgAsFieldActual() throws Exception { + findPattern("Subscriber\\s+actual[;\\)]", true); + } + + @Test + public void subscriberAsFieldS() throws Exception { + findPattern("Subscriber<.*>\\s+s[0-9]?;", true); + } + + @Test + public void observerAsFieldActual() throws Exception { + findPattern("Observer<.*>\\s+actual[;\\)]", true); + } + + @Test + public void observerAsFieldSO() throws Exception { + findPattern("Observer<.*>\\s+[so][0-9]?;", true); + } + + @Test + public void observerNoArgAsFieldActual() throws Exception { + findPattern("Observer\\s+actual[;\\)]", true); + } + + @Test + public void observerNoArgAsFieldCs() throws Exception { + findPattern("Observer\\s+cs[;\\)]", true); + } + + @Test + public void observerNoArgAsFieldSO() throws Exception { + findPattern("Observer\\s+[so][0-9]?;", true); + } + + @Test + public void queueDisposableAsD() throws Exception { + findPattern("Disposable<.*>\\s+q?s[0-9]?\\b", true); + } + + @Test + public void disposableAsDParenthesis() throws Exception { + findPattern("Disposable\\s+s[0-9]?\\)", true); + } + + @Test + public void compositeDisposableAsCs() throws Exception { + findPattern("CompositeDisposable\\s+cs[0-9]?", true); + } + } diff --git a/src/test/java/io/reactivex/FixLicenseHeaders.java b/src/test/java/io/reactivex/validators/FixLicenseHeaders.java similarity index 99% rename from src/test/java/io/reactivex/FixLicenseHeaders.java rename to src/test/java/io/reactivex/validators/FixLicenseHeaders.java index 6cd016a593..3c96e5615e 100644 --- a/src/test/java/io/reactivex/FixLicenseHeaders.java +++ b/src/test/java/io/reactivex/validators/FixLicenseHeaders.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.io.*; import java.util.*; diff --git a/src/test/java/io/reactivex/InternalWrongNaming.java b/src/test/java/io/reactivex/validators/InternalWrongNaming.java similarity index 99% rename from src/test/java/io/reactivex/InternalWrongNaming.java rename to src/test/java/io/reactivex/validators/InternalWrongNaming.java index aed20c265d..cbe1cbe104 100644 --- a/src/test/java/io/reactivex/InternalWrongNaming.java +++ b/src/test/java/io/reactivex/validators/InternalWrongNaming.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.io.*; import java.util.*; diff --git a/src/test/java/io/reactivex/JavadocFindUnescapedAngleBrackets.java b/src/test/java/io/reactivex/validators/JavadocFindUnescapedAngleBrackets.java similarity index 99% rename from src/test/java/io/reactivex/JavadocFindUnescapedAngleBrackets.java rename to src/test/java/io/reactivex/validators/JavadocFindUnescapedAngleBrackets.java index bf4d2cbff5..1d8354186d 100644 --- a/src/test/java/io/reactivex/JavadocFindUnescapedAngleBrackets.java +++ b/src/test/java/io/reactivex/validators/JavadocFindUnescapedAngleBrackets.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.io.*; import java.util.*; diff --git a/src/test/java/io/reactivex/JavadocForAnnotations.java b/src/test/java/io/reactivex/validators/JavadocForAnnotations.java similarity index 99% rename from src/test/java/io/reactivex/JavadocForAnnotations.java rename to src/test/java/io/reactivex/validators/JavadocForAnnotations.java index 45aae9b97e..230a622de7 100644 --- a/src/test/java/io/reactivex/JavadocForAnnotations.java +++ b/src/test/java/io/reactivex/validators/JavadocForAnnotations.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import static org.junit.Assert.fail; @@ -19,6 +19,8 @@ import org.junit.*; +import io.reactivex.*; + /** * Checks the source code of the base reactive types and locates missing * mention of {@code Backpressure:} and {@code Scheduler:} of methods. diff --git a/src/test/java/io/reactivex/JavadocWording.java b/src/test/java/io/reactivex/validators/JavadocWording.java similarity index 99% rename from src/test/java/io/reactivex/JavadocWording.java rename to src/test/java/io/reactivex/validators/JavadocWording.java index 41d50e8d25..c8d01d7b61 100644 --- a/src/test/java/io/reactivex/JavadocWording.java +++ b/src/test/java/io/reactivex/validators/JavadocWording.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.util.List; import java.util.regex.Pattern; @@ -19,7 +19,7 @@ import static org.junit.Assert.*; import org.junit.Test; -import io.reactivex.BaseTypeParser.RxMethod; +import io.reactivex.validators.BaseTypeParser.RxMethod; /** * Check if the method wording is consistent with the target base type. diff --git a/src/test/java/io/reactivex/MaybeNo2Dot0Since.java b/src/test/java/io/reactivex/validators/MaybeNo2Dot0Since.java similarity index 98% rename from src/test/java/io/reactivex/MaybeNo2Dot0Since.java rename to src/test/java/io/reactivex/validators/MaybeNo2Dot0Since.java index 774f4ee920..3ee13fbb18 100644 --- a/src/test/java/io/reactivex/MaybeNo2Dot0Since.java +++ b/src/test/java/io/reactivex/validators/MaybeNo2Dot0Since.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import static org.junit.Assert.fail; @@ -20,6 +20,8 @@ import org.junit.Test; +import io.reactivex.Maybe; + /** * Checks the source code of Maybe and finds unnecessary since 2.0 annotations in the * method's javadocs. diff --git a/src/test/java/io/reactivex/NoAnonymousInnerClassesTest.java b/src/test/java/io/reactivex/validators/NoAnonymousInnerClassesTest.java similarity index 98% rename from src/test/java/io/reactivex/NoAnonymousInnerClassesTest.java rename to src/test/java/io/reactivex/validators/NoAnonymousInnerClassesTest.java index c611000c57..e26e3fb91d 100644 --- a/src/test/java/io/reactivex/NoAnonymousInnerClassesTest.java +++ b/src/test/java/io/reactivex/validators/NoAnonymousInnerClassesTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.io.File; import java.net.URL; diff --git a/src/test/java/io/reactivex/OperatorsAreFinal.java b/src/test/java/io/reactivex/validators/OperatorsAreFinal.java similarity index 98% rename from src/test/java/io/reactivex/OperatorsAreFinal.java rename to src/test/java/io/reactivex/validators/OperatorsAreFinal.java index ae1df8a499..5a149a94c5 100644 --- a/src/test/java/io/reactivex/OperatorsAreFinal.java +++ b/src/test/java/io/reactivex/validators/OperatorsAreFinal.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.io.File; import java.lang.reflect.Modifier; diff --git a/src/test/java/io/reactivex/ParamValidationCheckerTest.java b/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java similarity index 99% rename from src/test/java/io/reactivex/ParamValidationCheckerTest.java rename to src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java index 45c6dcafbf..136ba29581 100644 --- a/src/test/java/io/reactivex/ParamValidationCheckerTest.java +++ b/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.lang.reflect.*; import java.util.*; @@ -20,6 +20,9 @@ import org.junit.Test; import org.reactivestreams.*; +import io.reactivex.*; +import io.reactivex.Observable; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; diff --git a/src/test/java/io/reactivex/PublicFinalMethods.java b/src/test/java/io/reactivex/validators/PublicFinalMethods.java similarity index 96% rename from src/test/java/io/reactivex/PublicFinalMethods.java rename to src/test/java/io/reactivex/validators/PublicFinalMethods.java index b71ce574e5..d3d1c47188 100644 --- a/src/test/java/io/reactivex/PublicFinalMethods.java +++ b/src/test/java/io/reactivex/validators/PublicFinalMethods.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import static org.junit.Assert.fail; @@ -19,6 +19,8 @@ import org.junit.Test; +import io.reactivex.*; + /** * Verifies that instance methods of the base reactive classes are all declared final. */ diff --git a/src/test/java/io/reactivex/TextualAorAn.java b/src/test/java/io/reactivex/validators/TextualAorAn.java similarity index 99% rename from src/test/java/io/reactivex/TextualAorAn.java rename to src/test/java/io/reactivex/validators/TextualAorAn.java index 81aba8ccce..b31f40cfa8 100644 --- a/src/test/java/io/reactivex/TextualAorAn.java +++ b/src/test/java/io/reactivex/validators/TextualAorAn.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.validators; import java.io.*; import java.util.*; From 3562dfc5d2529efa5de41a7b8689f6847b3fb616 Mon Sep 17 00:00:00 2001 From: Aleksandar Simic Date: Sun, 5 Aug 2018 22:40:16 +0200 Subject: [PATCH 052/211] Add marble diagrams for various Single operators (#6141) --- src/main/java/io/reactivex/Single.java | 43 ++++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 0a461709df..f75b275a90 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -414,6 +414,8 @@ public static Flowable concatArrayEager(SingleSource... sour /** * Concatenates a Publisher sequence of SingleSources eagerly into a single stream of values. *

    + * + *

    * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * emitted source Publishers as they are observed. The operator buffers the values emitted by these * Publishers and then drains them in order, each one after the previous one completes. @@ -439,6 +441,8 @@ public static Flowable concatEager(Publisher + * + *

    * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source SingleSources. The operator buffers the values emitted by these SingleSources and then drains them * in order, each one after the previous one completes. @@ -462,6 +466,8 @@ public static Flowable concatEager(Iterable + * + *

    * Example: *

    
          * Single.<Event>create(emitter -> {
    @@ -808,6 +814,8 @@ public static  Single just(final T item) {
         /**
          * Merges an Iterable sequence of SingleSource instances into a single Flowable sequence,
          * running all SingleSources at once.
    +     * 

    + * *

    *
    Backpressure:
    *
    The returned {@code Flowable} honors the backpressure of the downstream consumer.
    @@ -843,6 +851,8 @@ public static Flowable merge(Iterable /** * Merges a Flowable sequence of SingleSource instances into a single Flowable sequence, * running all SingleSources at once. + *

    + * *

    *
    Backpressure:
    *
    The returned {@code Flowable} honors the backpressure of the downstream consumer.
    @@ -881,7 +891,7 @@ public static Flowable merge(Publisher - * + * *
    *
    Scheduler:
    *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    @@ -910,7 +920,7 @@ public static Single merge(SingleSource - * + * *

    * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by * using the {@code merge} method. @@ -958,7 +968,7 @@ public static Flowable merge( /** * Flattens three Singles into a single Flowable, without any transformation. *

    - * + * *

    * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using * the {@code merge} method. @@ -1010,7 +1020,7 @@ public static Flowable merge( /** * Flattens four Singles into a single Flowable, without any transformation. *

    - * + * *

    * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using * the {@code merge} method. @@ -1299,6 +1309,8 @@ public static Single timer(final long delay, final TimeUnit unit, final Sc /** * Compares two SingleSources and emits true if they emit the same value (compared via Object.equals). + *

    + * *

    *
    Scheduler:
    *
    {@code equals} does not operate by default on a particular {@link Scheduler}.
    @@ -1913,6 +1925,8 @@ public static Single zipArray(Function /** * Signals the event of this or the other SingleSource whichever signals first. + *

    + * *

    *
    Scheduler:
    *
    {@code ambWith} does not operate by default on a particular {@link Scheduler}.
    @@ -1933,6 +1947,8 @@ public final Single ambWith(SingleSource other) { /** * Calls the specified converter function during assembly time and returns its resulting value. *

    + * + *

    * This allows fluent conversion to any other type. *

    *
    Scheduler:
    @@ -1972,6 +1988,8 @@ public final Single hide() { /** * Transform a Single by applying a particular Transformer function to it. *

    + * + *

    * This method operates on the Single itself whereas {@link #lift} operates on the Single's SingleObservers. *

    * If the operator you are creating is designed to act on the individual item emitted by a Single, use @@ -2281,7 +2299,10 @@ public final Single delaySubscription(long time, TimeUnit unit, Scheduler sch /** * Calls the specified consumer with the success item after this item has been emitted to the downstream. - *

    Note that the {@code doAfterSuccess} action is shared between subscriptions and as such + *

    + * + *

    + * Note that the {@code doAfterSuccess} action is shared between subscriptions and as such * should be thread-safe. *

    *
    Scheduler:
    @@ -2301,10 +2322,12 @@ public final Single doAfterSuccess(Consumer onAfterSuccess) { /** * Registers an {@link Action} to be called after this Single invokes either onSuccess or onError. - * *

    Note that the {@code doAfterTerminate} action is shared between subscriptions and as such - * should be thread-safe.

    *

    - * + * + *

    + * Note that the {@code doAfterTerminate} action is shared between subscriptions and as such + * should be thread-safe.

    + * *
    *
    Scheduler:
    *
    {@code doAfterTerminate} does not operate by default on a particular {@link Scheduler}.
    @@ -2884,7 +2907,7 @@ public final Single contains(final Object value, final BiPredicate - * + * *

    * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using * the {@code mergeWith} method. @@ -3654,6 +3677,8 @@ private Single timeout0(final long timeout, final TimeUnit unit, final Schedu /** * Calls the specified converter function with the current Single instance * during assembly time and returns its result. + *

    + * *

    *
    Scheduler:
    *
    {@code to} does not operate by default on a particular {@link Scheduler}.
    From 1ad606b71f3ebb45282cabe0c7377b0908f3b582 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 7 Aug 2018 08:57:12 +0200 Subject: [PATCH 053/211] 2.x: Add concatArrayEagerDelayError operator (expose feature) (#6143) * 2.x: Add concatArrayEagerDelayError operator (expose feature) * Change text to "Concatenates an array of" --- src/main/java/io/reactivex/Flowable.java | 77 ++++++++++++- src/main/java/io/reactivex/Observable.java | 66 ++++++++++- .../flowable/FlowableConcatMapEagerTest.java | 106 ++++++++++++++++++ .../ObservableConcatMapEagerTest.java | 106 ++++++++++++++++++ .../validators/JavadocForAnnotations.java | 4 +- 5 files changed, 348 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 1afe7b594f..6af68db61d 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -17,6 +17,7 @@ import org.reactivestreams.*; +import io.reactivex.Observable; import io.reactivex.annotations.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; @@ -1415,7 +1416,9 @@ public static Flowable concatArrayDelayError(Publisher... so } /** - * Concatenates a sequence of Publishers eagerly into a single stream of values. + * Concatenates an array of Publishers eagerly into a single stream of values. + *

    + * *

    * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source Publishers. The operator buffers the values emitted by these Publishers and then drains them @@ -1430,7 +1433,7 @@ public static Flowable concatArrayDelayError(Publisher... so *

    This method does not operate by default on a particular {@link Scheduler}.
    *
    * @param the value type - * @param sources a sequence of Publishers that need to be eagerly concatenated + * @param sources an array of Publishers that need to be eagerly concatenated * @return the new Publisher instance with the specified concatenation behavior * @since 2.0 */ @@ -1442,7 +1445,9 @@ public static Flowable concatArrayEager(Publisher... sources } /** - * Concatenates a sequence of Publishers eagerly into a single stream of values. + * Concatenates an array of Publishers eagerly into a single stream of values. + *

    + * *

    * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source Publishers. The operator buffers the values emitted by these Publishers and then drains them @@ -1457,7 +1462,7 @@ public static Flowable concatArrayEager(Publisher... sources *

    This method does not operate by default on a particular {@link Scheduler}.
    *
    * @param the value type - * @param sources a sequence of Publishers that need to be eagerly concatenated + * @param sources an array of Publishers that need to be eagerly concatenated * @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE * is interpreted as an indication to subscribe to all sources at once * @param prefetch the number of elements to prefetch from each Publisher source @@ -1475,6 +1480,70 @@ public static Flowable concatArrayEager(int maxConcurrency, int prefetch, return RxJavaPlugins.onAssembly(new FlowableConcatMapEager(new FlowableFromArray(sources), Functions.identity(), maxConcurrency, prefetch, ErrorMode.IMMEDIATE)); } + /** + * Concatenates an array of {@link Publisher}s eagerly into a single stream of values + * and delaying any errors until all sources terminate. + *

    + * + *

    + * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the + * source {@code Publisher}s. The operator buffers the values emitted by these {@code Publisher}s + * and then drains them in order, each one after the previous one completes. + *

    + *
    Backpressure:
    + *
    The operator honors backpressure from downstream. The {@code Publisher} + * sources are expected to honor backpressure as well. + * If any of the source {@code Publisher}s violate this, the operator will signal a + * {@code MissingBackpressureException}.
    + *
    Scheduler:
    + *
    This method does not operate by default on a particular {@link Scheduler}.
    + *
    + * @param the value type + * @param sources an array of {@code Publisher}s that need to be eagerly concatenated + * @return the new Flowable instance with the specified concatenation behavior + * @since 2.2.1 - experimental + */ + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + @BackpressureSupport(BackpressureKind.FULL) + public static Flowable concatArrayEagerDelayError(Publisher... sources) { + return concatArrayEagerDelayError(bufferSize(), bufferSize(), sources); + } + + /** + * Concatenates an array of {@link Publisher}s eagerly into a single stream of values + * and delaying any errors until all sources terminate. + *

    + * + *

    + * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the + * source {@code Publisher}s. The operator buffers the values emitted by these {@code Publisher}s + * and then drains them in order, each one after the previous one completes. + *

    + *
    Backpressure:
    + *
    The operator honors backpressure from downstream. The {@code Publisher} + * sources are expected to honor backpressure as well. + * If any of the source {@code Publisher}s violate this, the operator will signal a + * {@code MissingBackpressureException}.
    + *
    Scheduler:
    + *
    This method does not operate by default on a particular {@link Scheduler}.
    + *
    + * @param the value type + * @param sources an array of {@code Publisher}s that need to be eagerly concatenated + * @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE + * is interpreted as indication to subscribe to all sources at once + * @param prefetch the number of elements to prefetch from each {@code Publisher} source + * @return the new Flowable instance with the specified concatenation behavior + * @since 2.2.1 - experimental + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + @BackpressureSupport(BackpressureKind.FULL) + public static Flowable concatArrayEagerDelayError(int maxConcurrency, int prefetch, Publisher... sources) { + return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, true); + } + /** * Concatenates the Iterable sequence of Publishers into a single sequence by subscribing to each Publisher, * one after the other, one at a time and delays any errors till the all inner Publishers terminate. diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index ab38ab2374..2c43e0abf0 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -1294,19 +1294,19 @@ public static Observable concatArrayDelayError(ObservableSource + * *

    * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them * in order, each one after the previous one completes. - *

    - * *

    *
    Scheduler:
    *
    This method does not operate by default on a particular {@link Scheduler}.
    *
    * @param the value type - * @param sources a sequence of ObservableSources that need to be eagerly concatenated + * @param sources an array of ObservableSources that need to be eagerly concatenated * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @@ -1317,7 +1317,9 @@ public static Observable concatArrayEager(ObservableSource.. } /** - * Concatenates a sequence of ObservableSources eagerly into a single stream of values. + * Concatenates an array of ObservableSources eagerly into a single stream of values. + *

    + * *

    * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them @@ -1327,7 +1329,7 @@ public static Observable concatArrayEager(ObservableSource.. *

    This method does not operate by default on a particular {@link Scheduler}.
    *
    * @param the value type - * @param sources a sequence of ObservableSources that need to be eagerly concatenated + * @param sources an array of ObservableSources that need to be eagerly concatenated * @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE * is interpreted as indication to subscribe to all sources at once * @param prefetch the number of elements to prefetch from each ObservableSource source @@ -1341,6 +1343,58 @@ public static Observable concatArrayEager(int maxConcurrency, int prefetc return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, false); } + /** + * Concatenates an array of {@link ObservableSource}s eagerly into a single stream of values + * and delaying any errors until all sources terminate. + *

    + * + *

    + * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the + * source {@code ObservableSource}s. The operator buffers the values emitted by these {@code ObservableSource}s + * and then drains them in order, each one after the previous one completes. + *

    + *
    Scheduler:
    + *
    This method does not operate by default on a particular {@link Scheduler}.
    + *
    + * @param the value type + * @param sources an array of {@code ObservableSource}s that need to be eagerly concatenated + * @return the new Observable instance with the specified concatenation behavior + * @since 2.2.1 - experimental + */ + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + public static Observable concatArrayEagerDelayError(ObservableSource... sources) { + return concatArrayEagerDelayError(bufferSize(), bufferSize(), sources); + } + + /** + * Concatenates an array of {@link ObservableSource}s eagerly into a single stream of values + * and delaying any errors until all sources terminate. + *

    + * + *

    + * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the + * source {@code ObservableSource}s. The operator buffers the values emitted by these {@code ObservableSource}s + * and then drains them in order, each one after the previous one completes. + *

    + *
    Scheduler:
    + *
    This method does not operate by default on a particular {@link Scheduler}.
    + *
    + * @param the value type + * @param sources an array of {@code ObservableSource}s that need to be eagerly concatenated + * @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE + * is interpreted as indication to subscribe to all sources at once + * @param prefetch the number of elements to prefetch from each {@code ObservableSource} source + * @return the new Observable instance with the specified concatenation behavior + * @since 2.2.1 - experimental + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + public static Observable concatArrayEagerDelayError(int maxConcurrency, int prefetch, ObservableSource... sources) { + return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, true); + } + /** * Concatenates the Iterable sequence of ObservableSources into a single sequence by subscribing to each ObservableSource, * one after the other, one at a time and delays any errors till the all inner ObservableSources terminate. diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java index 39a9427181..3c77acb502 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java @@ -1228,4 +1228,110 @@ public void accept(List v) .awaitDone(5, TimeUnit.SECONDS) .assertResult(list); } + + @Test + public void arrayDelayErrorDefault() { + PublishProcessor pp1 = PublishProcessor.create(); + PublishProcessor pp2 = PublishProcessor.create(); + PublishProcessor pp3 = PublishProcessor.create(); + + @SuppressWarnings("unchecked") + TestSubscriber ts = Flowable.concatArrayEagerDelayError(pp1, pp2, pp3) + .test(); + + ts.assertEmpty(); + + assertTrue(pp1.hasSubscribers()); + assertTrue(pp2.hasSubscribers()); + assertTrue(pp3.hasSubscribers()); + + pp2.onNext(2); + pp2.onComplete(); + + ts.assertEmpty(); + + pp1.onNext(1); + + ts.assertValuesOnly(1); + + pp1.onComplete(); + + ts.assertValuesOnly(1, 2); + + pp3.onComplete(); + + ts.assertResult(1, 2); + } + + @Test + public void arrayDelayErrorMaxConcurrency() { + PublishProcessor pp1 = PublishProcessor.create(); + PublishProcessor pp2 = PublishProcessor.create(); + PublishProcessor pp3 = PublishProcessor.create(); + + @SuppressWarnings("unchecked") + TestSubscriber ts = Flowable.concatArrayEagerDelayError(2, 2, pp1, pp2, pp3) + .test(); + + ts.assertEmpty(); + + assertTrue(pp1.hasSubscribers()); + assertTrue(pp2.hasSubscribers()); + assertFalse(pp3.hasSubscribers()); + + pp2.onNext(2); + pp2.onComplete(); + + ts.assertEmpty(); + + pp1.onNext(1); + + ts.assertValuesOnly(1); + + pp1.onComplete(); + + assertTrue(pp3.hasSubscribers()); + + ts.assertValuesOnly(1, 2); + + pp3.onComplete(); + + ts.assertResult(1, 2); + } + + @Test + public void arrayDelayErrorMaxConcurrencyErrorDelayed() { + PublishProcessor pp1 = PublishProcessor.create(); + PublishProcessor pp2 = PublishProcessor.create(); + PublishProcessor pp3 = PublishProcessor.create(); + + @SuppressWarnings("unchecked") + TestSubscriber ts = Flowable.concatArrayEagerDelayError(2, 2, pp1, pp2, pp3) + .test(); + + ts.assertEmpty(); + + assertTrue(pp1.hasSubscribers()); + assertTrue(pp2.hasSubscribers()); + assertFalse(pp3.hasSubscribers()); + + pp2.onNext(2); + pp2.onError(new TestException()); + + ts.assertEmpty(); + + pp1.onNext(1); + + ts.assertValuesOnly(1); + + pp1.onComplete(); + + assertTrue(pp3.hasSubscribers()); + + ts.assertValuesOnly(1, 2); + + pp3.onComplete(); + + ts.assertFailure(TestException.class, 1, 2); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java index 8874eec137..0f6920ecb3 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java @@ -1036,4 +1036,110 @@ public void accept(List v) .awaitDone(5, TimeUnit.SECONDS) .assertResult(list); } + + @Test + public void arrayDelayErrorDefault() { + PublishSubject ps1 = PublishSubject.create(); + PublishSubject ps2 = PublishSubject.create(); + PublishSubject ps3 = PublishSubject.create(); + + @SuppressWarnings("unchecked") + TestObserver to = Observable.concatArrayEagerDelayError(ps1, ps2, ps3) + .test(); + + to.assertEmpty(); + + assertTrue(ps1.hasObservers()); + assertTrue(ps2.hasObservers()); + assertTrue(ps3.hasObservers()); + + ps2.onNext(2); + ps2.onComplete(); + + to.assertEmpty(); + + ps1.onNext(1); + + to.assertValuesOnly(1); + + ps1.onComplete(); + + to.assertValuesOnly(1, 2); + + ps3.onComplete(); + + to.assertResult(1, 2); + } + + @Test + public void arrayDelayErrorMaxConcurrency() { + PublishSubject ps1 = PublishSubject.create(); + PublishSubject ps2 = PublishSubject.create(); + PublishSubject ps3 = PublishSubject.create(); + + @SuppressWarnings("unchecked") + TestObserver to = Observable.concatArrayEagerDelayError(2, 2, ps1, ps2, ps3) + .test(); + + to.assertEmpty(); + + assertTrue(ps1.hasObservers()); + assertTrue(ps2.hasObservers()); + assertFalse(ps3.hasObservers()); + + ps2.onNext(2); + ps2.onComplete(); + + to.assertEmpty(); + + ps1.onNext(1); + + to.assertValuesOnly(1); + + ps1.onComplete(); + + assertTrue(ps3.hasObservers()); + + to.assertValuesOnly(1, 2); + + ps3.onComplete(); + + to.assertResult(1, 2); + } + + @Test + public void arrayDelayErrorMaxConcurrencyErrorDelayed() { + PublishSubject ps1 = PublishSubject.create(); + PublishSubject ps2 = PublishSubject.create(); + PublishSubject ps3 = PublishSubject.create(); + + @SuppressWarnings("unchecked") + TestObserver to = Observable.concatArrayEagerDelayError(2, 2, ps1, ps2, ps3) + .test(); + + to.assertEmpty(); + + assertTrue(ps1.hasObservers()); + assertTrue(ps2.hasObservers()); + assertFalse(ps3.hasObservers()); + + ps2.onNext(2); + ps2.onError(new TestException()); + + to.assertEmpty(); + + ps1.onNext(1); + + to.assertValuesOnly(1); + + ps1.onComplete(); + + assertTrue(ps3.hasObservers()); + + to.assertValuesOnly(1, 2); + + ps3.onComplete(); + + to.assertFailure(TestException.class, 1, 2); + } } diff --git a/src/test/java/io/reactivex/validators/JavadocForAnnotations.java b/src/test/java/io/reactivex/validators/JavadocForAnnotations.java index 230a622de7..9dae922016 100644 --- a/src/test/java/io/reactivex/validators/JavadocForAnnotations.java +++ b/src/test/java/io/reactivex/validators/JavadocForAnnotations.java @@ -129,8 +129,10 @@ static final void scanForBadMethod(StringBuilder sourceCode, String annotation, if ((ll < 0 || ll > idx) && (lm < 0 || lm > idx)) { int n = sourceCode.indexOf("{@code ", k); + int endDD = sourceCode.indexOf("", k); + // make sure the {@code is within the dt/dd section - if (n < idx) { + if (n < idx && n < endDD) { int m = sourceCode.indexOf("}", n); if (m < idx) { From fd63c492c576a2784a5665925457b75355ecffaa Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 8 Aug 2018 09:42:25 +0200 Subject: [PATCH 054/211] 2.x: Fix boundary fusion of concatMap and publish operator (#6145) --- .../operators/flowable/FlowableConcatMap.java | 2 +- .../operators/flowable/FlowablePublish.java | 16 +-- .../flowable/FlowableConcatMapTest.java | 104 ++++++++++++++++++ .../flowable/FlowablePublishTest.java | 51 +++++++++ 4 files changed, 164 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java index 27016a1dd8..4dc60faa5a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java @@ -113,7 +113,7 @@ public final void onSubscribe(Subscription s) { if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") QueueSubscription f = (QueueSubscription)s; - int m = f.requestFusion(QueueSubscription.ANY); + int m = f.requestFusion(QueueSubscription.ANY | QueueSubscription.BOUNDARY); if (m == QueueSubscription.SYNC) { sourceMode = m; queue = f; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java index 9bc0d63b65..6122974695 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java @@ -155,7 +155,7 @@ static final class PublishSubscriber */ final AtomicBoolean shouldConnect; - final AtomicReference s = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); /** Contains either an onComplete or an onError token from upstream. */ volatile Object terminalEvent; @@ -180,7 +180,7 @@ public void dispose() { InnerSubscriber[] ps = subscribers.getAndSet(TERMINATED); if (ps != TERMINATED) { current.compareAndSet(PublishSubscriber.this, null); - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); } } } @@ -192,12 +192,12 @@ public boolean isDisposed() { @Override public void onSubscribe(Subscription s) { - if (SubscriptionHelper.setOnce(this.s, s)) { + if (SubscriptionHelper.setOnce(this.upstream, s)) { if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") QueueSubscription qs = (QueueSubscription) s; - int m = qs.requestFusion(QueueSubscription.ANY); + int m = qs.requestFusion(QueueSubscription.ANY | QueueSubscription.BOUNDARY); if (m == QueueSubscription.SYNC) { sourceMode = m; queue = qs; @@ -482,7 +482,7 @@ void dispatch() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.get().cancel(); + upstream.get().cancel(); term = NotificationLite.error(ex); terminalEvent = term; v = null; @@ -493,7 +493,7 @@ void dispatch() { } // otherwise, just ask for a new value if (sourceMode != QueueSubscription.SYNC) { - s.get().request(1); + upstream.get().request(1); } // and retry emitting to potential new child subscribers continue; @@ -510,7 +510,7 @@ void dispatch() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.get().cancel(); + upstream.get().cancel(); term = NotificationLite.error(ex); terminalEvent = term; v = null; @@ -562,7 +562,7 @@ void dispatch() { // if we did emit at least one element, request more to replenish the queue if (d > 0) { if (sourceMode != QueueSubscription.SYNC) { - s.get().request(d); + upstream.get().request(d); } } // if we have requests but not an empty queue after emission diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java index c1ad560478..ac5c573910 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java @@ -13,9 +13,16 @@ package io.reactivex.internal.operators.flowable; +import java.util.concurrent.TimeUnit; + import org.junit.Test; +import org.reactivestreams.Publisher; +import io.reactivex.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Function; import io.reactivex.internal.operators.flowable.FlowableConcatMap.WeakScalarSubscription; +import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; public class FlowableConcatMapTest { @@ -39,4 +46,101 @@ public void weakSubscriptionRequest() { ts.assertResult(1); } + @Test + public void boundaryFusion() { + Flowable.range(1, 10000) + .observeOn(Schedulers.single()) + .map(new Function() { + @Override + public String apply(Integer t) throws Exception { + String name = Thread.currentThread().getName(); + if (name.contains("RxSingleScheduler")) { + return "RxSingleScheduler"; + } + return name; + } + }) + .concatMap(new Function>() { + @Override + public Publisher apply(String v) + throws Exception { + return Flowable.just(v); + } + }) + .observeOn(Schedulers.computation()) + .distinct() + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult("RxSingleScheduler"); + } + + @Test + public void boundaryFusionDelayError() { + Flowable.range(1, 10000) + .observeOn(Schedulers.single()) + .map(new Function() { + @Override + public String apply(Integer t) throws Exception { + String name = Thread.currentThread().getName(); + if (name.contains("RxSingleScheduler")) { + return "RxSingleScheduler"; + } + return name; + } + }) + .concatMapDelayError(new Function>() { + @Override + public Publisher apply(String v) + throws Exception { + return Flowable.just(v); + } + }) + .observeOn(Schedulers.computation()) + .distinct() + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult("RxSingleScheduler"); + } + + @Test + public void pollThrows() { + Flowable.just(1) + .map(new Function() { + @Override + public Integer apply(Integer v) throws Exception { + throw new TestException(); + } + }) + .compose(TestHelper.flowableStripBoundary()) + .concatMap(new Function>() { + @Override + public Publisher apply(Integer v) + throws Exception { + return Flowable.just(v); + } + }) + .test() + .assertFailure(TestException.class); + } + + @Test + public void pollThrowsDelayError() { + Flowable.just(1) + .map(new Function() { + @Override + public Integer apply(Integer v) throws Exception { + throw new TestException(); + } + }) + .compose(TestHelper.flowableStripBoundary()) + .concatMapDelayError(new Function>() { + @Override + public Publisher apply(Integer v) + throws Exception { + return Flowable.just(v); + } + }) + .test() + .assertFailure(TestException.class); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java index bf8b269196..c18cbc928b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java @@ -824,12 +824,36 @@ public Object apply(Integer v) throws Exception { throw new TestException(); } }) + .compose(TestHelper.flowableStripBoundary()) .publish() .autoConnect() .test() .assertFailure(TestException.class); } + @Test + public void pollThrowsNoSubscribers() { + ConnectableFlowable cf = Flowable.just(1, 2) + .map(new Function() { + @Override + public Integer apply(Integer v) throws Exception { + if (v == 2) { + throw new TestException(); + } + return v; + } + }) + .compose(TestHelper.flowableStripBoundary()) + .publish(); + + TestSubscriber ts = cf.take(1) + .test(); + + cf.connect(); + + ts.assertResult(1); + } + @Test public void dryRunCrash() { List errors = TestHelper.trackPluginErrors(); @@ -1316,4 +1340,31 @@ public void onComplete() { ts1.assertEmpty(); ts2.assertValuesOnly(1); } + + @Test + public void boundaryFusion() { + Flowable.range(1, 10000) + .observeOn(Schedulers.single()) + .map(new Function() { + @Override + public String apply(Integer t) throws Exception { + String name = Thread.currentThread().getName(); + if (name.contains("RxSingleScheduler")) { + return "RxSingleScheduler"; + } + return name; + } + }) + .share() + .observeOn(Schedulers.computation()) + .distinct() + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult("RxSingleScheduler"); + } + + @Test + public void badRequest() { + TestHelper.assertBadRequestReported(Flowable.range(1, 5).publish()); + } } From 10f8c6767b036b8b70bc93a74aa7c62a47431d27 Mon Sep 17 00:00:00 2001 From: spreddy2714 Date: Thu, 9 Aug 2018 13:24:35 +0530 Subject: [PATCH 055/211] Grammar fix (#6149) Scheduler description is grammatically error. Replaced "an unifrom" with "a uniform" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 957d1a05e6..92bdf2946f 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ Typically, you can move computations or blocking IO to some other thread via `su ### Schedulers -RxJava operators don't work with `Thread`s or `ExecutorService`s directly but with so called `Scheduler`s that abstract away sources of concurrency behind an uniform API. RxJava 2 features several standard schedulers accessible via `Schedulers` utility class. +RxJava operators don't work with `Thread`s or `ExecutorService`s directly but with so called `Scheduler`s that abstract away sources of concurrency behind a uniform API. RxJava 2 features several standard schedulers accessible via `Schedulers` utility class. - `Schedulers.computation()`: Run computation intensive work on a fixed number of dedicated threads in the background. Most asynchronous operator use this as their default `Scheduler`. - `Schedulers.io()`: Run I/O-like or blocking operations on a dynamically changing set of threads. From 0e7b8eaa61f9cac0538ef6a59bfbd0b119b87732 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 9 Aug 2018 16:35:12 +0200 Subject: [PATCH 056/211] 2.x: cleanup newline separation, some field namings (#6150) * 2.x: cleanup newline separation, some field namings * Fix missed two-empty-line cases --- .../io/reactivex/EachTypeFlatMapPerf.java | 5 + .../io/reactivex/LatchedSingleObserver.java | 3 + src/jmh/java/io/reactivex/PerfObserver.java | 4 + .../io/reactivex/PublishProcessorPerf.java | 3 - src/jmh/java/io/reactivex/ToFlowablePerf.java | 1 + .../internal/disposables/EmptyDisposable.java | 1 - .../observers/DisposableLambdaObserver.java | 1 - .../completable/CompletableFromPublisher.java | 1 - .../completable/CompletablePeek.java | 1 - .../completable/CompletableResumeNext.java | 3 - .../completable/CompletableUsing.java | 1 - .../operators/flowable/FlowableAll.java | 1 + .../operators/flowable/FlowableAllSingle.java | 1 + .../operators/flowable/FlowableAny.java | 1 + .../operators/flowable/FlowableAnySingle.java | 1 + .../flowable/FlowableBufferTimed.java | 1 - .../operators/flowable/FlowableCache.java | 4 + .../operators/flowable/FlowableConcatMap.java | 1 - .../flowable/FlowableDebounceTimed.java | 1 + .../operators/flowable/FlowableDefer.java | 1 + .../flowable/FlowableDematerialize.java | 1 + .../operators/flowable/FlowableError.java | 1 + .../operators/flowable/FlowableFlatMap.java | 5 + .../operators/flowable/FlowableFromArray.java | 2 +- .../flowable/FlowableFromCallable.java | 1 + .../flowable/FlowableFromIterable.java | 2 - .../flowable/FlowableOnBackpressureError.java | 1 - .../operators/flowable/FlowablePublish.java | 2 + .../operators/flowable/FlowableRange.java | 2 +- .../operators/flowable/FlowableRepeat.java | 1 + .../flowable/FlowableRepeatUntil.java | 1 + .../operators/flowable/FlowableReplay.java | 3 + .../flowable/FlowableRetryBiPredicate.java | 1 + .../flowable/FlowableRetryPredicate.java | 1 + .../operators/flowable/FlowableTake.java | 6 + .../flowable/FlowableTimeInterval.java | 1 - .../flowable/FlowableWithLatestFrom.java | 13 +- .../flowable/FlowableWithLatestFromMany.java | 4 +- .../operators/maybe/MaybeSwitchIfEmpty.java | 4 + .../maybe/MaybeSwitchIfEmptySingle.java | 3 + .../mixed/CompletableAndThenObservable.java | 1 - .../operators/observable/ObservableAll.java | 1 + .../observable/ObservableAllSingle.java | 1 + .../operators/observable/ObservableAny.java | 1 + .../observable/ObservableAnySingle.java | 1 + .../observable/ObservableBuffer.java | 1 - .../observable/ObservableBufferTimed.java | 1 - .../operators/observable/ObservableCache.java | 4 + .../observable/ObservableCollect.java | 2 - .../observable/ObservableCollectSingle.java | 2 - .../observable/ObservableCombineLatest.java | 1 - .../observable/ObservableConcatMap.java | 7 + .../operators/observable/ObservableCount.java | 1 - .../observable/ObservableCountSingle.java | 1 - .../observable/ObservableDebounceTimed.java | 1 + .../operators/observable/ObservableDefer.java | 1 + .../observable/ObservableDematerialize.java | 3 +- .../observable/ObservableDoOnEach.java | 2 - .../observable/ObservableElementAt.java | 3 +- .../observable/ObservableElementAtMaybe.java | 3 +- .../observable/ObservableElementAtSingle.java | 2 - .../operators/observable/ObservableError.java | 1 + .../observable/ObservableFlatMap.java | 5 + .../observable/ObservableFromArray.java | 1 + .../observable/ObservableFromCallable.java | 1 + .../observable/ObservableGenerate.java | 1 - .../observable/ObservableMapNotification.java | 2 - .../observable/ObservableMaterialize.java | 1 - .../observable/ObservableOnErrorReturn.java | 1 - .../observable/ObservablePublish.java | 2 + .../observable/ObservableRepeat.java | 1 + .../observable/ObservableRepeatUntil.java | 1 + .../observable/ObservableReplay.java | 4 + .../ObservableRetryBiPredicate.java | 1 + .../observable/ObservableRetryPredicate.java | 1 + .../observable/ObservableSampleTimed.java | 1 - .../operators/observable/ObservableScan.java | 2 - .../observable/ObservableScanSeed.java | 1 - .../observable/ObservableSingleMaybe.java | 3 +- .../observable/ObservableSingleSingle.java | 2 - .../observable/ObservableSkipLast.java | 1 - .../observable/ObservableSkipWhile.java | 2 - .../operators/observable/ObservableTake.java | 4 + .../observable/ObservableTakeUntil.java | 1 + .../observable/ObservableTakeWhile.java | 2 - .../observable/ObservableTimeInterval.java | 1 - .../observable/ObservableToList.java | 2 - .../observable/ObservableToListSingle.java | 2 - .../observable/ObservableWithLatestFrom.java | 1 + .../operators/observable/ObservableZip.java | 1 + .../observable/ObservableZipIterable.java | 2 - .../operators/single/SingleEquals.java | 1 + .../single/SingleInternalHelper.java | 1 + .../operators/single/SingleOnErrorReturn.java | 2 - .../internal/queue/SpscLinkedArrayQueue.java | 2 + .../schedulers/ComputationScheduler.java | 1 + .../internal/schedulers/IoScheduler.java | 1 + .../subscriptions/EmptySubscription.java | 7 + .../internal/util/LinkedArrayList.java | 1 + .../io/reactivex/observers/SafeObserver.java | 1 - .../observers/SerializedObserver.java | 2 - .../processors/PublishProcessor.java | 1 - .../reactivex/processors/ReplayProcessor.java | 2 +- .../io/reactivex/subjects/PublishSubject.java | 1 - .../reactivex/subjects/SerializedSubject.java | 1 - .../subscribers/DisposableSubscriber.java | 12 +- .../subscribers/ResourceSubscriber.java | 10 +- .../completable/CompletableTest.java | 2 +- .../disposables/CompositeDisposableTest.java | 1 + .../exceptions/CompositeExceptionTest.java | 1 + .../OnErrorNotImplementedExceptionTest.java | 1 - .../flowable/FlowableCollectTest.java | 5 - .../reactivex/flowable/FlowableNullTests.java | 1 - .../flowable/FlowableReduceTests.java | 1 - .../flowable/FlowableSubscriberTest.java | 1 - .../io/reactivex/flowable/FlowableTests.java | 2 - .../reactivex/internal/SubscribeWithTest.java | 1 - .../observers/BasicFuseableObserverTest.java | 5 + .../observers/DeferredScalarObserverTest.java | 1 - .../observers/LambdaObserverTest.java | 1 + .../completable/CompletableAmbTest.java | 1 - .../CompletableResumeNextTest.java | 1 - .../completable/CompletableSubscribeTest.java | 1 - .../completable/CompletableUsingTest.java | 1 - .../BlockingFlowableMostRecentTest.java | 1 - .../operators/flowable/FlowableAllTest.java | 2 + .../operators/flowable/FlowableAmbTest.java | 1 - .../operators/flowable/FlowableAnyTest.java | 2 + .../flowable/FlowableAsObservableTest.java | 1 + .../flowable/FlowableBufferTest.java | 11 +- .../operators/flowable/FlowableCacheTest.java | 2 + .../flowable/FlowableCombineLatestTest.java | 1 + .../FlowableConcatDelayErrorTest.java | 1 - .../flowable/FlowableConcatMapEagerTest.java | 1 - .../flowable/FlowableConcatTest.java | 2 + .../flowable/FlowableConcatWithMaybeTest.java | 1 - .../operators/flowable/FlowableCountTest.java | 1 - .../flowable/FlowableCreateTest.java | 1 - .../flowable/FlowableDebounceTest.java | 2 + .../flowable/FlowableDetachTest.java | 1 - .../flowable/FlowableDoFinallyTest.java | 1 - .../flowable/FlowableElementAtTest.java | 2 - .../FlowableFlatMapCompletableTest.java | 2 - .../flowable/FlowableFlatMapTest.java | 4 +- .../flowable/FlowableFromArrayTest.java | 1 + .../flowable/FlowableFromSourceTest.java | 3 - .../flowable/FlowableGroupByTest.java | 1 - .../flowable/FlowableIgnoreElementsTest.java | 1 - .../flowable/FlowableMergeDelayErrorTest.java | 3 +- .../FlowableMergeMaxConcurrentTest.java | 8 + .../operators/flowable/FlowableMergeTest.java | 5 +- .../flowable/FlowableObserveOnTest.java | 1 - .../FlowableOnBackpressureLatestTest.java | 3 + .../flowable/FlowableOnErrorReturnTest.java | 1 - ...eOnExceptionResumeNextViaFlowableTest.java | 1 - .../FlowablePublishMulticastTest.java | 1 - .../flowable/FlowablePublishTest.java | 1 + .../flowable/FlowableRangeLongTest.java | 3 + .../operators/flowable/FlowableRangeTest.java | 5 +- .../flowable/FlowableReduceTest.java | 1 - .../flowable/FlowableReplayTest.java | 2 + .../operators/flowable/FlowableRetryTest.java | 4 +- .../FlowableRetryWithPredicateTest.java | 5 + .../flowable/FlowableSequenceEqualTest.java | 1 - .../flowable/FlowableSingleTest.java | 1 - .../flowable/FlowableSwitchIfEmptyTest.java | 1 + .../flowable/FlowableSwitchTest.java | 1 - .../flowable/FlowableTakeLastTest.java | 1 - .../operators/flowable/FlowableTakeTest.java | 2 - .../FlowableTakeUntilPredicateTest.java | 6 + .../flowable/FlowableTakeUntilTest.java | 2 + .../flowable/FlowableThrottleFirstTest.java | 1 - .../flowable/FlowableThrottleLatestTest.java | 1 - .../flowable/FlowableTimeoutTests.java | 1 - .../operators/flowable/FlowableTimerTest.java | 3 + .../flowable/FlowableToListTest.java | 4 + .../operators/flowable/FlowableToMapTest.java | 1 - .../flowable/FlowableToMultimapTest.java | 1 - .../flowable/FlowableToSortedListTest.java | 2 + .../operators/flowable/FlowableUsingTest.java | 2 - .../FlowableWindowWithFlowableTest.java | 3 +- .../flowable/FlowableWindowWithSizeTest.java | 5 + .../flowable/FlowableWindowWithTimeTest.java | 3 +- .../flowable/FlowableWithLatestFromTest.java | 2 +- .../operators/flowable/FlowableZipTest.java | 4 +- .../operators/maybe/MaybeCacheTest.java | 1 - .../operators/maybe/MaybeContainsTest.java | 1 - .../operators/maybe/MaybeDelayOtherTest.java | 2 - .../operators/maybe/MaybeIsEmptyTest.java | 1 - .../maybe/MaybeSwitchIfEmptySingleTest.java | 1 - .../maybe/MaybeSwitchIfEmptyTest.java | 1 - .../operators/maybe/MaybeUsingTest.java | 1 - .../operators/maybe/MaybeZipArrayTest.java | 1 + .../CompletableAndThenObservableTest.java | 1 - .../mixed/FlowableSwitchMapMaybeTest.java | 1 - .../mixed/FlowableSwitchMapSingleTest.java | 1 - .../mixed/ObservableSwitchMapMaybeTest.java | 1 - .../mixed/ObservableSwitchMapSingleTest.java | 1 - .../observable/ObservableAllTest.java | 5 +- .../observable/ObservableAnyTest.java | 2 + .../observable/ObservableBufferTest.java | 10 ++ .../observable/ObservableCacheTest.java | 1 + .../ObservableConcatMapCompletableTest.java | 1 - .../ObservableConcatMapEagerTest.java | 1 - .../observable/ObservableConcatTest.java | 1 + .../ObservableConcatWithMaybeTest.java | 1 - .../observable/ObservableDebounceTest.java | 2 + .../ObservableDelaySubscriptionOtherTest.java | 1 - .../observable/ObservableDetachTest.java | 1 - .../observable/ObservableDoFinallyTest.java | 2 - .../ObservableFlatMapCompletableTest.java | 2 - .../observable/ObservableFlatMapTest.java | 4 +- .../ObservableMergeDelayErrorTest.java | 1 + .../ObservableMergeMaxConcurrentTest.java | 6 + .../observable/ObservableMergeTest.java | 3 + ...nExceptionResumeNextViaObservableTest.java | 1 - .../observable/ObservablePublishTest.java | 1 + .../observable/ObservableReduceTest.java | 1 - .../observable/ObservableReplayTest.java | 1 + .../observable/ObservableRetryTest.java | 2 + .../ObservableRetryWithPredicateTest.java | 5 + .../observable/ObservableSwitchTest.java | 2 - .../ObservableTakeUntilPredicateTest.java | 5 + .../observable/ObservableTakeUntilTest.java | 3 +- .../ObservableThrottleLatestTest.java | 1 - .../observable/ObservableTimerTest.java | 3 + .../observable/ObservableToMapTest.java | 1 - .../observable/ObservableToMultimapTest.java | 2 - .../ObservableToSortedListTest.java | 1 - .../observable/ObservableUsingTest.java | 2 - .../ObservableWindowWithObservableTest.java | 1 + .../ObservableWindowWithTimeTest.java | 1 + .../ObservableWithLatestFromTest.java | 2 +- .../observable/ObservableZipTest.java | 1 + .../operators/single/SingleConcatTest.java | 1 - .../operators/single/SingleFlatMapTest.java | 1 - .../single/SingleFromCallableTest.java | 1 - .../operators/single/SingleMergeTest.java | 1 - .../operators/single/SingleTakeUntilTest.java | 1 - .../operators/single/SingleZipArrayTest.java | 1 + .../schedulers/AbstractDirectTaskTest.java | 1 + .../ImmediateThinSchedulerTest.java | 1 + .../schedulers/ScheduledRunnableTest.java | 1 - .../subscribers/BlockingSubscriberTest.java | 2 + .../DeferredScalarSubscriberTest.java | 1 + .../InnerQueuedSubscriberTest.java | 4 + .../subscribers/LambdaSubscriberTest.java | 1 + .../subscriptions/SubscriptionHelperTest.java | 52 +++--- .../internal/util/EndConsumerHelperTest.java | 22 +++ .../internal/util/QueueDrainHelperTest.java | 1 + .../io/reactivex/maybe/MaybeCreateTest.java | 1 - .../java/io/reactivex/maybe/MaybeTest.java | 12 +- .../observable/ObservableNullTests.java | 1 - .../observable/ObservableReduceTests.java | 1 - .../observable/ObservableSubscriberTest.java | 1 - .../reactivex/observable/ObservableTest.java | 1 - .../reactivex/observers/SafeObserverTest.java | 4 + .../observers/SerializedObserverTest.java | 1 + .../reactivex/observers/TestObserverTest.java | 1 + .../parallel/ParallelDoOnNextTryTest.java | 1 + .../parallel/ParallelFilterTryTest.java | 1 + .../parallel/ParallelFlowableTest.java | 2 - .../parallel/ParallelMapTryTest.java | 2 + .../reactivex/plugins/RxJavaPluginsTest.java | 1 - .../processors/AsyncProcessorTest.java | 1 + .../processors/BehaviorProcessorTest.java | 5 + .../processors/MulticastProcessorTest.java | 3 - .../processors/PublishProcessorTest.java | 2 + ...ReplayProcessorBoundedConcurrencyTest.java | 4 + .../ReplayProcessorConcurrencyTest.java | 2 + .../processors/ReplayProcessorTest.java | 12 ++ .../processors/SerializedProcessorTest.java | 8 + .../schedulers/ComputationSchedulerTests.java | 1 - .../schedulers/ExecutorSchedulerTest.java | 1 + .../reactivex/schedulers/SchedulerTest.java | 1 - .../schedulers/TestSchedulerTest.java | 4 +- .../io/reactivex/single/SingleNullTests.java | 1 + .../reactivex/subjects/AsyncSubjectTest.java | 2 +- .../subjects/BehaviorSubjectTest.java | 6 +- .../subjects/PublishSubjectTest.java | 2 + .../ReplaySubjectBoundedConcurrencyTest.java | 4 + .../ReplaySubjectConcurrencyTest.java | 2 + .../reactivex/subjects/ReplaySubjectTest.java | 13 +- .../subjects/SerializedSubjectTest.java | 7 + .../subscribers/SafeSubscriberTest.java | 5 +- .../SafeSubscriberWithPluginTest.java | 2 + .../subscribers/SerializedSubscriberTest.java | 1 + .../subscribers/TestSubscriberTest.java | 3 - src/test/java/io/reactivex/tck/BaseTck.java | 1 - .../CheckLocalVariablesInTests.java | 5 + .../validators/NewLinesBeforeAnnotation.java | 162 ++++++++++++++++++ 291 files changed, 607 insertions(+), 262 deletions(-) create mode 100644 src/test/java/io/reactivex/validators/NewLinesBeforeAnnotation.java diff --git a/src/jmh/java/io/reactivex/EachTypeFlatMapPerf.java b/src/jmh/java/io/reactivex/EachTypeFlatMapPerf.java index d8793829f1..7d150960c0 100644 --- a/src/jmh/java/io/reactivex/EachTypeFlatMapPerf.java +++ b/src/jmh/java/io/reactivex/EachTypeFlatMapPerf.java @@ -86,10 +86,12 @@ public Single apply(Integer v) { public void bpRange(Blackhole bh) { bpRange.subscribe(new PerfSubscriber(bh)); } + @Benchmark public void bpRangeMapJust(Blackhole bh) { bpRangeMapJust.subscribe(new PerfSubscriber(bh)); } + @Benchmark public void bpRangeMapRange(Blackhole bh) { bpRangeMapRange.subscribe(new PerfSubscriber(bh)); @@ -99,10 +101,12 @@ public void bpRangeMapRange(Blackhole bh) { public void nbpRange(Blackhole bh) { nbpRange.subscribe(new PerfObserver(bh)); } + @Benchmark public void nbpRangeMapJust(Blackhole bh) { nbpRangeMapJust.subscribe(new PerfObserver(bh)); } + @Benchmark public void nbpRangeMapRange(Blackhole bh) { nbpRangeMapRange.subscribe(new PerfObserver(bh)); @@ -112,6 +116,7 @@ public void nbpRangeMapRange(Blackhole bh) { public void singleJust(Blackhole bh) { singleJust.subscribe(new LatchedSingleObserver(bh)); } + @Benchmark public void singleJustMapJust(Blackhole bh) { singleJustMapJust.subscribe(new LatchedSingleObserver(bh)); diff --git a/src/jmh/java/io/reactivex/LatchedSingleObserver.java b/src/jmh/java/io/reactivex/LatchedSingleObserver.java index 02e74c463e..59b980a0eb 100644 --- a/src/jmh/java/io/reactivex/LatchedSingleObserver.java +++ b/src/jmh/java/io/reactivex/LatchedSingleObserver.java @@ -26,15 +26,18 @@ public LatchedSingleObserver(Blackhole bh) { this.bh = bh; this.cdl = new CountDownLatch(1); } + @Override public void onSubscribe(Disposable d) { } + @Override public void onSuccess(T value) { bh.consume(value); cdl.countDown(); } + @Override public void onError(Throwable e) { e.printStackTrace(); diff --git a/src/jmh/java/io/reactivex/PerfObserver.java b/src/jmh/java/io/reactivex/PerfObserver.java index 33548155ba..8de241e6a0 100644 --- a/src/jmh/java/io/reactivex/PerfObserver.java +++ b/src/jmh/java/io/reactivex/PerfObserver.java @@ -26,19 +26,23 @@ public PerfObserver(Blackhole bh) { this.bh = bh; this.cdl = new CountDownLatch(1); } + @Override public void onSubscribe(Disposable d) { } + @Override public void onNext(Object value) { bh.consume(value); } + @Override public void onError(Throwable e) { e.printStackTrace(); cdl.countDown(); } + @Override public void onComplete() { cdl.countDown(); diff --git a/src/jmh/java/io/reactivex/PublishProcessorPerf.java b/src/jmh/java/io/reactivex/PublishProcessorPerf.java index 37afebfa4f..d9531ab267 100644 --- a/src/jmh/java/io/reactivex/PublishProcessorPerf.java +++ b/src/jmh/java/io/reactivex/PublishProcessorPerf.java @@ -71,7 +71,6 @@ public void bounded1() { bounded.onNext(1); } - @Benchmark public void bounded1k() { for (int i = 0; i < 1000; i++) { @@ -86,13 +85,11 @@ public void bounded1m() { } } - @Benchmark public void subject1() { subject.onNext(1); } - @Benchmark public void subject1k() { for (int i = 0; i < 1000; i++) { diff --git a/src/jmh/java/io/reactivex/ToFlowablePerf.java b/src/jmh/java/io/reactivex/ToFlowablePerf.java index 9bc41083f4..deb97a7e51 100644 --- a/src/jmh/java/io/reactivex/ToFlowablePerf.java +++ b/src/jmh/java/io/reactivex/ToFlowablePerf.java @@ -78,6 +78,7 @@ public Observable apply(Integer v) throws Exception { public Object flowable() { return flowable.blockingGet(); } + @Benchmark public Object flowableInner() { return flowableInner.blockingLast(); diff --git a/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java b/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java index 1a00840549..f87df26a17 100644 --- a/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java +++ b/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java @@ -83,7 +83,6 @@ public static void error(Throwable e, MaybeObserver observer) { observer.onError(e); } - @Override public boolean offer(Object value) { throw new UnsupportedOperationException("Should not be called!"); diff --git a/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java b/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java index 47d9990d4f..7e3941e260 100644 --- a/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java +++ b/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java @@ -74,7 +74,6 @@ public void onComplete() { } } - @Override public void dispose() { try { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromPublisher.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromPublisher.java index 3791931e92..ca33d582c9 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromPublisher.java @@ -53,7 +53,6 @@ public void onSubscribe(Subscription s) { } } - @Override public void onNext(T t) { // ignored diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java b/src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java index 327cee0116..02180e4e91 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java @@ -61,7 +61,6 @@ final class CompletableObserverImplementation implements CompletableObserver, Di this.downstream = downstream; } - @Override public void onSubscribe(final Disposable d) { try { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java index 940942c943..5111d46f32 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableResumeNext.java @@ -34,8 +34,6 @@ public CompletableResumeNext(CompletableSource source, this.errorMapper = errorMapper; } - - @Override protected void subscribeActual(final CompletableObserver observer) { ResumeNextObserver parent = new ResumeNextObserver(observer, errorMapper); @@ -60,7 +58,6 @@ static final class ResumeNextObserver this.errorMapper = errorMapper; } - @Override public void onSubscribe(Disposable d) { DisposableHelper.replace(this, d); diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java index a114199a91..0dc127ec82 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java @@ -40,7 +40,6 @@ public CompletableUsing(Callable resourceSupplier, this.eager = eager; } - @Override protected void subscribeActual(CompletableObserver observer) { R resource; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAll.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAll.java index b3f6076f43..608089ace4 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAll.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAll.java @@ -47,6 +47,7 @@ static final class AllSubscriber extends DeferredScalarSubscription super(actual); this.predicate = predicate; } + @Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.upstream, s)) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java index b26087b840..1ec3e9460d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAllSingle.java @@ -57,6 +57,7 @@ static final class AllSubscriber implements FlowableSubscriber, Disposable this.downstream = actual; this.predicate = predicate; } + @Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.upstream, s)) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAny.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAny.java index 5a3d7c966f..aed50107e4 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAny.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAny.java @@ -46,6 +46,7 @@ static final class AnySubscriber extends DeferredScalarSubscription super(actual); this.predicate = predicate; } + @Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.upstream, s)) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java index 7c665f2ab9..0c30c11107 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableAnySingle.java @@ -56,6 +56,7 @@ static final class AnySubscriber implements FlowableSubscriber, Disposable this.downstream = actual; this.predicate = predicate; } + @Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.upstream, s)) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java index 0fb2b19e6a..48212822ff 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java @@ -518,7 +518,6 @@ public boolean accept(Subscriber a, U v) { return true; } - @Override public void request(long n) { requested(n); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java index ad4de6050f..db4ccecfa1 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java @@ -200,6 +200,7 @@ public void connect() { source.subscribe(this); isConnected = true; } + @Override public void onNext(T t) { if (!sourceDone) { @@ -210,6 +211,7 @@ public void onNext(T t) { } } } + @SuppressWarnings("unchecked") @Override public void onError(Throwable e) { @@ -225,6 +227,7 @@ public void onError(Throwable e) { RxJavaPlugins.onError(e); } } + @SuppressWarnings("unchecked") @Override public void onComplete() { @@ -284,6 +287,7 @@ static final class ReplaySubscription this.state = state; this.requested = new AtomicLong(); } + @Override public void request(long n) { if (SubscriptionHelper.validate(n)) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java index 4dc60faa5a..bb408ef6c8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java @@ -417,7 +417,6 @@ public void innerNext(R value) { downstream.onNext(value); } - @Override public void innerError(Throwable e) { if (errors.addThrowable(e)) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java index 36ece502bd..b30a68c62d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java @@ -125,6 +125,7 @@ public void onComplete() { if (d != null) { d.dispose(); } + @SuppressWarnings("unchecked") DebounceEmitter de = (DebounceEmitter)d; if (de != null) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDefer.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDefer.java index 8a44a0019e..7ac266001f 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDefer.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDefer.java @@ -27,6 +27,7 @@ public final class FlowableDefer extends Flowable { public FlowableDefer(Callable> supplier) { this.supplier = supplier; } + @Override public void subscribeActual(Subscriber s) { Publisher pub; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java index 6257f48803..930f5aaee6 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java @@ -79,6 +79,7 @@ public void onError(Throwable t) { downstream.onError(t); } + @Override public void onComplete() { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableError.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableError.java index b74ad1d871..dc88f01d7e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableError.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableError.java @@ -27,6 +27,7 @@ public final class FlowableError extends Flowable { public FlowableError(Callable errorSupplier) { this.errorSupplier = errorSupplier; } + @Override public void subscribeActual(Subscriber s) { Throwable error; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java index 07e2b20db3..c68e82bb93 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java @@ -461,6 +461,7 @@ void drainLoop() { if (checkTerminate()) { return; } + @SuppressWarnings("unchecked") InnerSubscriber is = (InnerSubscriber)inner[j]; @@ -629,6 +630,7 @@ static final class InnerSubscriber extends AtomicReference this.bufferSize = parent.bufferSize; this.limit = bufferSize >> 2; } + @Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.setOnce(this, s)) { @@ -654,6 +656,7 @@ public void onSubscribe(Subscription s) { s.request(bufferSize); } } + @Override public void onNext(U t) { if (fusionMode != QueueSubscription.ASYNC) { @@ -662,11 +665,13 @@ public void onNext(U t) { parent.drain(); } } + @Override public void onError(Throwable t) { lazySet(SubscriptionHelper.CANCELLED); parent.innerError(this, t); } + @Override public void onComplete() { done = true; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java index 462a72481f..25b7610eaa 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java @@ -28,6 +28,7 @@ public final class FlowableFromArray extends Flowable { public FlowableFromArray(T[] array) { this.array = array; } + @Override public void subscribeActual(Subscriber s) { if (s instanceof ConditionalSubscriber) { @@ -92,7 +93,6 @@ public final void request(long n) { } } - @Override public final void cancel() { cancelled = true; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromCallable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromCallable.java index 4920c9f206..5a773dffc4 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromCallable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromCallable.java @@ -27,6 +27,7 @@ public final class FlowableFromCallable extends Flowable implements Callab public FlowableFromCallable(Callable callable) { this.callable = callable; } + @Override public void subscribeActual(Subscriber s) { DeferredScalarSubscription deferred = new DeferredScalarSubscription(s); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java index 9cf14837b6..3c3017bcfb 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java @@ -104,7 +104,6 @@ public final T poll() { return ObjectHelper.requireNonNull(it.next(), "Iterator.next() returned a null value"); } - @Override public final boolean isEmpty() { return it == null || !it.hasNext(); @@ -128,7 +127,6 @@ public final void request(long n) { } } - @Override public final void cancel() { cancelled = true; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java index 139e61d410..5d758096c3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java @@ -30,7 +30,6 @@ public FlowableOnBackpressureError(Flowable source) { super(source); } - @Override protected void subscribeActual(Subscriber s) { this.source.subscribe(new BackpressureErrorSubscriber(s)); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java index 6122974695..0e08551495 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java @@ -230,6 +230,7 @@ public void onNext(T t) { // loop to act on the current state serially dispatch(); } + @Override public void onError(Throwable e) { // The observer front is accessed serially as required by spec so @@ -243,6 +244,7 @@ public void onError(Throwable e) { RxJavaPlugins.onError(e); } } + @Override public void onComplete() { // The observer front is accessed serially as required by spec so diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java index 198721943b..185218480e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java @@ -31,6 +31,7 @@ public FlowableRange(int start, int count) { this.start = start; this.end = start + count; } + @Override public void subscribeActual(Subscriber s) { if (s instanceof ConditionalSubscriber) { @@ -94,7 +95,6 @@ public final void request(long n) { } } - @Override public final void cancel() { cancelled = true; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java index fe48ac17ea..f99bc48a20 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java @@ -64,6 +64,7 @@ public void onNext(T t) { produced++; downstream.onNext(t); } + @Override public void onError(Throwable t) { downstream.onError(t); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java index e2dbd532e8..d373a3865d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java @@ -66,6 +66,7 @@ public void onNext(T t) { produced++; downstream.onNext(t); } + @Override public void onError(Throwable t) { downstream.onError(t); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java index 7a837f5809..51943b9c48 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java @@ -409,6 +409,7 @@ public void onError(Throwable e) { RxJavaPlugins.onError(e); } } + @SuppressWarnings("unchecked") @Override public void onComplete() { @@ -624,6 +625,7 @@ static final class UnboundedReplayBuffer extends ArrayList implements UnboundedReplayBuffer(int capacityHint) { super(capacityHint); } + @Override public void next(T value) { add(NotificationLite.next(value)); @@ -1037,6 +1039,7 @@ void truncate() { setFirst(prev); } } + @Override void truncateFinal() { long timeLimit = scheduler.now(unit) - maxAge; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryBiPredicate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryBiPredicate.java index a049d76d51..662ddb694c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryBiPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryBiPredicate.java @@ -70,6 +70,7 @@ public void onNext(T t) { produced++; downstream.onNext(t); } + @Override public void onError(Throwable t) { boolean b; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java index b29b97b70a..47a8e3d878 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java @@ -73,6 +73,7 @@ public void onNext(T t) { produced++; downstream.onNext(t); } + @Override public void onError(Throwable t) { long r = remaining; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTake.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTake.java index badf1d8146..5d33c14523 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTake.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTake.java @@ -52,6 +52,7 @@ static final class TakeSubscriber extends AtomicBoolean implements FlowableSu this.limit = limit; this.remaining = limit; } + @Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.upstream, s)) { @@ -65,6 +66,7 @@ public void onSubscribe(Subscription s) { } } } + @Override public void onNext(T t) { if (!done && remaining-- > 0) { @@ -76,6 +78,7 @@ public void onNext(T t) { } } } + @Override public void onError(Throwable t) { if (!done) { @@ -86,6 +89,7 @@ public void onError(Throwable t) { RxJavaPlugins.onError(t); } } + @Override public void onComplete() { if (!done) { @@ -93,6 +97,7 @@ public void onComplete() { downstream.onComplete(); } } + @Override public void request(long n) { if (!SubscriptionHelper.validate(n)) { @@ -106,6 +111,7 @@ public void request(long n) { } upstream.request(n); } + @Override public void cancel() { upstream.cancel(); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeInterval.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeInterval.java index 4e673da5e6..cf8b7087a7 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeInterval.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeInterval.java @@ -31,7 +31,6 @@ public FlowableTimeInterval(Flowable source, TimeUnit unit, Scheduler schedul this.unit = unit; } - @Override protected void subscribeActual(Subscriber> s) { source.subscribe(new TimeIntervalSubscriber(s, unit, scheduler)); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFrom.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFrom.java index 5f403fb150..00017d431d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFrom.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFrom.java @@ -55,7 +55,7 @@ static final class WithLatestFromSubscriber extends AtomicReference final BiFunction combiner; - final AtomicReference s = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); final AtomicLong requested = new AtomicLong(); @@ -65,15 +65,16 @@ static final class WithLatestFromSubscriber extends AtomicReference this.downstream = actual; this.combiner = combiner; } + @Override public void onSubscribe(Subscription s) { - SubscriptionHelper.deferredSetOnce(this.s, requested, s); + SubscriptionHelper.deferredSetOnce(this.upstream, requested, s); } @Override public void onNext(T t) { if (!tryOnNext(t)) { - s.get().request(1); + upstream.get().request(1); } } @@ -111,12 +112,12 @@ public void onComplete() { @Override public void request(long n) { - SubscriptionHelper.deferredRequest(s, requested, n); + SubscriptionHelper.deferredRequest(upstream, requested, n); } @Override public void cancel() { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); SubscriptionHelper.cancel(other); } @@ -125,7 +126,7 @@ public boolean setOther(Subscription o) { } public void otherError(Throwable e) { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); downstream.onError(e); } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java index f0a2231f02..d3014113ed 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java @@ -131,9 +131,9 @@ static final class WithLatestFromSubscriber void subscribe(Publisher[] others, int n) { WithLatestInnerSubscriber[] subscribers = this.subscribers; - AtomicReference s = this.upstream; + AtomicReference upstream = this.upstream; for (int i = 0; i < n; i++) { - if (SubscriptionHelper.isCancelled(s.get())) { + if (SubscriptionHelper.isCancelled(upstream.get())) { return; } others[i].subscribe(subscribers[i]); diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmpty.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmpty.java index 77d2d8f333..68d3db37d7 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmpty.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmpty.java @@ -99,18 +99,22 @@ static final class OtherMaybeObserver implements MaybeObserver { this.downstream = actual; this.parent = parent; } + @Override public void onSubscribe(Disposable d) { DisposableHelper.setOnce(parent, d); } + @Override public void onSuccess(T value) { downstream.onSuccess(value); } + @Override public void onError(Throwable e) { downstream.onError(e); } + @Override public void onComplete() { downstream.onComplete(); diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingle.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingle.java index 798b3ef24f..bd94beb3ea 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingle.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingle.java @@ -106,14 +106,17 @@ static final class OtherSingleObserver implements SingleObserver { this.downstream = actual; this.parent = parent; } + @Override public void onSubscribe(Disposable d) { DisposableHelper.setOnce(parent, d); } + @Override public void onSuccess(T value) { downstream.onSuccess(value); } + @Override public void onError(Throwable e) { downstream.onError(e); diff --git a/src/main/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservable.java b/src/main/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservable.java index 39f1a79a19..454c45b4c1 100644 --- a/src/main/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservable.java +++ b/src/main/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservable.java @@ -81,7 +81,6 @@ public void onComplete() { } } - @Override public void dispose() { DisposableHelper.dispose(this); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAll.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAll.java index 71d0c32ebf..2349ce4893 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAll.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAll.java @@ -43,6 +43,7 @@ static final class AllObserver implements Observer, Disposable { this.downstream = actual; this.predicate = predicate; } + @Override public void onSubscribe(Disposable d) { if (DisposableHelper.validate(this.upstream, d)) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAllSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAllSingle.java index 3089007d6d..1fb756233d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAllSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAllSingle.java @@ -51,6 +51,7 @@ static final class AllObserver implements Observer, Disposable { this.downstream = actual; this.predicate = predicate; } + @Override public void onSubscribe(Disposable d) { if (DisposableHelper.validate(this.upstream, d)) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAny.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAny.java index 92f3aa02cf..c1500c3fb6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAny.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAny.java @@ -44,6 +44,7 @@ static final class AnyObserver implements Observer, Disposable { this.downstream = actual; this.predicate = predicate; } + @Override public void onSubscribe(Disposable d) { if (DisposableHelper.validate(this.upstream, d)) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAnySingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAnySingle.java index 87f0d7c64c..b8c7001ed5 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAnySingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAnySingle.java @@ -53,6 +53,7 @@ static final class AnyObserver implements Observer, Disposable { this.downstream = actual; this.predicate = predicate; } + @Override public void onSubscribe(Disposable d) { if (DisposableHelper.validate(this.upstream, d)) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java index 9cb6ba3de3..369eb4260d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java @@ -168,7 +168,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java index bbfef8ffae..59358c79a9 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java @@ -517,7 +517,6 @@ public void accept(Observer a, U v) { a.onNext(v); } - @Override public void dispose() { if (!cancelled) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java index 4d7563608f..3bfe796efc 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java @@ -216,6 +216,7 @@ public void connect() { source.subscribe(this); isConnected = true; } + @Override public void onNext(T t) { if (!sourceDone) { @@ -226,6 +227,7 @@ public void onNext(T t) { } } } + @SuppressWarnings("unchecked") @Override public void onError(Throwable e) { @@ -239,6 +241,7 @@ public void onError(Throwable e) { } } } + @SuppressWarnings("unchecked") @Override public void onComplete() { @@ -296,6 +299,7 @@ static final class ReplayDisposable public boolean isDisposed() { return cancelled; } + @Override public void dispose() { if (!cancelled) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCollect.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCollect.java index 8deff52c47..761fabd49e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCollect.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCollect.java @@ -69,7 +69,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -80,7 +79,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCollectSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCollectSingle.java index 04753eae0a..59c34a0048 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCollectSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCollectSingle.java @@ -77,7 +77,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -88,7 +87,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java index 27b869439a..ccbfc8e6d3 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java @@ -43,7 +43,6 @@ public ObservableCombineLatest(ObservableSource[] sources, this.delayError = delayError; } - @Override @SuppressWarnings("unchecked") public void subscribeActual(Observer observer) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java index 742661690a..642f0e01f1 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java @@ -40,6 +40,7 @@ public ObservableConcatMap(ObservableSource source, Function observer) { @@ -82,6 +83,7 @@ static final class SourceObserver extends AtomicInteger implements Observe this.bufferSize = bufferSize; this.inner = new InnerObserver(actual, this); } + @Override public void onSubscribe(Disposable d) { if (DisposableHelper.validate(this.upstream, d)) { @@ -117,6 +119,7 @@ public void onSubscribe(Disposable d) { downstream.onSubscribe(this); } } + @Override public void onNext(T t) { if (done) { @@ -127,6 +130,7 @@ public void onNext(T t) { } drain(); } + @Override public void onError(Throwable t) { if (done) { @@ -137,6 +141,7 @@ public void onError(Throwable t) { dispose(); downstream.onError(t); } + @Override public void onComplete() { if (done) { @@ -246,11 +251,13 @@ public void onSubscribe(Disposable d) { public void onNext(U t) { downstream.onNext(t); } + @Override public void onError(Throwable t) { parent.dispose(); downstream.onError(t); } + @Override public void onComplete() { parent.innerComplete(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCount.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCount.java index bf961d47c0..bae08e040b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCount.java @@ -46,7 +46,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCountSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCountSingle.java index 1568e00f97..6e534b0dcc 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCountSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCountSingle.java @@ -54,7 +54,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounceTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounceTimed.java index d37b99ecfd..49f490924a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounceTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounceTimed.java @@ -117,6 +117,7 @@ public void onComplete() { if (d != null) { d.dispose(); } + @SuppressWarnings("unchecked") DebounceEmitter de = (DebounceEmitter)d; if (de != null) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDefer.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDefer.java index 411530c81f..adc2c29008 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDefer.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDefer.java @@ -25,6 +25,7 @@ public final class ObservableDefer extends Observable { public ObservableDefer(Callable> supplier) { this.supplier = supplier; } + @Override public void subscribeActual(Observer observer) { ObservableSource pub; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java index 70dd6502b5..9e79e8eba4 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java @@ -49,7 +49,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -60,7 +59,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(Notification t) { if (done) { @@ -91,6 +89,7 @@ public void onError(Throwable t) { downstream.onError(t); } + @Override public void onComplete() { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoOnEach.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoOnEach.java index dc3b4561b2..a88218cbd5 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDoOnEach.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDoOnEach.java @@ -74,7 +74,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -85,7 +84,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAt.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAt.java index 7abc421572..5897fddfed 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAt.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAt.java @@ -31,6 +31,7 @@ public ObservableElementAt(ObservableSource source, long index, T defaultValu this.defaultValue = defaultValue; this.errorOnFewer = errorOnFewer; } + @Override public void subscribeActual(Observer t) { source.subscribe(new ElementAtObserver(t, index, defaultValue, errorOnFewer)); @@ -63,7 +64,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -74,7 +74,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtMaybe.java index 84f8d5baf7..921edd6ab3 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtMaybe.java @@ -26,6 +26,7 @@ public ObservableElementAtMaybe(ObservableSource source, long index) { this.source = source; this.index = index; } + @Override public void subscribeActual(MaybeObserver t) { source.subscribe(new ElementAtObserver(t, index)); @@ -59,7 +60,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -70,7 +70,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtSingle.java index 6c73a4e91a..7de1fa7bef 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableElementAtSingle.java @@ -67,7 +67,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -78,7 +77,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java index bc375ddf38..b0eeb95c56 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java @@ -25,6 +25,7 @@ public final class ObservableError extends Observable { public ObservableError(Callable errorSupplier) { this.errorSupplier = errorSupplier; } + @Override public void subscribeActual(Observer observer) { Throwable error; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java index 76247e8e08..0bc25cebaf 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java @@ -413,6 +413,7 @@ void drainLoop() { if (checkTerminate()) { return; } + @SuppressWarnings("unchecked") InnerObserver is = (InnerObserver)inner[j]; @@ -542,6 +543,7 @@ static final class InnerObserver extends AtomicReference this.id = id; this.parent = parent; } + @Override public void onSubscribe(Disposable d) { if (DisposableHelper.setOnce(this, d)) { @@ -564,6 +566,7 @@ public void onSubscribe(Disposable d) { } } } + @Override public void onNext(U t) { if (fusionMode == QueueDisposable.NONE) { @@ -572,6 +575,7 @@ public void onNext(U t) { parent.drain(); } } + @Override public void onError(Throwable t) { if (parent.errors.addThrowable(t)) { @@ -584,6 +588,7 @@ public void onError(Throwable t) { RxJavaPlugins.onError(t); } } + @Override public void onComplete() { done = true; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java index 0633d59726..11b871ee46 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java @@ -23,6 +23,7 @@ public final class ObservableFromArray extends Observable { public ObservableFromArray(T[] array) { this.array = array; } + @Override public void subscribeActual(Observer observer) { FromArrayDisposable d = new FromArrayDisposable(observer, array); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromCallable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromCallable.java index 214af8f4d7..fe3c364793 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromCallable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromCallable.java @@ -30,6 +30,7 @@ public final class ObservableFromCallable extends Observable implements Ca public ObservableFromCallable(Callable callable) { this.callable = callable; } + @Override public void subscribeActual(Observer observer) { DeferredScalarDisposable d = new DeferredScalarDisposable(observer); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java index c74f697b7d..61f4891d1e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java @@ -136,7 +136,6 @@ public boolean isDisposed() { return cancelled; } - @Override public void onNext(T t) { if (!terminate) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMapNotification.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMapNotification.java index d6b6e39f47..f4418e9927 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMapNotification.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMapNotification.java @@ -71,7 +71,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -82,7 +81,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { ObservableSource p; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java index 3a89194e97..a82668cfc3 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java @@ -46,7 +46,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturn.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturn.java index 2ed68d48e9..b91e364856 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturn.java @@ -50,7 +50,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java index 39975af10b..debc37875b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java @@ -172,6 +172,7 @@ public void onNext(T t) { inner.child.onNext(t); } } + @SuppressWarnings("unchecked") @Override public void onError(Throwable e) { @@ -185,6 +186,7 @@ public void onError(Throwable e) { RxJavaPlugins.onError(e); } } + @SuppressWarnings("unchecked") @Override public void onComplete() { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java index 426bed7dd9..a42a8e85f6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeat.java @@ -59,6 +59,7 @@ public void onSubscribe(Disposable d) { public void onNext(T t) { downstream.onNext(t); } + @Override public void onError(Throwable t) { downstream.onError(t); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java index 8d8b9e29ac..485eb1f51f 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatUntil.java @@ -61,6 +61,7 @@ public void onSubscribe(Disposable d) { public void onNext(T t) { downstream.onNext(t); } + @Override public void onError(Throwable t) { downstream.onError(t); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java index 26efd9be5a..a1c75b67c0 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java @@ -371,6 +371,7 @@ public void onNext(T t) { replay(); } } + @Override public void onError(Throwable e) { // The observer front is accessed serially as required by spec so @@ -383,6 +384,7 @@ public void onError(Throwable e) { RxJavaPlugins.onError(e); } } + @Override public void onComplete() { // The observer front is accessed serially as required by spec so @@ -511,6 +513,7 @@ static final class UnboundedReplayBuffer extends ArrayList implements UnboundedReplayBuffer(int capacityHint) { super(capacityHint); } + @Override public void next(T value) { add(NotificationLite.next(value)); @@ -862,6 +865,7 @@ void truncate() { setFirst(prev); } } + @Override void truncateFinal() { long timeLimit = scheduler.now(unit) - maxAge; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java index a743ae55c6..c9be2c75ca 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java @@ -65,6 +65,7 @@ public void onSubscribe(Disposable d) { public void onNext(T t) { downstream.onNext(t); } + @Override public void onError(Throwable t) { boolean b; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java index 3f98549c1d..6fb5d7b665 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java @@ -68,6 +68,7 @@ public void onSubscribe(Disposable d) { public void onNext(T t) { downstream.onNext(t); } + @Override public void onError(Throwable t) { long r = remaining; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleTimed.java index 9397438e09..a553a8dbb0 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleTimed.java @@ -36,7 +36,6 @@ public ObservableSampleTimed(ObservableSource source, long period, TimeUnit u this.emitLast = emitLast; } - @Override public void subscribeActual(Observer t) { SerializedObserver serial = new SerializedObserver(t); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableScan.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableScan.java index 13fd31fa1a..6b830e8d8f 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableScan.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableScan.java @@ -56,7 +56,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -67,7 +66,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableScanSeed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableScanSeed.java index 6f9222fbee..a9b4a63716 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableScanSeed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableScanSeed.java @@ -74,7 +74,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleMaybe.java index ab45f7b29f..d4e1b9a375 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleMaybe.java @@ -25,6 +25,7 @@ public final class ObservableSingleMaybe extends Maybe { public ObservableSingleMaybe(ObservableSource source) { this.source = source; } + @Override public void subscribeActual(MaybeObserver t) { source.subscribe(new SingleElementObserver(t)); @@ -51,7 +52,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -62,7 +62,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleSingle.java index 79f7aaa4b2..e1232f849f 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSingleSingle.java @@ -59,7 +59,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -70,7 +69,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java index 3c6de3847a..2ea5953c39 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipLast.java @@ -54,7 +54,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java index a39b553563..d452fdaf0a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSkipWhile.java @@ -49,7 +49,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -60,7 +59,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (notSkipping) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTake.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTake.java index 7bda3017d5..2796357c80 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTake.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTake.java @@ -42,6 +42,7 @@ static final class TakeObserver implements Observer, Disposable { this.downstream = actual; this.remaining = limit; } + @Override public void onSubscribe(Disposable d) { if (DisposableHelper.validate(this.upstream, d)) { @@ -55,6 +56,7 @@ public void onSubscribe(Disposable d) { } } } + @Override public void onNext(T t) { if (!done && remaining-- > 0) { @@ -65,6 +67,7 @@ public void onNext(T t) { } } } + @Override public void onError(Throwable t) { if (done) { @@ -76,6 +79,7 @@ public void onError(Throwable t) { upstream.dispose(); downstream.onError(t); } + @Override public void onComplete() { if (!done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntil.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntil.java index 35e04300e0..3b831b21d4 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntil.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeUntil.java @@ -28,6 +28,7 @@ public ObservableTakeUntil(ObservableSource source, ObservableSource child) { TakeUntilMainObserver parent = new TakeUntilMainObserver(child); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeWhile.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeWhile.java index 1b41c6e86b..c57e6dfd12 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeWhile.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeWhile.java @@ -53,7 +53,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -64,7 +63,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeInterval.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeInterval.java index 0cc1a2c018..7d06b18f5e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeInterval.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeInterval.java @@ -69,7 +69,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { long now = scheduler.now(unit); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableToList.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableToList.java index 53dd99fd2b..afeee5399d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableToList.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableToList.java @@ -71,7 +71,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -82,7 +81,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { collection.add(t); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableToListSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableToListSingle.java index 4358229f53..410af1e161 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableToListSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableToListSingle.java @@ -83,7 +83,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -94,7 +93,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { collection.add(t); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFrom.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFrom.java index 9bc7984dd6..83369a73a7 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFrom.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWithLatestFrom.java @@ -61,6 +61,7 @@ static final class WithLatestFromObserver extends AtomicReference im this.downstream = actual; this.combiner = combiner; } + @Override public void onSubscribe(Disposable d) { DisposableHelper.setOnce(this.upstream, d); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java index 5ac0027aeb..a259cd6d56 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java @@ -265,6 +265,7 @@ static final class ZipObserver implements Observer { this.parent = parent; this.queue = new SpscLinkedArrayQueue(bufferSize); } + @Override public void onSubscribe(Disposable d) { DisposableHelper.setOnce(this.upstream, d); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableZipIterable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableZipIterable.java index 8db76ed428..22b7b95196 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableZipIterable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableZipIterable.java @@ -90,7 +90,6 @@ public void onSubscribe(Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -101,7 +100,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(T t) { if (done) { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleEquals.java b/src/main/java/io/reactivex/internal/operators/single/SingleEquals.java index 83c40b1416..07d3f36602 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleEquals.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleEquals.java @@ -57,6 +57,7 @@ static class InnerObserver implements SingleObserver { this.downstream = observer; this.count = count; } + @Override public void onSubscribe(Disposable d) { set.add(d); diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleInternalHelper.java b/src/main/java/io/reactivex/internal/operators/single/SingleInternalHelper.java index f4ed04d151..7770fd38b4 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleInternalHelper.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleInternalHelper.java @@ -110,6 +110,7 @@ public Observable apply(SingleSource v) { return new SingleToObservable(v); } } + @SuppressWarnings({ "rawtypes", "unchecked" }) public static Function, Observable> toObservable() { return (Function)ToObservable.INSTANCE; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleOnErrorReturn.java b/src/main/java/io/reactivex/internal/operators/single/SingleOnErrorReturn.java index 3f1b0588cf..0ae695a3e8 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleOnErrorReturn.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleOnErrorReturn.java @@ -32,8 +32,6 @@ public SingleOnErrorReturn(SingleSource source, this.value = value; } - - @Override protected void subscribeActual(final SingleObserver observer) { diff --git a/src/main/java/io/reactivex/internal/queue/SpscLinkedArrayQueue.java b/src/main/java/io/reactivex/internal/queue/SpscLinkedArrayQueue.java index 35c86222cd..ec874209d0 100644 --- a/src/main/java/io/reactivex/internal/queue/SpscLinkedArrayQueue.java +++ b/src/main/java/io/reactivex/internal/queue/SpscLinkedArrayQueue.java @@ -113,6 +113,7 @@ private void resize(final AtomicReferenceArray oldBuffer, final long cur private void soNext(AtomicReferenceArray curr, AtomicReferenceArray next) { soElement(curr, calcDirectOffset(curr.length() - 1), next); } + @SuppressWarnings("unchecked") private AtomicReferenceArray lvNextBufferAndUnlink(AtomicReferenceArray curr, int nextIndex) { int nextOffset = calcDirectOffset(nextIndex); @@ -179,6 +180,7 @@ private T newBufferPeek(AtomicReferenceArray nextBuffer, final long inde final int offsetInNew = calcWrappedOffset(index, mask); return (T) lvElement(nextBuffer, offsetInNew);// LoadLoad } + @Override public void clear() { while (poll() != null || !isEmpty()) { } // NOPMD diff --git a/src/main/java/io/reactivex/internal/schedulers/ComputationScheduler.java b/src/main/java/io/reactivex/internal/schedulers/ComputationScheduler.java index dda22b9255..b7200dee34 100644 --- a/src/main/java/io/reactivex/internal/schedulers/ComputationScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/ComputationScheduler.java @@ -227,6 +227,7 @@ public Disposable schedule(@NonNull Runnable action) { return poolWorker.scheduleActual(action, 0, TimeUnit.MILLISECONDS, serial); } + @NonNull @Override public Disposable schedule(@NonNull Runnable action, long delayTime, @NonNull TimeUnit unit) { diff --git a/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java b/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java index f6913020a5..662335ef43 100644 --- a/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java @@ -167,6 +167,7 @@ public void start() { update.shutdown(); } } + @Override public void shutdown() { for (;;) { diff --git a/src/main/java/io/reactivex/internal/subscriptions/EmptySubscription.java b/src/main/java/io/reactivex/internal/subscriptions/EmptySubscription.java index 08fd1faae8..d4d78f3279 100644 --- a/src/main/java/io/reactivex/internal/subscriptions/EmptySubscription.java +++ b/src/main/java/io/reactivex/internal/subscriptions/EmptySubscription.java @@ -29,6 +29,7 @@ public enum EmptySubscription implements QueueSubscription { public void request(long n) { SubscriptionHelper.validate(n); } + @Override public void cancel() { // no-op @@ -67,27 +68,33 @@ public static void complete(Subscriber s) { s.onSubscribe(INSTANCE); s.onComplete(); } + @Nullable @Override public Object poll() { return null; // always empty } + @Override public boolean isEmpty() { return true; } + @Override public void clear() { // nothing to do } + @Override public int requestFusion(int mode) { return mode & ASYNC; // accept async mode: an onComplete or onError will be signalled after anyway } + @Override public boolean offer(Object value) { throw new UnsupportedOperationException("Should not be called!"); } + @Override public boolean offer(Object v1, Object v2) { throw new UnsupportedOperationException("Should not be called!"); diff --git a/src/main/java/io/reactivex/internal/util/LinkedArrayList.java b/src/main/java/io/reactivex/internal/util/LinkedArrayList.java index a54527bdfa..6dbf3fb6e4 100644 --- a/src/main/java/io/reactivex/internal/util/LinkedArrayList.java +++ b/src/main/java/io/reactivex/internal/util/LinkedArrayList.java @@ -87,6 +87,7 @@ public Object[] head() { public int size() { return size; } + @Override public String toString() { final int cap = capacityHint; diff --git a/src/main/java/io/reactivex/observers/SafeObserver.java b/src/main/java/io/reactivex/observers/SafeObserver.java index 8dddcf1d9e..77dbfb20da 100644 --- a/src/main/java/io/reactivex/observers/SafeObserver.java +++ b/src/main/java/io/reactivex/observers/SafeObserver.java @@ -63,7 +63,6 @@ public void onSubscribe(@NonNull Disposable d) { } } - @Override public void dispose() { upstream.dispose(); diff --git a/src/main/java/io/reactivex/observers/SerializedObserver.java b/src/main/java/io/reactivex/observers/SerializedObserver.java index d0cdd4eeab..31badf77f8 100644 --- a/src/main/java/io/reactivex/observers/SerializedObserver.java +++ b/src/main/java/io/reactivex/observers/SerializedObserver.java @@ -72,7 +72,6 @@ public void onSubscribe(@NonNull Disposable d) { } } - @Override public void dispose() { upstream.dispose(); @@ -83,7 +82,6 @@ public boolean isDisposed() { return upstream.isDisposed(); } - @Override public void onNext(@NonNull T t) { if (done) { diff --git a/src/main/java/io/reactivex/processors/PublishProcessor.java b/src/main/java/io/reactivex/processors/PublishProcessor.java index 713fc4190f..878ae92cbe 100644 --- a/src/main/java/io/reactivex/processors/PublishProcessor.java +++ b/src/main/java/io/reactivex/processors/PublishProcessor.java @@ -141,7 +141,6 @@ public static PublishProcessor create() { subscribers = new AtomicReference[]>(EMPTY); } - @Override protected void subscribeActual(Subscriber t) { PublishSubscription ps = new PublishSubscription(t, this); diff --git a/src/main/java/io/reactivex/processors/ReplayProcessor.java b/src/main/java/io/reactivex/processors/ReplayProcessor.java index 868d465748..a8c9c700b4 100644 --- a/src/main/java/io/reactivex/processors/ReplayProcessor.java +++ b/src/main/java/io/reactivex/processors/ReplayProcessor.java @@ -605,6 +605,7 @@ static final class ReplaySubscription extends AtomicInteger implements Subscr this.state = state; this.requested = new AtomicLong(); } + @Override public void request(long n) { if (SubscriptionHelper.validate(n)) { @@ -1117,7 +1118,6 @@ void trimFinal() { } } - @Override public void trimHead() { if (head.value != null) { diff --git a/src/main/java/io/reactivex/subjects/PublishSubject.java b/src/main/java/io/reactivex/subjects/PublishSubject.java index b97af134ca..f59ab36754 100644 --- a/src/main/java/io/reactivex/subjects/PublishSubject.java +++ b/src/main/java/io/reactivex/subjects/PublishSubject.java @@ -129,7 +129,6 @@ public static PublishSubject create() { subscribers = new AtomicReference[]>(EMPTY); } - @Override protected void subscribeActual(Observer t) { PublishDisposable ps = new PublishDisposable(t, this); diff --git a/src/main/java/io/reactivex/subjects/SerializedSubject.java b/src/main/java/io/reactivex/subjects/SerializedSubject.java index 5b8bc16204..ec4263b85e 100644 --- a/src/main/java/io/reactivex/subjects/SerializedSubject.java +++ b/src/main/java/io/reactivex/subjects/SerializedSubject.java @@ -49,7 +49,6 @@ protected void subscribeActual(Observer observer) { actual.subscribe(observer); } - @Override public void onSubscribe(Disposable d) { boolean cancel; diff --git a/src/main/java/io/reactivex/subscribers/DisposableSubscriber.java b/src/main/java/io/reactivex/subscribers/DisposableSubscriber.java index 5c460de70b..076dc9427f 100644 --- a/src/main/java/io/reactivex/subscribers/DisposableSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/DisposableSubscriber.java @@ -74,11 +74,11 @@ * @param the received value type. */ public abstract class DisposableSubscriber implements FlowableSubscriber, Disposable { - final AtomicReference s = new AtomicReference(); + final AtomicReference upstream = new AtomicReference(); @Override public final void onSubscribe(Subscription s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + if (EndConsumerHelper.setOnce(this.upstream, s, getClass())) { onStart(); } } @@ -87,7 +87,7 @@ public final void onSubscribe(Subscription s) { * Called once the single upstream Subscription is set via onSubscribe. */ protected void onStart() { - s.get().request(Long.MAX_VALUE); + upstream.get().request(Long.MAX_VALUE); } /** @@ -99,7 +99,7 @@ protected void onStart() { * @param n the request amount, positive */ protected final void request(long n) { - s.get().request(n); + upstream.get().request(n); } /** @@ -113,11 +113,11 @@ protected final void cancel() { @Override public final boolean isDisposed() { - return s.get() == SubscriptionHelper.CANCELLED; + return upstream.get() == SubscriptionHelper.CANCELLED; } @Override public final void dispose() { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(upstream); } } diff --git a/src/main/java/io/reactivex/subscribers/ResourceSubscriber.java b/src/main/java/io/reactivex/subscribers/ResourceSubscriber.java index 66c282842c..daa37a024b 100644 --- a/src/main/java/io/reactivex/subscribers/ResourceSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/ResourceSubscriber.java @@ -94,7 +94,7 @@ */ public abstract class ResourceSubscriber implements FlowableSubscriber, Disposable { /** The active subscription. */ - private final AtomicReference s = new AtomicReference(); + private final AtomicReference upstream = new AtomicReference(); /** The resource composite, can never be null. */ private final ListCompositeDisposable resources = new ListCompositeDisposable(); @@ -116,7 +116,7 @@ public final void add(Disposable resource) { @Override public final void onSubscribe(Subscription s) { - if (EndConsumerHelper.setOnce(this.s, s, getClass())) { + if (EndConsumerHelper.setOnce(this.upstream, s, getClass())) { long r = missedRequested.getAndSet(0L); if (r != 0L) { s.request(r); @@ -144,7 +144,7 @@ protected void onStart() { * @param n the request amount, must be positive */ protected final void request(long n) { - SubscriptionHelper.deferredRequest(s, missedRequested, n); + SubscriptionHelper.deferredRequest(upstream, missedRequested, n); } /** @@ -156,7 +156,7 @@ protected final void request(long n) { */ @Override public final void dispose() { - if (SubscriptionHelper.cancel(s)) { + if (SubscriptionHelper.cancel(upstream)) { resources.dispose(); } } @@ -167,6 +167,6 @@ public final void dispose() { */ @Override public final boolean isDisposed() { - return SubscriptionHelper.isCancelled(s.get()); + return SubscriptionHelper.isCancelled(upstream.get()); } } diff --git a/src/test/java/io/reactivex/completable/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java index 32461d5d41..4798973835 100644 --- a/src/test/java/io/reactivex/completable/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -2029,6 +2029,7 @@ public void onSubscribe(Disposable d) { }; } } + @Test(timeout = 5000, expected = TestException.class) public void liftOnCompleteError() { Completable c = normal.completable.lift(new CompletableOperatorSwap()); @@ -4660,7 +4661,6 @@ public void accept(final Throwable throwable) throws Exception { } } - @Test(timeout = 5000) public void subscribeTwoCallbacksDispose() { PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java b/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java index ce8cd412b2..aec399a3e7 100644 --- a/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java +++ b/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java @@ -277,6 +277,7 @@ public void run() { // we should have only disposed once assertEquals(1, counter.get()); } + @Test public void testTryRemoveIfNotIn() { CompositeDisposable cd = new CompositeDisposable(); diff --git a/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java b/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java index 4b9f96ba8a..3625aa099a 100644 --- a/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java +++ b/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java @@ -182,6 +182,7 @@ public void testNullCollection() { composite.getCause(); composite.printStackTrace(); } + @Test public void testNullElement() { CompositeException composite = new CompositeException(Collections.singletonList((Throwable) null)); diff --git a/src/test/java/io/reactivex/exceptions/OnErrorNotImplementedExceptionTest.java b/src/test/java/io/reactivex/exceptions/OnErrorNotImplementedExceptionTest.java index d7b69ca107..4097f9a52e 100644 --- a/src/test/java/io/reactivex/exceptions/OnErrorNotImplementedExceptionTest.java +++ b/src/test/java/io/reactivex/exceptions/OnErrorNotImplementedExceptionTest.java @@ -108,7 +108,6 @@ public void singleSubscribe1() { .subscribe(Functions.emptyConsumer()); } - @Test public void maybeSubscribe0() { Maybe.error(new TestException()) diff --git a/src/test/java/io/reactivex/flowable/FlowableCollectTest.java b/src/test/java/io/reactivex/flowable/FlowableCollectTest.java index 09bb562d2b..f187d5b240 100644 --- a/src/test/java/io/reactivex/flowable/FlowableCollectTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableCollectTest.java @@ -83,7 +83,6 @@ public void accept(StringBuilder sb, Integer v) { assertEquals("1-2-3", value); } - @Test public void testFactoryFailureResultsInErrorEmissionFlowable() { final RuntimeException e = new RuntimeException(); @@ -167,7 +166,6 @@ public void accept(Object o, Integer t) { assertFalse(added.get()); } - @SuppressWarnings("unchecked") @Test public void collectIntoFlowable() { @@ -183,7 +181,6 @@ public void accept(HashSet s, Integer v) throws Exception { .assertResult(new HashSet(Arrays.asList(1, 2))); } - @Test public void testCollectToList() { Single> o = Flowable.just(1, 2, 3) @@ -238,7 +235,6 @@ public void accept(StringBuilder sb, Integer v) { assertEquals("1-2-3", value); } - @Test public void testFactoryFailureResultsInErrorEmission() { final RuntimeException e = new RuntimeException(); @@ -319,7 +315,6 @@ public void accept(Object o, Integer t) { assertFalse(added.get()); } - @SuppressWarnings("unchecked") @Test public void collectInto() { diff --git a/src/test/java/io/reactivex/flowable/FlowableNullTests.java b/src/test/java/io/reactivex/flowable/FlowableNullTests.java index 80f70a75ad..3e9582363b 100644 --- a/src/test/java/io/reactivex/flowable/FlowableNullTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableNullTests.java @@ -2724,7 +2724,6 @@ public Object apply(Integer a, Integer b) { }); } - @Test(expected = NullPointerException.class) public void zipWithCombinerNull() { just1.zipWith(just1, null); diff --git a/src/test/java/io/reactivex/flowable/FlowableReduceTests.java b/src/test/java/io/reactivex/flowable/FlowableReduceTests.java index e98c56f0f5..8381a510a4 100644 --- a/src/test/java/io/reactivex/flowable/FlowableReduceTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableReduceTests.java @@ -77,7 +77,6 @@ public Movie apply(Movie t1, Movie t2) { assertNotNull(reduceResult2); } - @Test public void reduceInts() { Flowable f = Flowable.just(1, 2, 3); diff --git a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java index b72df7a98c..f7789656a3 100644 --- a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java @@ -771,7 +771,6 @@ public void safeSubscriberAlreadySafe() { ts.assertResult(1); } - @Test public void methodTestNoCancel() { PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/flowable/FlowableTests.java b/src/test/java/io/reactivex/flowable/FlowableTests.java index f3b7d2b371..377254f95e 100644 --- a/src/test/java/io/reactivex/flowable/FlowableTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableTests.java @@ -148,7 +148,6 @@ public Throwable call() { verify(w, times(1)).onError(any(RuntimeException.class)); } - @Test public void testCountAFewItems() { Flowable flowable = Flowable.just("a", "b", "c", "d"); @@ -862,7 +861,6 @@ public void testContainsWithEmptyObservableFlowable() { verify(subscriber, times(1)).onComplete(); } - @Test public void testContains() { Single single = Flowable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c" diff --git a/src/test/java/io/reactivex/internal/SubscribeWithTest.java b/src/test/java/io/reactivex/internal/SubscribeWithTest.java index e2c23b51d5..ee6cdf5c0b 100644 --- a/src/test/java/io/reactivex/internal/SubscribeWithTest.java +++ b/src/test/java/io/reactivex/internal/SubscribeWithTest.java @@ -30,7 +30,6 @@ public void withFlowable() { .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } - @Test public void withObservable() { Observable.range(1, 10) diff --git a/src/test/java/io/reactivex/internal/observers/BasicFuseableObserverTest.java b/src/test/java/io/reactivex/internal/observers/BasicFuseableObserverTest.java index 93aef221b2..797ae8e07a 100644 --- a/src/test/java/io/reactivex/internal/observers/BasicFuseableObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/BasicFuseableObserverTest.java @@ -30,13 +30,16 @@ public void offer() { public Integer poll() throws Exception { return null; } + @Override public int requestFusion(int mode) { return 0; } + @Override public void onNext(Integer value) { } + @Override protected boolean beforeDownstream() { return false; @@ -58,10 +61,12 @@ public void offer2() { public Integer poll() throws Exception { return null; } + @Override public int requestFusion(int mode) { return 0; } + @Override public void onNext(Integer value) { } diff --git a/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java b/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java index 8defb098ef..7d2640b71c 100644 --- a/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java @@ -181,7 +181,6 @@ static final class TakeLast extends DeferredScalarObserver { super(downstream); } - @Override public void onNext(Integer value) { this.value = value; diff --git a/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java b/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java index 8e520fd402..81221cfc21 100644 --- a/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java @@ -247,6 +247,7 @@ public void accept(Disposable d) throws Exception { RxJavaPlugins.reset(); } } + @Test public void badSourceEmitAfterDone() { List errors = TestHelper.trackPluginErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java index f6f3dc0337..0e45cd1c1b 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java @@ -187,7 +187,6 @@ public void ambRace() { } } - @Test public void untilCompletableMainComplete() { CompletableSubject main = CompletableSubject.create(); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java index c2a3af2769..1633954fbf 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java @@ -40,7 +40,6 @@ public CompletableSource apply(Completable c) throws Exception { }); } - @Test public void disposeInResume() { TestHelper.checkDisposedCompletable(new Function() { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableSubscribeTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableSubscribeTest.java index 543d7015c4..4f546e548f 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableSubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableSubscribeTest.java @@ -30,7 +30,6 @@ public void subscribeAlreadyCancelled() { assertFalse(pp.hasSubscribers()); } - @Test public void methodTestNoCancel() { PublishSubject ps = PublishSubject.create(); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java index 598abdd29c..5d1a4cfc42 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java @@ -347,7 +347,6 @@ public void accept(Object d) throws Exception { .assertFailure(TestException.class); } - @Test public void emptyDisposerCrashes() { Completable.using(new Callable() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java index 71c075c2c4..26e6eb5716 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java @@ -103,7 +103,6 @@ public void constructorshouldbeprivate() { TestHelper.checkUtilityClass(BlockingFlowableMostRecent.class); } - @Test public void empty() { Iterator it = Flowable.empty() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java index 7ab08915d2..e859766ca8 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java @@ -124,6 +124,7 @@ public boolean test(Integer i) { assertFalse(allOdd.blockingGet()); } + @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstream() { Flowable source = Flowable.just(1) @@ -297,6 +298,7 @@ public boolean test(Integer i) { assertFalse(allOdd.blockingFirst()); } + @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstreamFlowable() { Flowable source = Flowable.just(1) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java index 9e68ec3948..a4b03c633c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java @@ -236,7 +236,6 @@ public void testBackpressure() { assertEquals(Flowable.bufferSize() * 2, ts.values().size()); } - @SuppressWarnings("unchecked") @Test public void testSubscriptionOnlyHappensOnce() throws InterruptedException { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java index 76bd59591a..76d4b034b7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java @@ -223,6 +223,7 @@ public boolean test(Integer i) { assertTrue(anyEven.blockingGet()); } + @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstream() { Flowable source = Flowable.just(1).isEmpty() @@ -489,6 +490,7 @@ public boolean test(Integer i) { assertTrue(anyEven.blockingFirst()); } + @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstreamFlowable() { Flowable source = Flowable.just(1).isEmpty() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java index 23cf4ecf02..a297911040 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java @@ -45,6 +45,7 @@ public void testHiding() { verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); } + @Test public void testHidingError() { PublishProcessor src = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java index aa8c3ef23c..00568da3ec 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java @@ -496,6 +496,7 @@ public void bufferWithBOBoundaryThrows() { verify(subscriber, never()).onComplete(); verify(subscriber, never()).onNext(any()); } + @Test(timeout = 2000) public void bufferWithSizeTake1() { Flowable source = Flowable.just(1).repeat(); @@ -525,6 +526,7 @@ public void bufferWithSizeSkipTake1() { verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); } + @Test(timeout = 2000) public void bufferWithTimeTake1() { Flowable source = Flowable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); @@ -541,6 +543,7 @@ public void bufferWithTimeTake1() { verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); } + @Test(timeout = 2000) public void bufferWithTimeSkipTake2() { Flowable source = Flowable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); @@ -614,6 +617,7 @@ public void accept(List pv) { inOrder.verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); } + @Test public void bufferWithSizeThrows() { PublishProcessor source = PublishProcessor.create(); @@ -683,6 +687,7 @@ public void bufferWithTimeAndSize() { inOrder.verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); } + @Test public void bufferWithStartEndStartThrows() { PublishProcessor start = PublishProcessor.create(); @@ -711,6 +716,7 @@ public Flowable apply(Integer t1) { verify(subscriber, never()).onComplete(); verify(subscriber).onError(any(TestException.class)); } + @Test public void bufferWithStartEndEndFunctionThrows() { PublishProcessor start = PublishProcessor.create(); @@ -738,6 +744,7 @@ public Flowable apply(Integer t1) { verify(subscriber, never()).onComplete(); verify(subscriber).onError(any(TestException.class)); } + @Test public void bufferWithStartEndEndThrows() { PublishProcessor start = PublishProcessor.create(); @@ -881,7 +888,6 @@ public void cancel() { assertEquals(Long.MAX_VALUE, requested.get()); } - @Test public void testProducerRequestOverflowThroughBufferWithSize1() { TestSubscriber> ts = new TestSubscriber>(Long.MAX_VALUE >> 1); @@ -991,6 +997,7 @@ public void onNext(List t) { // FIXME I'm not sure why this is MAX_VALUE in 1.x because MAX_VALUE/2 is even and thus can't overflow when multiplied by 2 assertEquals(Long.MAX_VALUE - 1, requested.get()); } + @Test(timeout = 3000) public void testBufferWithTimeDoesntUnsubscribeDownstream() throws InterruptedException { final Subscriber subscriber = TestHelper.mockSubscriber(); @@ -1001,11 +1008,13 @@ public void testBufferWithTimeDoesntUnsubscribeDownstream() throws InterruptedEx public void onNext(Object t) { subscriber.onNext(t); } + @Override public void onError(Throwable e) { subscriber.onError(e); cdl.countDown(); } + @Override public void onComplete() { subscriber.onComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java index c26e612e09..f3d241bfd6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java @@ -54,6 +54,7 @@ public void testColdReplayNoBackpressure() { assertEquals((Integer)i, onNextEvents.get(i)); } } + @Test public void testColdReplayBackpressure() { FlowableCache source = new FlowableCache(Flowable.range(0, 1000), 16); @@ -178,6 +179,7 @@ public void testAsync() { assertEquals(10000, ts2.values().size()); } } + @Test public void testAsyncComeAndGo() { Flowable source = Flowable.interval(1, 1, TimeUnit.MILLISECONDS) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java index 2934084b0d..1d759a6e44 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java @@ -1206,6 +1206,7 @@ public Object apply(Object[] a) throws Exception { .test() .assertFailure(TestException.class, "[1, 2]"); } + @SuppressWarnings("unchecked") @Test public void combineLatestEmpty() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatDelayErrorTest.java index ab307df66f..7d343c1f3d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatDelayErrorTest.java @@ -216,7 +216,6 @@ static Flowable withError(Flowable source) { return source.concatWith(Flowable.error(new TestException())); } - @Test public void concatDelayErrorFlowable() { TestSubscriber ts = TestSubscriber.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java index 3c77acb502..1e34d2937b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java @@ -655,7 +655,6 @@ public Flowable apply(Integer t) { ts.assertValue(null); } - @Test public void testMaxConcurrent5() { final List requests = new ArrayList(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java index 7c53083548..4b199482e9 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java @@ -169,6 +169,7 @@ public void subscribe(final Subscriber> subscriber) { public void request(long n) { } + @Override public void cancel() { d.dispose(); @@ -636,6 +637,7 @@ public Flowable apply(Integer v) { inOrder.verify(o).onSuccess(list); verify(o, never()).onError(any(Throwable.class)); } + @Test public void concatVeryLongObservableOfObservablesTakeHalf() { final int n = 10000; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybeTest.java index eb1fd62fe2..64a7c62149 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithMaybeTest.java @@ -41,7 +41,6 @@ public void run() throws Exception { ts.assertResult(1, 2, 3, 4, 5, 100); } - @Test public void normalNonEmpty() { final TestSubscriber ts = new TestSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java index e11fb643eb..998569148d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java @@ -39,7 +39,6 @@ public void simple() { } - @Test public void dispose() { TestHelper.checkDisposed(Flowable.just(1).count()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java index 8aeef598c8..899f145ca2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java @@ -1001,7 +1001,6 @@ public void cancel() throws Exception { } } - @Test public void tryOnError() { for (BackpressureStrategy strategy : BackpressureStrategy.values()) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java index 40348b0ee6..8df7c9c193 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java @@ -239,6 +239,7 @@ public Flowable apply(Integer t1) { verify(subscriber, never()).onComplete(); verify(subscriber).onError(any(TestException.class)); } + @Test public void debounceTimedLastIsNotLost() { PublishProcessor source = PublishProcessor.create(); @@ -256,6 +257,7 @@ public void debounceTimedLastIsNotLost() { verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); } + @Test public void debounceSelectorLastIsNotLost() { PublishProcessor source = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java index a42c0d889f..1114f17a1d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java @@ -87,7 +87,6 @@ public void range() { ts.assertComplete(); } - @Test public void backpressured() throws Exception { o = new Object(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoFinallyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoFinallyTest.java index 943d92ff03..93dd960cf3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoFinallyTest.java @@ -157,7 +157,6 @@ public void asyncFusedBoundary() { assertEquals(1, calls); } - @Test public void normalJustConditional() { Flowable.just(1) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java index e8a395fc3b..d5665d6bf3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java @@ -186,7 +186,6 @@ public void elementAtOrErrorIndex1OnEmptySource() { .assertFailure(NoSuchElementException.class); } - @Test public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>() { @@ -229,7 +228,6 @@ public void errorFlowable() { .assertFailure(TestException.class); } - @Test public void error() { Flowable.error(new TestException()) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java index 01309ff55c..62cee79161 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java @@ -183,7 +183,6 @@ public CompletableSource apply(Integer v) throws Exception { .assertFailure(TestException.class); } - @Test public void fusedFlowable() { TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); @@ -338,7 +337,6 @@ public CompletableSource apply(Integer v) throws Exception { .assertFailure(TestException.class); } - @Test public void fused() { TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java index 9cdbfc26af..c9c24e7ef5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java @@ -355,6 +355,7 @@ public Flowable apply(Integer t1) { Assert.assertEquals(expected.size(), ts.valueCount()); Assert.assertTrue(expected.containsAll(ts.values())); } + @Test public void testFlatMapSelectorMaxConcurrent() { final int m = 4; @@ -478,6 +479,7 @@ public Flowable apply(Integer t) { } } } + @Test(timeout = 30000) public void flatMapRangeMixedAsyncLoop() { for (int i = 0; i < 2000; i++) { @@ -537,6 +539,7 @@ public Flowable apply(Integer t) { ts.assertValueCount(1000); } } + @Test public void flatMapTwoNestedSync() { for (final int n : new int[] { 1, 1000, 1000000 }) { @@ -856,7 +859,6 @@ public void run() { } } - @Test public void fusedInnerThrows() { Flowable.just(1).hide() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromArrayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromArrayTest.java index b07fe3bf2d..2112541c29 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromArrayTest.java @@ -33,6 +33,7 @@ Flowable create(int n) { } return Flowable.fromArray(array); } + @Test public void simple() { TestSubscriber ts = new TestSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java index e1f15bb261..b2452a65fb 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java @@ -40,7 +40,6 @@ public void before() { ts = new TestSubscriber(0L); } - @Test public void normalBuffered() { Flowable.create(source, BackpressureStrategy.BUFFER).subscribe(ts); @@ -125,7 +124,6 @@ public void normalMissingRequested() { ts.assertComplete(); } - @Test public void normalError() { Flowable.create(source, BackpressureStrategy.ERROR).subscribe(ts); @@ -489,7 +487,6 @@ public void unsubscribeNoCancel() { ts.assertNotComplete(); } - @Test public void unsubscribeInline() { TestSubscriber ts1 = new TestSubscriber() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java index 022ab3788f..9b2ae32416 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java @@ -1638,7 +1638,6 @@ public void accept(GroupedFlowable g) { .assertComplete(); } - @Test public void keySelectorAndDelayError() { Flowable.just(1).concatWith(Flowable.error(new TestException())) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java index 8656afde8d..1f6c9e23a5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java @@ -144,7 +144,6 @@ public void onNext(Integer t) { assertEquals(0, count.get()); } - @Test public void testWithEmpty() { assertNull(Flowable.empty().ignoreElements().blockingGet()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java index 03300d4dda..67129c956b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java @@ -436,6 +436,7 @@ public void onNext(String args) { } } + @Test @Ignore("Subscribers should not throw") public void testMergeSourceWhichDoesntPropagateExceptionBack() { @@ -559,6 +560,7 @@ public void run() { t.start(); } } + @Test public void testDelayErrorMaxConcurrent() { final List requests = new ArrayList(); @@ -737,7 +739,6 @@ public void array() { } } - @SuppressWarnings("unchecked") @Test public void mergeArrayDelayError() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java index 0973027f3b..ef5dd519ff 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java @@ -129,6 +129,7 @@ public void testMergeALotOfSourcesOneByOneSynchronously() { } assertEquals(j, n); } + @Test public void testMergeALotOfSourcesOneByOneSynchronouslyTakeHalf() { int n = 10000; @@ -163,6 +164,7 @@ public void testSimple() { ts.assertValueSequence(result); } } + @Test public void testSimpleOneLess() { for (int i = 2; i < 100; i++) { @@ -181,6 +183,7 @@ public void testSimpleOneLess() { ts.assertValueSequence(result); } } + @Test//(timeout = 20000) public void testSimpleAsyncLoop() { IoScheduler ios = (IoScheduler)Schedulers.io(); @@ -193,6 +196,7 @@ public void testSimpleAsyncLoop() { } } } + @Test(timeout = 10000) public void testSimpleAsync() { for (int i = 1; i < 50; i++) { @@ -213,12 +217,14 @@ public void testSimpleAsync() { assertEquals(expected, actual); } } + @Test(timeout = 10000) public void testSimpleOneLessAsyncLoop() { for (int i = 0; i < 200; i++) { testSimpleOneLessAsync(); } } + @Test(timeout = 10000) public void testSimpleOneLessAsync() { long t = System.currentTimeMillis(); @@ -243,6 +249,7 @@ public void testSimpleOneLessAsync() { assertEquals(expected, actual); } } + @Test(timeout = 5000) public void testBackpressureHonored() throws Exception { List> sourceList = new ArrayList>(3); @@ -273,6 +280,7 @@ public void onNext(Integer t) { ts.dispose(); } + @Test(timeout = 5000) public void testTake() throws Exception { List> sourceList = new ArrayList>(3); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java index e66206c865..fc09bd1dc5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java @@ -1360,10 +1360,12 @@ void runMerge(Function> func, TestSubscriber public void testFastMergeFullScalar() { runMerge(toScalar, new TestSubscriber()); } + @Test public void testFastMergeHiddenScalar() { runMerge(toHiddenScalar, new TestSubscriber()); } + @Test public void testSlowMergeFullScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { @@ -1382,6 +1384,7 @@ public void onNext(Integer t) { runMerge(toScalar, ts); } } + @Test public void testSlowMergeHiddenScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { @@ -1462,7 +1465,6 @@ public void mergeConcurrentJustRange() { ts.assertComplete(); } - @SuppressWarnings("unchecked") @Test @Ignore("No 2-9 argument merge()") @@ -1622,7 +1624,6 @@ public void array() { } } - @SuppressWarnings("unchecked") @Test public void mergeArray() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java index 10c1facc16..2beacebd84 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java @@ -794,7 +794,6 @@ public void onNext(Integer t) { assertEquals(Arrays.asList(128L), requests); } - @Test public void testErrorDelayed() { TestScheduler s = new TestScheduler(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatestTest.java index 6fb70da88b..db6b3d9580 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatestTest.java @@ -37,6 +37,7 @@ public void testSimple() { ts.assertTerminated(); ts.assertValues(1, 2, 3, 4, 5); } + @Test public void testSimpleError() { TestSubscriber ts = new TestSubscriber(); @@ -48,6 +49,7 @@ public void testSimpleError() { ts.assertError(TestException.class); ts.assertValues(1, 2, 3, 4, 5); } + @Test public void testSimpleBackpressure() { TestSubscriber ts = new TestSubscriber(2L); @@ -100,6 +102,7 @@ public void testSynchronousDrop() { ts.assertNoErrors(); ts.assertTerminated(); } + @Test public void testAsynchronousDrop() throws InterruptedException { TestSubscriber ts = new TestSubscriber(1L) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java index 9bcc27d5f3..eb2f120e43 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java @@ -242,7 +242,6 @@ public Integer apply(Throwable e) { ts.assertComplete(); } - @Test public void returnItem() { Flowable.error(new TestException()) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java index 3da05ffedf..e9f19585bf 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java @@ -186,7 +186,6 @@ public String apply(String s) { verify(subscriber, times(1)).onComplete(); } - @Test public void testBackpressure() { TestSubscriber ts = new TestSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticastTest.java index 8e004d7af7..4078b5b0b0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticastTest.java @@ -152,7 +152,6 @@ public void errorAllCancelled() { mp.errorAll(null); } - @Test public void completeAllCancelled() { MulticastProcessor mp = new MulticastProcessor(128, true); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java index c18cbc928b..c7c9865f24 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java @@ -371,6 +371,7 @@ public void testZeroRequested() { ts.assertNoErrors(); ts.assertTerminated(); } + @Test public void testConnectIsIdempotent() { final AtomicInteger calls = new AtomicInteger(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java index f97febd9e2..470e0e8cc0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java @@ -164,18 +164,21 @@ void testWithBackpressureAllAtOnce(long start) { ts.assertValueSequence(list); ts.assertTerminated(); } + @Test public void testWithBackpressure1() { for (long i = 0; i < 100; i++) { testWithBackpressureOneByOne(i); } } + @Test public void testWithBackpressureAllAtOnce() { for (long i = 0; i < 100; i++) { testWithBackpressureAllAtOnce(i); } } + @Test public void testWithBackpressureRequestWayMore() { Flowable source = Flowable.rangeLong(50, 100); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java index 36a345c617..b0af47585b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java @@ -164,18 +164,21 @@ void testWithBackpressureAllAtOnce(int start) { ts.assertValueSequence(list); ts.assertTerminated(); } + @Test public void testWithBackpressure1() { for (int i = 0; i < 100; i++) { testWithBackpressureOneByOne(i); } } + @Test public void testWithBackpressureAllAtOnce() { for (int i = 0; i < 100; i++) { testWithBackpressureAllAtOnce(i); } } + @Test public void testWithBackpressureRequestWayMore() { Flowable source = Flowable.range(50, 100); @@ -260,6 +263,7 @@ public void testNearMaxValueWithoutBackpressure() { ts.assertNoErrors(); ts.assertValues(Integer.MAX_VALUE - 1, Integer.MAX_VALUE); } + @Test(timeout = 1000) public void testNearMaxValueWithBackpressure() { TestSubscriber ts = new TestSubscriber(3L); @@ -270,7 +274,6 @@ public void testNearMaxValueWithBackpressure() { ts.assertValues(Integer.MAX_VALUE - 1, Integer.MAX_VALUE); } - @Test public void negativeCount() { try { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java index 12425aed42..e6103b5a7b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java @@ -141,7 +141,6 @@ public void testBackpressureWithInitialValueFlowable() throws InterruptedExcepti assertEquals(21, r.intValue()); } - @Test public void testAggregateAsIntSum() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java index 137565dae4..cb6db6ef11 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java @@ -876,6 +876,7 @@ public void testColdReplayNoBackpressure() { assertEquals((Integer)i, onNextEvents.get(i)); } } + @Test public void testColdReplayBackpressure() { Flowable source = Flowable.range(0, 1000).replay().autoConnect(); @@ -995,6 +996,7 @@ public void testAsync() { assertEquals(10000, ts2.values().size()); } } + @Test public void testAsyncComeAndGo() { Flowable source = Flowable.interval(1, 1, TimeUnit.MILLISECONDS) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java index e7a2bb8eaa..8b35cb37f9 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java @@ -433,6 +433,7 @@ public void request(long n) { } } } + @Override public void cancel() { // TODO Auto-generated method stub @@ -829,6 +830,7 @@ static StringBuilder sequenceFrequency(Iterable it) { return sb; } + @Test//(timeout = 3000) public void testIssue1900() throws InterruptedException { Subscriber subscriber = TestHelper.mockSubscriber(); @@ -869,6 +871,7 @@ public Flowable apply(GroupedFlowable t1) { inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } + @Test//(timeout = 3000) public void testIssue1900SourceNotSupportingBackpressure() { Subscriber subscriber = TestHelper.mockSubscriber(); @@ -997,7 +1000,6 @@ public boolean getAsBoolean() throws Exception { .assertResult(1, 1, 1, 1, 1); } - @Test public void shouldDisposeInnerObservable() { final PublishProcessor processor = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java index 1f9f8c0736..f25c276ece 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java @@ -70,6 +70,7 @@ public void testWithNothingToRetry() { inOrder.verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); } + @Test public void testRetryTwice() { Flowable source = Flowable.unsafeCreate(new Publisher() { @@ -105,6 +106,7 @@ public void subscribe(Subscriber t1) { verify(subscriber, never()).onError(any(Throwable.class)); } + @Test public void testRetryTwiceAndGiveUp() { Flowable source = Flowable.unsafeCreate(new Publisher() { @@ -132,6 +134,7 @@ public void subscribe(Subscriber t1) { verify(subscriber, never()).onComplete(); } + @Test public void testRetryOnSpecificException() { Flowable source = Flowable.unsafeCreate(new Publisher() { @@ -166,6 +169,7 @@ public void subscribe(Subscriber t1) { inOrder.verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); } + @Test public void testRetryOnSpecificExceptionAndNotOther() { final IOException ioe = new IOException(); @@ -289,6 +293,7 @@ public Integer apply(Integer t1) { assertEquals(6, c.get()); assertEquals(Collections.singletonList(e), ts.errors()); } + @Test public void testJustAndRetry() throws Exception { final AtomicBoolean throwException = new AtomicBoolean(true); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java index 4ee2fad368..fb65114e42 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java @@ -483,7 +483,6 @@ protected void subscribeActual(Subscriber s) { } } - @Test public void longSequenceEquals() { Flowable source = Flowable.range(1, Flowable.bufferSize() * 4).subscribeOn(Schedulers.computation()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java index 88cb84d40d..62f662804f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java @@ -192,7 +192,6 @@ public void onNext(Integer t) { assertEquals(Arrays.asList(Long.MAX_VALUE), requests); } - @Test public void testSingleWithPredicateFlowable() { Flowable flowable = Flowable.just(1, 2) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java index 6c7cc67603..e301c29aec 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java @@ -156,6 +156,7 @@ public void testSwitchRequestAlternativeObservableWithBackpressure() { ts.request(1); ts.assertValueCount(3); } + @Test public void testBackpressureNoRequest() { TestSubscriber ts = new TestSubscriber(0L); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java index 1878d133a4..d2caa4ada8 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java @@ -583,7 +583,6 @@ public Flowable apply(Long t) { assertTrue(ts.valueCount() > 0); } - @Test(timeout = 10000) public void testSecondaryRequestsDontOverflow() throws InterruptedException { TestSubscriber ts = new TestSubscriber(0L); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java index 3277d5f831..37f5ee0d1f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java @@ -241,7 +241,6 @@ public void onNext(Integer integer) { }); } - @Test public void testIgnoreRequest4() { // If `takeLast` does not ignore `request` properly, StackOverflowError will be thrown. diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java index 5510b534ea..91d4d4ea8b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java @@ -451,7 +451,6 @@ public void accept(Integer v) { ts.assertComplete(); } - @Test public void takeNegative() { try { @@ -485,7 +484,6 @@ public Flowable apply(Flowable f) throws Exception { }); } - @Test public void badRequest() { TestHelper.assertBadRequestReported(Flowable.never().take(1)); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java index 22e96421f0..acba2b1294 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java @@ -47,6 +47,7 @@ public boolean test(Object v) { verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber).onComplete(); } + @Test public void takeAll() { Subscriber subscriber = TestHelper.mockSubscriber(); @@ -63,6 +64,7 @@ public boolean test(Integer v) { verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber).onComplete(); } + @Test public void takeFirst() { Subscriber subscriber = TestHelper.mockSubscriber(); @@ -79,6 +81,7 @@ public boolean test(Integer v) { verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber).onComplete(); } + @Test public void takeSome() { Subscriber subscriber = TestHelper.mockSubscriber(); @@ -97,6 +100,7 @@ public boolean test(Integer t1) { verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber).onComplete(); } + @Test public void functionThrows() { Subscriber subscriber = TestHelper.mockSubscriber(); @@ -115,6 +119,7 @@ public boolean test(Integer t1) { verify(subscriber).onError(any(TestException.class)); verify(subscriber, never()).onComplete(); } + @Test public void sourceThrows() { Subscriber subscriber = TestHelper.mockSubscriber(); @@ -134,6 +139,7 @@ public boolean test(Integer v) { verify(subscriber).onError(any(TestException.class)); verify(subscriber, never()).onComplete(); } + @Test public void backpressure() { TestSubscriber ts = new TestSubscriber(5L); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java index 702f4660e1..b254ecdf8d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java @@ -209,6 +209,7 @@ public void testUntilFires() { assertFalse("Until still has observers", until.hasSubscribers()); assertFalse("TestSubscriber is unsubscribed", ts.isCancelled()); } + @Test public void testMainCompletes() { PublishProcessor source = PublishProcessor.create(); @@ -232,6 +233,7 @@ public void testMainCompletes() { assertFalse("Until still has observers", until.hasSubscribers()); assertFalse("TestSubscriber is unsubscribed", ts.isCancelled()); } + @Test public void testDownstreamUnsubscribes() { PublishProcessor source = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java index f9dc9c01f1..2e5fd020e7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java @@ -153,7 +153,6 @@ public void testThrottle() { inOrder.verifyNoMoreInteractions(); } - @Test public void throttleFirstDefaultScheduler() { Flowable.just(1).throttleFirst(100, TimeUnit.MILLISECONDS) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatestTest.java index 2b07d178d9..5612307c28 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatestTest.java @@ -130,7 +130,6 @@ public void normal() { ts.assertResult(1, 3, 5, 6); } - @Test public void normalEmitLast() { TestScheduler sch = new TestScheduler(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java index ded3661e95..8ba33edca7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java @@ -477,7 +477,6 @@ protected void subscribeActual(Subscriber subscriber) { } } - @Test public void timedTake() { PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java index 21009d0da7..e5b9c61de4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java @@ -86,6 +86,7 @@ public void testTimerPeriodically() { ts.assertNotComplete(); ts.assertNoErrors(); } + @Test public void testInterval() { Flowable w = Flowable.interval(1, TimeUnit.SECONDS, scheduler); @@ -226,6 +227,7 @@ public void testWithMultipleStaggeredSubscribersAndPublish() { ts2.assertNoErrors(); ts2.assertNotComplete(); } + @Test public void testOnceObserverThrows() { Flowable source = Flowable.timer(100, TimeUnit.MILLISECONDS, scheduler); @@ -254,6 +256,7 @@ public void onComplete() { verify(subscriber, never()).onNext(anyLong()); verify(subscriber, never()).onComplete(); } + @Test public void testPeriodicObserverThrows() { Flowable source = Flowable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java index 20a0534285..ffa4d0eba3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java @@ -101,6 +101,7 @@ public void testListWithBlockingFirstFlowable() { List actual = f.toList().toFlowable().blockingFirst(); Assert.assertEquals(Arrays.asList("one", "two", "three"), actual); } + @Test public void testBackpressureHonoredFlowable() { Flowable> w = Flowable.just(1, 2, 3, 4, 5).toList().toFlowable(); @@ -124,6 +125,7 @@ public void testBackpressureHonoredFlowable() { ts.assertNoErrors(); ts.assertComplete(); } + @Test(timeout = 2000) @Ignore("PublishProcessor no longer emits without requests so this test fails due to the race of onComplete and request") public void testAsyncRequestedFlowable() { @@ -230,6 +232,7 @@ public void testListWithBlockingFirst() { List actual = f.toList().blockingGet(); Assert.assertEquals(Arrays.asList("one", "two", "three"), actual); } + @Test @Ignore("Single doesn't do backpressure") public void testBackpressureHonored() { @@ -254,6 +257,7 @@ public void testBackpressureHonored() { to.assertNoErrors(); to.assertComplete(); } + @Test(timeout = 2000) @Ignore("PublishProcessor no longer emits without requests so this test fails due to the race of onComplete and request") public void testAsyncRequested() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java index f8914e7182..296f68eef6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java @@ -224,7 +224,6 @@ public String apply(String v) { verify(objectSubscriber, times(1)).onError(any(Throwable.class)); } - @Test public void testToMap() { Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java index 1546815355..bb77dab822 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java @@ -296,7 +296,6 @@ public Map> call() { verify(objectSubscriber, never()).onComplete(); } - @Test public void testToMultimap() { Flowable source = Flowable.just("a", "b", "cc", "dd"); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java index bea7ef749a..173da4830d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java @@ -69,6 +69,7 @@ public void testWithFollowingFirstFlowable() { Flowable f = Flowable.just(1, 3, 2, 5, 4); assertEquals(Arrays.asList(1, 2, 3, 4, 5), f.toSortedList().toFlowable().blockingFirst()); } + @Test public void testBackpressureHonoredFlowable() { Flowable> w = Flowable.just(1, 3, 2, 5, 4).toSortedList().toFlowable(); @@ -202,6 +203,7 @@ public void testWithFollowingFirst() { Flowable f = Flowable.just(1, 3, 2, 5, 4); assertEquals(Arrays.asList(1, 2, 3, 4, 5), f.toSortedList().blockingGet()); } + @Test @Ignore("Single doesn't do backpressure") public void testBackpressureHonored() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java index b67437e7a9..cfc8ab20b1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java @@ -331,8 +331,6 @@ public Flowable apply(Resource resource) { } - - @Test public void testUsingDisposesEagerlyBeforeError() { final List events = new ArrayList(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java index a6469281c4..014ebbf756 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java @@ -326,6 +326,7 @@ public Flowable call() { ts.assertNoErrors(); ts.assertValueCount(1); } + @Test public void testMainUnsubscribedOnBoundaryCompletion() { PublishProcessor source = PublishProcessor.create(); @@ -386,6 +387,7 @@ public Flowable call() { ts.assertNoErrors(); ts.assertValueCount(1); } + @Test public void testInnerBackpressure() { Flowable source = Flowable.range(1, 10); @@ -771,7 +773,6 @@ public Flowable apply( ts.assertResult(1); } - @Test public void mainAndBoundaryBothError() { List errors = TestHelper.trackPluginErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java index aeb5381da7..b6fb51f6d2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java @@ -211,6 +211,7 @@ public void testBackpressureOuter() { public void onStart() { request(1); } + @Override public void onNext(Flowable t) { t.subscribe(new DefaultSubscriber() { @@ -218,20 +219,24 @@ public void onNext(Flowable t) { public void onNext(Integer t) { list.add(t); } + @Override public void onError(Throwable e) { subscriber.onError(e); } + @Override public void onComplete() { subscriber.onComplete(); } }); } + @Override public void onError(Throwable e) { subscriber.onError(e); } + @Override public void onComplete() { subscriber.onComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java index 296c973963..d2eef83d88 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java @@ -158,6 +158,7 @@ public void onNext(T args) { } }; } + @Test public void testExactWindowSize() { Flowable> source = Flowable.range(1, 10) @@ -222,7 +223,6 @@ public void accept(Integer pv) { Assert.assertTrue(ts.valueCount() != 0); } - @Test public void timespanTimeskipCustomSchedulerBufferSize() { Flowable.range(1, 10) @@ -811,6 +811,7 @@ public void periodicWindowCompletionRestartTimerBoundedSomeData() { .assertNoErrors() .assertNotComplete(); } + @Test public void countRestartsOnTimeTick() { TestScheduler scheduler = new TestScheduler(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java index e87ff9fe50..070176bdb0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java @@ -134,7 +134,6 @@ public void testEmptyOther() { assertFalse(other.hasSubscribers()); } - @Test public void testUnsubscription() { PublishProcessor source = PublishProcessor.create(); @@ -189,6 +188,7 @@ public void testSourceThrows() { assertFalse(source.hasSubscribers()); assertFalse(other.hasSubscribers()); } + @Test public void testOtherThrows() { PublishProcessor source = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java index b02fa664fe..ef1223d66a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java @@ -1224,6 +1224,7 @@ public Integer apply(Integer i1, Integer i2) { } assertEquals(expected, zip2.toList().blockingGet()); } + @Test public void testUnboundedDownstreamOverrequesting() { Flowable source = Flowable.range(1, 2).zipWith(Flowable.range(1, 2), new BiFunction() { @@ -1247,6 +1248,7 @@ public void onNext(Integer t) { ts.assertTerminated(); ts.assertValues(11, 22); } + @Test(timeout = 10000) public void testZipRace() { long startTime = System.currentTimeMillis(); @@ -1570,6 +1572,7 @@ public Object apply(Integer a, Integer b, Integer c, Integer d, Integer e, Integ .test() .assertResult("12345678"); } + @Test public void zip9() { Flowable.zip(Flowable.just(1), @@ -1589,7 +1592,6 @@ public Object apply(Integer a, Integer b, Integer c, Integer d, Integer e, Integ .assertResult("123456789"); } - @Test public void zipArrayMany() { @SuppressWarnings("unchecked") diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCacheTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCacheTest.java index 57c856b472..bae05a46b4 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCacheTest.java @@ -52,7 +52,6 @@ public void offlineError() { .assertFailure(TestException.class); } - @Test public void offlineComplete() { Maybe source = Maybe.empty().cache(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeContainsTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeContainsTest.java index 588de845a8..60f319f873 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeContainsTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeContainsTest.java @@ -59,7 +59,6 @@ public void dispose() { assertFalse(pp.hasSubscribers()); } - @Test public void isDisposed() { PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherTest.java index 40cb873836..4719ac8977 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherTest.java @@ -65,7 +65,6 @@ public void justWithOnComplete() { to.assertResult(1); } - @Test public void justWithOnError() { PublishProcessor pp = PublishProcessor.create(); @@ -102,7 +101,6 @@ public void emptyWithOnNext() { to.assertResult(); } - @Test public void emptyWithOnComplete() { PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeIsEmptyTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeIsEmptyTest.java index 3efe9dbec3..3602d44aa0 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeIsEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeIsEmptyTest.java @@ -54,7 +54,6 @@ public void fusedBackToMaybe() { .toMaybe() instanceof MaybeIsEmpty); } - @Test public void normalToMaybe() { Maybe.just(1) diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java index bacd1c1870..2c242fc1a5 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java @@ -61,7 +61,6 @@ public void dispose() { assertFalse(pp.hasSubscribers()); } - @Test public void isDisposed() { PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptyTest.java index d2e53a7225..142943ba67 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptyTest.java @@ -76,7 +76,6 @@ public void dispose() { assertFalse(pp.hasSubscribers()); } - @Test public void isDisposed() { PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java index c78a7cf5d7..d007667097 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java @@ -346,7 +346,6 @@ public void accept(Object d) throws Exception { .assertFailure(TestException.class); } - @Test public void emptyDisposerCrashes() { Maybe.using(new Callable() { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java index 7fb24e1e27..cd97bea762 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java @@ -150,6 +150,7 @@ public void run() { } } } + @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipArrayOneIsNull() { diff --git a/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservableTest.java b/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservableTest.java index e75c8538ca..8493f9a15e 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservableTest.java @@ -63,7 +63,6 @@ public void cancelOther() { assertFalse(ps.hasObservers()); } - @Test public void errorMain() { CompletableSubject cs = CompletableSubject.create(); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybeTest.java index d080928047..58188a34eb 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybeTest.java @@ -399,7 +399,6 @@ public MaybeSource apply(Integer v) } } - @Test public void innerErrorAfterTermination() { List errors = TestHelper.trackPluginErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingleTest.java index 3c6c832b76..803e9bf013 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingleTest.java @@ -347,7 +347,6 @@ public SingleSource apply(Integer v) } } - @Test public void innerErrorAfterTermination() { List errors = TestHelper.trackPluginErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java index 3faa98caa5..7830b885da 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java @@ -375,7 +375,6 @@ public MaybeSource apply(Integer v) } } - @Test public void innerErrorAfterTermination() { List errors = TestHelper.trackPluginErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java index 03c38e54de..da35b10df1 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java @@ -344,7 +344,6 @@ public SingleSource apply(Integer v) } } - @Test public void innerErrorAfterTermination() { List errors = TestHelper.trackPluginErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java index d37fc5fb74..dc8445068c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java @@ -124,6 +124,7 @@ public boolean test(Integer i) { assertFalse(allOdd.blockingFirst()); } + @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstreamObservable() { Observable source = Observable.just(1) @@ -143,7 +144,6 @@ public Observable apply(Boolean t1) { assertEquals((Object)2, source.blockingFirst()); } - @Test public void testPredicateThrowsExceptionAndValueInCauseMessageObservable() { TestObserver to = new TestObserver(); @@ -166,7 +166,6 @@ public boolean test(String v) { // assertTrue(ex.getCause().getMessage().contains("Boo!")); } - @Test public void testAll() { Observable obs = Observable.just("one", "two", "six"); @@ -256,6 +255,7 @@ public boolean test(Integer i) { assertFalse(allOdd.blockingGet()); } + @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstream() { Observable source = Observable.just(1) @@ -275,7 +275,6 @@ public Observable apply(Boolean t1) { assertEquals((Object)2, source.blockingFirst()); } - @Test public void testPredicateThrowsExceptionAndValueInCauseMessage() { TestObserver to = new TestObserver(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java index 150a13580f..7c66cba3f6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java @@ -231,6 +231,7 @@ public boolean test(Integer i) { assertTrue(anyEven.blockingFirst()); } + @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstreamObservable() { Observable source = Observable.just(1).isEmpty().toObservable() @@ -452,6 +453,7 @@ public boolean test(Integer i) { assertTrue(anyEven.blockingGet()); } + @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstream() { Observable source = Observable.just(1).isEmpty() diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java index 9ce8103e77..961bb7bfed 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java @@ -497,6 +497,7 @@ public void bufferWithBOBoundaryThrows() { verify(o, never()).onComplete(); verify(o, never()).onNext(any()); } + @Test(timeout = 2000) public void bufferWithSizeTake1() { Observable source = Observable.just(1).repeat(); @@ -526,6 +527,7 @@ public void bufferWithSizeSkipTake1() { verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); } + @Test(timeout = 2000) public void bufferWithTimeTake1() { Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); @@ -542,6 +544,7 @@ public void bufferWithTimeTake1() { verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); } + @Test(timeout = 2000) public void bufferWithTimeSkipTake2() { Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); @@ -560,6 +563,7 @@ public void bufferWithTimeSkipTake2() { inOrder.verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); } + @Test(timeout = 2000) public void bufferWithBoundaryTake2() { Observable boundary = Observable.interval(60, 60, TimeUnit.MILLISECONDS, scheduler); @@ -614,6 +618,7 @@ public void accept(List pv) { inOrder.verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); } + @Test public void bufferWithSizeThrows() { PublishSubject source = PublishSubject.create(); @@ -683,6 +688,7 @@ public void bufferWithTimeAndSize() { inOrder.verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); } + @Test public void bufferWithStartEndStartThrows() { PublishSubject start = PublishSubject.create(); @@ -711,6 +717,7 @@ public Observable apply(Integer t1) { verify(o, never()).onComplete(); verify(o).onError(any(TestException.class)); } + @Test public void bufferWithStartEndEndFunctionThrows() { PublishSubject start = PublishSubject.create(); @@ -738,6 +745,7 @@ public Observable apply(Integer t1) { verify(o, never()).onComplete(); verify(o).onError(any(TestException.class)); } + @Test public void bufferWithStartEndEndThrows() { PublishSubject start = PublishSubject.create(); @@ -776,11 +784,13 @@ public void testBufferWithTimeDoesntUnsubscribeDownstream() throws InterruptedEx public void onNext(Object t) { o.onNext(t); } + @Override public void onError(Throwable e) { o.onError(e); cdl.countDown(); } + @Override public void onComplete() { o.onComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java index c664c2591c..614fb29bf5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java @@ -154,6 +154,7 @@ public void testAsync() { assertEquals(10000, to2.values().size()); } } + @Test public void testAsyncComeAndGo() { Observable source = Observable.interval(1, 1, TimeUnit.MILLISECONDS) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapCompletableTest.java index 63789a756d..ab34d4e03e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapCompletableTest.java @@ -155,7 +155,6 @@ public void mapperThrows() { .assertFailure(TestException.class); } - @Test public void fusedPollThrows() { Observable.just(1) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java index 0f6920ecb3..3959fab45e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java @@ -623,7 +623,6 @@ public Observable apply(Integer t) { to.assertValue(null); } - @Test @Ignore("Observable doesn't do backpressure") public void testMaxConcurrent5() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java index a9b6dc6faa..effef90136 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java @@ -623,6 +623,7 @@ public Observable apply(Integer v) { inOrder.verify(o).onSuccess(list); verify(o, never()).onError(any(Throwable.class)); } + @Test public void concatVeryLongObservableOfObservablesTakeHalf() { final int n = 10000; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java index cbbed97785..3d03c3d8a1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java @@ -42,7 +42,6 @@ public void run() throws Exception { to.assertResult(1, 2, 3, 4, 5, 100); } - @Test public void normalNonEmpty() { final TestObserver to = new TestObserver(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java index 9edae7bdc9..0aaacb1432 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java @@ -239,6 +239,7 @@ public Observable apply(Integer t1) { verify(o, never()).onComplete(); verify(o).onError(any(TestException.class)); } + @Test public void debounceTimedLastIsNotLost() { PublishSubject source = PublishSubject.create(); @@ -256,6 +257,7 @@ public void debounceTimedLastIsNotLost() { verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); } + @Test public void debounceSelectorLastIsNotLost() { PublishSubject source = PublishSubject.create(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDelaySubscriptionOtherTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDelaySubscriptionOtherTest.java index 6c416421a7..a37a2b00a7 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDelaySubscriptionOtherTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDelaySubscriptionOtherTest.java @@ -203,7 +203,6 @@ public Object apply(Observable o) throws Exception { }, false, 1, 1, 1); } - @Test public void afterDelayNoInterrupt() { ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java index 8a9c9f6daa..f8d274bc86 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java @@ -85,7 +85,6 @@ public void range() { to.assertComplete(); } - @Test @Ignore("Observable doesn't do backpressure") public void backpressured() throws Exception { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java index 82738bd4de..d6f08fff27 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java @@ -159,7 +159,6 @@ public void asyncFusedBoundary() { assertEquals(1, calls); } - @Test public void normalJustConditional() { Observable.just(1) @@ -445,7 +444,6 @@ public void onComplete() { assertEquals(1, calls); } - @Test public void eventOrdering() { final List list = new ArrayList(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java index 84ff5fa5ec..bd7dc12cf6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java @@ -166,7 +166,6 @@ public CompletableSource apply(Integer v) throws Exception { .assertFailure(TestException.class); } - @Test public void fusedObservable() { TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); @@ -332,7 +331,6 @@ public CompletableSource apply(Integer v) throws Exception { .assertFailure(TestException.class); } - @Test public void fused() { TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index 17382f4dad..4ace4eacb2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -350,6 +350,7 @@ public Observable apply(Integer t1) { Assert.assertEquals(expected.size(), to.valueCount()); Assert.assertTrue(expected.containsAll(to.values())); } + @Test public void testFlatMapSelectorMaxConcurrent() { final int m = 4; @@ -471,6 +472,7 @@ public Observable apply(Integer t) { } } } + @Test(timeout = 30000) public void flatMapRangeMixedAsyncLoop() { for (int i = 0; i < 2000; i++) { @@ -530,6 +532,7 @@ public Observable apply(Integer t) { to.assertValueCount(1000); } } + @Test public void flatMapTwoNestedSync() { for (final int n : new int[] { 1, 1000, 1000000 }) { @@ -895,7 +898,6 @@ public Object apply(Integer v, Object w) throws Exception { .assertFailureAndMessage(NullPointerException.class, "The mapper returned a null ObservableSource"); } - @Test public void failingFusedInnerCancelsSource() { final AtomicInteger counter = new AtomicInteger(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeDelayErrorTest.java index 472a25300b..833f9105c5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeDelayErrorTest.java @@ -429,6 +429,7 @@ public void onNext(String args) { } } + @Test @Ignore("Subscribers should not throw") public void testMergeSourceWhichDoesntPropagateExceptionBack() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeMaxConcurrentTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeMaxConcurrentTest.java index 582421d42b..ef52095f25 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeMaxConcurrentTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeMaxConcurrentTest.java @@ -137,6 +137,7 @@ public void testMergeALotOfSourcesOneByOneSynchronously() { } assertEquals(j, n); } + @Test public void testMergeALotOfSourcesOneByOneSynchronouslyTakeHalf() { int n = 10000; @@ -171,6 +172,7 @@ public void testSimple() { to.assertValueSequence(result); } } + @Test public void testSimpleOneLess() { for (int i = 2; i < 100; i++) { @@ -189,6 +191,7 @@ public void testSimpleOneLess() { to.assertValueSequence(result); } } + @Test//(timeout = 20000) public void testSimpleAsyncLoop() { IoScheduler ios = (IoScheduler)Schedulers.io(); @@ -201,6 +204,7 @@ public void testSimpleAsyncLoop() { } } } + @Test(timeout = 30000) public void testSimpleAsync() { for (int i = 1; i < 50; i++) { @@ -221,12 +225,14 @@ public void testSimpleAsync() { assertEquals(expected, actual); } } + @Test(timeout = 30000) public void testSimpleOneLessAsyncLoop() { for (int i = 0; i < 200; i++) { testSimpleOneLessAsync(); } } + @Test(timeout = 30000) public void testSimpleOneLessAsync() { long t = System.currentTimeMillis(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java index c178b3bddc..fb50ae0f0a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java @@ -1082,10 +1082,12 @@ void runMerge(Function> func, TestObserver public void testFastMergeFullScalar() { runMerge(toScalar, new TestObserver()); } + @Test public void testFastMergeHiddenScalar() { runMerge(toHiddenScalar, new TestObserver()); } + @Test public void testSlowMergeFullScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { @@ -1103,6 +1105,7 @@ public void onNext(Integer t) { runMerge(toScalar, to); } } + @Test public void testSlowMergeHiddenScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java index 173f506bce..181564df1c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java @@ -183,7 +183,6 @@ public String apply(String s) { verify(observer, times(1)).onComplete(); } - @Test public void testBackpressure() { TestObserver to = new TestObserver(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java index 18251f8f78..2f2a0e677e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java @@ -372,6 +372,7 @@ public void subscribe(Observer t) { assertEquals(2, calls.get()); } + @Test public void testObserveOn() { ConnectableObservable co = Observable.range(0, 1000).publish(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java index 5dce27dcaa..cb6e61e8f6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java @@ -145,7 +145,6 @@ public void testBackpressureWithInitialValueObservable() throws InterruptedExcep assertEquals(21, r.intValue()); } - @Test public void testAggregateAsIntSum() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java index 0c62893a77..b79e8c6c20 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java @@ -986,6 +986,7 @@ public void testAsync() { assertEquals(10000, to2.values().size()); } } + @Test public void testAsyncComeAndGo() { Observable source = Observable.interval(1, 1, TimeUnit.MILLISECONDS) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java index 9ebb3fd450..010b618c34 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java @@ -779,6 +779,7 @@ static StringBuilder sequenceFrequency(Iterable it) { return sb; } + @Test//(timeout = 3000) public void testIssue1900() throws InterruptedException { Observer observer = TestHelper.mockObserver(); @@ -819,6 +820,7 @@ public Observable apply(GroupedObservable t1) { inOrder.verify(observer, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); } + @Test//(timeout = 3000) public void testIssue1900SourceNotSupportingBackpressure() { Observer observer = TestHelper.mockObserver(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java index 79ca287629..bd03c8874b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java @@ -69,6 +69,7 @@ public void testWithNothingToRetry() { inOrder.verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); } + @Test public void testRetryTwice() { Observable source = Observable.unsafeCreate(new ObservableSource() { @@ -104,6 +105,7 @@ public void subscribe(Observer t1) { verify(o, never()).onError(any(Throwable.class)); } + @Test public void testRetryTwiceAndGiveUp() { Observable source = Observable.unsafeCreate(new ObservableSource() { @@ -131,6 +133,7 @@ public void subscribe(Observer t1) { verify(o, never()).onComplete(); } + @Test public void testRetryOnSpecificException() { Observable source = Observable.unsafeCreate(new ObservableSource() { @@ -165,6 +168,7 @@ public void subscribe(Observer t1) { inOrder.verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); } + @Test public void testRetryOnSpecificExceptionAndNotOther() { final IOException ioe = new IOException(); @@ -288,6 +292,7 @@ public Integer apply(Integer t1) { assertEquals(6, c.get()); assertEquals(Collections.singletonList(e), to.errors()); } + @Test public void testJustAndRetry() throws Exception { final AtomicBoolean throwException = new AtomicBoolean(true); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java index ab68bd6790..610f49eac4 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java @@ -484,7 +484,6 @@ public void onNext(String t) { Assert.assertEquals(250, to.valueCount()); } - @Test public void delayErrors() { PublishSubject> source = PublishSubject.create(); @@ -608,7 +607,6 @@ public ObservableSource apply(Object v) throws Exception { } - @Test public void switchMapInnerCancelled() { PublishSubject ps = PublishSubject.create(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java index 722da7890a..0e6f040972 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java @@ -46,6 +46,7 @@ public boolean test(Object v) { verify(o, never()).onError(any(Throwable.class)); verify(o).onComplete(); } + @Test public void takeAll() { Observer o = TestHelper.mockObserver(); @@ -62,6 +63,7 @@ public boolean test(Integer v) { verify(o, never()).onError(any(Throwable.class)); verify(o).onComplete(); } + @Test public void takeFirst() { Observer o = TestHelper.mockObserver(); @@ -78,6 +80,7 @@ public boolean test(Integer v) { verify(o, never()).onError(any(Throwable.class)); verify(o).onComplete(); } + @Test public void takeSome() { Observer o = TestHelper.mockObserver(); @@ -96,6 +99,7 @@ public boolean test(Integer t1) { verify(o, never()).onError(any(Throwable.class)); verify(o).onComplete(); } + @Test public void functionThrows() { Observer o = TestHelper.mockObserver(); @@ -114,6 +118,7 @@ public boolean test(Integer t1) { verify(o).onError(any(TestException.class)); verify(o, never()).onComplete(); } + @Test public void sourceThrows() { Observer o = TestHelper.mockObserver(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java index d78129e2ea..7ea5698be3 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java @@ -210,6 +210,7 @@ public void testUntilFires() { // 2.0.2 - not anymore // assertTrue("Not cancelled!", ts.isCancelled()); } + @Test public void testMainCompletes() { PublishSubject source = PublishSubject.create(); @@ -234,6 +235,7 @@ public void testMainCompletes() { // 2.0.2 - not anymore // assertTrue("Not cancelled!", ts.isCancelled()); } + @Test public void testDownstreamUnsubscribes() { PublishSubject source = PublishSubject.create(); @@ -273,7 +275,6 @@ public Observable apply(Observable o) throws Exception { }); } - @Test public void untilPublisherMainSuccess() { PublishSubject main = PublishSubject.create(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleLatestTest.java index 9d60e5d232..059d516da1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleLatestTest.java @@ -129,7 +129,6 @@ public void normal() { to.assertResult(1, 3, 5, 6); } - @Test public void normalEmitLast() { TestScheduler sch = new TestScheduler(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java index 416a5e10e0..c8af9d88b8 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java @@ -87,6 +87,7 @@ public void testTimerPeriodically() { to.assertNotComplete(); to.assertNoErrors(); } + @Test public void testInterval() { Observable w = Observable.interval(1, TimeUnit.SECONDS, scheduler); @@ -227,6 +228,7 @@ public void testWithMultipleStaggeredSubscribersAndPublish() { to2.assertNoErrors(); to2.assertNotComplete(); } + @Test public void testOnceObserverThrows() { Observable source = Observable.timer(100, TimeUnit.MILLISECONDS, scheduler); @@ -255,6 +257,7 @@ public void onComplete() { verify(observer, never()).onNext(anyLong()); verify(observer, never()).onComplete(); } + @Test public void testPeriodicObserverThrows() { Observable source = Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToMapTest.java index 1f477a0a38..f9eb6e1634 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToMapTest.java @@ -225,7 +225,6 @@ public String apply(String v) { verify(objectObserver, times(1)).onError(any(Throwable.class)); } - @Test public void testToMap() { Observable source = Observable.just("a", "bb", "ccc", "dddd"); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToMultimapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToMultimapTest.java index 9a1ebc44d8..f762930fc1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToMultimapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToMultimapTest.java @@ -296,8 +296,6 @@ public Map> call() { verify(objectObserver, never()).onComplete(); } - - @Test public void testToMultimap() { Observable source = Observable.just("a", "b", "cc", "dd"); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java index f715b6b08c..20ffdd236a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java @@ -115,7 +115,6 @@ public int compare(Integer a, Integer b) { .assertResult(Arrays.asList(5, 4, 3, 2, 1)); } - @Test public void testSortedList() { Observable w = Observable.just(1, 3, 2, 5, 4); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java index 286bb7d4a9..02fd41ef54 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java @@ -330,8 +330,6 @@ public Observable apply(Resource resource) { } - - @Test public void testUsingDisposesEagerlyBeforeError() { final List events = new ArrayList(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java index 000b116615..b015bfb737 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java @@ -329,6 +329,7 @@ public Observable call() { to.assertNoErrors(); to.assertValueCount(1); } + @Test public void testMainUnsubscribedOnBoundaryCompletion() { PublishSubject source = PublishSubject.create(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java index bfccb343da..8c81f6a70a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java @@ -158,6 +158,7 @@ public void onNext(T args) { } }; } + @Test public void testExactWindowSize() { Observable> source = Observable.range(1, 10) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java index 9b1ea3e54e..4f3c62b992 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java @@ -134,7 +134,6 @@ public void testEmptyOther() { assertFalse(other.hasObservers()); } - @Test public void testUnsubscription() { PublishSubject source = PublishSubject.create(); @@ -189,6 +188,7 @@ public void testSourceThrows() { assertFalse(source.hasObservers()); assertFalse(other.hasObservers()); } + @Test public void testOtherThrows() { PublishSubject source = PublishSubject.create(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java index ac68979af9..2fc7d7cb52 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java @@ -1261,6 +1261,7 @@ public Object apply(Integer a, Integer b, Integer c, Integer d, Integer e, Integ .test() .assertResult("12345678"); } + @Test public void zip9() { Observable.zip(Observable.just(1), diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleConcatTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleConcatTest.java index 52d67e742a..09a29e55ff 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleConcatTest.java @@ -163,7 +163,6 @@ public void subscribe(SingleEmitter s) throws Exception { assertEquals(1, calls[0]); } - @SuppressWarnings("unchecked") @Test public void noSubsequentSubscriptionIterable() { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapTest.java index ee1de82fb7..ca586a0907 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapTest.java @@ -105,7 +105,6 @@ public Completable apply(Integer t) throws Exception { assertFalse(b[0]); } - @Test public void flatMapObservable() { Single.just(1).flatMapObservable(new Function>() { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java index ebd0445358..2c4ebcc321 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java @@ -111,7 +111,6 @@ public void shouldNotInvokeFuncUntilSubscription() throws Exception { verify(func).call(); } - @Test public void noErrorLoss() throws Exception { List errors = TestHelper.trackPluginErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleMergeTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleMergeTest.java index bf1a100ac9..ef5f6de826 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleMergeTest.java @@ -125,7 +125,6 @@ public void mergeDelayError3() { .assertFailure(TestException.class, 1, 2); } - @Test public void mergeDelayError4() { Single.mergeDelayError( diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleTakeUntilTest.java index d646542a93..c7a1180a30 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleTakeUntilTest.java @@ -59,7 +59,6 @@ public void mainSuccessSingle() { to.assertResult(1); } - @Test public void mainSuccessCompletable() { PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java index 2f7e398c03..f188547bc9 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java @@ -150,6 +150,7 @@ public void run() { } } } + @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipArrayOneIsNull() { diff --git a/src/test/java/io/reactivex/internal/schedulers/AbstractDirectTaskTest.java b/src/test/java/io/reactivex/internal/schedulers/AbstractDirectTaskTest.java index 1357f27b5c..17a69ab93d 100644 --- a/src/test/java/io/reactivex/internal/schedulers/AbstractDirectTaskTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/AbstractDirectTaskTest.java @@ -115,6 +115,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { assertTrue(interrupted[0]); } + @Test public void setFutureCancelSameThread() { AbstractDirectTask task = new AbstractDirectTask(Functions.EMPTY_RUNNABLE) { diff --git a/src/test/java/io/reactivex/internal/schedulers/ImmediateThinSchedulerTest.java b/src/test/java/io/reactivex/internal/schedulers/ImmediateThinSchedulerTest.java index 747aa49bfe..507ebd32d0 100644 --- a/src/test/java/io/reactivex/internal/schedulers/ImmediateThinSchedulerTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/ImmediateThinSchedulerTest.java @@ -47,6 +47,7 @@ public void scheduleDirectTimed() { public void scheduleDirectPeriodic() { ImmediateThinScheduler.INSTANCE.schedulePeriodicallyDirect(Functions.EMPTY_RUNNABLE, 1, 1, TimeUnit.SECONDS); } + @Test public void schedule() { final int[] count = { 0 }; diff --git a/src/test/java/io/reactivex/internal/schedulers/ScheduledRunnableTest.java b/src/test/java/io/reactivex/internal/schedulers/ScheduledRunnableTest.java index add5de3ed0..9d1718f7d0 100644 --- a/src/test/java/io/reactivex/internal/schedulers/ScheduledRunnableTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/ScheduledRunnableTest.java @@ -372,7 +372,6 @@ public void asyncDisposeIdempotent() { assertEquals(ScheduledRunnable.ASYNC_DISPOSED, run.get(ScheduledRunnable.FUTURE_INDEX)); } - @Test public void noParentIsDisposed() { ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, null); diff --git a/src/test/java/io/reactivex/internal/subscribers/BlockingSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/BlockingSubscriberTest.java index 3c35e2315d..3d6017bad4 100644 --- a/src/test/java/io/reactivex/internal/subscribers/BlockingSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/BlockingSubscriberTest.java @@ -93,6 +93,7 @@ public void cancelOnRequest() { public void request(long n) { bf.cancelled = true; } + @Override public void cancel() { b.set(true); @@ -118,6 +119,7 @@ public void cancelUpfront() { public void request(long n) { b.set(true); } + @Override public void cancel() { } diff --git a/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java index 8643924bad..7b47129559 100644 --- a/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java @@ -303,6 +303,7 @@ public void callsAfterUnsubscribe() { ts.assertNoErrors(); ts.assertNotComplete(); } + @Test public void emissionRequestRace() { Worker w = Schedulers.computation().createWorker(); diff --git a/src/test/java/io/reactivex/internal/subscribers/InnerQueuedSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/InnerQueuedSubscriberTest.java index 28058606c4..f71ad289d0 100644 --- a/src/test/java/io/reactivex/internal/subscribers/InnerQueuedSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/InnerQueuedSubscriberTest.java @@ -27,12 +27,15 @@ public void requestInBatches() { @Override public void innerNext(InnerQueuedSubscriber inner, Integer value) { } + @Override public void innerError(InnerQueuedSubscriber inner, Throwable e) { } + @Override public void innerComplete(InnerQueuedSubscriber inner) { } + @Override public void drain() { } @@ -47,6 +50,7 @@ public void drain() { public void request(long n) { requests.add(n); } + @Override public void cancel() { // ignore diff --git a/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java index 7f16d6e0ee..d61d1a4dfe 100644 --- a/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java @@ -242,6 +242,7 @@ public void accept(Subscription s) throws Exception { assertEquals(Arrays.asList(1, 100), received); } + @Test public void badSourceEmitAfterDone() { Flowable source = Flowable.fromPublisher(new Publisher() { diff --git a/src/test/java/io/reactivex/internal/subscriptions/SubscriptionHelperTest.java b/src/test/java/io/reactivex/internal/subscriptions/SubscriptionHelperTest.java index f7314b1d68..dd010ca100 100644 --- a/src/test/java/io/reactivex/internal/subscriptions/SubscriptionHelperTest.java +++ b/src/test/java/io/reactivex/internal/subscriptions/SubscriptionHelperTest.java @@ -51,15 +51,15 @@ public void cancelNoOp() { @Test public void set() { - AtomicReference s = new AtomicReference(); + AtomicReference atomicSubscription = new AtomicReference(); BooleanSubscription bs1 = new BooleanSubscription(); - assertTrue(SubscriptionHelper.set(s, bs1)); + assertTrue(SubscriptionHelper.set(atomicSubscription, bs1)); BooleanSubscription bs2 = new BooleanSubscription(); - assertTrue(SubscriptionHelper.set(s, bs2)); + assertTrue(SubscriptionHelper.set(atomicSubscription, bs2)); assertTrue(bs1.isCancelled()); @@ -68,15 +68,15 @@ public void set() { @Test public void replace() { - AtomicReference s = new AtomicReference(); + AtomicReference atomicSubscription = new AtomicReference(); BooleanSubscription bs1 = new BooleanSubscription(); - assertTrue(SubscriptionHelper.replace(s, bs1)); + assertTrue(SubscriptionHelper.replace(atomicSubscription, bs1)); BooleanSubscription bs2 = new BooleanSubscription(); - assertTrue(SubscriptionHelper.replace(s, bs2)); + assertTrue(SubscriptionHelper.replace(atomicSubscription, bs2)); assertFalse(bs1.isCancelled()); @@ -86,12 +86,12 @@ public void replace() { @Test public void cancelRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final AtomicReference s = new AtomicReference(); + final AtomicReference atomicSubscription = new AtomicReference(); Runnable r = new Runnable() { @Override public void run() { - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(atomicSubscription); } }; @@ -102,7 +102,7 @@ public void run() { @Test public void setRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final AtomicReference s = new AtomicReference(); + final AtomicReference atomicSubscription = new AtomicReference(); final BooleanSubscription bs1 = new BooleanSubscription(); final BooleanSubscription bs2 = new BooleanSubscription(); @@ -110,14 +110,14 @@ public void setRace() { Runnable r1 = new Runnable() { @Override public void run() { - SubscriptionHelper.set(s, bs1); + SubscriptionHelper.set(atomicSubscription, bs1); } }; Runnable r2 = new Runnable() { @Override public void run() { - SubscriptionHelper.set(s, bs2); + SubscriptionHelper.set(atomicSubscription, bs2); } }; @@ -130,7 +130,7 @@ public void run() { @Test public void replaceRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final AtomicReference s = new AtomicReference(); + final AtomicReference atomicSubscription = new AtomicReference(); final BooleanSubscription bs1 = new BooleanSubscription(); final BooleanSubscription bs2 = new BooleanSubscription(); @@ -138,14 +138,14 @@ public void replaceRace() { Runnable r1 = new Runnable() { @Override public void run() { - SubscriptionHelper.replace(s, bs1); + SubscriptionHelper.replace(atomicSubscription, bs1); } }; Runnable r2 = new Runnable() { @Override public void run() { - SubscriptionHelper.replace(s, bs2); + SubscriptionHelper.replace(atomicSubscription, bs2); } }; @@ -158,31 +158,31 @@ public void run() { @Test public void cancelAndChange() { - AtomicReference s = new AtomicReference(); + AtomicReference atomicSubscription = new AtomicReference(); - SubscriptionHelper.cancel(s); + SubscriptionHelper.cancel(atomicSubscription); BooleanSubscription bs1 = new BooleanSubscription(); - assertFalse(SubscriptionHelper.set(s, bs1)); + assertFalse(SubscriptionHelper.set(atomicSubscription, bs1)); assertTrue(bs1.isCancelled()); - assertFalse(SubscriptionHelper.set(s, null)); + assertFalse(SubscriptionHelper.set(atomicSubscription, null)); BooleanSubscription bs2 = new BooleanSubscription(); - assertFalse(SubscriptionHelper.replace(s, bs2)); + assertFalse(SubscriptionHelper.replace(atomicSubscription, bs2)); assertTrue(bs2.isCancelled()); - assertFalse(SubscriptionHelper.replace(s, null)); + assertFalse(SubscriptionHelper.replace(atomicSubscription, null)); } @Test public void invalidDeferredRequest() { - AtomicReference s = new AtomicReference(); + AtomicReference atomicSubscription = new AtomicReference(); AtomicLong r = new AtomicLong(); List errors = TestHelper.trackPluginErrors(); try { - SubscriptionHelper.deferredRequest(s, r, -99); + SubscriptionHelper.deferredRequest(atomicSubscription, r, -99); TestHelper.assertError(errors, 0, IllegalArgumentException.class, "n > 0 required but it was -99"); } finally { @@ -193,7 +193,7 @@ public void invalidDeferredRequest() { @Test public void deferredRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final AtomicReference s = new AtomicReference(); + final AtomicReference atomicSubscription = new AtomicReference(); final AtomicLong r = new AtomicLong(); final AtomicLong q = new AtomicLong(); @@ -213,20 +213,20 @@ public void cancel() { Runnable r1 = new Runnable() { @Override public void run() { - SubscriptionHelper.deferredSetOnce(s, r, a); + SubscriptionHelper.deferredSetOnce(atomicSubscription, r, a); } }; Runnable r2 = new Runnable() { @Override public void run() { - SubscriptionHelper.deferredRequest(s, r, 1); + SubscriptionHelper.deferredRequest(atomicSubscription, r, 1); } }; TestHelper.race(r1, r2); - assertSame(a, s.get()); + assertSame(a, atomicSubscription.get()); assertEquals(1, q.get()); assertEquals(0, r.get()); } diff --git a/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java b/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java index 9fbddd4279..13a672f566 100644 --- a/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java +++ b/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java @@ -54,9 +54,11 @@ public void checkDoubleDefaultSubscriber() { @Override public void onNext(Integer t) { } + @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -85,9 +87,11 @@ static final class EndDefaultSubscriber extends DefaultSubscriber { @Override public void onNext(Integer t) { } + @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -124,9 +128,11 @@ public void checkDoubleDisposableSubscriber() { @Override public void onNext(Integer t) { } + @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -157,9 +163,11 @@ public void checkDoubleResourceSubscriber() { @Override public void onNext(Integer t) { } + @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -190,9 +198,11 @@ public void checkDoubleDefaultObserver() { @Override public void onNext(Integer t) { } + @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -223,9 +233,11 @@ public void checkDoubleDisposableObserver() { @Override public void onNext(Integer t) { } + @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -256,9 +268,11 @@ public void checkDoubleResourceObserver() { @Override public void onNext(Integer t) { } + @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -289,6 +303,7 @@ public void checkDoubleDisposableSingleObserver() { @Override public void onSuccess(Integer t) { } + @Override public void onError(Throwable t) { } @@ -319,6 +334,7 @@ public void checkDoubleResourceSingleObserver() { @Override public void onSuccess(Integer t) { } + @Override public void onError(Throwable t) { } @@ -349,9 +365,11 @@ public void checkDoubleDisposableMaybeObserver() { @Override public void onSuccess(Integer t) { } + @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -382,9 +400,11 @@ public void checkDoubleResourceMaybeObserver() { @Override public void onSuccess(Integer t) { } + @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -415,6 +435,7 @@ public void checkDoubleDisposableCompletableObserver() { @Override public void onError(Throwable t) { } + @Override public void onComplete() { } @@ -445,6 +466,7 @@ public void checkDoubleResourceCompletableObserver() { @Override public void onError(Throwable t) { } + @Override public void onComplete() { } diff --git a/src/test/java/io/reactivex/internal/util/QueueDrainHelperTest.java b/src/test/java/io/reactivex/internal/util/QueueDrainHelperTest.java index 14375b506a..6be3075191 100644 --- a/src/test/java/io/reactivex/internal/util/QueueDrainHelperTest.java +++ b/src/test/java/io/reactivex/internal/util/QueueDrainHelperTest.java @@ -814,6 +814,7 @@ public void accept(Observer a, Integer v) { to.assertFailure(TestException.class); } + @Test public void observerCheckTerminatedNonDelayErrorErrorResource() { TestObserver to = new TestObserver(); diff --git a/src/test/java/io/reactivex/maybe/MaybeCreateTest.java b/src/test/java/io/reactivex/maybe/MaybeCreateTest.java index e13b5f09cb..f6d24bd980 100644 --- a/src/test/java/io/reactivex/maybe/MaybeCreateTest.java +++ b/src/test/java/io/reactivex/maybe/MaybeCreateTest.java @@ -92,7 +92,6 @@ public void subscribe(MaybeEmitter e) throws Exception { assertTrue(d.isDisposed()); } - @Test public void basicWithCompletion() { final Disposable d = Disposables.empty(); diff --git a/src/test/java/io/reactivex/maybe/MaybeTest.java b/src/test/java/io/reactivex/maybe/MaybeTest.java index 94c7c9eb8a..b726b77611 100644 --- a/src/test/java/io/reactivex/maybe/MaybeTest.java +++ b/src/test/java/io/reactivex/maybe/MaybeTest.java @@ -350,7 +350,6 @@ public void completableMaybeCompletable() { Completable.complete().toMaybe().ignoreElement().test().assertResult(); } - @Test public void unsafeCreate() { Maybe.unsafeCreate(new MaybeSource() { @@ -646,7 +645,6 @@ public void accept(Throwable e) throws Exception { assertNotEquals(main, name[0]); } - @Test public void observeOnCompleteThread() { String main = Thread.currentThread().getName(); @@ -688,7 +686,6 @@ public void subscribeOnComplete() { ; } - @Test public void fromAction() { final int[] call = { 0 }; @@ -801,7 +798,6 @@ public void accept(Integer v) throws Exception { .assertFailure(TestException.class); } - @Test public void doOnSubscribe() { final Disposable[] value = { null }; @@ -830,7 +826,6 @@ public void accept(Disposable v) throws Exception { .assertFailure(TestException.class); } - @Test public void doOnCompleteThrows() { Maybe.empty().doOnComplete(new Action() { @@ -862,7 +857,6 @@ public void run() throws Exception { assertEquals(1, call[0]); } - @Test public void doOnDisposeThrows() { List list = TestHelper.trackPluginErrors(); @@ -971,7 +965,6 @@ public void run() throws Exception { assertEquals(-1, call[0]); } - @Test public void doAfterTerminateComplete() { final int[] call = { 0 }; @@ -1013,7 +1006,6 @@ public void subscribe(MaybeObserver observer) { } } - @Test public void sourceThrowsIAE() { try { @@ -1180,6 +1172,7 @@ public void ignoreElementComplete() { .test() .assertResult(); } + @Test public void ignoreElementSuccessMaybe() { Maybe.just(1) @@ -2436,7 +2429,6 @@ public void accept(Integer v, Throwable e) throws Exception { assertEquals(2, list.size()); } - @Test public void doOnEventCompleteThrows() { Maybe.empty() @@ -2880,7 +2872,6 @@ public void zipArray() { .assertResult("[1]"); } - @SuppressWarnings("unchecked") @Test public void zipIterable() { @@ -2983,7 +2974,6 @@ public void zip9() { .assertResult("123456789"); } - @Test public void ambWith1SignalsSuccess() { PublishProcessor pp1 = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/observable/ObservableNullTests.java b/src/test/java/io/reactivex/observable/ObservableNullTests.java index 7a429c4555..847b7c0422 100644 --- a/src/test/java/io/reactivex/observable/ObservableNullTests.java +++ b/src/test/java/io/reactivex/observable/ObservableNullTests.java @@ -2768,7 +2768,6 @@ public Object apply(Integer a, Integer b) { }); } - @Test(expected = NullPointerException.class) public void zipWithCombinerNull() { just1.zipWith(just1, null); diff --git a/src/test/java/io/reactivex/observable/ObservableReduceTests.java b/src/test/java/io/reactivex/observable/ObservableReduceTests.java index 5a08fd2d65..a5bdacf48b 100644 --- a/src/test/java/io/reactivex/observable/ObservableReduceTests.java +++ b/src/test/java/io/reactivex/observable/ObservableReduceTests.java @@ -77,7 +77,6 @@ public Movie apply(Movie t1, Movie t2) { assertNotNull(reduceResult2); } - @Test public void reduceInts() { Observable o = Observable.just(1, 2, 3); diff --git a/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java b/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java index 14af3cf2d0..9544bb5030 100644 --- a/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java +++ b/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java @@ -180,7 +180,6 @@ public void safeSubscriberAlreadySafe() { to.assertResult(1); } - @Test public void methodTestNoCancel() { PublishSubject ps = PublishSubject.create(); diff --git a/src/test/java/io/reactivex/observable/ObservableTest.java b/src/test/java/io/reactivex/observable/ObservableTest.java index fbe071714b..1d754c5e68 100644 --- a/src/test/java/io/reactivex/observable/ObservableTest.java +++ b/src/test/java/io/reactivex/observable/ObservableTest.java @@ -145,7 +145,6 @@ public Throwable call() { verify(w, times(1)).onError(any(RuntimeException.class)); } - @Test public void testCountAFewItems() { Observable o = Observable.just("a", "b", "c", "d"); diff --git a/src/test/java/io/reactivex/observers/SafeObserverTest.java b/src/test/java/io/reactivex/observers/SafeObserverTest.java index 12c355905f..edd725b7ed 100644 --- a/src/test/java/io/reactivex/observers/SafeObserverTest.java +++ b/src/test/java/io/reactivex/observers/SafeObserverTest.java @@ -452,10 +452,12 @@ public void testOnCompletedThrows() { public void onNext(Integer t) { } + @Override public void onError(Throwable e) { error.set(e); } + @Override public void onComplete() { throw new TestException(); @@ -476,9 +478,11 @@ public void testActual() { @Override public void onNext(Integer t) { } + @Override public void onError(Throwable e) { } + @Override public void onComplete() { } diff --git a/src/test/java/io/reactivex/observers/SerializedObserverTest.java b/src/test/java/io/reactivex/observers/SerializedObserverTest.java index 726ca7aee4..a2f0e63ece 100644 --- a/src/test/java/io/reactivex/observers/SerializedObserverTest.java +++ b/src/test/java/io/reactivex/observers/SerializedObserverTest.java @@ -974,6 +974,7 @@ public void onNext(Integer v) { to.assertValue(1); to.assertError(TestException.class); } + @Test public void testCompleteReentry() { final AtomicReference> serial = new AtomicReference>(); diff --git a/src/test/java/io/reactivex/observers/TestObserverTest.java b/src/test/java/io/reactivex/observers/TestObserverTest.java index 1b638ace38..efe9798bae 100644 --- a/src/test/java/io/reactivex/observers/TestObserverTest.java +++ b/src/test/java/io/reactivex/observers/TestObserverTest.java @@ -272,6 +272,7 @@ public void testTerminalErrorOnce() { } fail("Failed to report multiple onError terminal events!"); } + @Test public void testTerminalCompletedOnce() { TestSubscriber ts = new TestSubscriber(); diff --git a/src/test/java/io/reactivex/parallel/ParallelDoOnNextTryTest.java b/src/test/java/io/reactivex/parallel/ParallelDoOnNextTryTest.java index 3a40edc229..41f82363d6 100644 --- a/src/test/java/io/reactivex/parallel/ParallelDoOnNextTryTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelDoOnNextTryTest.java @@ -49,6 +49,7 @@ public void doOnNextNoError() { calls = 0; } } + @Test public void doOnNextErrorNoError() { for (ParallelFailureHandling e : ParallelFailureHandling.values()) { diff --git a/src/test/java/io/reactivex/parallel/ParallelFilterTryTest.java b/src/test/java/io/reactivex/parallel/ParallelFilterTryTest.java index bb7d919ce0..e49090acf8 100644 --- a/src/test/java/io/reactivex/parallel/ParallelFilterTryTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelFilterTryTest.java @@ -94,6 +94,7 @@ public void filterConditionalNoError() { .assertResult(1); } } + @Test public void filterErrorConditionalNoError() { for (ParallelFailureHandling e : ParallelFailureHandling.values()) { diff --git a/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java b/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java index 577d4be1cd..ab98b5a9f4 100644 --- a/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java @@ -454,7 +454,6 @@ public void accept(List v) throws Exception { } } - @Test public void collectAsync2() { ExecutorService exec = Executors.newFixedThreadPool(3); @@ -551,7 +550,6 @@ public void accept(List v) throws Exception { } } - @Test public void collectAsync3Fused() { ExecutorService exec = Executors.newFixedThreadPool(3); diff --git a/src/test/java/io/reactivex/parallel/ParallelMapTryTest.java b/src/test/java/io/reactivex/parallel/ParallelMapTryTest.java index bed3f5eae8..09b3dbcf6d 100644 --- a/src/test/java/io/reactivex/parallel/ParallelMapTryTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelMapTryTest.java @@ -44,6 +44,7 @@ public void mapNoError() { .assertResult(1); } } + @Test public void mapErrorNoError() { for (ParallelFailureHandling e : ParallelFailureHandling.values()) { @@ -68,6 +69,7 @@ public void mapConditionalNoError() { .assertResult(1); } } + @Test public void mapErrorConditionalNoError() { for (ParallelFailureHandling e : ParallelFailureHandling.values()) { diff --git a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java index a8c9668731..f522b84fd3 100644 --- a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java +++ b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java @@ -1954,7 +1954,6 @@ public Subscriber apply(Flowable f, Subscriber s) throws Exception { } } - @SuppressWarnings("rawtypes") @Test public void maybeCreate() { diff --git a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java index c97f3398e1..d90fe6705f 100644 --- a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java +++ b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java @@ -368,6 +368,7 @@ public void testCurrentStateMethodsEmpty() { assertNull(as.getValue()); assertNull(as.getThrowable()); } + @Test public void testCurrentStateMethodsError() { AsyncProcessor as = AsyncProcessor.create(); diff --git a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java index 59d8cbff02..d7f3dca92b 100644 --- a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java +++ b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java @@ -282,6 +282,7 @@ public void onComplete() { verify(subscriber, never()).onError(any(Throwable.class)); } } + @Test public void testStartEmpty() { BehaviorProcessor source = BehaviorProcessor.create(); @@ -307,6 +308,7 @@ public void testStartEmpty() { } + @Test public void testStartEmptyThenAddOne() { BehaviorProcessor source = BehaviorProcessor.create(); @@ -329,6 +331,7 @@ public void testStartEmptyThenAddOne() { verify(subscriber, never()).onError(any(Throwable.class)); } + @Test public void testStartEmptyCompleteWithOne() { BehaviorProcessor source = BehaviorProcessor.create(); @@ -406,6 +409,7 @@ public void testTakeOneSubscriber() { // // even though the onError above throws we should still receive it on the other subscriber // assertEquals(1, ts.getOnErrorEvents().size()); // } + @Test public void testEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); @@ -550,6 +554,7 @@ public void testCurrentStateMethodsEmpty() { assertNull(as.getValue()); assertNull(as.getThrowable()); } + @Test public void testCurrentStateMethodsError() { BehaviorProcessor as = BehaviorProcessor.create(); diff --git a/src/test/java/io/reactivex/processors/MulticastProcessorTest.java b/src/test/java/io/reactivex/processors/MulticastProcessorTest.java index c85665eacd..63a7b1a60b 100644 --- a/src/test/java/io/reactivex/processors/MulticastProcessorTest.java +++ b/src/test/java/io/reactivex/processors/MulticastProcessorTest.java @@ -185,7 +185,6 @@ public void longRunning() { mp.test().assertValueCount(1000).assertNoErrors().assertComplete(); } - @Test public void oneByOne() { MulticastProcessor mp = MulticastProcessor.create(16); @@ -419,7 +418,6 @@ public void onNextNull() { mp.onNext(null); } - @Test(expected = NullPointerException.class) public void onOfferNull() { MulticastProcessor mp = MulticastProcessor.create(4, false); @@ -623,7 +621,6 @@ public void cancelUpfront() { assertFalse(mp.hasSubscribers()); } - @Test public void cancelUpfrontOtherConsumersPresent() { MulticastProcessor mp = MulticastProcessor.create(); diff --git a/src/test/java/io/reactivex/processors/PublishProcessorTest.java b/src/test/java/io/reactivex/processors/PublishProcessorTest.java index 8d9d4b7a88..4160ed27ea 100644 --- a/src/test/java/io/reactivex/processors/PublishProcessorTest.java +++ b/src/test/java/io/reactivex/processors/PublishProcessorTest.java @@ -384,6 +384,7 @@ public void onComplete() { // // even though the onError above throws we should still receive it on the other subscriber // assertEquals(1, ts.getOnErrorEvents().size()); // } + @Test public void testCurrentStateMethodsNormal() { PublishProcessor as = PublishProcessor.create(); @@ -419,6 +420,7 @@ public void testCurrentStateMethodsEmpty() { assertTrue(as.hasComplete()); assertNull(as.getThrowable()); } + @Test public void testCurrentStateMethodsError() { PublishProcessor as = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java index dd0f32821f..8a26d4d80d 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java @@ -318,6 +318,7 @@ public void run() { } } } + @Test public void testReplaySubjectEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); @@ -403,6 +404,7 @@ public void run() { worker.dispose(); } } + @Test(timeout = 5000) public void testConcurrentSizeAndHasAnyValue() throws InterruptedException { final ReplayProcessor rs = ReplayProcessor.createUnbounded(); @@ -457,6 +459,7 @@ public void run() { t.join(); } + @Test(timeout = 5000) public void testConcurrentSizeAndHasAnyValueBounded() throws InterruptedException { final ReplayProcessor rs = ReplayProcessor.createWithSize(3); @@ -500,6 +503,7 @@ public void run() { t.join(); } + @Test(timeout = 10000) public void testConcurrentSizeAndHasAnyValueTimeBounded() throws InterruptedException { final ReplayProcessor rs = ReplayProcessor.createWithTime(1, TimeUnit.MILLISECONDS, Schedulers.computation()); diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java index e63f8f361f..6161c484fa 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java @@ -318,6 +318,7 @@ public void run() { } } } + @Test public void testReplaySubjectEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); @@ -391,6 +392,7 @@ public void run() { worker.dispose(); } } + @Test(timeout = 10000) public void testConcurrentSizeAndHasAnyValue() throws InterruptedException { final ReplayProcessor rs = ReplayProcessor.create(); diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java index fc5635d975..3038840266 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java @@ -350,6 +350,7 @@ public void onNext(String v) { assertEquals("three", lastValueForSubscriber2.get()); } + @Test public void testSubscriptionLeak() { ReplayProcessor replaySubject = ReplayProcessor.create(); @@ -403,6 +404,7 @@ public void onComplete() { verify(subscriber, never()).onError(any(Throwable.class)); } } + @Test public void testTerminateOnce() { ReplayProcessor source = ReplayProcessor.create(); @@ -455,6 +457,7 @@ public void testReplay1AfterTermination() { verify(subscriber, never()).onError(any(Throwable.class)); } } + @Test public void testReplay1Directly() { ReplayProcessor source = ReplayProcessor.createWithSize(1); @@ -618,6 +621,7 @@ public void testCurrentStateMethodsEmpty() { assertTrue(as.hasComplete()); assertNull(as.getThrowable()); } + @Test public void testCurrentStateMethodsError() { ReplayProcessor as = ReplayProcessor.create(); @@ -632,6 +636,7 @@ public void testCurrentStateMethodsError() { assertFalse(as.hasComplete()); assertTrue(as.getThrowable() instanceof TestException); } + @Test public void testSizeAndHasAnyValueUnbounded() { ReplayProcessor rs = ReplayProcessor.create(); @@ -654,6 +659,7 @@ public void testSizeAndHasAnyValueUnbounded() { assertEquals(2, rs.size()); assertTrue(rs.hasValue()); } + @Test public void testSizeAndHasAnyValueEffectivelyUnbounded() { ReplayProcessor rs = ReplayProcessor.createUnbounded(); @@ -699,6 +705,7 @@ public void testSizeAndHasAnyValueUnboundedError() { assertEquals(2, rs.size()); assertTrue(rs.hasValue()); } + @Test public void testSizeAndHasAnyValueEffectivelyUnboundedError() { ReplayProcessor rs = ReplayProcessor.createUnbounded(); @@ -731,6 +738,7 @@ public void testSizeAndHasAnyValueUnboundedEmptyError() { assertEquals(0, rs.size()); assertFalse(rs.hasValue()); } + @Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyError() { ReplayProcessor rs = ReplayProcessor.createUnbounded(); @@ -750,6 +758,7 @@ public void testSizeAndHasAnyValueUnboundedEmptyCompleted() { assertEquals(0, rs.size()); assertFalse(rs.hasValue()); } + @Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() { ReplayProcessor rs = ReplayProcessor.createUnbounded(); @@ -802,6 +811,7 @@ public void testSizeAndHasAnyValueTimeBounded() { assertEquals(0, rs.size()); assertFalse(rs.hasValue()); } + @Test public void testGetValues() { ReplayProcessor rs = ReplayProcessor.create(); @@ -816,6 +826,7 @@ public void testGetValues() { assertArrayEquals(expected, rs.getValues()); } + @Test public void testGetValuesUnbounded() { ReplayProcessor rs = ReplayProcessor.createUnbounded(); @@ -1533,6 +1544,7 @@ public void timeBoundCancelAfterOne() { source.subscribeWith(take1AndCancel()) .assertResult(1); } + @Test public void timeAndSizeBoundCancelAfterOne() { ReplayProcessor source = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.MINUTES, Schedulers.single(), 16); diff --git a/src/test/java/io/reactivex/processors/SerializedProcessorTest.java b/src/test/java/io/reactivex/processors/SerializedProcessorTest.java index efbfe02a69..9d5b51c152 100644 --- a/src/test/java/io/reactivex/processors/SerializedProcessorTest.java +++ b/src/test/java/io/reactivex/processors/SerializedProcessorTest.java @@ -121,6 +121,7 @@ public void testPublishSubjectValueEmpty() { assertFalse(serial.hasThrowable()); assertNull(serial.getThrowable()); } + @Test public void testPublishSubjectValueError() { PublishProcessor async = PublishProcessor.create(); @@ -248,6 +249,7 @@ public void testReplaySubjectValueRelay() { assertArrayEquals(new Integer[] { 1 }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { 1, null }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectValueRelayIncomplete() { ReplayProcessor async = ReplayProcessor.create(); @@ -265,6 +267,7 @@ public void testReplaySubjectValueRelayIncomplete() { assertArrayEquals(new Integer[] { 1 }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { 1, null }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectValueRelayBounded() { ReplayProcessor async = ReplayProcessor.createWithSize(1); @@ -284,6 +287,7 @@ public void testReplaySubjectValueRelayBounded() { assertArrayEquals(new Integer[] { 1 }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { 1, null }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectValueRelayBoundedIncomplete() { ReplayProcessor async = ReplayProcessor.createWithSize(1); @@ -302,6 +306,7 @@ public void testReplaySubjectValueRelayBoundedIncomplete() { assertArrayEquals(new Integer[] { 1 }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { 1, null }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectValueRelayBoundedEmptyIncomplete() { ReplayProcessor async = ReplayProcessor.createWithSize(1); @@ -318,6 +323,7 @@ public void testReplaySubjectValueRelayBoundedEmptyIncomplete() { assertArrayEquals(new Integer[] { null }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { null, 0 }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectValueRelayEmptyIncomplete() { ReplayProcessor async = ReplayProcessor.create(); @@ -352,6 +358,7 @@ public void testReplaySubjectEmpty() { assertArrayEquals(new Integer[] { null }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { null, 0 }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectError() { ReplayProcessor async = ReplayProcessor.create(); @@ -388,6 +395,7 @@ public void testReplaySubjectBoundedEmpty() { assertArrayEquals(new Integer[] { null }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { null, 0 }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectBoundedError() { ReplayProcessor async = ReplayProcessor.createWithSize(1); diff --git a/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java b/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java index 9caa79e7b3..b33efed40b 100644 --- a/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java +++ b/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java @@ -111,7 +111,6 @@ public void accept(String t) { }); } - @Test public final void testMergeWithExecutorScheduler() { diff --git a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java index 954981a91e..312ccf92df 100644 --- a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java @@ -204,6 +204,7 @@ public void run() { w.dispose(); } } + @Test public void testCancelledWorkerDoesntRunTasks() { final AtomicInteger calls = new AtomicInteger(); diff --git a/src/test/java/io/reactivex/schedulers/SchedulerTest.java b/src/test/java/io/reactivex/schedulers/SchedulerTest.java index bee0b3935b..99ffca6afb 100644 --- a/src/test/java/io/reactivex/schedulers/SchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/SchedulerTest.java @@ -204,7 +204,6 @@ public void run() { } - @Test public void periodicDirectTaskRaceIO() throws Exception { final Scheduler scheduler = Schedulers.io(); diff --git a/src/test/java/io/reactivex/schedulers/TestSchedulerTest.java b/src/test/java/io/reactivex/schedulers/TestSchedulerTest.java index 2d5484cbb3..4139365384 100644 --- a/src/test/java/io/reactivex/schedulers/TestSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/TestSchedulerTest.java @@ -232,9 +232,9 @@ public void timedRunnableToString() { TimedRunnable r = new TimedRunnable((TestWorker) new TestScheduler().createWorker(), 5, new Runnable() { @Override public void run() { - // TODO Auto-generated method stub - + // deliberately no-op } + @Override public String toString() { return "Runnable"; diff --git a/src/test/java/io/reactivex/single/SingleNullTests.java b/src/test/java/io/reactivex/single/SingleNullTests.java index 3efcbbcc6e..96ffe78eeb 100644 --- a/src/test/java/io/reactivex/single/SingleNullTests.java +++ b/src/test/java/io/reactivex/single/SingleNullTests.java @@ -809,6 +809,7 @@ public void subscribeOnErrorNull() { public void accept(Integer v) { } }, null); } + @Test(expected = NullPointerException.class) public void subscribeSubscriberNull() { just1.toFlowable().subscribe((Subscriber)null); diff --git a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java b/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java index 9376962b95..5e628f3ec6 100644 --- a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java @@ -367,6 +367,7 @@ public void testCurrentStateMethodsEmpty() { assertNull(as.getValue()); assertNull(as.getThrowable()); } + @Test public void testCurrentStateMethodsError() { AsyncSubject as = AsyncSubject.create(); @@ -386,7 +387,6 @@ public void testCurrentStateMethodsError() { assertTrue(as.getThrowable() instanceof TestException); } - @Test public void fusionLive() { AsyncSubject ap = new AsyncSubject(); diff --git a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java b/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java index f8044d5a11..06b7079fdf 100644 --- a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java @@ -282,6 +282,7 @@ public void onComplete() { verify(o, never()).onError(any(Throwable.class)); } } + @Test public void testStartEmpty() { BehaviorSubject source = BehaviorSubject.create(); @@ -307,6 +308,7 @@ public void testStartEmpty() { } + @Test public void testStartEmptyThenAddOne() { BehaviorSubject source = BehaviorSubject.create(); @@ -329,6 +331,7 @@ public void testStartEmptyThenAddOne() { verify(o, never()).onError(any(Throwable.class)); } + @Test public void testStartEmptyCompleteWithOne() { BehaviorSubject source = BehaviorSubject.create(); @@ -406,6 +409,7 @@ public void testTakeOneSubscriber() { // // even though the onError above throws we should still receive it on the other subscriber // assertEquals(1, to.getOnErrorEvents().size()); // } + @Test public void testEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); @@ -550,6 +554,7 @@ public void testCurrentStateMethodsEmpty() { assertNull(as.getValue()); assertNull(as.getThrowable()); } + @Test public void testCurrentStateMethodsError() { BehaviorSubject as = BehaviorSubject.create(); @@ -716,7 +721,6 @@ public void onComplete() { }); } - @Test public void completeSubscribeRace() throws Exception { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { diff --git a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java index 12f4116814..dd9f964100 100644 --- a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java @@ -384,6 +384,7 @@ public void onComplete() { // // even though the onError above throws we should still receive it on the other subscriber // assertEquals(1, to.getOnErrorEvents().size()); // } + @Test public void testCurrentStateMethodsNormal() { PublishSubject as = PublishSubject.create(); @@ -419,6 +420,7 @@ public void testCurrentStateMethodsEmpty() { assertTrue(as.hasComplete()); assertNull(as.getThrowable()); } + @Test public void testCurrentStateMethodsError() { PublishSubject as = PublishSubject.create(); diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java index 4a03449597..9379e0059f 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java @@ -322,6 +322,7 @@ public void run() { } } } + @Test public void testReplaySubjectEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); @@ -407,6 +408,7 @@ public void run() { worker.dispose(); } } + @Test(timeout = 5000) public void testConcurrentSizeAndHasAnyValue() throws InterruptedException { final ReplaySubject rs = ReplaySubject.createUnbounded(); @@ -461,6 +463,7 @@ public void run() { t.join(); } + @Test(timeout = 5000) public void testConcurrentSizeAndHasAnyValueBounded() throws InterruptedException { final ReplaySubject rs = ReplaySubject.createWithSize(3); @@ -504,6 +507,7 @@ public void run() { t.join(); } + @Test(timeout = 10000) public void testConcurrentSizeAndHasAnyValueTimeBounded() throws InterruptedException { final ReplaySubject rs = ReplaySubject.createWithTime(1, TimeUnit.MILLISECONDS, Schedulers.computation()); diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java index adf238118f..bec6a10b2d 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java @@ -322,6 +322,7 @@ public void run() { } } } + @Test public void testReplaySubjectEmissionSubscriptionRace() throws Exception { Scheduler s = Schedulers.io(); @@ -395,6 +396,7 @@ public void run() { worker.dispose(); } } + @Test(timeout = 10000) public void testConcurrentSizeAndHasAnyValue() throws InterruptedException { final ReplaySubject rs = ReplaySubject.create(); diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java index 24d9704b8a..2326241cfd 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java @@ -348,6 +348,7 @@ public void onNext(String v) { assertEquals("three", lastValueForSubscriber2.get()); } + @Test public void testSubscriptionLeak() { ReplaySubject subject = ReplaySubject.create(); @@ -360,6 +361,7 @@ public void testSubscriptionLeak() { assertEquals(0, subject.observerCount()); } + @Test(timeout = 1000) public void testUnsubscriptionCase() { ReplaySubject src = ReplaySubject.create(); @@ -401,6 +403,7 @@ public void onComplete() { verify(o, never()).onError(any(Throwable.class)); } } + @Test public void testTerminateOnce() { ReplaySubject source = ReplaySubject.create(); @@ -453,6 +456,7 @@ public void testReplay1AfterTermination() { verify(o, never()).onError(any(Throwable.class)); } } + @Test public void testReplay1Directly() { ReplaySubject source = ReplaySubject.createWithSize(1); @@ -616,6 +620,7 @@ public void testCurrentStateMethodsEmpty() { assertTrue(as.hasComplete()); assertNull(as.getThrowable()); } + @Test public void testCurrentStateMethodsError() { ReplaySubject as = ReplaySubject.create(); @@ -630,6 +635,7 @@ public void testCurrentStateMethodsError() { assertFalse(as.hasComplete()); assertTrue(as.getThrowable() instanceof TestException); } + @Test public void testSizeAndHasAnyValueUnbounded() { ReplaySubject rs = ReplaySubject.create(); @@ -652,6 +658,7 @@ public void testSizeAndHasAnyValueUnbounded() { assertEquals(2, rs.size()); assertTrue(rs.hasValue()); } + @Test public void testSizeAndHasAnyValueEffectivelyUnbounded() { ReplaySubject rs = ReplaySubject.createUnbounded(); @@ -697,6 +704,7 @@ public void testSizeAndHasAnyValueUnboundedError() { assertEquals(2, rs.size()); assertTrue(rs.hasValue()); } + @Test public void testSizeAndHasAnyValueEffectivelyUnboundedError() { ReplaySubject rs = ReplaySubject.createUnbounded(); @@ -729,6 +737,7 @@ public void testSizeAndHasAnyValueUnboundedEmptyError() { assertEquals(0, rs.size()); assertFalse(rs.hasValue()); } + @Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyError() { ReplaySubject rs = ReplaySubject.createUnbounded(); @@ -748,6 +757,7 @@ public void testSizeAndHasAnyValueUnboundedEmptyCompleted() { assertEquals(0, rs.size()); assertFalse(rs.hasValue()); } + @Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() { ReplaySubject rs = ReplaySubject.createUnbounded(); @@ -800,6 +810,7 @@ public void testSizeAndHasAnyValueTimeBounded() { assertEquals(0, rs.size()); assertFalse(rs.hasValue()); } + @Test public void testGetValues() { ReplaySubject rs = ReplaySubject.create(); @@ -814,6 +825,7 @@ public void testGetValues() { assertArrayEquals(expected, rs.getValues()); } + @Test public void testGetValuesUnbounded() { ReplaySubject rs = ReplaySubject.createUnbounded(); @@ -1205,7 +1217,6 @@ public void noHeadRetentionCompleteSize() { assertSame(o, buf.head); } - @Test public void noHeadRetentionSize() { ReplaySubject source = ReplaySubject.createWithSize(1); diff --git a/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java b/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java index 31498d7a04..8d679b7024 100644 --- a/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java @@ -122,6 +122,7 @@ public void testPublishSubjectValueEmpty() { assertFalse(serial.hasThrowable()); assertNull(serial.getThrowable()); } + @Test public void testPublishSubjectValueError() { PublishSubject async = PublishSubject.create(); @@ -267,6 +268,7 @@ public void testReplaySubjectValueRelayIncomplete() { assertArrayEquals(new Integer[] { 1 }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { 1, null }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectValueRelayBounded() { ReplaySubject async = ReplaySubject.createWithSize(1); @@ -286,6 +288,7 @@ public void testReplaySubjectValueRelayBounded() { assertArrayEquals(new Integer[] { 1 }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { 1, null }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectValueRelayBoundedIncomplete() { ReplaySubject async = ReplaySubject.createWithSize(1); @@ -304,6 +307,7 @@ public void testReplaySubjectValueRelayBoundedIncomplete() { assertArrayEquals(new Integer[] { 1 }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { 1, null }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectValueRelayBoundedEmptyIncomplete() { ReplaySubject async = ReplaySubject.createWithSize(1); @@ -320,6 +324,7 @@ public void testReplaySubjectValueRelayBoundedEmptyIncomplete() { assertArrayEquals(new Integer[] { null }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { null, 0 }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectValueRelayEmptyIncomplete() { ReplaySubject async = ReplaySubject.create(); @@ -354,6 +359,7 @@ public void testReplaySubjectEmpty() { assertArrayEquals(new Integer[] { null }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { null, 0 }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectError() { ReplaySubject async = ReplaySubject.create(); @@ -390,6 +396,7 @@ public void testReplaySubjectBoundedEmpty() { assertArrayEquals(new Integer[] { null }, async.getValues(new Integer[] { 0 })); assertArrayEquals(new Integer[] { null, 0 }, async.getValues(new Integer[] { 0, 0 })); } + @Test public void testReplaySubjectBoundedError() { ReplaySubject async = ReplaySubject.createWithSize(1); diff --git a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java index d66a1ceecf..3ac4a19d7c 100644 --- a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java @@ -579,10 +579,12 @@ public void testOnCompletedThrows() { public void onNext(Integer t) { } + @Override public void onError(Throwable e) { error.set(e); } + @Override public void onComplete() { throw new TestException(); @@ -603,9 +605,11 @@ public void testActual() { @Override public void onNext(Integer t) { } + @Override public void onError(Throwable e) { } + @Override public void onComplete() { } @@ -1085,7 +1089,6 @@ public void cancelCrash() { } } - @Test public void requestCancelCrash() { List list = TestHelper.trackPluginErrors(); diff --git a/src/test/java/io/reactivex/subscribers/SafeSubscriberWithPluginTest.java b/src/test/java/io/reactivex/subscribers/SafeSubscriberWithPluginTest.java index 2f3df019ce..b95f00b3fd 100644 --- a/src/test/java/io/reactivex/subscribers/SafeSubscriberWithPluginTest.java +++ b/src/test/java/io/reactivex/subscribers/SafeSubscriberWithPluginTest.java @@ -171,6 +171,7 @@ public void onError(Throwable e) { safe.onError(new TestException()); } + @Test(expected = RuntimeException.class) @Ignore("Subscribers can't throw") public void testPluginExceptionWhileOnErrorThrowsAndUnsubscribeThrows() { @@ -195,6 +196,7 @@ public void onError(Throwable e) { safe.onError(new TestException()); } + @Test(expected = RuntimeException.class) @Ignore("Subscribers can't throw") public void testPluginExceptionWhenUnsubscribing2() { diff --git a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java index a6d4d4411f..0ecec64e8e 100644 --- a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java @@ -976,6 +976,7 @@ public void onNext(Integer v) { ts.assertValue(1); ts.assertError(TestException.class); } + @Test public void testCompleteReentry() { final AtomicReference> serial = new AtomicReference>(); diff --git a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java index 85cd58baad..bd2748371f 100644 --- a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java @@ -746,7 +746,6 @@ public void onError(Throwable e) { ts.awaitTerminalEvent(); } - @Test public void createDelegate() { TestSubscriber ts1 = TestSubscriber.create(); @@ -1611,7 +1610,6 @@ public void onComplete() { } } - @Test public void syncQueueThrows() { TestSubscriber ts = new TestSubscriber(); @@ -1826,7 +1824,6 @@ public void timeoutIndicated2() throws InterruptedException { } } - @Test public void timeoutIndicated3() throws InterruptedException { TestSubscriber ts = Flowable.never() diff --git a/src/test/java/io/reactivex/tck/BaseTck.java b/src/test/java/io/reactivex/tck/BaseTck.java index 42df479448..a06522a399 100644 --- a/src/test/java/io/reactivex/tck/BaseTck.java +++ b/src/test/java/io/reactivex/tck/BaseTck.java @@ -44,7 +44,6 @@ public Publisher createFailedPublisher() { return Flowable.error(new TestException()); } - @Override public long maxElementsFromPublisher() { return 1024; diff --git a/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java b/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java index 9877a66cc1..8f8acaf3d4 100644 --- a/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java +++ b/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java @@ -332,6 +332,11 @@ public void atomicSubscriptionAsS() throws Exception { findPattern("AtomicReference\\s+s[0-9]?;", true); } + @Test + public void atomicSubscriptionAsSInit() throws Exception { + findPattern("AtomicReference\\s+s[0-9]?\\s", true); + } + @Test public void atomicSubscriptionAsSubscription() throws Exception { findPattern("AtomicReference\\s+subscription[0-9]?", true); diff --git a/src/test/java/io/reactivex/validators/NewLinesBeforeAnnotation.java b/src/test/java/io/reactivex/validators/NewLinesBeforeAnnotation.java new file mode 100644 index 0000000000..49f19daec0 --- /dev/null +++ b/src/test/java/io/reactivex/validators/NewLinesBeforeAnnotation.java @@ -0,0 +1,162 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.validators; + +import java.io.*; +import java.util.*; + +import org.junit.Test; + +/** + * These tests verify the code style that a typical closing curly brace + * and the next annotation @ indicator + * are not separated by less than or more than one empty line. + *

    Thus this is detected: + *

    
    + * }
    + * @Override
    + * 
    + *

    + * as well as + *

    
    + * }
    + * 
    + * 
    + * @Override
    + * 
    + */ +public class NewLinesBeforeAnnotation { + + @Test + public void missingEmptyNewLine() throws Exception { + findPattern(0); + } + + @Test + public void tooManyEmptyNewLines2() throws Exception { + findPattern(2); + } + + @Test + public void tooManyEmptyNewLines3() throws Exception { + findPattern(3); + } + + @Test + public void tooManyEmptyNewLines4() throws Exception { + findPattern(5); + } + + @Test + public void tooManyEmptyNewLines5() throws Exception { + findPattern(5); + } + + static void findPattern(int newLines) throws Exception { + File f = MaybeNo2Dot0Since.findSource("Flowable"); + if (f == null) { + System.out.println("Unable to find sources of RxJava"); + return; + } + + Queue dirs = new ArrayDeque(); + + StringBuilder fail = new StringBuilder(); + fail.append("The following code pattern was found: "); + fail.append("\\}\\R"); + for (int i = 0; i < newLines; i++) { + fail.append("\\R"); + } + fail.append("[ ]+@\n"); + + File parent = f.getParentFile(); + + dirs.offer(new File(parent.getAbsolutePath().replace('\\', '/'))); + dirs.offer(new File(parent.getAbsolutePath().replace('\\', '/').replace("src/main/java", "src/test/java"))); + + int total = 0; + + while (!dirs.isEmpty()) { + f = dirs.poll(); + + File[] list = f.listFiles(); + if (list != null && list.length != 0) { + + for (File u : list) { + if (u.isDirectory()) { + dirs.offer(u); + } else { + String fname = u.getName(); + if (fname.endsWith(".java")) { + + List lines = new ArrayList(); + BufferedReader in = new BufferedReader(new FileReader(u)); + try { + for (;;) { + String line = in.readLine(); + if (line == null) { + break; + } + lines.add(line); + } + } finally { + in.close(); + } + + for (int i = 0; i < lines.size() - 1; i++) { + String line = lines.get(i); + if (line.endsWith("}") && !line.trim().startsWith("*") && !line.trim().startsWith("//")) { + int emptyLines = 0; + boolean found = false; + for (int j = i + 1; j < lines.size(); j++) { + String line2 = lines.get(j); + if (line2.trim().startsWith("@")) { + found = true; + break; + } + if (!line2.trim().isEmpty()) { + break; + } + emptyLines++; + } + + if (emptyLines == newLines && found) { + fail + .append(fname) + .append("#L").append(i + 1) + .append(" "); + for (int k = 0; k < emptyLines + 2; k++) { + fail + .append(lines.get(k + i)) + .append("\\R"); + } + fail.append("\n"); + total++; + } + } + } + } + } + } + } + } + if (total != 0) { + fail.append("Found ") + .append(total) + .append(" instances"); + System.out.println(fail); + throw new AssertionError(fail.toString()); + } + } +} From a16f63fa9030dc7ed4a5b9e2b8c948e02d92e557 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 10 Aug 2018 10:15:21 +0200 Subject: [PATCH 057/211] 2.x: Clarify TestObserver.assertValueSet in docs and via tests (#6152) * 2.x: Clarify TestObserver.assertValueSet in docs and via tests * Grammar. --- .../reactivex/observers/BaseTestConsumer.java | 9 +++-- .../reactivex/observers/TestObserverTest.java | 34 +++++++++++++++++++ .../subscribers/TestSubscriberTest.java | 34 +++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/observers/BaseTestConsumer.java b/src/main/java/io/reactivex/observers/BaseTestConsumer.java index 373339f020..69d227d91d 100644 --- a/src/main/java/io/reactivex/observers/BaseTestConsumer.java +++ b/src/main/java/io/reactivex/observers/BaseTestConsumer.java @@ -565,9 +565,14 @@ public final U assertValuesOnly(T... values) { } /** - * Assert that the TestObserver/TestSubscriber received only the specified values in any order. - *

    This helps asserting when the order of the values is not guaranteed, i.e., when merging + * Assert that the TestObserver/TestSubscriber received only items that are in the specified + * collection as well, irrespective of the order they were received. + *

    + * This helps asserting when the order of the values is not guaranteed, i.e., when merging * asynchronous streams. + *

    + * To ensure that only the expected items have been received, no more and no less, in any order, + * apply {@link #assertValueCount(int)} with {@code expected.size()}. * * @param expected the collection of values expected in any order * @return this diff --git a/src/test/java/io/reactivex/observers/TestObserverTest.java b/src/test/java/io/reactivex/observers/TestObserverTest.java index efe9798bae..27f4f7442c 100644 --- a/src/test/java/io/reactivex/observers/TestObserverTest.java +++ b/src/test/java/io/reactivex/observers/TestObserverTest.java @@ -1626,4 +1626,38 @@ public void assertValueSequenceOnlyThrowsWhenErrored() { // expected } } + + @Test + public void assertValueSetWiderSet() { + Set set = new HashSet(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7)); + + Observable.just(4, 5, 1, 3, 2) + .test() + .assertValueSet(set); + } + + @Test + public void assertValueSetExact() { + Set set = new HashSet(Arrays.asList(1, 2, 3, 4, 5)); + + Observable.just(4, 5, 1, 3, 2) + .test() + .assertValueSet(set) + .assertValueCount(set.size()); + } + + @Test + public void assertValueSetMissing() { + Set set = new HashSet(Arrays.asList(0, 1, 2, 4, 5, 6, 7)); + + try { + Observable.range(1, 5) + .test() + .assertValueSet(set); + + throw new RuntimeException("Should have failed"); + } catch (AssertionError ex) { + assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3)); + } + } } diff --git a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java index bd2748371f..d4358f4bb8 100644 --- a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java @@ -2186,4 +2186,38 @@ public void awaitCount0() { TestSubscriber ts = TestSubscriber.create(); ts.awaitCount(0, TestWaitStrategy.SLEEP_1MS, 0); } + + @Test + public void assertValueSetWiderSet() { + Set set = new HashSet(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7)); + + Flowable.just(4, 5, 1, 3, 2) + .test() + .assertValueSet(set); + } + + @Test + public void assertValueSetExact() { + Set set = new HashSet(Arrays.asList(1, 2, 3, 4, 5)); + + Flowable.just(4, 5, 1, 3, 2) + .test() + .assertValueSet(set) + .assertValueCount(set.size()); + } + + @Test + public void assertValueSetMissing() { + Set set = new HashSet(Arrays.asList(0, 1, 2, 4, 5, 6, 7)); + + try { + Flowable.range(1, 5) + .test() + .assertValueSet(set); + + throw new RuntimeException("Should have failed"); + } catch (AssertionError ex) { + assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3)); + } + } } From 835ab00699d39c092ef6e90cf1868722b9180fe1 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 10 Aug 2018 12:08:24 +0200 Subject: [PATCH 058/211] 2.x: Fix marble of Maybe.flatMap events to MaybeSource (#6155) --- src/main/java/io/reactivex/Maybe.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 519a64f6b9..4bc994e3d3 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -2909,7 +2909,7 @@ public final Maybe flatMap(Function - * + * *

    *
    Scheduler:
    *
    {@code flatMap} does not operate by default on a particular {@link Scheduler}.
    From 7d652913772abcdbb429d5b132b830462661ee23 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 14 Aug 2018 14:53:54 +0200 Subject: [PATCH 059/211] 2.x: Make Flowable.fromCallable consitent with the other fromCallables (#6158) 2.x: Make Flowable.fromCallable consistent with the other fromCallables --- .../flowable/FlowableFromCallable.java | 7 ++++- .../flowable/FlowableFromCallableTest.java | 29 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromCallable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromCallable.java index 5a773dffc4..6dcb226daa 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromCallable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromCallable.java @@ -21,6 +21,7 @@ import io.reactivex.exceptions.Exceptions; import io.reactivex.internal.functions.ObjectHelper; import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import io.reactivex.plugins.RxJavaPlugins; public final class FlowableFromCallable extends Flowable implements Callable { final Callable callable; @@ -38,7 +39,11 @@ public void subscribeActual(Subscriber s) { t = ObjectHelper.requireNonNull(callable.call(), "The callable returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - s.onError(ex); + if (deferred.isCancelled()) { + RxJavaPlugins.onError(ex); + } else { + s.onError(ex); + } return; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java index f3f5e00fa5..f3239001ee 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java @@ -16,9 +16,11 @@ package io.reactivex.internal.operators.flowable; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.junit.Assert.*; +import java.util.List; import java.util.concurrent.*; import org.junit.Test; @@ -27,7 +29,9 @@ import org.reactivestreams.*; import io.reactivex.*; +import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; @@ -238,4 +242,27 @@ public Object call() throws Exception { .test() .assertFailure(NullPointerException.class); } + + @Test(timeout = 5000) + public void undeliverableUponCancellation() throws Exception { + List errors = TestHelper.trackPluginErrors(); + try { + final TestSubscriber ts = new TestSubscriber(); + + Flowable.fromCallable(new Callable() { + @Override + public Integer call() throws Exception { + ts.cancel(); + throw new TestException(); + } + }) + .subscribe(ts); + + ts.assertEmpty(); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } } From 592b991dd8d148351fe4d52de6e8512f274285de Mon Sep 17 00:00:00 2001 From: Muh Isfhani Ghiath Date: Wed, 22 Aug 2018 00:56:58 +0700 Subject: [PATCH 060/211] Error handle on Completable.fromCallable with RxJavaPlugins (#6165) --- .../operators/completable/CompletableFromCallable.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromCallable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromCallable.java index 3dbd3701b5..6b7e68defb 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromCallable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromCallable.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.Exceptions; +import io.reactivex.plugins.RxJavaPlugins; public final class CompletableFromCallable extends Completable { @@ -37,6 +38,8 @@ protected void subscribeActual(CompletableObserver observer) { Exceptions.throwIfFatal(e); if (!d.isDisposed()) { observer.onError(e); + } else { + RxJavaPlugins.onError(e); } return; } From 5c67fe4ec72f41256874fc1ecd4faf2b92d1899f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Karnok?= Date: Wed, 22 Aug 2018 13:51:04 +0200 Subject: [PATCH 061/211] Update `unsubscribeOn` tests to avoid the termination-cancel race --- .../operators/flowable/FlowableUnsubscribeOnTest.java | 10 ++++++++-- .../observable/ObservableUnsubscribeOnTest.java | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java index 3ed444424f..cd6f22ea56 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java @@ -47,7 +47,10 @@ public void subscribe(Subscriber t1) { t1.onSubscribe(subscription); t1.onNext(1); t1.onNext(2); - t1.onComplete(); + // observeOn will prevent canceling the upstream upon its termination now + // this call is racing for that state in this test + // not doing it will make sure the unsubscribeOn always gets through + // t1.onComplete(); } }); @@ -93,7 +96,10 @@ public void subscribe(Subscriber t1) { t1.onSubscribe(subscription); t1.onNext(1); t1.onNext(2); - t1.onComplete(); + // observeOn will prevent canceling the upstream upon its termination now + // this call is racing for that state in this test + // not doing it will make sure the unsubscribeOn always gets through + // t1.onComplete(); } }); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java index cdb21dafa5..2b7d7f4141 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java @@ -46,7 +46,10 @@ public void subscribe(Observer t1) { t1.onSubscribe(subscription); t1.onNext(1); t1.onNext(2); - t1.onComplete(); + // observeOn will prevent canceling the upstream upon its termination now + // this call is racing for that state in this test + // not doing it will make sure the unsubscribeOn always gets through + // t1.onComplete(); } }); @@ -92,7 +95,10 @@ public void subscribe(Observer t1) { t1.onSubscribe(subscription); t1.onNext(1); t1.onNext(2); - t1.onComplete(); + // observeOn will prevent canceling the upstream upon its termination now + // this call is racing for that state in this test + // not doing it will make sure the unsubscribeOn always gets through + // t1.onComplete(); } }); From ab649824e6d55505cc7b3e6d9fb033143146b110 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 22 Aug 2018 16:58:17 +0200 Subject: [PATCH 062/211] 2.x: Make observeOn not let worker.dispose() called prematurely (#6167) * 2.x: Make observeOn not let worker.dispose() called prematurely * Merge in master. --- .../operators/flowable/FlowableObserveOn.java | 13 ++ .../observable/ObservableObserveOn.java | 18 +- .../flowable/FlowableObserveOnTest.java | 162 +++++++++++++++++- .../observable/ObservableObserveOnTest.java | 76 ++++++++ 4 files changed, 262 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java index d1c97b6801..2a7d499d1a 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java @@ -191,6 +191,7 @@ final boolean checkTerminated(boolean d, boolean empty, Subscriber a) { if (d) { if (delayError) { if (empty) { + cancelled = true; Throwable e = error; if (e != null) { a.onError(e); @@ -203,12 +204,14 @@ final boolean checkTerminated(boolean d, boolean empty, Subscriber a) { } else { Throwable e = error; if (e != null) { + cancelled = true; clear(); a.onError(e); worker.dispose(); return true; } else if (empty) { + cancelled = true; a.onComplete(); worker.dispose(); return true; @@ -314,6 +317,7 @@ void runSync() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); + cancelled = true; upstream.cancel(); a.onError(ex); worker.dispose(); @@ -324,6 +328,7 @@ void runSync() { return; } if (v == null) { + cancelled = true; a.onComplete(); worker.dispose(); return; @@ -339,6 +344,7 @@ void runSync() { } if (q.isEmpty()) { + cancelled = true; a.onComplete(); worker.dispose(); return; @@ -379,6 +385,7 @@ void runAsync() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); + cancelled = true; upstream.cancel(); q.clear(); @@ -441,6 +448,7 @@ void runBackfused() { downstream.onNext(null); if (d) { + cancelled = true; Throwable e = error; if (e != null) { downstream.onError(e); @@ -552,6 +560,7 @@ void runSync() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); + cancelled = true; upstream.cancel(); a.onError(ex); worker.dispose(); @@ -562,6 +571,7 @@ void runSync() { return; } if (v == null) { + cancelled = true; a.onComplete(); worker.dispose(); return; @@ -577,6 +587,7 @@ void runSync() { } if (q.isEmpty()) { + cancelled = true; a.onComplete(); worker.dispose(); return; @@ -617,6 +628,7 @@ void runAsync() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); + cancelled = true; upstream.cancel(); q.clear(); @@ -680,6 +692,7 @@ void runBackfused() { downstream.onNext(null); if (d) { + cancelled = true; Throwable e = error; if (e != null) { downstream.onError(e); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java index f415e7016f..abf1f0bb85 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java @@ -62,7 +62,7 @@ static final class ObserveOnObserver extends BasicIntQueueDisposable Throwable error; volatile boolean done; - volatile boolean cancelled; + volatile boolean disposed; int sourceMode; @@ -141,8 +141,8 @@ public void onComplete() { @Override public void dispose() { - if (!cancelled) { - cancelled = true; + if (!disposed) { + disposed = true; upstream.dispose(); worker.dispose(); if (getAndIncrement() == 0) { @@ -153,7 +153,7 @@ public void dispose() { @Override public boolean isDisposed() { - return cancelled; + return disposed; } void schedule() { @@ -181,6 +181,7 @@ void drainNormal() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); + disposed = true; upstream.dispose(); q.clear(); a.onError(ex); @@ -211,7 +212,7 @@ void drainFused() { int missed = 1; for (;;) { - if (cancelled) { + if (disposed) { return; } @@ -219,6 +220,7 @@ void drainFused() { Throwable ex = error; if (!delayError && d && ex != null) { + disposed = true; downstream.onError(error); worker.dispose(); return; @@ -227,6 +229,7 @@ void drainFused() { downstream.onNext(null); if (d) { + disposed = true; ex = error; if (ex != null) { downstream.onError(ex); @@ -254,7 +257,7 @@ public void run() { } boolean checkTerminated(boolean d, boolean empty, Observer a) { - if (cancelled) { + if (disposed) { queue.clear(); return true; } @@ -262,6 +265,7 @@ boolean checkTerminated(boolean d, boolean empty, Observer a) { Throwable e = error; if (delayError) { if (empty) { + disposed = true; if (e != null) { a.onError(e); } else { @@ -272,12 +276,14 @@ boolean checkTerminated(boolean d, boolean empty, Observer a) { } } else { if (e != null) { + disposed = true; queue.clear(); a.onError(e); worker.dispose(); return true; } else if (empty) { + disposed = true; a.onComplete(); worker.dispose(); return true; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java index 2beacebd84..d4fdbe15db 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java @@ -21,12 +21,13 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import io.reactivex.annotations.Nullable; import org.junit.Test; import org.mockito.InOrder; import org.reactivestreams.*; import io.reactivex.*; +import io.reactivex.annotations.Nullable; +import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -1781,4 +1782,163 @@ public void syncFusedRequestOneByOneConditional() { .test() .assertResult(1, 2, 3, 4, 5); } + + public static final class DisposeTrackingScheduler extends Scheduler { + + public final AtomicInteger disposedCount = new AtomicInteger(); + + @Override + public Worker createWorker() { + return new TrackingWorker(); + } + + final class TrackingWorker extends Scheduler.Worker { + + @Override + public void dispose() { + disposedCount.getAndIncrement(); + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public Disposable schedule(Runnable run, long delay, + TimeUnit unit) { + run.run(); + return Disposables.empty(); + } + } + } + + @Test + public void workerNotDisposedPrematurelyNormalInNormalOut() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + Flowable.concat( + Flowable.just(1).hide().observeOn(s), + Flowable.just(2) + ) + .test() + .assertResult(1, 2); + + assertEquals(1, s.disposedCount.get()); + } + + @Test + public void workerNotDisposedPrematurelySyncInNormalOut() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + Flowable.concat( + Flowable.just(1).observeOn(s), + Flowable.just(2) + ) + .test() + .assertResult(1, 2); + + assertEquals(1, s.disposedCount.get()); + } + + @Test + public void workerNotDisposedPrematurelyAsyncInNormalOut() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + UnicastProcessor up = UnicastProcessor.create(); + up.onNext(1); + up.onComplete(); + + Flowable.concat( + up.observeOn(s), + Flowable.just(2) + ) + .test() + .assertResult(1, 2); + + assertEquals(1, s.disposedCount.get()); + } + + static final class TestSubscriberFusedCanceling + extends TestSubscriber { + + public TestSubscriberFusedCanceling() { + super(); + initialFusionMode = QueueFuseable.ANY; + } + + @Override + public void onComplete() { + cancel(); + super.onComplete(); + } + } + + @Test + public void workerNotDisposedPrematurelyNormalInAsyncOut() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + TestSubscriber ts = new TestSubscriberFusedCanceling(); + + Flowable.just(1).hide().observeOn(s).subscribe(ts); + + assertEquals(1, s.disposedCount.get()); + } + + @Test + public void workerNotDisposedPrematurelyNormalInNormalOutConditional() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + Flowable.concat( + Flowable.just(1).hide().observeOn(s).filter(Functions.alwaysTrue()), + Flowable.just(2) + ) + .test() + .assertResult(1, 2); + + assertEquals(1, s.disposedCount.get()); + } + + @Test + public void workerNotDisposedPrematurelySyncInNormalOutConditional() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + Flowable.concat( + Flowable.just(1).observeOn(s).filter(Functions.alwaysTrue()), + Flowable.just(2) + ) + .test() + .assertResult(1, 2); + + assertEquals(1, s.disposedCount.get()); + } + + @Test + public void workerNotDisposedPrematurelyAsyncInNormalOutConditional() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + UnicastProcessor up = UnicastProcessor.create(); + up.onNext(1); + up.onComplete(); + + Flowable.concat( + up.observeOn(s).filter(Functions.alwaysTrue()), + Flowable.just(2) + ) + .test() + .assertResult(1, 2); + + assertEquals(1, s.disposedCount.get()); + } + + @Test + public void workerNotDisposedPrematurelyNormalInAsyncOutConditional() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + TestSubscriber ts = new TestSubscriberFusedCanceling(); + + Flowable.just(1).hide().observeOn(s).filter(Functions.alwaysTrue()).subscribe(ts); + + assertEquals(1, s.disposedCount.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java index 1ac99fcb5e..227b734b3a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java @@ -32,12 +32,15 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.fuseable.*; +import io.reactivex.internal.operators.flowable.FlowableObserveOnTest.DisposeTrackingScheduler; import io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver; import io.reactivex.internal.schedulers.ImmediateThinScheduler; import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.processors.UnicastProcessor; import io.reactivex.schedulers.*; import io.reactivex.subjects.*; +import io.reactivex.subscribers.TestSubscriber; public class ObservableObserveOnTest { @@ -740,4 +743,77 @@ public void onNext(Integer t) { }) .assertValuesOnly(2, 3); } + + @Test + public void workerNotDisposedPrematurelyNormalInNormalOut() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + Observable.concat( + Observable.just(1).hide().observeOn(s), + Observable.just(2) + ) + .test() + .assertResult(1, 2); + + assertEquals(1, s.disposedCount.get()); + } + + @Test + public void workerNotDisposedPrematurelySyncInNormalOut() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + Observable.concat( + Observable.just(1).observeOn(s), + Observable.just(2) + ) + .test() + .assertResult(1, 2); + + assertEquals(1, s.disposedCount.get()); + } + + @Test + public void workerNotDisposedPrematurelyAsyncInNormalOut() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + UnicastSubject up = UnicastSubject.create(); + up.onNext(1); + up.onComplete(); + + Observable.concat( + up.observeOn(s), + Observable.just(2) + ) + .test() + .assertResult(1, 2); + + assertEquals(1, s.disposedCount.get()); + } + + static final class TestObserverFusedCanceling + extends TestObserver { + + public TestObserverFusedCanceling() { + super(); + initialFusionMode = QueueFuseable.ANY; + } + + @Override + public void onComplete() { + cancel(); + super.onComplete(); + } + } + + @Test + public void workerNotDisposedPrematurelyNormalInAsyncOut() { + DisposeTrackingScheduler s = new DisposeTrackingScheduler(); + + TestObserver to = new TestObserverFusedCanceling(); + + Observable.just(1).hide().observeOn(s).subscribe(to); + + assertEquals(1, s.disposedCount.get()); + } + } From eceae80aedfb942c82f66890c4c7c7e2bcf80d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Karnok?= Date: Wed, 22 Aug 2018 22:10:47 +0200 Subject: [PATCH 063/211] Remove unused imports --- .../internal/operators/observable/ObservableObserveOnTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java index 227b734b3a..70f047a005 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java @@ -37,10 +37,8 @@ import io.reactivex.internal.schedulers.ImmediateThinScheduler; import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.UnicastProcessor; import io.reactivex.schedulers.*; import io.reactivex.subjects.*; -import io.reactivex.subscribers.TestSubscriber; public class ObservableObserveOnTest { From 5445b4a18088a14185eb4bd7f2f7556a48698755 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 23 Aug 2018 10:22:23 +0200 Subject: [PATCH 064/211] Release 2.2.1 --- CHANGES.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 86d4eda074..a4dfea7e35 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,43 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.1 - August 23, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.1%7C)) + +#### API changes + + - [Pull 6143](https://github.com/ReactiveX/RxJava/pull/6143): Add `concatArrayEagerDelayError` operator (expose feature). + +#### Bugfixes + + - [Pull 6145](https://github.com/ReactiveX/RxJava/pull/6145): Fix boundary fusion of `concatMap` and `publish` operator. + - [Pull 6158](https://github.com/ReactiveX/RxJava/pull/6158): Make `Flowable.fromCallable` consistent with the other `fromCallable`s. + - [Pull 6165](https://github.com/ReactiveX/RxJava/pull/6165): Handle undeliverable error in `Completable.fromCallable` via `RxJavaPlugins`. + - [Pull 6167](https://github.com/ReactiveX/RxJava/pull/6167): Make `observeOn` not let `worker.dispose()` get called prematurely. + +#### Performance improvements + + - [Pull 6123](https://github.com/ReactiveX/RxJava/pull/6123): Improve `Completable.onErrorResumeNext` internals. + - [Pull 6121](https://github.com/ReactiveX/RxJava/pull/6121): `Flowable.onErrorResumeNext` improvements. + +#### Documentation changes + +##### JavaDocs + + - [Pull 6095](https://github.com/ReactiveX/RxJava/pull/6095): Add marbles for `Single.timer`, `Single.defer` and `Single.toXXX` operators. + - [Pull 6137](https://github.com/ReactiveX/RxJava/pull/6137): Add marbles for `Single.concat` operator. + - [Pull 6141](https://github.com/ReactiveX/RxJava/pull/6141): Add marble diagrams for various `Single` operators. + - [Pull 6152](https://github.com/ReactiveX/RxJava/pull/6152): Clarify `TestObserver.assertValueSet` in docs and via tests. + - [Pull 6155](https://github.com/ReactiveX/RxJava/pull/6155): Fix marble of `Maybe.flatMap` events to `MaybeSource`. + +##### Wiki changes + + - [Pull 6128](https://github.com/ReactiveX/RxJava/pull/6128): Remove `fromEmitter()` in wiki. + - [Pull 6133](https://github.com/ReactiveX/RxJava/pull/6133): Update `_Sidebar.md` with new order of topics. + - [Pull 6135](https://github.com/ReactiveX/RxJava/pull/6135): Initial clean up for Combining Observables docs. + - [Pull 6131](https://github.com/ReactiveX/RxJava/pull/6131): Expand `Creating-Observables.md` wiki. + - [Pull 6134](https://github.com/ReactiveX/RxJava/pull/6134): Update RxJava Android Module documentation. + - [Pull 6140](https://github.com/ReactiveX/RxJava/pull/6140): Update Mathematical and Aggregate Operators docs. + ### Version 2.2.0 - July 31, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.0%7C)) #### Summary From 3e2b1b3fa19aa394c846e32735f6589bc5aa551a Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sat, 25 Aug 2018 09:53:04 +0200 Subject: [PATCH 065/211] 2.x: Add explanation text to Undeliverable & OnErrorNotImplemented exs (#6171) * 2.x: Add explanation text to Undeliverable & OnErrorNotImplemented exs * Link to the wiki instead of the docs directory due to broken [[]] links * Reword OnErrorNotImplemented --- .../reactivex/exceptions/OnErrorNotImplementedException.java | 2 +- .../java/io/reactivex/exceptions/UndeliverableException.java | 2 +- src/test/java/io/reactivex/exceptions/ExceptionsTest.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java b/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java index 994a5c25a5..6fdc42aeec 100644 --- a/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java +++ b/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java @@ -48,6 +48,6 @@ public OnErrorNotImplementedException(String message, @NonNull Throwable e) { * the {@code Throwable} to signal; if null, a NullPointerException is constructed */ public OnErrorNotImplementedException(@NonNull Throwable e) { - super(e != null ? e.getMessage() : null, e != null ? e : new NullPointerException()); + this("The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: https://github.com/ReactiveX/RxJava/wiki/Error-Handling | " + (e != null ? e.getMessage() : ""), e); } } \ No newline at end of file diff --git a/src/main/java/io/reactivex/exceptions/UndeliverableException.java b/src/main/java/io/reactivex/exceptions/UndeliverableException.java index 6f6aec0938..d8bb99ce5c 100644 --- a/src/main/java/io/reactivex/exceptions/UndeliverableException.java +++ b/src/main/java/io/reactivex/exceptions/UndeliverableException.java @@ -28,6 +28,6 @@ public final class UndeliverableException extends IllegalStateException { * @param cause the cause, not null */ public UndeliverableException(Throwable cause) { - super(cause); + super("The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | " + cause.getMessage(), cause); } } diff --git a/src/test/java/io/reactivex/exceptions/ExceptionsTest.java b/src/test/java/io/reactivex/exceptions/ExceptionsTest.java index 43b316a7f7..4928f14bf1 100644 --- a/src/test/java/io/reactivex/exceptions/ExceptionsTest.java +++ b/src/test/java/io/reactivex/exceptions/ExceptionsTest.java @@ -53,7 +53,8 @@ public void accept(Integer t1) { }); - TestHelper.assertError(errors, 0, RuntimeException.class, "hello"); + TestHelper.assertError(errors, 0, RuntimeException.class); + assertTrue(errors.get(0).toString(), errors.get(0).getMessage().contains("hello")); RxJavaPlugins.reset(); } From ba7bbb497d43a1353a3e5f81b0887b26bf4cadfb Mon Sep 17 00:00:00 2001 From: Aaron Friedman Date: Sat, 25 Aug 2018 22:42:56 -1000 Subject: [PATCH 066/211] Auto-clean up RxJavaPlugins JavaDocs HTML (#6173) (#6174) --- gradle/javadoc_cleanup.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle/javadoc_cleanup.gradle b/gradle/javadoc_cleanup.gradle index 32db33b963..79f4d5411a 100644 --- a/gradle/javadoc_cleanup.gradle +++ b/gradle/javadoc_cleanup.gradle @@ -11,6 +11,7 @@ task javadocCleanup(dependsOn: "javadoc") doLast { fixJavadocFile(rootProject.file('build/docs/javadoc/io/reactivex/subjects/ReplaySubject.html')); fixJavadocFile(rootProject.file('build/docs/javadoc/io/reactivex/processors/ReplayProcessor.html')); + fixJavadocFile(rootProject.file('build/docs/javadoc/io/reactivex/plugins/RxJavaPlugins.html')); } def fixJavadocFile(file) { From e2a21599fa451ff26f00ec52133604e8daf7d78c Mon Sep 17 00:00:00 2001 From: punitd Date: Sun, 26 Aug 2018 16:44:52 +0530 Subject: [PATCH 067/211] 2.x: explain null observer/subscriber return errors from RxJavaPlugins in detail (#6175) --- src/main/java/io/reactivex/Completable.java | 2 ++ src/main/java/io/reactivex/Flowable.java | 2 +- src/main/java/io/reactivex/Maybe.java | 2 +- src/main/java/io/reactivex/Observable.java | 2 +- src/main/java/io/reactivex/Single.java | 2 +- src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java | 2 +- .../java/io/reactivex/observable/ObservableSubscriberTest.java | 2 +- 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index b4f18a56c2..cb08465a2a 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -2168,6 +2168,8 @@ public final void subscribe(CompletableObserver observer) { observer = RxJavaPlugins.onSubscribe(this, observer); + ObjectHelper.requireNonNull(observer, "The RxJavaPlugins.onSubscribe hook returned a null CompletableObserver. Please check the handler provided to RxJavaPlugins.setOnCompletableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins"); + subscribeActual(observer); } catch (NullPointerException ex) { // NOPMD throw ex; diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 6af68db61d..15abe6bd95 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -14473,7 +14473,7 @@ public final void subscribe(FlowableSubscriber s) { try { Subscriber z = RxJavaPlugins.onSubscribe(this, s); - ObjectHelper.requireNonNull(z, "Plugin returned null Subscriber"); + ObjectHelper.requireNonNull(z, "The RxJavaPlugins.onSubscribe hook returned a null FlowableSubscriber. Please check the handler provided to RxJavaPlugins.setOnFlowableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins"); subscribeActual(z); } catch (NullPointerException e) { // NOPMD diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 4bc994e3d3..1338323569 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -4150,7 +4150,7 @@ public final void subscribe(MaybeObserver observer) { observer = RxJavaPlugins.onSubscribe(this, observer); - ObjectHelper.requireNonNull(observer, "observer returned by the RxJavaPlugins hook is null"); + ObjectHelper.requireNonNull(observer, "The RxJavaPlugins.onSubscribe hook returned a null MaybeObserver. Please check the handler provided to RxJavaPlugins.setOnMaybeSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins"); try { subscribeActual(observer); diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 2c43e0abf0..9781a3dad4 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -12079,7 +12079,7 @@ public final void subscribe(Observer observer) { try { observer = RxJavaPlugins.onSubscribe(this, observer); - ObjectHelper.requireNonNull(observer, "Plugin returned null Observer"); + ObjectHelper.requireNonNull(observer, "The RxJavaPlugins.onSubscribe hook returned a null Observer. Please change the handler provided to RxJavaPlugins.setOnObservableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins"); subscribeActual(observer); } catch (NullPointerException e) { // NOPMD diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index f75b275a90..b6896e7cec 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -3427,7 +3427,7 @@ public final void subscribe(SingleObserver observer) { observer = RxJavaPlugins.onSubscribe(this, observer); - ObjectHelper.requireNonNull(observer, "subscriber returned by the RxJavaPlugins hook is null"); + ObjectHelper.requireNonNull(observer, "The RxJavaPlugins.onSubscribe hook returned a null SingleObserver. Please check the handler provided to RxJavaPlugins.setOnSingleSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins"); try { subscribeActual(observer); diff --git a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java index f7789656a3..189747dfa4 100644 --- a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java @@ -815,7 +815,7 @@ public Subscriber apply(Flowable a, Subscriber b) throws Exception { Flowable.just(1).test(); fail("Should have thrown"); } catch (NullPointerException ex) { - assertEquals("Plugin returned null Subscriber", ex.getMessage()); + assertEquals("The RxJavaPlugins.onSubscribe hook returned a null FlowableSubscriber. Please check the handler provided to RxJavaPlugins.setOnFlowableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins", ex.getMessage()); } } finally { RxJavaPlugins.reset(); diff --git a/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java b/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java index 9544bb5030..848d6128e1 100644 --- a/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java +++ b/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java @@ -205,7 +205,7 @@ public Observer apply(Observable a, Observer b) throws Exception { Observable.just(1).test(); fail("Should have thrown"); } catch (NullPointerException ex) { - assertEquals("Plugin returned null Observer", ex.getMessage()); + assertEquals("The RxJavaPlugins.onSubscribe hook returned a null Observer. Please change the handler provided to RxJavaPlugins.setOnObservableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins", ex.getMessage()); } } finally { RxJavaPlugins.reset(); From 13f7b01f4e681a6aa7494cdae5f2cf4474b2baab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Bia=C5=82orucki?= Date: Tue, 28 Aug 2018 10:54:19 +0200 Subject: [PATCH 068/211] Update Additional-Reading.md (#6180) * Update Additional-Reading.md Check existing links, add new links about RxAndroid * Update Additional-Reading.md Add code version marks where possible --- docs/Additional-Reading.md | 42 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/docs/Additional-Reading.md b/docs/Additional-Reading.md index 6f65b4f677..b5a4a2604a 100644 --- a/docs/Additional-Reading.md +++ b/docs/Additional-Reading.md @@ -1,11 +1,11 @@ (A more complete and up-to-date list of resources can be found at the reactivex.io site: [[http://reactivex.io/tutorials.html]]) # Introducing Reactive Programming -* [Introduction to Rx](http://www.introtorx.com/): a free, on-line book by Lee Campbell +* [Introduction to Rx](http://www.introtorx.com/): a free, on-line book by Lee Campbell **(1.x)** * [The introduction to Reactive Programming you've been missing](https://gist.github.com/staltz/868e7e9bc2a7b8c1f754) by Andre Staltz -* [Mastering Observables](http://docs.couchbase.com/developer/java-2.0/observables.html) from the Couchbase documentation -* [Reactive Programming in Java 8 With RxJava](http://pluralsight.com/training/Courses/TableOfContents/reactive-programming-java-8-rxjava), a course designed by Russell Elledge -* [33rd Degree Reactive Java](http://www.slideshare.net/tkowalcz/33rd-degree-reactive-java) by Tomasz Kowalczewski +* [Mastering Observables](http://docs.couchbase.com/developer/java-2.0/observables.html) from the Couchbase documentation **(1.x)** +* [Reactive Programming in Java 8 With RxJava](http://pluralsight.com/training/Courses/TableOfContents/reactive-programming-java-8-rxjava), a course designed by Russell Elledge **(1.x)** +* [33rd Degree Reactive Java](http://www.slideshare.net/tkowalcz/33rd-degree-reactive-java) by Tomasz Kowalczewski **(1.x)** * [What Every Hipster Should Know About Functional Reactive Programming](http://www.infoq.com/presentations/game-functional-reactive-programming) - Bodil Stokke demos the creation of interactive game mechanics in RxJS * [Your Mouse is a Database](http://queue.acm.org/detail.cfm?id=2169076) by Erik Meijer * [A Playful Introduction to Rx](https://www.youtube.com/watch?v=WKore-AkisY) a video lecture by Erik Meijer @@ -14,18 +14,17 @@ * [2 minute introduction to Rx](https://medium.com/@andrestaltz/2-minute-introduction-to-rx-24c8ca793877) by André Staltz * StackOverflow: [What is (functional) reactive programming?](http://stackoverflow.com/a/1030631/1946802) * [The Reactive Manifesto](http://www.reactivemanifesto.org/) -* Grokking RxJava, [Part 1: The Basics](http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/), [Part 2: Operator, Operator](http://blog.danlew.net/2014/09/22/grokking-rxjava-part-2/), [Part 3: Reactive with Benefits](http://blog.danlew.net/2014/09/30/grokking-rxjava-part-3/), [Part 4: Reactive Android](http://blog.danlew.net/2014/10/08/grokking-rxjava-part-4/) - published in Sep/Oct 2014 by Daniel Lew -* [FRP on Android](http://slides.com/yaroslavheriatovych/frponandroid#/) - publish in Jan 2014 by Yaroslav Heriatovych +* Grokking RxJava, [Part 1: The Basics](http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/), [Part 2: Operator, Operator](http://blog.danlew.net/2014/09/22/grokking-rxjava-part-2/), [Part 3: Reactive with Benefits](http://blog.danlew.net/2014/09/30/grokking-rxjava-part-3/), [Part 4: Reactive Android](http://blog.danlew.net/2014/10/08/grokking-rxjava-part-4/) - published in Sep/Oct 2014 by Daniel Lew **(1.x)** # How Netflix Is Using RxJava -* LambdaJam Chicago 2013: [Functional Reactive Programming in the Netflix API](https://speakerdeck.com/benjchristensen/functional-reactive-programming-in-the-netflix-api-lambdajam-2013) by Ben Christensen -* QCon London 2013 presentation: [Functional Reactive Programming in the Netflix API](http://www.infoq.com/presentations/netflix-functional-rx) and a related [interview](http://www.infoq.com/interviews/christensen-hystrix-rxjava) with Ben Christensen -* [Functional Reactive in the Netflix API with RxJava](http://techblog.netflix.com/2013/02/rxjava-netflix-api.html) by Ben Christensen and Jafar Husain -* [Optimizing the Netflix API](http://techblog.netflix.com/2013/01/optimizing-netflix-api.html) by Ben Christensen -* [Reactive Programming at Netflix](http://techblog.netflix.com/2013/01/reactive-programming-at-netflix.html) by Jafar Husain +* LambdaJam Chicago 2013: [Functional Reactive Programming in the Netflix API](https://speakerdeck.com/benjchristensen/functional-reactive-programming-in-the-netflix-api-lambdajam-2013) by Ben Christensen **(1.x)** +* QCon London 2013 presentation: [Functional Reactive Programming in the Netflix API](http://www.infoq.com/presentations/netflix-functional-rx) and a related [interview](http://www.infoq.com/interviews/christensen-hystrix-rxjava) with Ben Christensen **(1.x)** +* [Functional Reactive in the Netflix API with RxJava](http://techblog.netflix.com/2013/02/rxjava-netflix-api.html) by Ben Christensen and Jafar Husain **(1.x)** +* [Optimizing the Netflix API](http://techblog.netflix.com/2013/01/optimizing-netflix-api.html) by Ben Christensen **(1.x)** +* [Reactive Programming at Netflix](http://techblog.netflix.com/2013/01/reactive-programming-at-netflix.html) by Jafar Husain **(1.x)** # RxScala -* [RxJava: Reactive Extensions in Scala](http://www.youtube.com/watch?v=tOMK_FYJREw&feature=youtu.be): video of Ben Christensen and Matt Jacobs presenting at SF Scala +* [RxJava: Reactive Extensions in Scala](http://www.youtube.com/watch?v=tOMK_FYJREw&feature=youtu.be): video of Ben Christensen and Matt Jacobs presenting at SF Scala **(1.x)** # Rx.NET * [rx.codeplex.com](https://rx.codeplex.com) @@ -44,7 +43,20 @@ * [RxJS](https://xgrommx.github.io/rx-book/), an on-line book by @xgrommx * [Journey from procedural to reactive Javascript with stops](https://glebbahmutov.com/blog/journey-from-procedural-to-reactive-javascript-with-stops/) by Gleb Bahmutov +# RxAndroid + +* [FRP on Android](http://slides.com/yaroslavheriatovych/frponandroid#/) - publish in Jan 2014 by Yaroslav Heriatovych **(1.x)** +* [RxAndroid Github page](https://github.com/ReactiveX/RxAndroid) **(2.x)** +* [RxAndroid basics](https://medium.com/@kurtisnusbaum/rxandroid-basics-part-1-c0d5edcf6850) **(1.x & 2.x)** +* [RxJava and RxAndroid on AndroidHive](https://www.androidhive.info/RxJava/) **(1.x & 2.x)** +* [Reactive Programming with RxAndroid in Kotlin: An Introduction](https://www.raywenderlich.com/384-reactive-programming-with-rxandroid-in-kotlin-an-introduction) **(2.x)** +* [Difference between RxJava and RxAndroid](https://stackoverflow.com/questions/49651249/difference-between-rxjava-and-rxandroid) **(2.x)** +* [Reactive programming with RxAndroid](https://www.androidauthority.com/reactive-programming-with-rxandroid-711104/) **(1.x)** +* [RxJava - Vogella.com](http://www.vogella.com/tutorials/RxJava/article.html) **(2.x)** +* [Funcitional reactive Android](https://www.toptal.com/android/functional-reactive-android-rxjava) **(1.x)** +* [Reactive Programming with RxAndroid and Kotlin](https://www.pluralsight.com/courses/rxandroid-kotlin-reactive-programming) + # Miscellany -* [RxJava Observables and Akka Actors](http://onoffswitch.net/rxjava-observables-akka-actors/) by Anton Kropp -* [Vert.x and RxJava](http://slid.es/petermd/eclipsecon2014) by @petermd -* [RxJava in Different Flavours of Java](http://instil.co/2014/08/05/rxjava-in-different-flavours-of-java/): Java 7 and Java 8 implementations of the same code \ No newline at end of file +* [RxJava Observables and Akka Actors](http://onoffswitch.net/rxjava-observables-akka-actors/) by Anton Kropp **(1.x & 2.x)** +* [Vert.x and RxJava](http://slid.es/petermd/eclipsecon2014) by @petermd **(1.x)** +* [RxJava in Different Flavours of Java](http://instil.co/2014/08/05/rxjava-in-different-flavours-of-java/): Java 7 and Java 8 implementations of the same code **(1.x)** From 2e566fbc34e47de59cf76d862e5bfb631e36215c Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 28 Aug 2018 17:33:10 +0200 Subject: [PATCH 069/211] 2.x: Cleanup multiple empty lines in sources (#6182) --- gradle/stylesheet.css | 1 - src/jmh/java/io/reactivex/XMapYPerf.java | 4 - src/main/java/io/reactivex/Completable.java | 2 - src/main/java/io/reactivex/Flowable.java | 6 - src/main/java/io/reactivex/Maybe.java | 9 -- src/main/java/io/reactivex/Observable.java | 1 - src/main/java/io/reactivex/Scheduler.java | 1 - src/main/java/io/reactivex/Single.java | 2 - .../disposables/CancellableDisposable.java | 1 - .../disposables/DisposableHelper.java | 1 - .../internal/disposables/EmptyDisposable.java | 1 - .../disposables/SequentialDisposable.java | 1 - .../internal/fuseable/QueueFuseable.java | 1 - .../observers/BasicIntQueueDisposable.java | 1 - .../observers/BiConsumerSingleObserver.java | 1 - .../CallbackCompletableObserver.java | 1 - .../observers/ConsumerSingleObserver.java | 1 - .../observers/EmptyCompletableObserver.java | 1 - .../observers/ForEachWhileObserver.java | 1 - .../observers/InnerQueuedObserver.java | 1 - .../completable/CompletableObserveOn.java | 1 - .../completable/CompletableUsing.java | 1 - .../operators/flowable/FlowableBuffer.java | 2 - .../flowable/FlowableBufferTimed.java | 2 - .../flowable/FlowableCombineLatest.java | 3 - .../operators/flowable/FlowableConcatMap.java | 6 - .../operators/flowable/FlowableCount.java | 1 - .../operators/flowable/FlowableCreate.java | 6 - .../flowable/FlowableDebounceTimed.java | 1 - .../FlowableDistinctUntilChanged.java | 1 - .../operators/flowable/FlowableFilter.java | 2 - .../flowable/FlowableFlattenIterable.java | 1 - .../operators/flowable/FlowableFromArray.java | 3 - .../flowable/FlowableFromIterable.java | 3 - .../operators/flowable/FlowableGroupJoin.java | 1 - .../operators/flowable/FlowableJoin.java | 1 - .../operators/flowable/FlowableMap.java | 1 - .../flowable/FlowableMapPublisher.java | 1 - .../flowable/FlowableOnBackpressureError.java | 1 - .../operators/flowable/FlowableRange.java | 3 - .../operators/flowable/FlowableRangeLong.java | 2 - .../flowable/FlowableReduceMaybe.java | 2 - .../operators/flowable/FlowableRefCount.java | 1 - .../flowable/FlowableRepeatWhen.java | 1 - .../operators/flowable/FlowableRetryWhen.java | 1 - .../operators/flowable/FlowableSwitchMap.java | 1 - .../flowable/FlowableThrottleFirstTimed.java | 2 - .../flowable/FlowableTimeoutTimed.java | 1 - .../operators/flowable/FlowableToList.java | 2 - .../operators/flowable/FlowableWindow.java | 4 - .../FlowableWindowBoundarySelector.java | 1 - .../operators/flowable/FlowableZip.java | 2 - .../internal/operators/maybe/MaybeAmb.java | 1 - .../maybe/MaybeCallbackObserver.java | 1 - .../internal/operators/maybe/MaybeCreate.java | 1 - .../operators/maybe/MaybeEqualSingle.java | 1 - .../internal/operators/maybe/MaybeFilter.java | 3 - .../maybe/MaybeFlatMapIterableFlowable.java | 1 - .../maybe/MaybeFlatMapIterableObservable.java | 1 - .../maybe/MaybeFlatMapNotification.java | 1 - .../operators/maybe/MaybeFlatten.java | 1 - .../internal/operators/maybe/MaybeMap.java | 3 - .../operators/maybe/MaybeMergeArray.java | 1 - .../operators/maybe/MaybeObserveOn.java | 1 - .../operators/maybe/MaybeOnErrorNext.java | 1 - .../operators/maybe/MaybeTimeoutMaybe.java | 3 - .../maybe/MaybeTimeoutPublisher.java | 5 - .../internal/operators/maybe/MaybeUsing.java | 1 - .../operators/maybe/MaybeZipArray.java | 2 - .../BlockingObservableIterable.java | 1 - .../BlockingObservableMostRecent.java | 1 - .../observable/ObservableBufferTimed.java | 1 - .../observable/ObservableConcatMap.java | 1 - .../observable/ObservableCreate.java | 1 - .../observable/ObservableFlatMap.java | 1 - .../observable/ObservableGroupJoin.java | 1 - .../observable/ObservableInternalHelper.java | 1 - .../observable/ObservableInterval.java | 1 - .../observable/ObservableIntervalRange.java | 1 - .../operators/observable/ObservableJoin.java | 1 - .../operators/observable/ObservableMap.java | 2 - .../observable/ObservableMaterialize.java | 1 - .../ObservableThrottleFirstTimed.java | 2 - .../observable/ObservableTimeoutTimed.java | 1 - .../ObservableWindowBoundarySelector.java | 1 - .../observable/ObservableWindowTimed.java | 1 - .../operators/parallel/ParallelCollect.java | 1 - .../parallel/ParallelFromPublisher.java | 1 - .../operators/parallel/ParallelReduce.java | 1 - .../parallel/ParallelReduceFull.java | 1 - .../parallel/ParallelSortedJoin.java | 1 - .../single/SingleDelayWithCompletable.java | 1 - .../single/SingleDelayWithObservable.java | 1 - .../single/SingleDelayWithPublisher.java | 1 - .../single/SingleDelayWithSingle.java | 1 - .../single/SingleFlatMapIterableFlowable.java | 1 - .../SingleFlatMapIterableObservable.java | 1 - .../operators/single/SingleToFlowable.java | 1 - .../operators/single/SingleZipArray.java | 2 - .../schedulers/ComputationScheduler.java | 1 - .../schedulers/ExecutorScheduler.java | 1 - .../internal/schedulers/NewThreadWorker.java | 1 - .../subscribers/ForEachWhileSubscriber.java | 1 - .../subscribers/InnerQueuedSubscriber.java | 1 - .../BasicIntQueueSubscription.java | 1 - .../subscriptions/BasicQueueSubscription.java | 1 - .../DeferredScalarSubscription.java | 1 - .../util/AppendOnlyLinkedArrayList.java | 1 - .../internal/util/AtomicThrowable.java | 1 - .../internal/util/HalfSerializer.java | 1 - .../reactivex/internal/util/OpenHashSet.java | 1 - .../java/io/reactivex/internal/util/Pow2.java | 1 - .../reactivex/observers/BaseTestConsumer.java | 4 - .../reactivex/parallel/ParallelFlowable.java | 2 - .../processors/BehaviorProcessor.java | 2 - .../reactivex/processors/ReplayProcessor.java | 1 - .../processors/UnicastProcessor.java | 1 - .../reactivex/subjects/BehaviorSubject.java | 1 - .../io/reactivex/subjects/ReplaySubject.java | 2 - .../io/reactivex/subjects/UnicastSubject.java | 2 - .../reactivex/subscribers/SafeSubscriber.java | 1 - .../reactivex/subscribers/TestSubscriber.java | 1 - .../reactivex/exceptions/TestException.java | 2 - .../flowable/FlowableBackpressureTests.java | 1 - .../flowable/FlowableSubscriberTest.java | 3 +- .../reactivex/flowable/FlowableZipTests.java | 1 - .../reactivex/internal/SubscribeWithTest.java | 1 - .../operators/flowable/FlowableCacheTest.java | 1 - .../flowable/FlowableConcatTest.java | 1 - .../flowable/FlowableDetachTest.java | 1 - .../FlowableDistinctUntilChangedTest.java | 1 - .../flowable/FlowableFlatMapTest.java | 1 - ...wableOnBackpressureBufferStrategyTest.java | 1 - ...eOnExceptionResumeNextViaFlowableTest.java | 1 - .../flowable/FlowablePublishFunctionTest.java | 1 - .../flowable/FlowableReplayTest.java | 5 - .../flowable/FlowableSwitchIfEmptyTest.java | 2 - .../flowable/FlowableSwitchTest.java | 1 - .../FlowableWindowWithFlowableTest.java | 3 - .../flowable/FlowableWindowWithTimeTest.java | 1 - .../flowable/NotificationLiteTest.java | 1 - .../operators/maybe/MaybeConcatArrayTest.java | 1 - .../maybe/MaybeFromCompletableTest.java | 1 - .../operators/maybe/MaybeZipArrayTest.java | 1 - .../observable/ObservableCacheTest.java | 1 - .../observable/ObservableConcatTest.java | 1 - .../observable/ObservableDebounceTest.java | 1 - .../observable/ObservableDetachTest.java | 1 - .../observable/ObservableFlatMapTest.java | 1 - .../ObservableFromCallableTest.java | 3 - ...nExceptionResumeNextViaObservableTest.java | 1 - .../observable/ObservableReplayTest.java | 4 - .../ObservableSwitchIfEmptyTest.java | 2 - .../ObservableWindowWithObservableTest.java | 2 - .../ObservableWindowWithSizeTest.java | 1 - .../ObservableWindowWithTimeTest.java | 1 - .../ObservableWithLatestFromTest.java | 1 - .../single/SingleInternalHelperTest.java | 1 - .../operators/single/SingleZipArrayTest.java | 1 - .../ExecutorSchedulerDelayedRunnableTest.java | 1 - .../DeferredScalarSubscriberTest.java | 1 - .../reactivex/observers/ObserverFusion.java | 1 - .../reactivex/observers/TestObserverTest.java | 3 - .../reactivex/plugins/RxJavaPluginsTest.java | 2 - .../processors/AsyncProcessorTest.java | 1 - .../processors/BehaviorProcessorTest.java | 2 - .../processors/PublishProcessorTest.java | 1 - .../processors/ReplayProcessorTest.java | 3 - .../processors/UnicastProcessorTest.java | 2 - .../schedulers/AbstractSchedulerTests.java | 1 - .../schedulers/ExecutorSchedulerTest.java | 1 - .../schedulers/SchedulerLifecycleTest.java | 1 - .../io/reactivex/single/SingleNullTests.java | 1 - .../reactivex/subjects/AsyncSubjectTest.java | 1 - .../subjects/BehaviorSubjectTest.java | 2 - .../subjects/PublishSubjectTest.java | 1 - .../subjects/UnicastSubjectTest.java | 2 - .../subscribers/TestSubscriberTest.java | 4 - .../validators/JavadocForAnnotations.java | 1 - .../validators/NewLinesBeforeAnnotation.java | 2 +- .../ParamValidationCheckerTest.java | 1 - .../validators/TooManyEmptyNewLines.java | 132 ++++++++++++++++++ 182 files changed, 134 insertions(+), 277 deletions(-) create mode 100644 src/test/java/io/reactivex/validators/TooManyEmptyNewLines.java diff --git a/gradle/stylesheet.css b/gradle/stylesheet.css index 5e381dce8b..60f1d665bf 100644 --- a/gradle/stylesheet.css +++ b/gradle/stylesheet.css @@ -534,7 +534,6 @@ td.colLast div { padding-top:0px; } - td.colLast a { padding-bottom:3px; } diff --git a/src/jmh/java/io/reactivex/XMapYPerf.java b/src/jmh/java/io/reactivex/XMapYPerf.java index 389a89000f..d9e198b284 100644 --- a/src/jmh/java/io/reactivex/XMapYPerf.java +++ b/src/jmh/java/io/reactivex/XMapYPerf.java @@ -94,7 +94,6 @@ public class XMapYPerf { Observable obsFlatMapIterableAsObs0; - @Setup public void setup() { Integer[] values = new Integer[times]; @@ -158,7 +157,6 @@ public Iterable apply(Integer v) throws Exception { } }); - flowFlatMapSingle1 = fsource.flatMapSingle(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { @@ -231,7 +229,6 @@ public Publisher apply(Integer v) throws Exception { } }); - // ------------------------------------------------------------------- Observable osource = Observable.fromArray(values); @@ -271,7 +268,6 @@ public MaybeSource apply(Integer v) throws Exception { } }); - obsFlatMapCompletable0 = osource.flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index cb08465a2a..6cf5aa75f4 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -388,7 +388,6 @@ public static Completable error(final Throwable error) { return RxJavaPlugins.onAssembly(new CompletableError(error)); } - /** * Returns a Completable instance that runs the given Action for each subscriber and * emits either an unchecked exception or simply completes. @@ -790,7 +789,6 @@ public static Completable mergeDelayError(Iterable return RxJavaPlugins.onAssembly(new CompletableMergeDelayErrorIterable(sources)); } - /** * Returns a Completable that subscribes to all Completables in the source sequence and delays * any error emitted by either the sources observable or any of the inner Completables until all of diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 15abe6bd95..bab8443357 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -3474,7 +3474,6 @@ public static Flowable mergeDelayError(Iterable Flowable mergeDelayError(Publisher source1, Pu return fromArray(source1, source2, source3).flatMap((Function)Functions.identity(), true, 3); } - /** * Flattens four Publishers into one Publisher, in a way that allows a Subscriber to receive all * successfully emitted items from all of the source Publishers without being interrupted by an error @@ -4629,7 +4627,6 @@ public static Flowable zip( return zipArray(Functions.toFunction(zipper), delayError, bufferSize(), source1, source2); } - /** * Returns a Flowable that emits the results of a specified combiner function applied to combinations of * two items emitted, in sequence, by two other Publishers. @@ -7357,7 +7354,6 @@ public final Flowable concatMapDelayError(Function(this, mapper, prefetch, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY)); } - /** * Maps a sequence of values into Publishers and concatenates these Publishers eagerly into a single * Publisher. @@ -10749,7 +10745,6 @@ public final Flowable join( this, other, leftEnd, rightEnd, resultSelector)); } - /** * Returns a Maybe that emits the last item emitted by this Flowable or completes if * this Flowable is empty. @@ -14703,7 +14698,6 @@ public final Flowable switchMap(Function Maybe fromRunnable(final Runnable run) { return RxJavaPlugins.onAssembly(new MaybeFromRunnable(run)); } - /** * Returns a {@code Maybe} that emits a specified item. *

    @@ -1238,7 +1237,6 @@ public static Flowable mergeArrayDelayError(MaybeSource... s return Flowable.fromArray(sources).flatMap((Function)MaybeToPublisher.instance(), true, sources.length); } - /** * Flattens an Iterable of MaybeSources into one Flowable, in a way that allows a Subscriber to receive all * successfully emitted items from each of the source MaybeSources without being interrupted by an error @@ -1274,7 +1272,6 @@ public static Flowable mergeDelayError(Iterable Flowable mergeDelayError(Publisher Flowable mergeDelayError(MaybeSource source1, return mergeArrayDelayError(source1, source2, source3); } - /** * Flattens four MaybeSources into one Flowable, in a way that allows a Subscriber to receive all * successfully emitted items from all of the source MaybeSources without being interrupted by an error @@ -1503,7 +1498,6 @@ public static Maybe never() { return RxJavaPlugins.onAssembly((Maybe)MaybeNever.INSTANCE); } - /** * Returns a Single that emits a Boolean value that indicates whether two MaybeSource sequences are the * same by comparing the items emitted by each MaybeSource pairwise. @@ -2388,7 +2382,6 @@ public final Maybe concatMap(Function(this, mapper)); } - /** * Returns a Flowable that emits the items emitted from the current MaybeSource, then the next, one after * the other, without interleaving them. @@ -2486,7 +2479,6 @@ public final Maybe defaultIfEmpty(T defaultItem) { return switchIfEmpty(just(defaultItem)); } - /** * Returns a Maybe that signals the events emitted by the source Maybe shifted forward in time by a * specified delay. @@ -3838,7 +3830,6 @@ public final Flowable repeatWhen(final Function, ? e return toFlowable().repeatWhen(handler); } - /** * Returns a Maybe that mirrors the source Maybe, resubscribing to it if it calls {@code onError} * (infinite retry count). diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 9781a3dad4..d1adc46efa 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -5429,7 +5429,6 @@ public final void blockingSubscribe(Consumer onNext, Consumeron the current thread. *

    diff --git a/src/main/java/io/reactivex/Scheduler.java b/src/main/java/io/reactivex/Scheduler.java index 0f4806d4a0..2e99e288f1 100644 --- a/src/main/java/io/reactivex/Scheduler.java +++ b/src/main/java/io/reactivex/Scheduler.java @@ -110,7 +110,6 @@ public static long clockDriftTolerance() { return CLOCK_DRIFT_TOLERANCE_NANOSECONDS; } - /** * Retrieves or creates a new {@link Scheduler.Worker} that represents sequential execution of actions. *

    diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index b6896e7cec..51a896c887 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -1072,7 +1072,6 @@ public static Flowable merge( return merge(Flowable.fromArray(source1, source2, source3, source4)); } - /** * Merges an Iterable sequence of SingleSource instances into a single Flowable sequence, * running all SingleSources at once and delaying any error(s) until all sources succeed or fail. @@ -1121,7 +1120,6 @@ public static Flowable mergeDelayError(Publisher implements Disposable { - private static final long serialVersionUID = 5718521705281392066L; public CancellableDisposable(Cancellable cancellable) { diff --git a/src/main/java/io/reactivex/internal/disposables/DisposableHelper.java b/src/main/java/io/reactivex/internal/disposables/DisposableHelper.java index f9ad177399..46f13bd743 100644 --- a/src/main/java/io/reactivex/internal/disposables/DisposableHelper.java +++ b/src/main/java/io/reactivex/internal/disposables/DisposableHelper.java @@ -20,7 +20,6 @@ import io.reactivex.internal.functions.ObjectHelper; import io.reactivex.plugins.RxJavaPlugins; - /** * Utility methods for working with Disposables atomically. */ diff --git a/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java b/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java index f87df26a17..4e90491b69 100644 --- a/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java +++ b/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java @@ -114,5 +114,4 @@ public int requestFusion(int mode) { return mode & ASYNC; } - } diff --git a/src/main/java/io/reactivex/internal/disposables/SequentialDisposable.java b/src/main/java/io/reactivex/internal/disposables/SequentialDisposable.java index e250bf1925..458194ab63 100644 --- a/src/main/java/io/reactivex/internal/disposables/SequentialDisposable.java +++ b/src/main/java/io/reactivex/internal/disposables/SequentialDisposable.java @@ -28,7 +28,6 @@ public final class SequentialDisposable extends AtomicReference implements Disposable { - private static final long serialVersionUID = -754898800686245608L; /** diff --git a/src/main/java/io/reactivex/internal/fuseable/QueueFuseable.java b/src/main/java/io/reactivex/internal/fuseable/QueueFuseable.java index 850e9284af..f5e803807e 100644 --- a/src/main/java/io/reactivex/internal/fuseable/QueueFuseable.java +++ b/src/main/java/io/reactivex/internal/fuseable/QueueFuseable.java @@ -13,7 +13,6 @@ package io.reactivex.internal.fuseable; - /** * Represents a SimpleQueue plus the means and constants for requesting a fusion mode. * @param the value type returned by the SimpleQueue.poll() diff --git a/src/main/java/io/reactivex/internal/observers/BasicIntQueueDisposable.java b/src/main/java/io/reactivex/internal/observers/BasicIntQueueDisposable.java index 39d68c80dc..a5d2adf430 100644 --- a/src/main/java/io/reactivex/internal/observers/BasicIntQueueDisposable.java +++ b/src/main/java/io/reactivex/internal/observers/BasicIntQueueDisposable.java @@ -26,7 +26,6 @@ public abstract class BasicIntQueueDisposable extends AtomicInteger implements QueueDisposable { - private static final long serialVersionUID = -1001730202384742097L; @Override diff --git a/src/main/java/io/reactivex/internal/observers/BiConsumerSingleObserver.java b/src/main/java/io/reactivex/internal/observers/BiConsumerSingleObserver.java index e14425f70e..188c78b1b3 100644 --- a/src/main/java/io/reactivex/internal/observers/BiConsumerSingleObserver.java +++ b/src/main/java/io/reactivex/internal/observers/BiConsumerSingleObserver.java @@ -26,7 +26,6 @@ public final class BiConsumerSingleObserver extends AtomicReference implements SingleObserver, Disposable { - private static final long serialVersionUID = 4943102778943297569L; final BiConsumer onCallback; diff --git a/src/main/java/io/reactivex/internal/observers/CallbackCompletableObserver.java b/src/main/java/io/reactivex/internal/observers/CallbackCompletableObserver.java index 3555751a8e..ee059c5b37 100644 --- a/src/main/java/io/reactivex/internal/observers/CallbackCompletableObserver.java +++ b/src/main/java/io/reactivex/internal/observers/CallbackCompletableObserver.java @@ -27,7 +27,6 @@ public final class CallbackCompletableObserver extends AtomicReference implements CompletableObserver, Disposable, Consumer, LambdaConsumerIntrospection { - private static final long serialVersionUID = -4361286194466301354L; final Consumer onError; diff --git a/src/main/java/io/reactivex/internal/observers/ConsumerSingleObserver.java b/src/main/java/io/reactivex/internal/observers/ConsumerSingleObserver.java index 7c3c4ad3b7..59735e9c11 100644 --- a/src/main/java/io/reactivex/internal/observers/ConsumerSingleObserver.java +++ b/src/main/java/io/reactivex/internal/observers/ConsumerSingleObserver.java @@ -28,7 +28,6 @@ public final class ConsumerSingleObserver extends AtomicReference implements SingleObserver, Disposable, LambdaConsumerIntrospection { - private static final long serialVersionUID = -7012088219455310787L; final Consumer onSuccess; diff --git a/src/main/java/io/reactivex/internal/observers/EmptyCompletableObserver.java b/src/main/java/io/reactivex/internal/observers/EmptyCompletableObserver.java index 5b70ddb624..38d0f3746e 100644 --- a/src/main/java/io/reactivex/internal/observers/EmptyCompletableObserver.java +++ b/src/main/java/io/reactivex/internal/observers/EmptyCompletableObserver.java @@ -26,7 +26,6 @@ public final class EmptyCompletableObserver extends AtomicReference implements CompletableObserver, Disposable, LambdaConsumerIntrospection { - private static final long serialVersionUID = -7545121636549663526L; @Override diff --git a/src/main/java/io/reactivex/internal/observers/ForEachWhileObserver.java b/src/main/java/io/reactivex/internal/observers/ForEachWhileObserver.java index 54b8fdbd5c..22ba3f80a8 100644 --- a/src/main/java/io/reactivex/internal/observers/ForEachWhileObserver.java +++ b/src/main/java/io/reactivex/internal/observers/ForEachWhileObserver.java @@ -26,7 +26,6 @@ public final class ForEachWhileObserver extends AtomicReference implements Observer, Disposable { - private static final long serialVersionUID = -4403180040475402120L; final Predicate onNext; diff --git a/src/main/java/io/reactivex/internal/observers/InnerQueuedObserver.java b/src/main/java/io/reactivex/internal/observers/InnerQueuedObserver.java index 27d800e183..3a18b38153 100644 --- a/src/main/java/io/reactivex/internal/observers/InnerQueuedObserver.java +++ b/src/main/java/io/reactivex/internal/observers/InnerQueuedObserver.java @@ -31,7 +31,6 @@ public final class InnerQueuedObserver extends AtomicReference implements Observer, Disposable { - private static final long serialVersionUID = -5417183359794346637L; final InnerQueuedObserverSupport parent; diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java index 11dbebe280..b931ed4a5d 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableObserveOn.java @@ -38,7 +38,6 @@ static final class ObserveOnCompletableObserver extends AtomicReference implements CompletableObserver, Disposable, Runnable { - private static final long serialVersionUID = 8571289934935992137L; final CompletableObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java index 0dc127ec82..1f107f2c00 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableUsing.java @@ -88,7 +88,6 @@ static final class UsingObserver extends AtomicReference implements CompletableObserver, Disposable { - private static final long serialVersionUID = -674404550052917487L; final CompletableObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBuffer.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBuffer.java index bf0cda25b1..f2f940ac2e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBuffer.java @@ -159,7 +159,6 @@ static final class PublisherBufferSkipSubscriber, Subscription { - private static final long serialVersionUID = -5616169793639412593L; final Subscriber downstream; @@ -286,7 +285,6 @@ public void onComplete() { } } - static final class PublisherBufferOverlappingSubscriber> extends AtomicLong implements FlowableSubscriber, Subscription, BooleanSupplier { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java index 48212822ff..4e3be8a9e5 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java @@ -78,7 +78,6 @@ protected void subscribeActual(Subscriber s) { bufferSupplier, timespan, timeskip, unit, w)); } - static final class BufferExactUnboundedSubscriber> extends QueueDrainSubscriber implements Subscription, Runnable, Disposable { final Callable bufferSupplier; @@ -236,7 +235,6 @@ static final class BufferSkipBoundedSubscriber actual, Callable bufferSupplier, long timespan, long timeskip, TimeUnit unit, Worker w) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCombineLatest.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCombineLatest.java index a4bc8f6bc4..c690701fcf 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCombineLatest.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCombineLatest.java @@ -136,7 +136,6 @@ public void subscribeActual(Subscriber s) { return; } - CombineLatestCoordinator coordinator = new CombineLatestCoordinator(s, combiner, n, bufferSize, delayErrors); @@ -148,7 +147,6 @@ public void subscribeActual(Subscriber s) { static final class CombineLatestCoordinator extends BasicIntQueueSubscription { - private static final long serialVersionUID = -5082275438355852221L; final Subscriber downstream; @@ -494,7 +492,6 @@ static final class CombineLatestInnerSubscriber extends AtomicReference implements FlowableSubscriber { - private static final long serialVersionUID = -8730235182291002949L; final CombineLatestCoordinator parent; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java index bb408ef6c8..edde82442e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java @@ -173,11 +173,9 @@ public final void innerComplete() { } - static final class ConcatMapImmediate extends BaseConcatMapSubscriber { - private static final long serialVersionUID = 7898995095634264146L; final Subscriber downstream; @@ -303,7 +301,6 @@ void drain() { } } - if (p instanceof Callable) { @SuppressWarnings("unchecked") Callable callable = (Callable) p; @@ -320,7 +317,6 @@ void drain() { return; } - if (vr == null) { continue; } @@ -382,7 +378,6 @@ public void cancel() { static final class ConcatMapDelayed extends BaseConcatMapSubscriber { - private static final long serialVersionUID = -2945777694260521066L; final Subscriber downstream; @@ -569,7 +564,6 @@ static final class ConcatMapInner extends SubscriptionArbiter implements FlowableSubscriber { - private static final long serialVersionUID = 897683679971470653L; final ConcatMapSupport parent; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCount.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCount.java index ebe2b07024..b29e2690a1 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCount.java @@ -32,7 +32,6 @@ protected void subscribeActual(Subscriber s) { static final class CountSubscriber extends DeferredScalarSubscription implements FlowableSubscriber { - private static final long serialVersionUID = 4973004223787171406L; Subscription upstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCreate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCreate.java index e7d43e466b..caf6d31101 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCreate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCreate.java @@ -28,7 +28,6 @@ import io.reactivex.internal.util.*; import io.reactivex.plugins.RxJavaPlugins; - public final class FlowableCreate extends Flowable { final FlowableOnSubscribe source; @@ -352,7 +351,6 @@ public String toString() { static final class MissingEmitter extends BaseEmitter { - private static final long serialVersionUID = 3776720187248809713L; MissingEmitter(Subscriber downstream) { @@ -414,7 +412,6 @@ public final void onNext(T t) { static final class DropAsyncEmitter extends NoOverflowBaseAsyncEmitter { - private static final long serialVersionUID = 8360058422307496563L; DropAsyncEmitter(Subscriber downstream) { @@ -430,7 +427,6 @@ void onOverflow() { static final class ErrorAsyncEmitter extends NoOverflowBaseAsyncEmitter { - private static final long serialVersionUID = 338953216916120960L; ErrorAsyncEmitter(Subscriber downstream) { @@ -446,7 +442,6 @@ void onOverflow() { static final class BufferAsyncEmitter extends BaseEmitter { - private static final long serialVersionUID = 2427151001689639875L; final SpscLinkedArrayQueue queue; @@ -589,7 +584,6 @@ void drain() { static final class LatestAsyncEmitter extends BaseEmitter { - private static final long serialVersionUID = 4023437720691792495L; final AtomicReference queue; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java index b30a68c62d..51d365e849 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounceTimed.java @@ -175,7 +175,6 @@ static final class DebounceEmitter extends AtomicReference implem final AtomicBoolean once = new AtomicBoolean(); - DebounceEmitter(T value, long idx, DebounceTimedSubscriber parent) { this.value = value; this.idx = idx; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChanged.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChanged.java index f54be6360b..c1cf54658e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChanged.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChanged.java @@ -46,7 +46,6 @@ protected void subscribeActual(Subscriber s) { static final class DistinctUntilChangedSubscriber extends BasicFuseableSubscriber implements ConditionalSubscriber { - final Function keySelector; final BiPredicate comparer; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFilter.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFilter.java index 30487f90d7..dd90b2c1ec 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFilter.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFilter.java @@ -102,8 +102,6 @@ public T poll() throws Exception { } } } - - } static final class FilterConditionalSubscriber extends BasicFuseableConditionalSubscriber { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterable.java index 29e425f58e..01398b9a29 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterable.java @@ -85,7 +85,6 @@ static final class FlattenIterableSubscriber extends BasicIntQueueSubscription implements FlowableSubscriber { - private static final long serialVersionUID = -3096000382929934955L; final Subscriber downstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java index 25b7610eaa..c8c6201daa 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java @@ -98,7 +98,6 @@ public final void cancel() { cancelled = true; } - abstract void fastPath(); abstract void slowPath(long r); @@ -106,7 +105,6 @@ public final void cancel() { static final class ArraySubscription extends BaseArraySubscription { - private static final long serialVersionUID = 2587302975077663557L; final Subscriber downstream; @@ -190,7 +188,6 @@ void slowPath(long r) { static final class ArrayConditionalSubscription extends BaseArraySubscription { - private static final long serialVersionUID = 2587302975077663557L; final ConditionalSubscriber downstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java index 3c3017bcfb..e893dca7e8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromIterable.java @@ -139,7 +139,6 @@ public final void cancel() { static final class IteratorSubscription extends BaseRangeSubscription { - private static final long serialVersionUID = -6022804456014692607L; final Subscriber downstream; @@ -193,7 +192,6 @@ void fastPath() { return; } - if (!b) { if (!cancelled) { a.onComplete(); @@ -277,7 +275,6 @@ void slowPath(long r) { static final class IteratorConditionalSubscription extends BaseRangeSubscription { - private static final long serialVersionUID = -6022804456014692607L; final ConditionalSubscriber downstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java index d42e3e05af..c9a2b69adb 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java @@ -89,7 +89,6 @@ interface JoinSupport { static final class GroupJoinSubscription extends AtomicInteger implements Subscription, JoinSupport { - private static final long serialVersionUID = -6071216598687999801L; final Subscriber downstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableJoin.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableJoin.java index 5ff5c97c3f..2bd33b64a3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableJoin.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableJoin.java @@ -73,7 +73,6 @@ protected void subscribeActual(Subscriber s) { static final class JoinSubscription extends AtomicInteger implements Subscription, JoinSupport { - private static final long serialVersionUID = -6071216598687999801L; final Subscriber downstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMap.java index 905f3cb6cb..7b6632dcf9 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMap.java @@ -11,7 +11,6 @@ * the License for the specific language governing permissions and limitations under the License. */ - package io.reactivex.internal.operators.flowable; import org.reactivestreams.Subscriber; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapPublisher.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapPublisher.java index ac9fee861e..3378af4b15 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMapPublisher.java @@ -11,7 +11,6 @@ * the License for the specific language governing permissions and limitations under the License. */ - package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java index 5d758096c3..f60c43bc31 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java @@ -25,7 +25,6 @@ public final class FlowableOnBackpressureError extends AbstractFlowableWithUpstream { - public FlowableOnBackpressureError(Flowable source) { super(source); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java index 185218480e..d4b6b50a59 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRange.java @@ -100,7 +100,6 @@ public final void cancel() { cancelled = true; } - abstract void fastPath(); abstract void slowPath(long r); @@ -108,7 +107,6 @@ public final void cancel() { static final class RangeSubscription extends BaseRangeSubscription { - private static final long serialVersionUID = 2587302975077663557L; final Subscriber downstream; @@ -177,7 +175,6 @@ void slowPath(long r) { static final class RangeConditionalSubscription extends BaseRangeSubscription { - private static final long serialVersionUID = 2587302975077663557L; final ConditionalSubscriber downstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRangeLong.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRangeLong.java index 96bc5cddb0..d641e6a285 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRangeLong.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRangeLong.java @@ -102,7 +102,6 @@ public final void cancel() { cancelled = true; } - abstract void fastPath(); abstract void slowPath(long r); @@ -178,7 +177,6 @@ void slowPath(long r) { static final class RangeConditionalSubscription extends BaseRangeSubscription { - private static final long serialVersionUID = 2587302975077663557L; final ConditionalSubscriber downstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceMaybe.java index 7745c047a7..569dcdccf8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReduceMaybe.java @@ -138,7 +138,5 @@ public void onComplete() { downstream.onComplete(); } } - - } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java index deec615b20..82a1373228 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java @@ -114,7 +114,6 @@ void cancel(RefConnection rc) { sd.replace(scheduler.scheduleDirect(rc, timeout, unit)); } - void terminated(RefConnection rc) { synchronized (this) { if (connection != null) { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java index ce137d4f52..c5fac022ad 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java @@ -178,7 +178,6 @@ public final void cancel() { static final class RepeatWhenSubscriber extends WhenSourceSubscriber { - private static final long serialVersionUID = -2680129890138081029L; RepeatWhenSubscriber(Subscriber actual, FlowableProcessor processor, diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryWhen.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryWhen.java index 4cf535cd90..de0f735802 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryWhen.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryWhen.java @@ -64,7 +64,6 @@ public void subscribeActual(Subscriber s) { static final class RetryWhenSubscriber extends WhenSourceSubscriber { - private static final long serialVersionUID = -2680129890138081029L; RetryWhenSubscriber(Subscriber actual, FlowableProcessor processor, diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java index 0b00c03c9a..9730bd38b2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java @@ -57,7 +57,6 @@ static final class SwitchMapSubscriber extends AtomicInteger implements Fl final int bufferSize; final boolean delayErrors; - volatile boolean done; final AtomicThrowable error; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTimed.java index 727bd4d484..ca10e8d47c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTimed.java @@ -107,8 +107,6 @@ public void onNext(T t) { timer.replace(worker.schedule(this, timeout, unit)); } - - } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java index 9be6bc847b..28f00cfe1b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java @@ -152,7 +152,6 @@ public void cancel() { } } - static final class TimeoutTask implements Runnable { final TimeoutSupport parent; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableToList.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableToList.java index a49c3dcc8c..60508e3e7e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableToList.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableToList.java @@ -44,12 +44,10 @@ protected void subscribeActual(Subscriber s) { source.subscribe(new ToListSubscriber(s, coll)); } - static final class ToListSubscriber> extends DeferredScalarSubscription implements FlowableSubscriber, Subscription { - private static final long serialVersionUID = -8134157938864266736L; Subscription upstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindow.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindow.java index bbe2f2b6e0..e9c1259b65 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindow.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindow.java @@ -55,7 +55,6 @@ static final class WindowExactSubscriber extends AtomicInteger implements FlowableSubscriber, Subscription, Runnable { - private static final long serialVersionUID = -2365647875069161133L; final Subscriber> downstream; @@ -164,7 +163,6 @@ static final class WindowSkipSubscriber extends AtomicInteger implements FlowableSubscriber, Subscription, Runnable { - private static final long serialVersionUID = -8792836352386833856L; final Subscriber> downstream; @@ -211,7 +209,6 @@ public void onNext(T t) { if (i == 0) { getAndIncrement(); - w = UnicastProcessor.create(bufferSize, this); window = w; @@ -292,7 +289,6 @@ static final class WindowOverlapSubscriber extends AtomicInteger implements FlowableSubscriber, Subscription, Runnable { - private static final long serialVersionUID = 2428527070996323976L; final Subscriber> downstream; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java index 246b1be106..0e3fe58b83 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java @@ -240,7 +240,6 @@ void drainLoop() { continue; } - w = UnicastProcessor.create(bufferSize); long r = requested(); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableZip.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableZip.java index 1d585cc02c..b8516a93e9 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableZip.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableZip.java @@ -83,7 +83,6 @@ static final class ZipCoordinator extends AtomicInteger implements Subscription { - private static final long serialVersionUID = -2434867452883857743L; final Subscriber downstream; @@ -320,7 +319,6 @@ void drain() { } } - static final class ZipSubscriber extends AtomicReference implements FlowableSubscriber, Subscription { private static final long serialVersionUID = -4627193790118206028L; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java index fb6940c479..d9c1c6963c 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java @@ -91,7 +91,6 @@ static final class AmbMaybeObserver extends AtomicBoolean implements MaybeObserver, Disposable { - private static final long serialVersionUID = -7044685185359438206L; final MaybeObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCallbackObserver.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCallbackObserver.java index 1a3da7d04b..9dc56e137f 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCallbackObserver.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCallbackObserver.java @@ -33,7 +33,6 @@ public final class MaybeCallbackObserver extends AtomicReference implements MaybeObserver, Disposable, LambdaConsumerIntrospection { - private static final long serialVersionUID = -6076952298809384986L; final Consumer onSuccess; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java index 5a3852662a..e328a2b3c7 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java @@ -59,7 +59,6 @@ static final class Emitter this.downstream = downstream; } - private static final long serialVersionUID = -2467358622224974244L; @Override diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeEqualSingle.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeEqualSingle.java index 4f843635aa..f5f83fbcfc 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeEqualSingle.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeEqualSingle.java @@ -127,7 +127,6 @@ static final class EqualObserver extends AtomicReference implements MaybeObserver { - private static final long serialVersionUID = -3031974433025990931L; final EqualCoordinator parent; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilter.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilter.java index fd556c3a66..763ad258e0 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilter.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFilter.java @@ -101,8 +101,5 @@ public void onError(Throwable e) { public void onComplete() { downstream.onComplete(); } - - } - } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowable.java index 5ea9adb386..f4d174d924 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowable.java @@ -158,7 +158,6 @@ void fastPath(Subscriber a, Iterator iterator) { return; } - boolean b; try { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java index 4e5755fb8f..5513eb5e8f 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java @@ -128,7 +128,6 @@ public void onSuccess(T value) { return; } - boolean b; try { diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotification.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotification.java index f5bb71e110..81eb167484 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotification.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotification.java @@ -56,7 +56,6 @@ static final class FlatMapMaybeObserver extends AtomicReference implements MaybeObserver, Disposable { - private static final long serialVersionUID = 4375739915521278546L; final MaybeObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatten.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatten.java index b05aebd236..6463ef270b 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatten.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatten.java @@ -46,7 +46,6 @@ static final class FlatMapMaybeObserver extends AtomicReference implements MaybeObserver, Disposable { - private static final long serialVersionUID = 4375739915521278546L; final MaybeObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeMap.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMap.java index cda167855c..7d7c7a47b5 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeMap.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMap.java @@ -98,8 +98,5 @@ public void onError(Throwable e) { public void onComplete() { downstream.onComplete(); } - - } - } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeMergeArray.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMergeArray.java index 762452ba7a..1edfdd69da 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeMergeArray.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMergeArray.java @@ -318,7 +318,6 @@ static final class MpscFillOnceSimpleQueue extends AtomicReferenceArray implements SimpleQueueWithConsumerIndex { - private static final long serialVersionUID = -7969063454040569579L; final AtomicInteger producerIndex; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeObserveOn.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeObserveOn.java index a3d83612d5..cce201fedb 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeObserveOn.java @@ -42,7 +42,6 @@ static final class ObserveOnMaybeObserver extends AtomicReference implements MaybeObserver, Disposable, Runnable { - private static final long serialVersionUID = 8571289934935992137L; final MaybeObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorNext.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorNext.java index 5591d41c20..f7fff884ad 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorNext.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeOnErrorNext.java @@ -50,7 +50,6 @@ static final class OnErrorNextMaybeObserver extends AtomicReference implements MaybeObserver, Disposable { - private static final long serialVersionUID = 2026620218879969836L; final MaybeObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutMaybe.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutMaybe.java index d162573139..83d22cf232 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutMaybe.java @@ -54,7 +54,6 @@ static final class TimeoutMainMaybeObserver extends AtomicReference implements MaybeObserver, Disposable { - private static final long serialVersionUID = -5955289211445418871L; final MaybeObserver downstream; @@ -141,7 +140,6 @@ static final class TimeoutOtherMaybeObserver extends AtomicReference implements MaybeObserver { - private static final long serialVersionUID = 8663801314800248617L; final TimeoutMainMaybeObserver parent; @@ -174,7 +172,6 @@ static final class TimeoutFallbackMaybeObserver extends AtomicReference implements MaybeObserver { - private static final long serialVersionUID = 8663801314800248617L; final MaybeObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisher.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisher.java index 64ab706f5e..f0d690d567 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisher.java @@ -57,7 +57,6 @@ static final class TimeoutMainMaybeObserver extends AtomicReference implements MaybeObserver, Disposable { - private static final long serialVersionUID = -5955289211445418871L; final MaybeObserver downstream; @@ -144,7 +143,6 @@ static final class TimeoutOtherMaybeObserver extends AtomicReference implements FlowableSubscriber { - private static final long serialVersionUID = 8663801314800248617L; final TimeoutMainMaybeObserver parent; @@ -179,7 +177,6 @@ static final class TimeoutFallbackMaybeObserver extends AtomicReference implements MaybeObserver { - private static final long serialVersionUID = 8663801314800248617L; final MaybeObserver downstream; @@ -208,6 +205,4 @@ public void onComplete() { downstream.onComplete(); } } - - } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeUsing.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeUsing.java index 786772eacf..4628d1261c 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeUsing.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeUsing.java @@ -99,7 +99,6 @@ static final class UsingObserver extends AtomicReference implements MaybeObserver, Disposable { - private static final long serialVersionUID = -674404550052917487L; final MaybeObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeZipArray.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeZipArray.java index 430d3ff2b6..d9cc0028af 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeZipArray.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeZipArray.java @@ -39,7 +39,6 @@ protected void subscribeActual(MaybeObserver observer) { MaybeSource[] sources = this.sources; int n = sources.length; - if (n == 1) { sources[0].subscribe(new MaybeMap.MapMaybeObserver(observer, new SingletonArrayFunc())); return; @@ -66,7 +65,6 @@ protected void subscribeActual(MaybeObserver observer) { static final class ZipCoordinator extends AtomicInteger implements Disposable { - private static final long serialVersionUID = -5556924161382950569L; final MaybeObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java index 776721c84e..3fdd26f9b6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java @@ -44,7 +44,6 @@ static final class BlockingObservableIterator extends AtomicReference implements io.reactivex.Observer, Iterator, Disposable { - private static final long serialVersionUID = 6695226475494099826L; final SpscLinkedArrayQueue queue; diff --git a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecent.java b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecent.java index 44156e1171..90a603f65c 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecent.java +++ b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecent.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; - import java.util.*; import io.reactivex.ObservableSource; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java index 59358c79a9..8a6fafea6e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java @@ -223,7 +223,6 @@ static final class BufferSkipBoundedObserver> final Worker w; final List buffers; - Disposable upstream; BufferSkipBoundedObserver(Observer actual, diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java index 642f0e01f1..831cfd1c55 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java @@ -273,7 +273,6 @@ static final class ConcatMapDelayErrorObserver extends AtomicInteger implements Observer, Disposable { - private static final long serialVersionUID = -6951100001833242599L; final Observer downstream; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCreate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCreate.java index 1e48bdabee..03ba3f1186 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCreate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCreate.java @@ -48,7 +48,6 @@ static final class CreateEmitter extends AtomicReference implements ObservableEmitter, Disposable { - private static final long serialVersionUID = -3434801548987643227L; final Observer observer; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java index 0bc25cebaf..9039aa78a6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java @@ -232,7 +232,6 @@ boolean tryEmitScalar(Callable value) { return true; } - if (get() == 0 && compareAndSet(0, 1)) { downstream.onNext(u); if (decrementAndGet() == 0) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java index 3b4baaa78a..23e39af881 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupJoin.java @@ -88,7 +88,6 @@ interface JoinSupport { static final class GroupJoinDisposable extends AtomicInteger implements Disposable, JoinSupport { - private static final long serialVersionUID = -6071216598687999801L; final Observer downstream; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableInternalHelper.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableInternalHelper.java index 0af4a15f0a..733b18f0ee 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableInternalHelper.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableInternalHelper.java @@ -83,7 +83,6 @@ public static Function> itemDelay(final Function(itemDelay); } - static final class ObserverOnNext implements Consumer { final Observer observer; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java index f786cffaba..947a3941fa 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableInterval.java @@ -56,7 +56,6 @@ static final class IntervalObserver extends AtomicReference implements Disposable, Runnable { - private static final long serialVersionUID = 346773832286157679L; final Observer downstream; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java index 2e69495e66..5d48d1d3d0 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableIntervalRange.java @@ -60,7 +60,6 @@ static final class IntervalRangeObserver extends AtomicReference implements Disposable, Runnable { - private static final long serialVersionUID = 1891866368734007884L; final Observer downstream; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java index b8393e3f78..9a293ca7d5 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableJoin.java @@ -74,7 +74,6 @@ protected void subscribeActual(Observer observer) { static final class JoinDisposable extends AtomicInteger implements Disposable, JoinSupport { - private static final long serialVersionUID = -6071216598687999801L; final Observer downstream; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMap.java index 5df2a6c341..475963ce85 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMap.java @@ -11,7 +11,6 @@ * the License for the specific language governing permissions and limitations under the License. */ - package io.reactivex.internal.operators.observable; import io.reactivex.*; @@ -33,7 +32,6 @@ public void subscribeActual(Observer t) { source.subscribe(new MapObserver(t, function)); } - static final class MapObserver extends BasicFuseableObserver { final Function mapper; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java index a82668cfc3..9cfe82b16a 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMaterialize.java @@ -19,7 +19,6 @@ public final class ObservableMaterialize extends AbstractObservableWithUpstream> { - public ObservableMaterialize(ObservableSource source) { super(source); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTimed.java index 54e94ab0b7..ab1ce459f4 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTimed.java @@ -87,8 +87,6 @@ public void onNext(T t) { } DisposableHelper.replace(this, worker.schedule(this, timeout, unit)); } - - } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java index 7c955939c0..7ceda44b73 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java @@ -147,7 +147,6 @@ public boolean isDisposed() { } } - static final class TimeoutTask implements Runnable { final TimeoutSupport parent; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java index b15d4ee140..1e2a2ea052 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java @@ -233,7 +233,6 @@ void drainLoop() { continue; } - w = UnicastSubject.create(bufferSize); ws.add(w); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java index 5b76d067e7..1ffc0f475e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java @@ -264,7 +264,6 @@ static final class WindowExactBoundedObserver UnicastSubject window; - volatile boolean terminated; final AtomicReference timer = new AtomicReference(); diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelCollect.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelCollect.java index 4f7b53ed94..b1052b2fd6 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelCollect.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelCollect.java @@ -87,7 +87,6 @@ public int parallelism() { static final class ParallelCollectSubscriber extends DeferredScalarSubscriber { - private static final long serialVersionUID = -4767392946044436228L; final BiConsumer collector; diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelFromPublisher.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelFromPublisher.java index fc7288a1a1..33d83ca34c 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelFromPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelFromPublisher.java @@ -62,7 +62,6 @@ static final class ParallelDispatcher extends AtomicInteger implements FlowableSubscriber { - private static final long serialVersionUID = -4470634016609963609L; final Subscriber[] subscribers; diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduce.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduce.java index 8e421ef112..0c3bcfbba1 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduce.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduce.java @@ -86,7 +86,6 @@ public int parallelism() { static final class ParallelReduceSubscriber extends DeferredScalarSubscriber { - private static final long serialVersionUID = 8200530050639449080L; final BiFunction reducer; diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduceFull.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduceFull.java index 347ce2ead9..8757752322 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduceFull.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelReduceFull.java @@ -52,7 +52,6 @@ protected void subscribeActual(Subscriber s) { static final class ParallelReduceFullMainSubscriber extends DeferredScalarSubscription { - private static final long serialVersionUID = -5370107872170712765L; final ParallelReduceFullInnerSubscriber[] subscribers; diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelSortedJoin.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelSortedJoin.java index 1151716fff..a7c4947709 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelSortedJoin.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelSortedJoin.java @@ -266,7 +266,6 @@ static final class SortedJoinInnerSubscriber extends AtomicReference implements FlowableSubscriber> { - private static final long serialVersionUID = 6751017204873808094L; final SortedJoinSubscription parent; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java index ba5beeec9d..86dbd4d39f 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithCompletable.java @@ -40,7 +40,6 @@ static final class OtherObserver extends AtomicReference implements CompletableObserver, Disposable { - private static final long serialVersionUID = -8565274649390031272L; final SingleObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java index 0614c091c0..c905bba0c6 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithObservable.java @@ -41,7 +41,6 @@ static final class OtherSubscriber extends AtomicReference implements Observer, Disposable { - private static final long serialVersionUID = -8565274649390031272L; final SingleObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java index bbc8a9e460..ee93007020 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithPublisher.java @@ -44,7 +44,6 @@ static final class OtherSubscriber extends AtomicReference implements FlowableSubscriber, Disposable { - private static final long serialVersionUID = -8565274649390031272L; final SingleObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java index 1c1b4aabe3..83255b95c3 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDelayWithSingle.java @@ -40,7 +40,6 @@ static final class OtherObserver extends AtomicReference implements SingleObserver, Disposable { - private static final long serialVersionUID = -8565274649390031272L; final SingleObserver downstream; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowable.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowable.java index 1243413dff..f6f4c79cf5 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowable.java @@ -235,7 +235,6 @@ void slowPath(Subscriber a, Iterator iterator) { return; } - boolean b; try { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java index 760a052278..b3f822cc91 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservable.java @@ -126,7 +126,6 @@ public void onSuccess(T value) { return; } - boolean b; try { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleToFlowable.java b/src/main/java/io/reactivex/internal/operators/single/SingleToFlowable.java index f48aa4659b..de2b8a9ed8 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleToFlowable.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleToFlowable.java @@ -40,7 +40,6 @@ public void subscribeActual(final Subscriber s) { static final class SingleToFlowableObserver extends DeferredScalarSubscription implements SingleObserver { - private static final long serialVersionUID = 187782011903685568L; Disposable upstream; diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleZipArray.java b/src/main/java/io/reactivex/internal/operators/single/SingleZipArray.java index e9ba27d755..31fd470ecd 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleZipArray.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleZipArray.java @@ -39,7 +39,6 @@ protected void subscribeActual(SingleObserver observer) { SingleSource[] sources = this.sources; int n = sources.length; - if (n == 1) { sources[0].subscribe(new SingleMap.MapSingleObserver(observer, new SingletonArrayFunc())); return; @@ -67,7 +66,6 @@ protected void subscribeActual(SingleObserver observer) { static final class ZipCoordinator extends AtomicInteger implements Disposable { - private static final long serialVersionUID = -5556924161382950569L; final SingleObserver downstream; diff --git a/src/main/java/io/reactivex/internal/schedulers/ComputationScheduler.java b/src/main/java/io/reactivex/internal/schedulers/ComputationScheduler.java index b7200dee34..6f10ab2867 100644 --- a/src/main/java/io/reactivex/internal/schedulers/ComputationScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/ComputationScheduler.java @@ -187,7 +187,6 @@ public void shutdown() { } } - static final class EventLoopWorker extends Scheduler.Worker { private final ListCompositeDisposable serial; private final CompositeDisposable timed; diff --git a/src/main/java/io/reactivex/internal/schedulers/ExecutorScheduler.java b/src/main/java/io/reactivex/internal/schedulers/ExecutorScheduler.java index b18e18d16d..45e3c1850e 100644 --- a/src/main/java/io/reactivex/internal/schedulers/ExecutorScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/ExecutorScheduler.java @@ -162,7 +162,6 @@ public Disposable schedule(@NonNull Runnable run, long delay, @NonNull TimeUnit return EmptyDisposable.INSTANCE; } - SequentialDisposable first = new SequentialDisposable(); final SequentialDisposable mar = new SequentialDisposable(first); diff --git a/src/main/java/io/reactivex/internal/schedulers/NewThreadWorker.java b/src/main/java/io/reactivex/internal/schedulers/NewThreadWorker.java index 3499168f71..9ef225aceb 100644 --- a/src/main/java/io/reactivex/internal/schedulers/NewThreadWorker.java +++ b/src/main/java/io/reactivex/internal/schedulers/NewThreadWorker.java @@ -116,7 +116,6 @@ public Disposable schedulePeriodicallyDirect(Runnable run, long initialDelay, lo } } - /** * Wraps the given runnable into a ScheduledRunnable and schedules it * on the underlying ScheduledExecutorService. diff --git a/src/main/java/io/reactivex/internal/subscribers/ForEachWhileSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/ForEachWhileSubscriber.java index c296ffe088..ebf47f12a6 100644 --- a/src/main/java/io/reactivex/internal/subscribers/ForEachWhileSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/ForEachWhileSubscriber.java @@ -28,7 +28,6 @@ public final class ForEachWhileSubscriber extends AtomicReference implements FlowableSubscriber, Disposable { - private static final long serialVersionUID = -4403180040475402120L; final Predicate onNext; diff --git a/src/main/java/io/reactivex/internal/subscribers/InnerQueuedSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/InnerQueuedSubscriber.java index fc6647a83b..70ea26740e 100644 --- a/src/main/java/io/reactivex/internal/subscribers/InnerQueuedSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/InnerQueuedSubscriber.java @@ -32,7 +32,6 @@ public final class InnerQueuedSubscriber extends AtomicReference implements FlowableSubscriber, Subscription { - private static final long serialVersionUID = 22876611072430776L; final InnerQueuedSubscriberSupport parent; diff --git a/src/main/java/io/reactivex/internal/subscriptions/BasicIntQueueSubscription.java b/src/main/java/io/reactivex/internal/subscriptions/BasicIntQueueSubscription.java index eea08d07e7..a3d2259fd9 100644 --- a/src/main/java/io/reactivex/internal/subscriptions/BasicIntQueueSubscription.java +++ b/src/main/java/io/reactivex/internal/subscriptions/BasicIntQueueSubscription.java @@ -24,7 +24,6 @@ */ public abstract class BasicIntQueueSubscription extends AtomicInteger implements QueueSubscription { - private static final long serialVersionUID = -6671519529404341862L; @Override diff --git a/src/main/java/io/reactivex/internal/subscriptions/BasicQueueSubscription.java b/src/main/java/io/reactivex/internal/subscriptions/BasicQueueSubscription.java index 8776e8c5a3..ebb9935ed8 100644 --- a/src/main/java/io/reactivex/internal/subscriptions/BasicQueueSubscription.java +++ b/src/main/java/io/reactivex/internal/subscriptions/BasicQueueSubscription.java @@ -24,7 +24,6 @@ */ public abstract class BasicQueueSubscription extends AtomicLong implements QueueSubscription { - private static final long serialVersionUID = -6671519529404341862L; @Override diff --git a/src/main/java/io/reactivex/internal/subscriptions/DeferredScalarSubscription.java b/src/main/java/io/reactivex/internal/subscriptions/DeferredScalarSubscription.java index 536ddf4c00..131d1d2342 100644 --- a/src/main/java/io/reactivex/internal/subscriptions/DeferredScalarSubscription.java +++ b/src/main/java/io/reactivex/internal/subscriptions/DeferredScalarSubscription.java @@ -34,7 +34,6 @@ */ public class DeferredScalarSubscription extends BasicIntQueueSubscription { - private static final long serialVersionUID = -2151279923272604993L; /** The Subscriber to emit the value to. */ diff --git a/src/main/java/io/reactivex/internal/util/AppendOnlyLinkedArrayList.java b/src/main/java/io/reactivex/internal/util/AppendOnlyLinkedArrayList.java index fce0130657..12c4d062c0 100644 --- a/src/main/java/io/reactivex/internal/util/AppendOnlyLinkedArrayList.java +++ b/src/main/java/io/reactivex/internal/util/AppendOnlyLinkedArrayList.java @@ -125,7 +125,6 @@ public boolean accept(Subscriber subscriber) { return false; } - /** * Interprets the contents as NotificationLite objects and calls * the appropriate Observer method. diff --git a/src/main/java/io/reactivex/internal/util/AtomicThrowable.java b/src/main/java/io/reactivex/internal/util/AtomicThrowable.java index 5f4d4940d8..60c19155c5 100644 --- a/src/main/java/io/reactivex/internal/util/AtomicThrowable.java +++ b/src/main/java/io/reactivex/internal/util/AtomicThrowable.java @@ -23,7 +23,6 @@ */ public final class AtomicThrowable extends AtomicReference { - private static final long serialVersionUID = 3949248817947090603L; /** diff --git a/src/main/java/io/reactivex/internal/util/HalfSerializer.java b/src/main/java/io/reactivex/internal/util/HalfSerializer.java index 011528ec2a..8e160ab2ea 100644 --- a/src/main/java/io/reactivex/internal/util/HalfSerializer.java +++ b/src/main/java/io/reactivex/internal/util/HalfSerializer.java @@ -74,7 +74,6 @@ public static void onError(Subscriber subscriber, Throwable ex, } } - /** * Emits an onComplete signal or an onError signal with the given error or indicates * the concurrently running onNext should do that. diff --git a/src/main/java/io/reactivex/internal/util/OpenHashSet.java b/src/main/java/io/reactivex/internal/util/OpenHashSet.java index 8a1b4fe50e..f971002ad0 100644 --- a/src/main/java/io/reactivex/internal/util/OpenHashSet.java +++ b/src/main/java/io/reactivex/internal/util/OpenHashSet.java @@ -140,7 +140,6 @@ void rehash() { T[] b = (T[])new Object[newCap]; - for (int j = size; j-- != 0; ) { while (a[--i] == null) { } // NOPMD int pos = mix(a[i].hashCode()) & m; diff --git a/src/main/java/io/reactivex/internal/util/Pow2.java b/src/main/java/io/reactivex/internal/util/Pow2.java index d9782a53b0..db4317132c 100644 --- a/src/main/java/io/reactivex/internal/util/Pow2.java +++ b/src/main/java/io/reactivex/internal/util/Pow2.java @@ -11,7 +11,6 @@ * the License for the specific language governing permissions and limitations under the License. */ - /* * Original License: https://github.com/JCTools/JCTools/blob/master/LICENSE * Original location: https://github.com/JCTools/JCTools/blob/master/jctools-core/src/main/java/org/jctools/util/Pow2.java diff --git a/src/main/java/io/reactivex/observers/BaseTestConsumer.java b/src/main/java/io/reactivex/observers/BaseTestConsumer.java index 69d227d91d..2bb9285787 100644 --- a/src/main/java/io/reactivex/observers/BaseTestConsumer.java +++ b/src/main/java/io/reactivex/observers/BaseTestConsumer.java @@ -148,7 +148,6 @@ public final int errorCount() { return errors.size(); } - /** * Fail with the given message and add the sequence of errors as suppressed ones. *

    Note this is deliberately the only fail method. Most of the times an assertion @@ -869,7 +868,6 @@ public final U awaitDone(long time, TimeUnit unit) { return (U)this; } - /** * Assert that the TestObserver/TestSubscriber has received a Disposable but no other events. * @return this @@ -958,7 +956,6 @@ static void sleep(int millis) { } } - /** * Await until the TestObserver/TestSubscriber receives the given * number of items or terminates by sleeping 10 milliseconds at a time @@ -1065,7 +1062,6 @@ public final U assertTimeout() { return (U)this; } - /** * Asserts that some awaitX method has not timed out. *

    History: 2.0.7 - experimental diff --git a/src/main/java/io/reactivex/parallel/ParallelFlowable.java b/src/main/java/io/reactivex/parallel/ParallelFlowable.java index 519e731776..13ebb021a4 100644 --- a/src/main/java/io/reactivex/parallel/ParallelFlowable.java +++ b/src/main/java/io/reactivex/parallel/ParallelFlowable.java @@ -228,7 +228,6 @@ public final ParallelFlowable filter(@NonNull Predicate predicate, return RxJavaPlugins.onAssembly(new ParallelFilterTry(this, predicate, errorHandler)); } - /** * Filters the source values on each 'rail' and * handles errors based on the returned value by the handler function. @@ -536,7 +535,6 @@ public final ParallelFlowable doOnNext(@NonNull Consumer onNext) { )); } - /** * Call the specified consumer with the current element passing through any 'rail' and * handles errors based on the given {@link ParallelFailureHandling} enumeration value. diff --git a/src/main/java/io/reactivex/processors/BehaviorProcessor.java b/src/main/java/io/reactivex/processors/BehaviorProcessor.java index ff69ef4273..a81c51085e 100644 --- a/src/main/java/io/reactivex/processors/BehaviorProcessor.java +++ b/src/main/java/io/reactivex/processors/BehaviorProcessor.java @@ -346,7 +346,6 @@ public boolean hasSubscribers() { return subscribers.get().length != 0; } - /* test support*/ int subscriberCount() { return subscribers.get().length; } @@ -447,7 +446,6 @@ public boolean hasValue() { return o != null && !NotificationLite.isComplete(o) && !NotificationLite.isError(o); } - boolean add(BehaviorSubscription rs) { for (;;) { BehaviorSubscription[] a = subscribers.get(); diff --git a/src/main/java/io/reactivex/processors/ReplayProcessor.java b/src/main/java/io/reactivex/processors/ReplayProcessor.java index a8c9c700b4..ff98ff25d9 100644 --- a/src/main/java/io/reactivex/processors/ReplayProcessor.java +++ b/src/main/java/io/reactivex/processors/ReplayProcessor.java @@ -1049,7 +1049,6 @@ static final class SizeAndTimeBoundReplayBuffer Throwable error; volatile boolean done; - SizeAndTimeBoundReplayBuffer(int maxSize, long maxAge, TimeUnit unit, Scheduler scheduler) { this.maxSize = ObjectHelper.verifyPositive(maxSize, "maxSize"); this.maxAge = ObjectHelper.verifyPositive(maxAge, "maxAge"); diff --git a/src/main/java/io/reactivex/processors/UnicastProcessor.java b/src/main/java/io/reactivex/processors/UnicastProcessor.java index c754629374..47f02489b4 100644 --- a/src/main/java/io/reactivex/processors/UnicastProcessor.java +++ b/src/main/java/io/reactivex/processors/UnicastProcessor.java @@ -506,7 +506,6 @@ protected void subscribeActual(Subscriber s) { final class UnicastQueueSubscription extends BasicIntQueueSubscription { - private static final long serialVersionUID = -4896760517184205454L; @Nullable diff --git a/src/main/java/io/reactivex/subjects/BehaviorSubject.java b/src/main/java/io/reactivex/subjects/BehaviorSubject.java index 7f13dfb432..c58cb40779 100644 --- a/src/main/java/io/reactivex/subjects/BehaviorSubject.java +++ b/src/main/java/io/reactivex/subjects/BehaviorSubject.java @@ -298,7 +298,6 @@ public boolean hasObservers() { return subscribers.get().length != 0; } - /* test support*/ int subscriberCount() { return subscribers.get().length; } diff --git a/src/main/java/io/reactivex/subjects/ReplaySubject.java b/src/main/java/io/reactivex/subjects/ReplaySubject.java index 344ef99fee..703692bd57 100644 --- a/src/main/java/io/reactivex/subjects/ReplaySubject.java +++ b/src/main/java/io/reactivex/subjects/ReplaySubject.java @@ -700,7 +700,6 @@ public T[] getValues(T[] array) { } } - if (array.length < s) { array = (T[])Array.newInstance(array.getClass().getComponentType(), s); } @@ -1051,7 +1050,6 @@ static final class SizeAndTimeBoundReplayBuffer volatile boolean done; - SizeAndTimeBoundReplayBuffer(int maxSize, long maxAge, TimeUnit unit, Scheduler scheduler) { this.maxSize = ObjectHelper.verifyPositive(maxSize, "maxSize"); this.maxAge = ObjectHelper.verifyPositive(maxAge, "maxAge"); diff --git a/src/main/java/io/reactivex/subjects/UnicastSubject.java b/src/main/java/io/reactivex/subjects/UnicastSubject.java index 72f0563637..8c3eae8af0 100644 --- a/src/main/java/io/reactivex/subjects/UnicastSubject.java +++ b/src/main/java/io/reactivex/subjects/UnicastSubject.java @@ -251,7 +251,6 @@ public static UnicastSubject create(boolean delayError) { return new UnicastSubject(bufferSize(), delayError); } - /** * Creates an UnicastSubject with the given capacity hint and delay error flag. *

    History: 2.0.8 - experimental @@ -522,7 +521,6 @@ public boolean hasComplete() { final class UnicastQueueDisposable extends BasicIntQueueDisposable { - private static final long serialVersionUID = 7926949470189395511L; @Override diff --git a/src/main/java/io/reactivex/subscribers/SafeSubscriber.java b/src/main/java/io/reactivex/subscribers/SafeSubscriber.java index a7c1fb3ad6..e903a5519c 100644 --- a/src/main/java/io/reactivex/subscribers/SafeSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/SafeSubscriber.java @@ -176,7 +176,6 @@ public void onComplete() { return; } - try { downstream.onComplete(); } catch (Throwable e) { diff --git a/src/main/java/io/reactivex/subscribers/TestSubscriber.java b/src/main/java/io/reactivex/subscribers/TestSubscriber.java index 30c1a22b03..3b02dbdd09 100644 --- a/src/main/java/io/reactivex/subscribers/TestSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/TestSubscriber.java @@ -167,7 +167,6 @@ public void onSubscribe(Subscription s) { } } - downstream.onSubscribe(s); long mr = missedRequested.getAndSet(0L); diff --git a/src/test/java/io/reactivex/exceptions/TestException.java b/src/test/java/io/reactivex/exceptions/TestException.java index 6893fe54b4..eef7a47a85 100644 --- a/src/test/java/io/reactivex/exceptions/TestException.java +++ b/src/test/java/io/reactivex/exceptions/TestException.java @@ -52,6 +52,4 @@ public TestException(String message) { public TestException(Throwable cause) { super(cause); } - - } diff --git a/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java b/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java index 9db71ac805..7898628f70 100644 --- a/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java @@ -181,7 +181,6 @@ public void testMergeAsyncThenObserveOnLoop() { .take(num) .subscribe(ts); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); ts.assertComplete(); ts.assertNoErrors(); diff --git a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java index 189747dfa4..e95d5a9ab2 100644 --- a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java @@ -231,9 +231,8 @@ public void onError(Throwable e) { public void onNext(String t) { } - - }; + return as; } }; diff --git a/src/test/java/io/reactivex/flowable/FlowableZipTests.java b/src/test/java/io/reactivex/flowable/FlowableZipTests.java index 78ffa8cee5..d901d36bc2 100644 --- a/src/test/java/io/reactivex/flowable/FlowableZipTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableZipTests.java @@ -129,7 +129,6 @@ public void accept(ExtendedResult t1) { } }; - @Test public void zipWithDelayError() { Flowable.just(1) diff --git a/src/test/java/io/reactivex/internal/SubscribeWithTest.java b/src/test/java/io/reactivex/internal/SubscribeWithTest.java index ee6cdf5c0b..942762009c 100644 --- a/src/test/java/io/reactivex/internal/SubscribeWithTest.java +++ b/src/test/java/io/reactivex/internal/SubscribeWithTest.java @@ -37,7 +37,6 @@ public void withObservable() { .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } - class ObserverImpl implements SingleObserver, CompletableObserver { Object value; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java index f3d241bfd6..6a427124bd 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java @@ -246,7 +246,6 @@ public void testValuesAndThenError() { .concatWith(Flowable.error(new TestException())) .cache(); - TestSubscriber ts = new TestSubscriber(); source.subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java index 4b199482e9..ed0f556b7f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java @@ -158,7 +158,6 @@ public void testNestedAsyncConcat() throws InterruptedException { final CountDownLatch parentHasStarted = new CountDownLatch(1); final CountDownLatch parentHasFinished = new CountDownLatch(1); - Flowable> observableOfObservables = Flowable.unsafeCreate(new Publisher>() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java index 1114f17a1d..2b5bcea1e6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java @@ -26,7 +26,6 @@ import io.reactivex.functions.Function; import io.reactivex.subscribers.TestSubscriber; - public class FlowableDetachTest { Object o; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java index 2e5e97bb67..0502283132 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java @@ -469,7 +469,6 @@ public boolean test(Integer v) throws Exception { }) .subscribe(ts); - TestHelper.emit(up, 1, 2, 1, 3, 3, 4, 3, 5, 5); SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java index c9c24e7ef5..b05b847c90 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java @@ -203,7 +203,6 @@ public void testFlatMapTransformsException() { Flowable. error(new RuntimeException("Forced failure!")) ); - Subscriber subscriber = TestHelper.mockSubscriber(); source.flatMap(just(onNext), just(onError), just0(onComplete)).subscribe(subscriber); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategyTest.java index 85468f8753..c52888548d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategyTest.java @@ -116,7 +116,6 @@ public void subscribe(Subscriber s) { } }); - @Test(expected = IllegalArgumentException.class) public void backpressureBufferNegativeCapacity() throws InterruptedException { Flowable.empty().onBackpressureBuffer(-1, EMPTY_ACTION , DROP_OLDEST); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java index e9f19585bf..ee1b4e3051 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java @@ -214,7 +214,6 @@ public Integer apply(Integer t1) { ts.assertNoErrors(); } - private static class TestObservable implements Publisher { final String[] values; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java index 039114d1c7..e744a00aa1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java @@ -33,7 +33,6 @@ import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; - public class FlowablePublishFunctionTest { @Test public void concatTakeFirstLastCompletes() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java index cb6db6ef11..e20c417da9 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java @@ -506,7 +506,6 @@ public void run() { } } - /* * test the basic expectation of OperatorMulticast via replay */ @@ -696,7 +695,6 @@ public static Worker workerSpy(final Disposable mockDisposable) { return spy(new InprocessWorker(mockDisposable)); } - private static class InprocessWorker extends Worker { private final Disposable mockDisposable; public boolean unsubscribed; @@ -1063,7 +1061,6 @@ public void testValuesAndThenError() { .concatWith(Flowable.error(new TestException())) .replay().autoConnect(); - TestSubscriber ts = new TestSubscriber(); source.subscribe(ts); @@ -1169,7 +1166,6 @@ public void testSubscribersComeAndGoAtRequestBoundaries() { ts22.assertNoErrors(); ts22.dispose(); - TestSubscriber ts3 = new TestSubscriber(); source.subscribe(ts3); @@ -1225,7 +1221,6 @@ public void testSubscribersComeAndGoAtRequestBoundaries2() { ts22.assertNoErrors(); ts22.dispose(); - TestSubscriber ts3 = new TestSubscriber(); source.subscribe(ts3); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java index e301c29aec..2ab9d75bfd 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java @@ -29,7 +29,6 @@ import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; - public class FlowableSwitchIfEmptyTest { @Test @@ -122,7 +121,6 @@ public void onNext(Long aLong) { } }).subscribe(); - assertTrue(bs.isCancelled()); // FIXME no longer assertable // assertTrue(sub.isUnsubscribed()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java index d2caa4ada8..dc5f2a8313 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java @@ -449,7 +449,6 @@ public void testBackpressure() { publishCompleted(o2, 50); publishCompleted(o3, 55); - final TestSubscriber testSubscriber = new TestSubscriber(); Flowable.switchOnNext(o).subscribe(new DefaultSubscriber() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java index 014ebbf756..919ca0e468 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java @@ -75,7 +75,6 @@ public void onComplete() { } source.onComplete(); - verify(subscriber, never()).onError(any(Throwable.class)); assertEquals(n / 3, values.size()); @@ -346,7 +345,6 @@ public Flowable call() { boundary.onComplete(); - assertFalse(source.hasSubscribers()); assertFalse(boundary.hasSubscribers()); @@ -374,7 +372,6 @@ public Flowable call() { ts.dispose(); - assertTrue(source.hasSubscribers()); assertFalse(boundary.hasSubscribers()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java index d2eef83d88..157faae1a5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java @@ -32,7 +32,6 @@ import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; - public class FlowableWindowWithTimeTest { private TestScheduler scheduler; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java b/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java index a03d91385f..1f29136e00 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java @@ -23,7 +23,6 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.internal.util.NotificationLite; - public class NotificationLiteTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayTest.java index 29eac9a2a3..fb14e27a19 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayTest.java @@ -151,7 +151,6 @@ protected void subscribeActual(MaybeObserver observer) { o[0].onError(new TestException()); - TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaPlugins.reset(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCompletableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCompletableTest.java index 1b511dd515..3086eb6c57 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCompletableTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.maybe; - import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.HasUpstreamCompletableSource; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java index cd97bea762..8d07b6be3a 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java @@ -36,7 +36,6 @@ public Object apply(Object a, Object b) throws Exception { } }; - final Function3 addString3 = new Function3() { @Override public Object apply(Object a, Object b, Object c) throws Exception { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java index 614fb29bf5..9629946ecb 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java @@ -221,7 +221,6 @@ public void testValuesAndThenError() { .concatWith(Observable.error(new TestException())) .cache(); - TestObserver to = new TestObserver(); source.subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java index effef90136..fc2a01619b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java @@ -155,7 +155,6 @@ public void testNestedAsyncConcat() throws InterruptedException { final CountDownLatch parentHasStarted = new CountDownLatch(1); final CountDownLatch parentHasFinished = new CountDownLatch(1); - Observable> observableOfObservables = Observable.unsafeCreate(new ObservableSource>() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java index 0aaacb1432..01bf61ac6e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; - import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java index f8d274bc86..ab20fccc38 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java @@ -24,7 +24,6 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; - public class ObservableDetachTest { Object o; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index 4ace4eacb2..22a6889abc 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -205,7 +205,6 @@ public void testFlatMapTransformsException() { Observable. error(new RuntimeException("Forced failure!")) ); - Observer o = TestHelper.mockObserver(); source.flatMap(just(onNext), just(onError), just0(onComplete)).subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java index 56d7b7ee47..542165907f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java @@ -310,7 +310,4 @@ public Object call() throws Exception { .test() .assertResult(1); } - - - } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java index 181564df1c..50312e3884 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java @@ -211,7 +211,6 @@ public Integer apply(Integer t1) { to.assertNoErrors(); } - private static class TestObservable implements ObservableSource { final String[] values; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java index b79e8c6c20..c480a3b1df 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java @@ -506,7 +506,6 @@ public void run() { } } - /* * test the basic expectation of OperatorMulticast via replay */ @@ -644,7 +643,6 @@ public void testIssue2191_SchedulerUnsubscribeOnError() throws Exception { verify(mockObserverBeforeConnect).onSubscribe((Disposable)any()); verify(mockObserverAfterConnect).onSubscribe((Disposable)any()); - mockScheduler.advanceTimeBy(1, TimeUnit.SECONDS); // verify interactions verify(sourceNext, times(1)).accept(1); @@ -681,7 +679,6 @@ public static Worker workerSpy(final Disposable mockDisposable) { return spy(new InprocessWorker(mockDisposable)); } - static class InprocessWorker extends Worker { private final Disposable mockDisposable; public boolean unsubscribed; @@ -1053,7 +1050,6 @@ public void testValuesAndThenError() { .concatWith(Observable.error(new TestException())) .replay().autoConnect(); - TestObserver to = new TestObserver(); source.subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmptyTest.java index 20c5018d01..83024d1ea5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchIfEmptyTest.java @@ -25,7 +25,6 @@ import io.reactivex.functions.Consumer; import io.reactivex.observers.DefaultObserver; - public class ObservableSwitchIfEmptyTest { @Test @@ -90,7 +89,6 @@ public void onNext(Long aLong) { } }).subscribe(); - assertTrue(d.isDisposed()); // FIXME no longer assertable // assertTrue(sub.isUnsubscribed()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java index b015bfb737..a82e876464 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java @@ -76,7 +76,6 @@ public void onComplete() { } source.onComplete(); - verify(o, never()).onError(any(Throwable.class)); assertEquals(n / 3, values.size()); @@ -349,7 +348,6 @@ public Observable call() { boundary.onComplete(); - assertFalse(source.hasObservers()); assertFalse(boundary.hasObservers()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java index 8ef033d5f1..af1503e8a7 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java @@ -204,7 +204,6 @@ private List list(String... args) { return list; } - public static Observable hotStream() { return Observable.unsafeCreate(new ObservableSource() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java index 8c81f6a70a..4eb90f4e50 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java @@ -32,7 +32,6 @@ import io.reactivex.schedulers.*; import io.reactivex.subjects.*; - public class ObservableWindowWithTimeTest { private TestScheduler scheduler; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java index 4f3c62b992..713772c535 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java @@ -260,7 +260,6 @@ public void testNoDownstreamUnsubscribe() { // assertTrue("Not cancelled!", ts.isCancelled()); } - static final Function toArray = new Function() { @Override public String apply(Object[] args) { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleInternalHelperTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleInternalHelperTest.java index 5d4459259b..0a6d5473f7 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleInternalHelperTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleInternalHelperTest.java @@ -21,7 +21,6 @@ import io.reactivex.*; - public class SingleInternalHelperTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java index f188547bc9..7d1175bfc2 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java @@ -36,7 +36,6 @@ public Object apply(Object a, Object b) throws Exception { } }; - final Function3 addString3 = new Function3() { @Override public Object apply(Object a, Object b, Object c) throws Exception { diff --git a/src/test/java/io/reactivex/internal/schedulers/ExecutorSchedulerDelayedRunnableTest.java b/src/test/java/io/reactivex/internal/schedulers/ExecutorSchedulerDelayedRunnableTest.java index 0356ed6cbf..a8f61daeab 100644 --- a/src/test/java/io/reactivex/internal/schedulers/ExecutorSchedulerDelayedRunnableTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/ExecutorSchedulerDelayedRunnableTest.java @@ -24,7 +24,6 @@ public class ExecutorSchedulerDelayedRunnableTest { - @Test(expected = TestException.class) public void delayedRunnableCrash() { DelayedRunnable dl = new DelayedRunnable(new Runnable() { diff --git a/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java index 7b47129559..726828bbd7 100644 --- a/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java @@ -230,7 +230,6 @@ public void doubleComplete() { ds.onComplete(); ds.onComplete(); - ts.assertValue(1); ts.assertNoErrors(); ts.assertComplete(); diff --git a/src/test/java/io/reactivex/observers/ObserverFusion.java b/src/test/java/io/reactivex/observers/ObserverFusion.java index 22b3466b19..05b694eba6 100644 --- a/src/test/java/io/reactivex/observers/ObserverFusion.java +++ b/src/test/java/io/reactivex/observers/ObserverFusion.java @@ -150,7 +150,6 @@ public static Consumer> assertFusionMode(final int mode) { return new AssertFusionConsumer(mode); } - /** * Constructs a TestObserver with the given required fusion mode. * @param the value type diff --git a/src/test/java/io/reactivex/observers/TestObserverTest.java b/src/test/java/io/reactivex/observers/TestObserverTest.java index 27f4f7442c..2258d15779 100644 --- a/src/test/java/io/reactivex/observers/TestObserverTest.java +++ b/src/test/java/io/reactivex/observers/TestObserverTest.java @@ -485,8 +485,6 @@ public boolean test(Throwable t) throws Exception { to.assertValueCount(0); to.assertNoValues(); - - } @Test @@ -898,7 +896,6 @@ public void assertTerminated2() { // expected } - to = TestObserver.create(); to.onSubscribe(Disposables.empty()); diff --git a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java index f522b84fd3..cd66ce7b7e 100644 --- a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java +++ b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java @@ -1285,7 +1285,6 @@ public Completable apply(Completable completable) throws Exception { } }; - RxJavaPlugins.setInitComputationSchedulerHandler(callable2scheduler); RxJavaPlugins.setComputationSchedulerHandler(scheduler2scheduler); RxJavaPlugins.setIoSchedulerHandler(scheduler2scheduler); @@ -1378,7 +1377,6 @@ public void subscribeActual(MaybeObserver t) { assertSame(myb, RxJavaPlugins.onAssembly(myb)); - Runnable action = Functions.EMPTY_RUNNABLE; assertSame(action, RxJavaPlugins.onSchedule(action)); diff --git a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java index d90fe6705f..963171d30e 100644 --- a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java +++ b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java @@ -296,7 +296,6 @@ public void run() { // assertEquals(1, ts.getOnErrorEvents().size()); // } - // FIXME subscriber methods are not allowed to throw // /** // * This one has multiple failures so should get a CompositeException diff --git a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java index d7f3dca92b..a0e3996f41 100644 --- a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java +++ b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java @@ -305,8 +305,6 @@ public void testStartEmpty() { inOrder.verify(subscriber).onNext(1); inOrder.verify(subscriber).onComplete(); inOrder.verifyNoMoreInteractions(); - - } @Test diff --git a/src/test/java/io/reactivex/processors/PublishProcessorTest.java b/src/test/java/io/reactivex/processors/PublishProcessorTest.java index 4160ed27ea..f91e61551f 100644 --- a/src/test/java/io/reactivex/processors/PublishProcessorTest.java +++ b/src/test/java/io/reactivex/processors/PublishProcessorTest.java @@ -338,7 +338,6 @@ public void onComplete() { } } - // FIXME RS subscribers are not allowed to throw // @Test // public void testOnErrorThrowsDoesntPreventDelivery() { diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java index 3038840266..810e80d9e5 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java @@ -859,7 +859,6 @@ public void testBackpressureHonored() { ts.assertNotComplete(); ts.assertNoErrors(); - ts.request(1); ts.assertValues(1, 2); ts.assertNotComplete(); @@ -888,7 +887,6 @@ public void testBackpressureHonoredSizeBound() { ts.assertNotComplete(); ts.assertNoErrors(); - ts.request(1); ts.assertValues(1, 2); ts.assertNotComplete(); @@ -917,7 +915,6 @@ public void testBackpressureHonoredTimeBound() { ts.assertNotComplete(); ts.assertNoErrors(); - ts.request(1); ts.assertValues(1, 2); ts.assertNotComplete(); diff --git a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java index fdd8d4e2a9..b058d51e16 100644 --- a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java +++ b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java @@ -373,7 +373,6 @@ public void hasObservers() { public void drainFusedFailFast() { UnicastProcessor us = UnicastProcessor.create(false); - TestSubscriber ts = us.to(SubscriberFusion.test(1, QueueFuseable.ANY, false)); us.done = true; @@ -386,7 +385,6 @@ public void drainFusedFailFast() { public void drainFusedFailFastEmpty() { UnicastProcessor us = UnicastProcessor.create(false); - TestSubscriber ts = us.to(SubscriberFusion.test(1, QueueFuseable.ANY, false)); us.drainFused(ts); diff --git a/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java b/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java index ed67bce571..0c9755fd60 100644 --- a/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java +++ b/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java @@ -707,7 +707,6 @@ public void unwrapDefaultPeriodicTask() throws InterruptedException { return; } - final CountDownLatch cdl = new CountDownLatch(1); Runnable countDownRunnable = new Runnable() { @Override diff --git a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java index 312ccf92df..eaa5b692f1 100644 --- a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java @@ -59,7 +59,6 @@ public static void testCancelledRetention(Scheduler.Worker w, boolean periodic) Thread.sleep(1000); - MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); long initial = memHeap.getUsed(); diff --git a/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java b/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java index 7f3098ef90..aa0af9816b 100644 --- a/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java +++ b/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java @@ -92,7 +92,6 @@ public void run() { cd.add(w4); w4.schedule(countAction); - if (!cdl.await(3, TimeUnit.SECONDS)) { fail("countAction was not run by every worker"); } diff --git a/src/test/java/io/reactivex/single/SingleNullTests.java b/src/test/java/io/reactivex/single/SingleNullTests.java index 96ffe78eeb..ff7ddf19d0 100644 --- a/src/test/java/io/reactivex/single/SingleNullTests.java +++ b/src/test/java/io/reactivex/single/SingleNullTests.java @@ -13,7 +13,6 @@ package io.reactivex.single; - import java.lang.reflect.*; import java.util.*; import java.util.concurrent.*; diff --git a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java b/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java index 5e628f3ec6..efd643e8d9 100644 --- a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java @@ -295,7 +295,6 @@ public void run() { // assertEquals(1, to.getOnErrorEvents().size()); // } - // FIXME subscriber methods are not allowed to throw // /** // * This one has multiple failures so should get a CompositeException diff --git a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java b/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java index 06b7079fdf..9a2b52f8f7 100644 --- a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java @@ -305,8 +305,6 @@ public void testStartEmpty() { inOrder.verify(o).onNext(1); inOrder.verify(o).onComplete(); inOrder.verifyNoMoreInteractions(); - - } @Test diff --git a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java index dd9f964100..7731d508f8 100644 --- a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java @@ -338,7 +338,6 @@ public void onComplete() { } } - // FIXME RS subscribers are not allowed to throw // @Test // public void testOnErrorThrowsDoesntPreventDelivery() { diff --git a/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java b/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java index 41a1d3e759..ca13ba0495 100644 --- a/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java @@ -438,7 +438,6 @@ public void hasObservers() { public void drainFusedFailFast() { UnicastSubject us = UnicastSubject.create(false); - TestObserver to = us.to(ObserverFusion.test(QueueFuseable.ANY, false)); us.done = true; @@ -451,7 +450,6 @@ public void drainFusedFailFast() { public void drainFusedFailFastEmpty() { UnicastSubject us = UnicastSubject.create(false); - TestObserver to = us.to(ObserverFusion.test(QueueFuseable.ANY, false)); us.drainFused(to); diff --git a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java index d4358f4bb8..6c634d8d91 100644 --- a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java @@ -79,7 +79,6 @@ public void testAssertNotMatchValue() { // FIXME different message pattern // thrown.expectMessage("Value at index: 1 expected to be [3] (Integer) but was: [2] (Integer)"); - ts.assertValues(1, 3); ts.assertValueCount(2); ts.assertTerminated(); @@ -928,8 +927,6 @@ public boolean test(Throwable t) { ts.assertValueCount(0); ts.assertNoValues(); - - } @Test @@ -1340,7 +1337,6 @@ public void assertTerminated2() { // expected } - ts = TestSubscriber.create(); ts.onSubscribe(new BooleanSubscription()); diff --git a/src/test/java/io/reactivex/validators/JavadocForAnnotations.java b/src/test/java/io/reactivex/validators/JavadocForAnnotations.java index 9dae922016..3912ced5ce 100644 --- a/src/test/java/io/reactivex/validators/JavadocForAnnotations.java +++ b/src/test/java/io/reactivex/validators/JavadocForAnnotations.java @@ -104,7 +104,6 @@ static final void scanFor(StringBuilder sourceCode, String annotation, String in } } - static final void scanForBadMethod(StringBuilder sourceCode, String annotation, String inDoc, StringBuilder e, String baseClassName) { int index = 0; diff --git a/src/test/java/io/reactivex/validators/NewLinesBeforeAnnotation.java b/src/test/java/io/reactivex/validators/NewLinesBeforeAnnotation.java index 49f19daec0..e7c1c13bb3 100644 --- a/src/test/java/io/reactivex/validators/NewLinesBeforeAnnotation.java +++ b/src/test/java/io/reactivex/validators/NewLinesBeforeAnnotation.java @@ -55,7 +55,7 @@ public void tooManyEmptyNewLines3() throws Exception { @Test public void tooManyEmptyNewLines4() throws Exception { - findPattern(5); + findPattern(4); } @Test diff --git a/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java b/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java index 136ba29581..ac078393e1 100644 --- a/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java +++ b/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java @@ -326,7 +326,6 @@ public void checkParallelFlowable() { addOverride(new ParamOverride(Single.class, 0, ParamMode.ANY, "delay", Long.TYPE, TimeUnit.class, Scheduler.class)); addOverride(new ParamOverride(Single.class, 0, ParamMode.ANY, "delay", Long.TYPE, TimeUnit.class, Scheduler.class, Boolean.TYPE)); - // zero repeat is allowed addOverride(new ParamOverride(Single.class, 0, ParamMode.NON_NEGATIVE, "repeat", Long.TYPE)); diff --git a/src/test/java/io/reactivex/validators/TooManyEmptyNewLines.java b/src/test/java/io/reactivex/validators/TooManyEmptyNewLines.java new file mode 100644 index 0000000000..2da65b36c8 --- /dev/null +++ b/src/test/java/io/reactivex/validators/TooManyEmptyNewLines.java @@ -0,0 +1,132 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.validators; + +import java.io.*; +import java.util.*; + +import org.junit.Test; + +/** + * Test verifying there are no 2..5 empty newlines in the code. + */ +public class TooManyEmptyNewLines { + + @Test + public void tooManyEmptyNewLines2() throws Exception { + findPattern(2); + } + + @Test + public void tooManyEmptyNewLines3() throws Exception { + findPattern(3); + } + + @Test + public void tooManyEmptyNewLines4() throws Exception { + findPattern(4); + } + + @Test + public void tooManyEmptyNewLines5() throws Exception { + findPattern(5); + } + + static void findPattern(int newLines) throws Exception { + File f = MaybeNo2Dot0Since.findSource("Flowable"); + if (f == null) { + System.out.println("Unable to find sources of TestHelper.findSourceDir()"); + return; + } + + Queue dirs = new ArrayDeque(); + + StringBuilder fail = new StringBuilder(); + fail.append("The following code pattern was found: "); + fail.append("\\R"); + for (int i = 0; i < newLines; i++) { + fail.append("\\R"); + } + fail.append("\n"); + + File parent = f.getParentFile(); + + dirs.offer(new File(parent.getAbsolutePath().replace('\\', '/'))); + dirs.offer(new File(parent.getAbsolutePath().replace('\\', '/').replace("src/main/java", "src/test/java"))); + + int total = 0; + + while (!dirs.isEmpty()) { + f = dirs.poll(); + + File[] list = f.listFiles(); + if (list != null && list.length != 0) { + + for (File u : list) { + if (u.isDirectory()) { + dirs.offer(u); + } else { + String fname = u.getName(); + if (fname.endsWith(".java")) { + + List lines = new ArrayList(); + BufferedReader in = new BufferedReader(new FileReader(u)); + try { + for (;;) { + String line = in.readLine(); + if (line == null) { + break; + } + lines.add(line); + } + } finally { + in.close(); + } + + for (int i = 0; i < lines.size() - newLines; i++) { + String line1 = lines.get(i); + if (line1.isEmpty()) { + int c = 1; + for (int j = i + 1; j < lines.size(); j++) { + if (lines.get(j).isEmpty()) { + c++; + } else { + break; + } + } + + if (c == newLines) { + fail + .append(fname) + .append("#L").append(i + 1) + .append("\n"); + total++; + i += c; + } + } + } + } + } + } + } + } + if (total != 0) { + fail.append("Found ") + .append(total) + .append(" instances"); + System.out.println(fail); + throw new AssertionError(fail.toString()); + } + } +} From c7d91c68ef8011f9d753111a8c839297850aeb66 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 30 Aug 2018 15:29:58 +0200 Subject: [PATCH 070/211] 2.x: Fix refCount termination-reconnect race (#6187) * 2.x: Fix refCount termination-reconnect race * Add/restore coverage * Update ResettableConnectable interface and definitions --- .../disposables/ResettableConnectable.java | 54 +++++++++++++ .../operators/flowable/FlowableRefCount.java | 11 ++- .../operators/flowable/FlowableReplay.java | 14 ++-- .../observable/ObservableRefCount.java | 11 ++- .../observable/ObservableReplay.java | 13 +-- .../flowable/FlowableRefCountTest.java | 78 ++++++++++++++++-- .../observable/ObservableRefCountTest.java | 80 +++++++++++++++++-- 7 files changed, 229 insertions(+), 32 deletions(-) create mode 100644 src/main/java/io/reactivex/internal/disposables/ResettableConnectable.java diff --git a/src/main/java/io/reactivex/internal/disposables/ResettableConnectable.java b/src/main/java/io/reactivex/internal/disposables/ResettableConnectable.java new file mode 100644 index 0000000000..a111080a77 --- /dev/null +++ b/src/main/java/io/reactivex/internal/disposables/ResettableConnectable.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.disposables; + +import io.reactivex.annotations.Experimental; +import io.reactivex.disposables.Disposable; +import io.reactivex.flowables.ConnectableFlowable; +import io.reactivex.observables.ConnectableObservable; + +/** + * Interface allowing conditional resetting of connections in {@link ConnectableObservable}s + * and {@link ConnectableFlowable}s. + * @since 2.2.2 - experimental + */ +@Experimental +public interface ResettableConnectable { + + /** + * Reset the connectable source only if the given {@link Disposable} {@code connection} instance + * is still representing a connection established by a previous {@code connect()} connection. + *

    + * For example, an immediately previous connection should reset the connectable source: + *

    
    +     * Disposable d = connectable.connect();
    +     * 
    +     * ((ResettableConnectable)connectable).resetIf(d);
    +     * 
    + * However, if the connection indicator {@code Disposable} is from a much earlier connection, + * it should not affect the current connection: + *
    
    +     * Disposable d1 = connectable.connect();
    +     * d.dispose();
    +     *
    +     * Disposable d2 = connectable.connect();
    +     *
    +     * ((ResettableConnectable)connectable).resetIf(d);
    +     * 
    +     * assertFalse(d2.isDisposed());
    +     * 
    + * @param connection the disposable received from a previous {@code connect()} call. + */ + void resetIf(Disposable connection); +} diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java index 82a1373228..f966f01365 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java @@ -95,7 +95,7 @@ protected void subscribeActual(Subscriber s) { void cancel(RefConnection rc) { SequentialDisposable sd; synchronized (this) { - if (connection == null) { + if (connection == null || connection != rc) { return; } long c = rc.subscriberCount - 1; @@ -116,13 +116,17 @@ void cancel(RefConnection rc) { void terminated(RefConnection rc) { synchronized (this) { - if (connection != null) { + if (connection != null && connection == rc) { connection = null; if (rc.timer != null) { rc.timer.dispose(); } + } + if (--rc.subscriberCount == 0) { if (source instanceof Disposable) { ((Disposable)source).dispose(); + } else if (source instanceof ResettableConnectable) { + ((ResettableConnectable)source).resetIf(rc.get()); } } } @@ -132,9 +136,12 @@ void timeout(RefConnection rc) { synchronized (this) { if (rc.subscriberCount == 0 && rc == connection) { connection = null; + Disposable connectionObject = rc.get(); DisposableHelper.dispose(rc); if (source instanceof Disposable) { ((Disposable)source).dispose(); + } else if (source instanceof ResettableConnectable) { + ((ResettableConnectable)source).resetIf(connectionObject); } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java index 51943b9c48..21b1b1d39c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java @@ -24,6 +24,7 @@ import io.reactivex.exceptions.Exceptions; import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.*; +import io.reactivex.internal.disposables.ResettableConnectable; import io.reactivex.internal.functions.ObjectHelper; import io.reactivex.internal.fuseable.HasUpstreamPublisher; import io.reactivex.internal.subscribers.SubscriberResourceWrapper; @@ -32,7 +33,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Timed; -public final class FlowableReplay extends ConnectableFlowable implements HasUpstreamPublisher, Disposable { +public final class FlowableReplay extends ConnectableFlowable implements HasUpstreamPublisher, ResettableConnectable { /** The source observable. */ final Flowable source; /** Holds the current subscriber that is, will be or just was subscribed to the source observable. */ @@ -161,15 +162,10 @@ protected void subscribeActual(Subscriber s) { onSubscribe.subscribe(s); } + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override - public void dispose() { - current.lazySet(null); - } - - @Override - public boolean isDisposed() { - Disposable d = current.get(); - return d == null || d.isDisposed(); + public void resetIf(Disposable connectionObject) { + current.compareAndSet((ReplaySubscriber)connectionObject, null); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java index 59b571640d..3dced24de6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java @@ -92,7 +92,7 @@ protected void subscribeActual(Observer observer) { void cancel(RefConnection rc) { SequentialDisposable sd; synchronized (this) { - if (connection == null) { + if (connection == null || connection != rc) { return; } long c = rc.subscriberCount - 1; @@ -113,13 +113,17 @@ void cancel(RefConnection rc) { void terminated(RefConnection rc) { synchronized (this) { - if (connection != null) { + if (connection != null && connection == rc) { connection = null; if (rc.timer != null) { rc.timer.dispose(); } + } + if (--rc.subscriberCount == 0) { if (source instanceof Disposable) { ((Disposable)source).dispose(); + } else if (source instanceof ResettableConnectable) { + ((ResettableConnectable)source).resetIf(rc.get()); } } } @@ -129,9 +133,12 @@ void timeout(RefConnection rc) { synchronized (this) { if (rc.subscriberCount == 0 && rc == connection) { connection = null; + Disposable connectionObject = rc.get(); DisposableHelper.dispose(rc); if (source instanceof Disposable) { ((Disposable)source).dispose(); + } else if (source instanceof ResettableConnectable) { + ((ResettableConnectable)source).resetIf(connectionObject); } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java index a1c75b67c0..89db184d6b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java @@ -31,7 +31,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Timed; -public final class ObservableReplay extends ConnectableObservable implements HasUpstreamObservableSource, Disposable { +public final class ObservableReplay extends ConnectableObservable implements HasUpstreamObservableSource, ResettableConnectable { /** The source observable. */ final ObservableSource source; /** Holds the current subscriber that is, will be or just was subscribed to the source observable. */ @@ -159,15 +159,10 @@ public ObservableSource source() { return source; } + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override - public void dispose() { - current.lazySet(null); - } - - @Override - public boolean isDisposed() { - Disposable d = current.get(); - return d == null || d.isDisposed(); + public void resetIf(Disposable connectionObject) { + current.compareAndSet((ReplayObserver)connectionObject, null); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java index 8eefc701e3..6bd46295e3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java @@ -788,15 +788,17 @@ public void replayIsUnsubscribed() { ConnectableFlowable cf = Flowable.just(1) .replay(); - assertTrue(((Disposable)cf).isDisposed()); + if (cf instanceof Disposable) { + assertTrue(((Disposable)cf).isDisposed()); - Disposable connection = cf.connect(); + Disposable connection = cf.connect(); - assertFalse(((Disposable)cf).isDisposed()); + assertFalse(((Disposable)cf).isDisposed()); - connection.dispose(); + connection.dispose(); - assertTrue(((Disposable)cf).isDisposed()); + assertTrue(((Disposable)cf).isDisposed()); + } } static final class BadFlowableSubscribe extends ConnectableFlowable { @@ -1325,5 +1327,71 @@ public void cancelTerminateStateExclusion() { rc.connected = true; o.connection = rc; o.cancel(rc); + + o.connection = rc; + o.cancel(new RefConnection(o)); + } + + @Test + public void replayRefCountShallBeThreadSafe() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + Flowable flowable = Flowable.just(1).replay(1).refCount(); + + TestSubscriber ts1 = flowable + .subscribeOn(Schedulers.io()) + .test(); + + TestSubscriber ts2 = flowable + .subscribeOn(Schedulers.io()) + .test(); + + ts1 + .withTag("" + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(1); + + ts2 + .withTag("" + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(1); + } + } + + static final class TestConnectableFlowable extends ConnectableFlowable + implements Disposable { + + volatile boolean disposed; + + @Override + public void dispose() { + disposed = true; + } + + @Override + public boolean isDisposed() { + return disposed; + } + + @Override + public void connect(Consumer connection) { + // not relevant + } + + @Override + protected void subscribeActual(Subscriber subscriber) { + // not relevant + } + } + + @Test + public void timeoutDisposesSource() { + FlowableRefCount o = (FlowableRefCount)new TestConnectableFlowable().refCount(); + + RefConnection rc = new RefConnection(o); + o.connection = rc; + + o.timeout(rc); + + assertTrue(((Disposable)o.source).isDisposed()); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index 37efa77570..d75498bc69 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -765,15 +765,17 @@ public void replayIsUnsubscribed() { ConnectableObservable co = Observable.just(1).concatWith(Observable.never()) .replay(); - assertTrue(((Disposable)co).isDisposed()); + if (co instanceof Disposable) { + assertTrue(((Disposable)co).isDisposed()); - Disposable connection = co.connect(); + Disposable connection = co.connect(); - assertFalse(((Disposable)co).isDisposed()); + assertFalse(((Disposable)co).isDisposed()); - connection.dispose(); + connection.dispose(); - assertTrue(((Disposable)co).isDisposed()); + assertTrue(((Disposable)co).isDisposed()); + } } static final class BadObservableSubscribe extends ConnectableObservable { @@ -1239,6 +1241,8 @@ public void cancelTerminateStateExclusion() { o.cancel(null); + o.cancel(new RefConnection(o)); + RefConnection rc = new RefConnection(o); o.connection = null; rc.subscriberCount = 0; @@ -1274,5 +1278,71 @@ public void cancelTerminateStateExclusion() { rc.connected = true; o.connection = rc; o.cancel(rc); + + o.connection = rc; + o.cancel(new RefConnection(o)); + } + + @Test + public void replayRefCountShallBeThreadSafe() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + Observable observable = Observable.just(1).replay(1).refCount(); + + TestObserver observer1 = observable + .subscribeOn(Schedulers.io()) + .test(); + + TestObserver observer2 = observable + .subscribeOn(Schedulers.io()) + .test(); + + observer1 + .withTag("" + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(1); + + observer2 + .withTag("" + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(1); + } + } + + static final class TestConnectableObservable extends ConnectableObservable + implements Disposable { + + volatile boolean disposed; + + @Override + public void dispose() { + disposed = true; + } + + @Override + public boolean isDisposed() { + return disposed; + } + + @Override + public void connect(Consumer connection) { + // not relevant + } + + @Override + protected void subscribeActual(Observer observer) { + // not relevant + } + } + + @Test + public void timeoutDisposesSource() { + ObservableRefCount o = (ObservableRefCount)new TestConnectableObservable().refCount(); + + RefConnection rc = new RefConnection(o); + o.connection = rc; + + o.timeout(rc); + + assertTrue(((Disposable)o.source).isDisposed()); } } From 205fea69982f5f0f2eb7f1b767e864c0d3901a71 Mon Sep 17 00:00:00 2001 From: Yannick Lecaillez Date: Mon, 3 Sep 2018 14:05:58 +0200 Subject: [PATCH 071/211] #6195 Fix Flowable.reduce(BiFunction) JavaDoc (#6197) Empty source does not signal NoSuchElementException. --- src/main/java/io/reactivex/Flowable.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index bab8443357..0abe33c93c 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -12130,8 +12130,6 @@ public final Flowable rebatchRequests(int n) { * Publisher into the same function, and so on until all items have been emitted by the finite source Publisher, * and emits the final result from the final call to your function as its sole item. *

    - * If the source is empty, a {@code NoSuchElementException} is signaled. - *

    * *

    * This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate," From e0532b71f7eb6e2973b8c9b155b53a671caa0e9f Mon Sep 17 00:00:00 2001 From: luis-cortes Date: Mon, 3 Sep 2018 08:33:36 -0400 Subject: [PATCH 072/211] Add "error handling" java docs section to from callable & co (#6193) * #6179 Adding Error handling javadocs to Observable#fromCallable(), Single#fromCallable(), and Completable#fromCallable(). * #6179 Adding Error handling javadocs to Maybe#fromAction() and Completable#fromAction(). * #6179 Removing cancellation language since only the `Flowable` type has `cancel()` * #6179 Adding error handling JavaDocs to Flowable#fromCallable() --- src/main/java/io/reactivex/Completable.java | 14 ++++++++++++++ src/main/java/io/reactivex/Flowable.java | 7 +++++++ src/main/java/io/reactivex/Maybe.java | 7 +++++++ src/main/java/io/reactivex/Observable.java | 8 +++++++- src/main/java/io/reactivex/Single.java | 7 +++++++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 6cf5aa75f4..430440b248 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -396,6 +396,13 @@ public static Completable error(final Throwable error) { *

    *
    Scheduler:
    *
    {@code fromAction} does not operate by default on a particular {@link Scheduler}.
    + *
    Error handling:
    + *
    If the {@link Action} throws an exception, the respective {@link Throwable} is + * delivered to the downstream via {@link CompletableObserver#onError(Throwable)}, + * except when the downstream has disposed this {@code Completable} source. + * In this latter case, the {@code Throwable} is delivered to the global error handler via + * {@link RxJavaPlugins#onError(Throwable)} as an {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}. + *
    *
    * @param run the runnable to run for each subscriber * @return the new Completable instance @@ -416,6 +423,13 @@ public static Completable fromAction(final Action run) { *
    *
    Scheduler:
    *
    {@code fromCallable} does not operate by default on a particular {@link Scheduler}.
    + *
    Error handling:
    + *
    If the {@link Callable} throws an exception, the respective {@link Throwable} is + * delivered to the downstream via {@link CompletableObserver#onError(Throwable)}, + * except when the downstream has disposed this {@code Completable} source. + * In this latter case, the {@code Throwable} is delivered to the global error handler via + * {@link RxJavaPlugins#onError(Throwable)} as an {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}. + *
    *
    * @param callable the callable instance to execute for each subscriber * @return the new Completable instance diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 0abe33c93c..42c2082b10 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -1955,6 +1955,13 @@ public static Flowable fromArray(T... items) { *
    The operator honors backpressure from downstream.
    *
    Scheduler:
    *
    {@code fromCallable} does not operate by default on a particular {@link Scheduler}.
    + *
    Error handling:
    + *
    If the {@link Callable} throws an exception, the respective {@link Throwable} is + * delivered to the downstream via {@link Subscriber#onError(Throwable)}, + * except when the downstream has canceled this {@code Flowable} source. + * In this latter case, the {@code Throwable} is delivered to the global error handler via + * {@link RxJavaPlugins#onError(Throwable)} as an {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}. + *
    * * * @param supplier diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 8750c83cd2..be9c888762 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -657,6 +657,13 @@ public static Maybe error(Callable supplier) { *
    *
    Scheduler:
    *
    {@code fromAction} does not operate by default on a particular {@link Scheduler}.
    + *
    Error handling:
    + *
    If the {@link Action} throws an exception, the respective {@link Throwable} is + * delivered to the downstream via {@link MaybeObserver#onError(Throwable)}, + * except when the downstream has disposed this {@code Maybe} source. + * In this latter case, the {@code Throwable} is delivered to the global error handler via + * {@link RxJavaPlugins#onError(Throwable)} as an {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}. + *
    *
    * @param the target type * @param run the runnable to run for each subscriber diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index d1adc46efa..541c15215c 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -1757,8 +1757,14 @@ public static Observable fromArray(T... items) { *
    *
    Scheduler:
    *
    {@code fromCallable} does not operate by default on a particular {@link Scheduler}.
    + *
    Error handling:
    + *
    If the {@link Callable} throws an exception, the respective {@link Throwable} is + * delivered to the downstream via {@link Observer#onError(Throwable)}, + * except when the downstream has disposed this {@code Observable} source. + * In this latter case, the {@code Throwable} is delivered to the global error handler via + * {@link RxJavaPlugins#onError(Throwable)} as an {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}. + *
    *
    - * * @param supplier * a function, the execution of which should be deferred; {@code fromCallable} will invoke this * function only when an observer subscribes to the ObservableSource that {@code fromCallable} returns diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 51a896c887..dca4eb9ed0 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -583,6 +583,13 @@ public static Single error(final Throwable exception) { *
    *
    Scheduler:
    *
    {@code fromCallable} does not operate by default on a particular {@link Scheduler}.
    + *
    Error handling:
    + *
    If the {@link Callable} throws an exception, the respective {@link Throwable} is + * delivered to the downstream via {@link SingleObserver#onError(Throwable)}, + * except when the downstream has disposed this {@code Single} source. + * In this latter case, the {@code Throwable} is delivered to the global error handler via + * {@link RxJavaPlugins#onError(Throwable)} as an {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}. + *
    *
    * * @param callable From fbbae6c37bca0a22e32aad6f2901cf65fc460d8a Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 4 Sep 2018 10:28:24 +0200 Subject: [PATCH 073/211] 2.x: Fix toFlowable marbles and descriptions (#6200) * 2.x: Fix toFlowable marbles and descriptions * Adjust wording --- src/main/java/io/reactivex/Flowable.java | 11 ++++++----- src/main/java/io/reactivex/Observable.java | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 42c2082b10..2e9e6c20ba 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -5842,15 +5842,16 @@ public final T blockingSingle(T defaultItem) { } /** - * Returns a {@link Future} representing the single value emitted by this {@code Flowable}. + * Returns a {@link Future} representing the only value emitted by this {@code Flowable}. + *

    + * *

    * If the {@link Flowable} emits more than one item, {@link java.util.concurrent.Future} will receive an - * {@link java.lang.IllegalArgumentException}. If the {@link Flowable} is empty, {@link java.util.concurrent.Future} - * will receive a {@link java.util.NoSuchElementException}. + * {@link java.lang.IndexOutOfBoundsException}. If the {@link Flowable} is empty, {@link java.util.concurrent.Future} + * will receive a {@link java.util.NoSuchElementException}. The {@code Flowable} source has to terminate in order + * for the returned {@code Future} to terminate as well. *

    * If the {@code Flowable} may emit more than one item, use {@code Flowable.toList().toFuture()}. - *

    - * *

    *
    Backpressure:
    *
    The operator consumes the source {@code Flowable} in an unbounded manner diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 541c15215c..4c11350715 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -5340,15 +5340,16 @@ public final T blockingSingle(T defaultItem) { } /** - * Returns a {@link Future} representing the single value emitted by this {@code Observable}. + * Returns a {@link Future} representing the only value emitted by this {@code Observable}. + *

    + * *

    * If the {@link Observable} emits more than one item, {@link java.util.concurrent.Future} will receive an - * {@link java.lang.IllegalArgumentException}. If the {@link Observable} is empty, {@link java.util.concurrent.Future} - * will receive an {@link java.util.NoSuchElementException}. + * {@link java.lang.IndexOutOfBoundsException}. If the {@link Observable} is empty, {@link java.util.concurrent.Future} + * will receive an {@link java.util.NoSuchElementException}. The {@code Observable} source has to terminate in order + * for the returned {@code Future} to terminate as well. *

    * If the {@code Observable} may emit more than one item, use {@code Observable.toList().toFuture()}. - *

    - * *

    *
    Scheduler:
    *
    {@code toFuture} does not operate by default on a particular {@link Scheduler}.
    From 59454ea47965547e7e218039ed152b591a51e268 Mon Sep 17 00:00:00 2001 From: luis-cortes Date: Tue, 4 Sep 2018 12:08:06 -0400 Subject: [PATCH 074/211] Fix terminology of cancel/dispose in the JavaDocs (#6199) * #6196 Fixing terminology of cancel/dispose in the JavaDocs for Completable. * #6196 Fixing terminology of cancel/dispose in the JavaDocs for Maybe. * #6196 Fixing terminology of cancel/dispose in the JavaDocs for Observable. * #6196 Fixing terminology of cancel/dispose in the JavaDocs for Single. * #6196 Switching from subscribers to observers in `Completable.fromFuture()` JavaDoc --- src/main/java/io/reactivex/Completable.java | 44 ++++++------- src/main/java/io/reactivex/Maybe.java | 40 ++++++------ src/main/java/io/reactivex/Observable.java | 68 ++++++++++----------- src/main/java/io/reactivex/Single.java | 32 +++++----- 4 files changed, 92 insertions(+), 92 deletions(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 430440b248..704e74c613 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -90,7 +90,7 @@ * d.dispose(); * *

    - * Note that by design, subscriptions via {@link #subscribe(CompletableObserver)} can't be cancelled/disposed + * Note that by design, subscriptions via {@link #subscribe(CompletableObserver)} can't be disposed * from the outside (hence the * {@code void} return of the {@link #subscribe(CompletableObserver)} method) and it is the * responsibility of the implementor of the {@code CompletableObserver} to allow this to happen. @@ -105,7 +105,7 @@ public abstract class Completable implements CompletableSource { /** * Returns a Completable which terminates as soon as one of the source Completables - * terminates (normally or with an error) and cancels all other Completables. + * terminates (normally or with an error) and disposes all other Completables. *

    * *

    @@ -133,7 +133,7 @@ public static Completable ambArray(final CompletableSource... sources) { /** * Returns a Completable which terminates as soon as one of the source Completables - * terminates (normally or with an error) and cancels all other Completables. + * terminates (normally or with an error) and disposes all other Completables. *

    * *

    @@ -306,7 +306,7 @@ public static Completable create(CompletableOnSubscribe source) { /** * Constructs a Completable instance by wrapping the given source callback * without any safeguards; you should manage the lifecycle and response - * to downstream cancellation/dispose. + * to downstream disposal. *

    * *

    @@ -446,7 +446,7 @@ public static Completable fromCallable(final Callable callable) { *

    * *

    - * Note that cancellation from any of the subscribers to this Completable will cancel the future. + * Note that if any of the observers to this Completable call dispose, this Completable will cancel the future. *

    *
    Scheduler:
    *
    {@code fromFuture} does not operate by default on a particular {@link Scheduler}.
    @@ -594,13 +594,13 @@ public static Completable fromSingle(final SingleSource single) { *
    {@code mergeArray} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code CompletableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are cancelled. + * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are disposed. * If more than one {@code CompletableSource} signals an error, the resulting {@code Completable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Completable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Completable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeArrayDelayError(CompletableSource...)} to merge sources and terminate only when all source {@code CompletableSource}s * have completed or failed with an error. @@ -634,13 +634,13 @@ public static Completable mergeArray(CompletableSource... sources) { *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code CompletableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are cancelled. + * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are disposed. * If more than one {@code CompletableSource} signals an error, the resulting {@code Completable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Completable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Completable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(Iterable)} to merge sources and terminate only when all source {@code CompletableSource}s * have completed or failed with an error. @@ -671,13 +671,13 @@ public static Completable merge(Iterable sources) { *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code CompletableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are cancelled. + * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are disposed. * If more than one {@code CompletableSource} signals an error, the resulting {@code Completable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Completable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Completable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(Publisher)} to merge sources and terminate only when all source {@code CompletableSource}s * have completed or failed with an error. @@ -708,13 +708,13 @@ public static Completable merge(Publisher sources) *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code CompletableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are cancelled. + * {@code Completable} terminates with that {@code Throwable} and all other source {@code CompletableSource}s are disposed. * If more than one {@code CompletableSource} signals an error, the resulting {@code Completable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Completable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Completable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(Publisher, int)} to merge sources and terminate only when all source {@code CompletableSource}s * have completed or failed with an error. @@ -952,7 +952,7 @@ public static Completable using(Callable resourceSupplier, *

    * *

    - * If this overload performs a lazy cancellation after the terminal event is emitted. + * If this overload performs a lazy disposal after the terminal event is emitted. * Exceptions thrown at this time will be delivered to RxJavaPlugins only. *

    *
    Scheduler:
    @@ -1585,7 +1585,7 @@ public final Completable doAfterTerminate(final Action onAfterTerminate) { *
    {@code doFinally} does not operate by default on a particular {@link Scheduler}.
    *
    *

    History: 2.0.1 - experimental - * @param onFinally the action called when this Completable terminates or gets cancelled + * @param onFinally the action called when this Completable terminates or gets disposed * @return the new Completable instance * @since 2.1 */ @@ -1852,7 +1852,7 @@ public final Completable onTerminateDetach() { } /** - * Returns a Completable that repeatedly subscribes to this Completable until cancelled. + * Returns a Completable that repeatedly subscribes to this Completable until disposed. *

    * *

    @@ -2155,7 +2155,7 @@ public final Completable hide() { } /** - * Subscribes to this CompletableConsumable and returns a Disposable which can be used to cancel + * Subscribes to this CompletableConsumable and returns a Disposable which can be used to dispose * the subscription. *

    * @@ -2163,7 +2163,7 @@ public final Completable hide() { *

    Scheduler:
    *
    {@code subscribe} does not operate by default on a particular {@link Scheduler}.
    *
    - * @return the Disposable that allows cancelling the subscription + * @return the Disposable that allows disposing the subscription */ @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe() { @@ -2245,7 +2245,7 @@ public final E subscribeWith(E observer) { *
    * @param onComplete the runnable that is called if the Completable completes normally * @param onError the consumer that is called if this Completable emits an error - * @return the Disposable that can be used for cancelling the subscription asynchronously + * @return the Disposable that can be used for disposing the subscription asynchronously * @throws NullPointerException if either callback is null */ @CheckReturnValue @@ -2273,7 +2273,7 @@ public final Disposable subscribe(final Action onComplete, final Consumer{@code subscribe} does not operate by default on a particular {@link Scheduler}.
    *
    * @param onComplete the runnable called when this Completable completes normally - * @return the Disposable that allows cancelling the subscription + * @return the Disposable that allows disposing the subscription */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @@ -2583,7 +2583,7 @@ public final Single toSingleDefault(final T completionValue) { } /** - * Returns a Completable which makes sure when a subscriber cancels the subscription, the + * Returns a Completable which makes sure when a subscriber disposes the subscription, the * dispose is called on the specified scheduler. *

    * @@ -2591,7 +2591,7 @@ public final Single toSingleDefault(final T completionValue) { *

    Scheduler:
    *
    {@code unsubscribeOn} calls dispose() of the upstream on the {@link Scheduler} you specify.
    * - * @param scheduler the target scheduler where to execute the cancellation + * @param scheduler the target scheduler where to execute the disposing * @return the new Completable instance * @throws NullPointerException if scheduler is null */ diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index be9c888762..346d35e16a 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -93,7 +93,7 @@ * d.dispose(); * *

    - * Note that by design, subscriptions via {@link #subscribe(MaybeObserver)} can't be cancelled/disposed + * Note that by design, subscriptions via {@link #subscribe(MaybeObserver)} can't be disposed * from the outside (hence the * {@code void} return of the {@link #subscribe(MaybeObserver)} method) and it is the * responsibility of the implementor of the {@code MaybeObserver} to allow this to happen. @@ -110,7 +110,7 @@ public abstract class Maybe implements MaybeSource { /** - * Runs multiple MaybeSources and signals the events of the first one that signals (cancelling + * Runs multiple MaybeSources and signals the events of the first one that signals (disposing * the rest). *

    * @@ -131,7 +131,7 @@ public static Maybe amb(final Iterable } /** - * Runs multiple MaybeSources and signals the events of the first one that signals (cancelling + * Runs multiple MaybeSources and signals the events of the first one that signals (disposing * the rest). *

    * @@ -767,7 +767,7 @@ public static Maybe fromCallable(@NonNull final Callable cal *

    * Important note: This Maybe is blocking; you cannot dispose it. *

    - * Unlike 1.x, cancelling the Maybe won't cancel the future. If necessary, one can use composition to achieve the + * Unlike 1.x, disposing the Maybe won't cancel the future. If necessary, one can use composition to achieve the * cancellation effect: {@code futureMaybe.doOnDispose(() -> future.cancel(true));}. *

    *
    Scheduler:
    @@ -798,7 +798,7 @@ public static Maybe fromFuture(Future future) { * return value of the {@link Future#get} method of that object, by passing the object into the {@code fromFuture} * method. *

    - * Unlike 1.x, cancelling the Maybe won't cancel the future. If necessary, one can use composition to achieve the + * Unlike 1.x, disposing the Maybe won't cancel the future. If necessary, one can use composition to achieve the * cancellation effect: {@code futureMaybe.doOnCancel(() -> future.cancel(true));}. *

    * Important note: This Maybe is blocking on the thread it gets subscribed on; you cannot dispose it. @@ -882,7 +882,7 @@ public static Maybe just(T item) { *

    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed. * If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -916,7 +916,7 @@ public static Flowable merge(Iterable> *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed. * If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -950,7 +950,7 @@ public static Flowable merge(Publisher *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed. * If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -1023,7 +1023,7 @@ public static Maybe merge(MaybeSource> *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed. * If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -1071,7 +1071,7 @@ public static Flowable merge( *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed. * If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -1123,7 +1123,7 @@ public static Flowable merge( *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed. * If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -1174,7 +1174,7 @@ public static Flowable merge( *
    {@code mergeArray} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed. * If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -2700,7 +2700,7 @@ public final Maybe doAfterTerminate(Action onAfterTerminate) { *
    {@code doFinally} does not operate by default on a particular {@link Scheduler}.
    *
    *

    History: 2.0.1 - experimental - * @param onFinally the action called when this Maybe terminates or gets cancelled + * @param onFinally the action called when this Maybe terminates or gets disposed * @return the new Maybe instance * @since 2.1 */ @@ -2718,7 +2718,7 @@ public final Maybe doFinally(Action onFinally) { *

    Scheduler:
    *
    {@code doOnDispose} does not operate by default on a particular {@link Scheduler}.
    * - * @param onDispose the action called when the subscription is cancelled (disposed) + * @param onDispose the action called when the subscription is disposed * @throws NullPointerException if onDispose is null * @return the new Maybe instance */ @@ -3499,7 +3499,7 @@ public final Flowable toFlowable() { } /** - * Converts this Maybe into an Observable instance composing cancellation + * Converts this Maybe into an Observable instance composing disposal * through. *
    *
    Scheduler:
    @@ -3518,7 +3518,7 @@ public final Observable toObservable() { } /** - * Converts this Maybe into a Single instance composing cancellation + * Converts this Maybe into a Single instance composing disposal * through and turning an empty Maybe into a Single that emits the given * value through onSuccess. *
    @@ -3536,7 +3536,7 @@ public final Single toSingle(T defaultValue) { } /** - * Converts this Maybe into a Single instance composing cancellation + * Converts this Maybe into a Single instance composing disposal * through and turning an empty Maybe into a signal of NoSuchElementException. *
    *
    Scheduler:
    @@ -4451,7 +4451,7 @@ public final Maybe timeout(MaybeSource timeoutIndicator) { /** * If the current {@code Maybe} didn't signal an event before the {@code timeoutIndicator} {@link MaybeSource} signals, - * the current {@code Maybe} is cancelled and the {@code fallback} {@code MaybeSource} subscribed to + * the current {@code Maybe} is disposed and the {@code fallback} {@code MaybeSource} subscribed to * as a continuation. *
    *
    Scheduler:
    @@ -4496,7 +4496,7 @@ public final Maybe timeout(Publisher timeoutIndicator) { /** * If the current {@code Maybe} didn't signal an event before the {@code timeoutIndicator} {@link Publisher} signals, - * the current {@code Maybe} is cancelled and the {@code fallback} {@code MaybeSource} subscribed to + * the current {@code Maybe} is disposed and the {@code fallback} {@code MaybeSource} subscribed to * as a continuation. *
    *
    Backpressure:
    @@ -4527,7 +4527,7 @@ public final Maybe timeout(Publisher timeoutIndicator, MaybeSourceScheduler: *
    {@code unsubscribeOn} calls dispose() of the upstream on the {@link Scheduler} you specify.
    *
    - * @param scheduler the target scheduler where to execute the cancellation + * @param scheduler the target scheduler where to execute the disposal * @return the new Maybe instance * @throws NullPointerException if scheduler is null */ diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 4c11350715..ef3c5ed450 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -53,7 +53,7 @@ * The design of this class was derived from the * Reactive-Streams design and specification * by removing any backpressure-related infrastructure and implementation detail, replacing the - * {@code org.reactivestreams.Subscription} with {@link Disposable} as the primary means to cancel + * {@code org.reactivestreams.Subscription} with {@link Disposable} as the primary means to dispose of * a flow. *

    * The {@code Observable} follows the protocol @@ -64,7 +64,7 @@ * the stream can be disposed through the {@code Disposable} instance provided to consumers through * {@code Observer.onSubscribe}. *

    - * Unlike the {@code Observable} of version 1.x, {@link #subscribe(Observer)} does not allow external cancellation + * Unlike the {@code Observable} of version 1.x, {@link #subscribe(Observer)} does not allow external disposal * of a subscription and the {@code Observer} instance is expected to expose such capability. *

    Example: *

    
    @@ -86,7 +86,7 @@
      *     });
      * 
      * Thread.sleep(500);
    - * // the sequence now can be cancelled via dispose()
    + * // the sequence can now be disposed via dispose()
      * d.dispose();
      * 
    * @@ -2054,7 +2054,7 @@ public static Observable generate(Callable initialState, final BiCo * {@code onComplete} to signal a value or a terminal event. Signalling multiple {@code onNext} * in a call will make the operator signal {@code IllegalStateException}. * @param disposeState the Consumer that is called with the current state when the generator - * terminates the sequence or it gets cancelled + * terminates the sequence or it gets disposed * @return the new Observable instance */ @CheckReturnValue @@ -2110,7 +2110,7 @@ public static Observable generate(Callable initialState, BiFunction * the next invocation. Signalling multiple {@code onNext} * in a call will make the operator signal {@code IllegalStateException}. * @param disposeState the Consumer that is called with the current state when the generator - * terminates the sequence or it gets cancelled + * terminates the sequence or it gets disposed * @return the new Observable instance */ @CheckReturnValue @@ -2698,13 +2698,13 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(Iterable, int, int)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -2745,13 +2745,13 @@ public static Observable merge(Iterable{@code mergeArray} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeArrayDelayError(int, int, ObservableSource...)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -2791,13 +2791,13 @@ public static Observable mergeArray(int maxConcurrency, int bufferSize, O *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(Iterable)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -2832,13 +2832,13 @@ public static Observable merge(Iterable{@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(Iterable, int)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -2877,13 +2877,13 @@ public static Observable merge(Iterable{@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -2920,13 +2920,13 @@ public static Observable merge(ObservableSource{@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource, int)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -2967,13 +2967,13 @@ public static Observable merge(ObservableSource{@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource, ObservableSource)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -3010,13 +3010,13 @@ public static Observable merge(ObservableSource source1, Obs *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource, ObservableSource, ObservableSource)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -3056,13 +3056,13 @@ public static Observable merge(ObservableSource source1, Obs *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource, ObservableSource, ObservableSource, ObservableSource)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -3107,13 +3107,13 @@ public static Observable merge( *
    {@code mergeArray} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are cancelled. + * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s - * signaled by source(s) after the returned {@code Observable} has been cancelled or terminated with a + * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeArrayDelayError(ObservableSource...)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. @@ -3909,7 +3909,7 @@ public static Observable timer(long delay, TimeUnit unit, Scheduler schedu /** * Create an Observable by wrapping an ObservableSource which has to be implemented according * to the Reactive-Streams-based Observable specification by handling - * cancellation correctly; no safeguards are provided by the Observable itself. + * disposal correctly; no safeguards are provided by the Observable itself. *
    *
    Scheduler:
    *
    {@code unsafeCreate} by default doesn't operate on any particular {@link Scheduler}.
    @@ -7582,10 +7582,10 @@ public final Observable delaySubscription(long delay, TimeUnit unit, Schedule *

    * When the upstream signals an {@link Notification#createOnError(Throwable) onError} or * {@link Notification#createOnComplete() onComplete} item, the - * returned Observable cancels the flow and terminates with that type of terminal event: + * returned Observable disposes of the flow and terminates with that type of terminal event: *

    
          * Observable.just(createOnNext(1), createOnComplete(), createOnNext(2))
    -     * .doOnDispose(() -> System.out.println("Cancelled!"));
    +     * .doOnDispose(() -> System.out.println("Disposed!"));
          * .test()
          * .assertResult(1);
          * 
    @@ -7883,7 +7883,7 @@ public final Observable doAfterTerminate(Action onFinally) { *
    This operator supports boundary-limited synchronous or asynchronous queue-fusion.
    *
    *

    History: 2.0.1 - experimental - * @param onFinally the action called when this Observable terminates or gets cancelled + * @param onFinally the action called when this Observable terminates or gets disposed * @return the new Observable instance * @since 2.1 */ @@ -8046,7 +8046,7 @@ public final Observable doOnError(Consumer onError) { /** * Calls the appropriate onXXX method (shared between all Observer) for the lifecycle events of - * the sequence (subscription, cancellation, requesting). + * the sequence (subscription, disposal, requesting). *

    * *

    @@ -8919,7 +8919,7 @@ public final Observable flatMapSingle(FunctionReactiveX operators documentation: Subscribe @@ -8947,7 +8947,7 @@ public final Disposable forEach(Consumer onNext) { * @param onNext * {@link Predicate} to execute for each item. * @return - * a Disposable that allows cancelling an asynchronous sequence + * a Disposable that allows disposing of an asynchronous sequence * @throws NullPointerException * if {@code onNext} is null * @see ReactiveX operators documentation: Subscribe @@ -8971,7 +8971,7 @@ public final Disposable forEachWhile(Predicate onNext) { * @param onError * {@link Consumer} to execute when an error is emitted. * @return - * a Disposable that allows cancelling an asynchronous sequence + * a Disposable that allows disposing of an asynchronous sequence * @throws NullPointerException * if {@code onNext} is null, or * if {@code onError} is null @@ -8998,7 +8998,7 @@ public final Disposable forEachWhile(Predicate onNext, Consumer *

    - * Note that by design, subscriptions via {@link #subscribe(SingleObserver)} can't be cancelled/disposed + * Note that by design, subscriptions via {@link #subscribe(SingleObserver)} can't be disposed * from the outside (hence the * {@code void} return of the {@link #subscribe(SingleObserver)} method) and it is the * responsibility of the implementor of the {@code SingleObserver} to allow this to happen. @@ -114,7 +114,7 @@ public abstract class Single implements SingleSource { /** - * Runs multiple SingleSources and signals the events of the first one that signals (cancelling + * Runs multiple SingleSources and signals the events of the first one that signals (disposing * the rest). *

    * @@ -136,7 +136,7 @@ public static Single amb(final Iterable * @@ -830,7 +830,7 @@ public static Single just(final T item) { *

    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code SingleSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are disposed. * If more than one {@code SingleSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -867,7 +867,7 @@ public static Flowable merge(Iterable *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code SingleSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are disposed. * If more than one {@code SingleSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -938,7 +938,7 @@ public static Single merge(SingleSource{@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code SingleSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are disposed. * If more than one {@code SingleSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -986,7 +986,7 @@ public static Flowable merge( *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code SingleSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are disposed. * If more than one {@code SingleSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -1038,7 +1038,7 @@ public static Flowable merge( *
    {@code merge} does not operate by default on a particular {@link Scheduler}.
    *
    Error handling:
    *
    If any of the source {@code SingleSource}s signal a {@code Throwable} via {@code onError}, the resulting - * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are cancelled. + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are disposed. * If more than one {@code SingleSource} signals an error, the resulting {@code Flowable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. @@ -1374,7 +1374,7 @@ public static Single unsafeCreate(SingleSource onSubscribe) { * to be run by the operator * @param disposer the consumer of the generated resource that is called exactly once for * that particular resource when the generated SingleSource terminates - * (successfully or with an error) or gets cancelled. + * (successfully or with an error) or gets disposed. * @return the new Single instance * @since 2.0 */ @@ -1401,7 +1401,7 @@ public static Single using(Callable resourceSupplier, * to be run by the operator * @param disposer the consumer of the generated resource that is called exactly once for * that particular resource when the generated SingleSource terminates - * (successfully or with an error) or gets cancelled. + * (successfully or with an error) or gets disposed. * @param eager * if true, the disposer is called before the terminal event is signalled * if false, the disposer is called after the terminal event is delivered to downstream @@ -1457,7 +1457,7 @@ public static Single wrap(SingleSource source) { *

    * *

    - * If any of the SingleSources signal an error, all other SingleSources get cancelled and the + * If any of the SingleSources signal an error, all other SingleSources get disposed and the * error emitted to downstream immediately. *

    *
    Scheduler:
    @@ -1902,7 +1902,7 @@ public static Single zip( *

    * *

    - * If any of the SingleSources signal an error, all other SingleSources get cancelled and the + * If any of the SingleSources signal an error, all other SingleSources get disposed and the * error emitted to downstream immediately. *

    *
    Scheduler:
    @@ -2368,7 +2368,7 @@ public final Single doAfterTerminate(Action onAfterTerminate) { *
    {@code doFinally} does not operate by default on a particular {@link Scheduler}.
    *
    *

    History: 2.0.1 - experimental - * @param onFinally the action called when this Single terminates or gets cancelled + * @param onFinally the action called when this Single terminates or gets disposed * @return the new Single instance * @since 2.1 */ @@ -3629,7 +3629,7 @@ public final Single timeout(long timeout, TimeUnit unit, Scheduler scheduler) /** * Runs the current Single and if it doesn't signal within the specified timeout window, it is - * cancelled and the other SingleSource subscribed to. + * disposed and the other SingleSource subscribed to. *

    *
    Scheduler:
    *
    {@code timeout} subscribes to the other SingleSource on the {@link Scheduler} you specify.
    @@ -3650,7 +3650,7 @@ public final Single timeout(long timeout, TimeUnit unit, Scheduler scheduler, /** * Runs the current Single and if it doesn't signal within the specified timeout window, it is - * cancelled and the other SingleSource subscribed to. + * disposed and the other SingleSource subscribed to. *
    *
    Scheduler:
    *
    {@code timeout} subscribes to the other SingleSource on @@ -3839,7 +3839,7 @@ public final Observable toObservable() { *
    {@code unsubscribeOn} calls dispose() of the upstream on the {@link Scheduler} you specify.
    *
    *

    History: 2.0.9 - experimental - * @param scheduler the target scheduler where to execute the cancellation + * @param scheduler the target scheduler where to execute the disposal * @return the new Single instance * @throws NullPointerException if scheduler is null * @since 2.2 From cc459751031f6122330c08dcc2e57c9b5370cee3 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 6 Sep 2018 09:30:42 +0200 Subject: [PATCH 075/211] Release 2.2.2 --- CHANGES.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index a4dfea7e35..308c8e606b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,23 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.2 - September 6, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.2%7C)) + +#### Bugfixes + + - [Pull 6187](https://github.com/ReactiveX/RxJava/pull/6187): Fix `refCount` termination-reconnect race. + +#### Documentation changes + + - [Pull 6171](https://github.com/ReactiveX/RxJava/pull/6171): Add explanation text to `Undeliverable` & `OnErrorNotImplemented` exceptions. + - [Pull 6174](https://github.com/ReactiveX/RxJava/pull/6174): Auto-clean up RxJavaPlugins JavaDocs HTML. + - [Pull 6175](https://github.com/ReactiveX/RxJava/pull/6175): Explain `null` observer/subscriber return errors from `RxJavaPlugins` in detail. + - [Pull 6180](https://github.com/ReactiveX/RxJava/pull/6180): Update `Additional-Reading.md`. + - [Pull 6180](https://github.com/ReactiveX/RxJava/pull/6180): Fix `Flowable.reduce(BiFunction)` JavaDoc; the operator does not signal `NoSuchElementException`. + - [Pull 6193](https://github.com/ReactiveX/RxJava/pull/6193): Add "error handling" java docs section to `fromCallable` & co. + - [Pull 6199](https://github.com/ReactiveX/RxJava/pull/6199): Fix terminology of cancel/dispose in the JavaDocs. + - [Pull 6200](https://github.com/ReactiveX/RxJava/pull/6200): Fix `toFuture` marbles and descriptions. + ### Version 2.2.1 - August 23, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.1%7C)) #### API changes From b9c00a8e562e04328dff26d37a4acdd811db174d Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 7 Sep 2018 15:00:30 +0200 Subject: [PATCH 076/211] 2.x: Assert instead of print Undeliverable in some tests (#6205) * 2.x: Assert instead of print Undeliverable in some tests * Fix error count not guaranteed to be 4. --- .../io/reactivex/maybe/MaybeCreateTest.java | 162 +++++++++++------- .../java/io/reactivex/maybe/MaybeTest.java | 144 ++++++++++------ .../observers/SerializedObserverTest.java | 44 +++-- .../subscribers/SerializedSubscriberTest.java | 97 +++++++---- 4 files changed, 271 insertions(+), 176 deletions(-) diff --git a/src/test/java/io/reactivex/maybe/MaybeCreateTest.java b/src/test/java/io/reactivex/maybe/MaybeCreateTest.java index f6d24bd980..90689133d5 100644 --- a/src/test/java/io/reactivex/maybe/MaybeCreateTest.java +++ b/src/test/java/io/reactivex/maybe/MaybeCreateTest.java @@ -15,12 +15,15 @@ import static org.junit.Assert.assertTrue; +import java.util.List; + import org.junit.Test; import io.reactivex.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Cancellable; +import io.reactivex.plugins.RxJavaPlugins; public class MaybeCreateTest { @Test(expected = NullPointerException.class) @@ -30,84 +33,111 @@ public void nullArgument() { @Test public void basic() { - final Disposable d = Disposables.empty(); - - Maybe.create(new MaybeOnSubscribe() { - @Override - public void subscribe(MaybeEmitter e) throws Exception { - e.setDisposable(d); - - e.onSuccess(1); - e.onError(new TestException()); - e.onSuccess(2); - e.onError(new TestException()); - } - }).test().assertResult(1); - - assertTrue(d.isDisposed()); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); + + Maybe.create(new MaybeOnSubscribe() { + @Override + public void subscribe(MaybeEmitter e) throws Exception { + e.setDisposable(d); + + e.onSuccess(1); + e.onError(new TestException()); + e.onSuccess(2); + e.onError(new TestException()); + } + }).test().assertResult(1); + + assertTrue(d.isDisposed()); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithCancellable() { - final Disposable d1 = Disposables.empty(); - final Disposable d2 = Disposables.empty(); - - Maybe.create(new MaybeOnSubscribe() { - @Override - public void subscribe(MaybeEmitter e) throws Exception { - e.setDisposable(d1); - e.setCancellable(new Cancellable() { - @Override - public void cancel() throws Exception { - d2.dispose(); - } - }); - - e.onSuccess(1); - e.onError(new TestException()); - e.onSuccess(2); - e.onError(new TestException()); - } - }).test().assertResult(1); - - assertTrue(d1.isDisposed()); - assertTrue(d2.isDisposed()); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d1 = Disposables.empty(); + final Disposable d2 = Disposables.empty(); + + Maybe.create(new MaybeOnSubscribe() { + @Override + public void subscribe(MaybeEmitter e) throws Exception { + e.setDisposable(d1); + e.setCancellable(new Cancellable() { + @Override + public void cancel() throws Exception { + d2.dispose(); + } + }); + + e.onSuccess(1); + e.onError(new TestException()); + e.onSuccess(2); + e.onError(new TestException()); + } + }).test().assertResult(1); + + assertTrue(d1.isDisposed()); + assertTrue(d2.isDisposed()); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithError() { - final Disposable d = Disposables.empty(); - - Maybe.create(new MaybeOnSubscribe() { - @Override - public void subscribe(MaybeEmitter e) throws Exception { - e.setDisposable(d); - - e.onError(new TestException()); - e.onSuccess(2); - e.onError(new TestException()); - } - }).test().assertFailure(TestException.class); - - assertTrue(d.isDisposed()); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); + + Maybe.create(new MaybeOnSubscribe() { + @Override + public void subscribe(MaybeEmitter e) throws Exception { + e.setDisposable(d); + + e.onError(new TestException()); + e.onSuccess(2); + e.onError(new TestException()); + } + }).test().assertFailure(TestException.class); + + assertTrue(d.isDisposed()); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithCompletion() { - final Disposable d = Disposables.empty(); - - Maybe.create(new MaybeOnSubscribe() { - @Override - public void subscribe(MaybeEmitter e) throws Exception { - e.setDisposable(d); - - e.onComplete(); - e.onSuccess(2); - e.onError(new TestException()); - } - }).test().assertComplete(); - - assertTrue(d.isDisposed()); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); + + Maybe.create(new MaybeOnSubscribe() { + @Override + public void subscribe(MaybeEmitter e) throws Exception { + e.setDisposable(d); + + e.onComplete(); + e.onSuccess(2); + e.onError(new TestException()); + } + }).test().assertComplete(); + + assertTrue(d.isDisposed()); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test(expected = IllegalArgumentException.class) diff --git a/src/test/java/io/reactivex/maybe/MaybeTest.java b/src/test/java/io/reactivex/maybe/MaybeTest.java index b726b77611..41225a47cc 100644 --- a/src/test/java/io/reactivex/maybe/MaybeTest.java +++ b/src/test/java/io/reactivex/maybe/MaybeTest.java @@ -1496,68 +1496,91 @@ public void nullArgument() { @Test public void basic() { - final Disposable d = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); - Maybe.create(new MaybeOnSubscribe() { - @Override - public void subscribe(MaybeEmitter e) throws Exception { - e.setDisposable(d); + Maybe.create(new MaybeOnSubscribe() { + @Override + public void subscribe(MaybeEmitter e) throws Exception { + e.setDisposable(d); + + e.onSuccess(1); + e.onError(new TestException()); + e.onSuccess(2); + e.onError(new TestException()); + e.onComplete(); + } + }) + .test() + .assertResult(1); - e.onSuccess(1); - e.onError(new TestException()); - e.onSuccess(2); - e.onError(new TestException()); - e.onComplete(); - } - }) - .test() - .assertResult(1); + assertTrue(d.isDisposed()); - assertTrue(d.isDisposed()); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + TestHelper.assertUndeliverable(errors, 1, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithError() { - final Disposable d = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); - Maybe.create(new MaybeOnSubscribe() { - @Override - public void subscribe(MaybeEmitter e) throws Exception { - e.setDisposable(d); + Maybe.create(new MaybeOnSubscribe() { + @Override + public void subscribe(MaybeEmitter e) throws Exception { + e.setDisposable(d); - e.onError(new TestException()); - e.onSuccess(2); - e.onError(new TestException()); - e.onComplete(); - } - }) - .test() - .assertFailure(TestException.class); + e.onError(new TestException()); + e.onSuccess(2); + e.onError(new TestException()); + e.onComplete(); + } + }) + .test() + .assertFailure(TestException.class); + + assertTrue(d.isDisposed()); - assertTrue(d.isDisposed()); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test public void basicWithComplete() { - final Disposable d = Disposables.empty(); + List errors = TestHelper.trackPluginErrors(); + try { + final Disposable d = Disposables.empty(); - Maybe.create(new MaybeOnSubscribe() { - @Override - public void subscribe(MaybeEmitter e) throws Exception { - e.setDisposable(d); + Maybe.create(new MaybeOnSubscribe() { + @Override + public void subscribe(MaybeEmitter e) throws Exception { + e.setDisposable(d); + + e.onComplete(); + e.onSuccess(1); + e.onError(new TestException()); + e.onComplete(); + e.onSuccess(2); + e.onError(new TestException()); + } + }) + .test() + .assertResult(); - e.onComplete(); - e.onSuccess(1); - e.onError(new TestException()); - e.onComplete(); - e.onSuccess(2); - e.onError(new TestException()); - } - }) - .test() - .assertResult(); + assertTrue(d.isDisposed()); - assertTrue(d.isDisposed()); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + TestHelper.assertUndeliverable(errors, 1, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test(expected = IllegalArgumentException.class) @@ -2359,21 +2382,28 @@ public void accept(Integer v, Throwable e) throws Exception { @Test public void doOnEventError() { - final List list = new ArrayList(); + List errors = TestHelper.trackPluginErrors(); + try { + final List list = new ArrayList(); - TestException ex = new TestException(); + TestException ex = new TestException(); - assertTrue(Maybe.error(ex) - .doOnEvent(new BiConsumer() { - @Override - public void accept(Integer v, Throwable e) throws Exception { - list.add(v); - list.add(e); - } - }) - .subscribe().isDisposed()); + assertTrue(Maybe.error(ex) + .doOnEvent(new BiConsumer() { + @Override + public void accept(Integer v, Throwable e) throws Exception { + list.add(v); + list.add(e); + } + }) + .subscribe().isDisposed()); + + assertEquals(Arrays.asList(null, ex), list); - assertEquals(Arrays.asList(null, ex), list); + TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/observers/SerializedObserverTest.java b/src/test/java/io/reactivex/observers/SerializedObserverTest.java index a2f0e63ece..f094ad7fc7 100644 --- a/src/test/java/io/reactivex/observers/SerializedObserverTest.java +++ b/src/test/java/io/reactivex/observers/SerializedObserverTest.java @@ -156,6 +156,7 @@ public void testMultiThreadedWithNPEinMiddle() { @Test public void runOutOfOrderConcurrencyTest() { ExecutorService tp = Executors.newFixedThreadPool(20); + List errors = TestHelper.trackPluginErrors(); try { TestConcurrencySubscriber tw = new TestConcurrencySubscriber(); // we need Synchronized + SafeObserver to handle synchronization plus life-cycle @@ -190,6 +191,10 @@ public void runOutOfOrderConcurrencyTest() { @SuppressWarnings("unused") int numNextEvents = tw.assertEvents(null); // no check of type since we don't want to test barging results here, just interleaving behavior // System.out.println("Number of events executed: " + numNextEvents); + + for (int i = 0; i < errors.size(); i++) { + TestHelper.assertUndeliverable(errors, i, RuntimeException.class); + } } catch (Throwable e) { fail("Concurrency test failed: " + e.getMessage()); e.printStackTrace(); @@ -200,6 +205,8 @@ public void runOutOfOrderConcurrencyTest() { } catch (InterruptedException e) { e.printStackTrace(); } + + RxJavaPlugins.reset(); } } @@ -955,24 +962,31 @@ public void onNext(Integer t) { @Test public void testErrorReentry() { - final AtomicReference> serial = new AtomicReference>(); + List errors = TestHelper.trackPluginErrors(); + try { + final AtomicReference> serial = new AtomicReference>(); - TestObserver to = new TestObserver() { - @Override - public void onNext(Integer v) { - serial.get().onError(new TestException()); - serial.get().onError(new TestException()); - super.onNext(v); - } - }; - SerializedObserver sobs = new SerializedObserver(to); - sobs.onSubscribe(Disposables.empty()); - serial.set(sobs); + TestObserver to = new TestObserver() { + @Override + public void onNext(Integer v) { + serial.get().onError(new TestException()); + serial.get().onError(new TestException()); + super.onNext(v); + } + }; + SerializedObserver sobs = new SerializedObserver(to); + sobs.onSubscribe(Disposables.empty()); + serial.set(sobs); - sobs.onNext(1); + sobs.onNext(1); - to.assertValue(1); - to.assertError(TestException.class); + to.assertValue(1); + to.assertError(TestException.class); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test diff --git a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java index 0ecec64e8e..c38105eb68 100644 --- a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java @@ -158,6 +158,7 @@ public void testMultiThreadedWithNPEinMiddle() { @Test public void runOutOfOrderConcurrencyTest() { ExecutorService tp = Executors.newFixedThreadPool(20); + List errors = TestHelper.trackPluginErrors(); try { TestConcurrencySubscriber tw = new TestConcurrencySubscriber(); // we need Synchronized + SafeSubscriber to handle synchronization plus life-cycle @@ -192,6 +193,10 @@ public void runOutOfOrderConcurrencyTest() { @SuppressWarnings("unused") int numNextEvents = tw.assertEvents(null); // no check of type since we don't want to test barging results here, just interleaving behavior // System.out.println("Number of events executed: " + numNextEvents); + + for (int i = 0; i < errors.size(); i++) { + TestHelper.assertUndeliverable(errors, i, RuntimeException.class); + } } catch (Throwable e) { fail("Concurrency test failed: " + e.getMessage()); e.printStackTrace(); @@ -202,6 +207,8 @@ public void runOutOfOrderConcurrencyTest() { } catch (InterruptedException e) { e.printStackTrace(); } + + RxJavaPlugins.reset(); } } @@ -957,24 +964,31 @@ public void onNext(Integer t) { @Test public void testErrorReentry() { - final AtomicReference> serial = new AtomicReference>(); + List errors = TestHelper.trackPluginErrors(); + try { + final AtomicReference> serial = new AtomicReference>(); - TestSubscriber ts = new TestSubscriber() { - @Override - public void onNext(Integer v) { - serial.get().onError(new TestException()); - serial.get().onError(new TestException()); - super.onNext(v); - } - }; - SerializedSubscriber sobs = new SerializedSubscriber(ts); - sobs.onSubscribe(new BooleanSubscription()); - serial.set(sobs); + TestSubscriber ts = new TestSubscriber() { + @Override + public void onNext(Integer v) { + serial.get().onError(new TestException()); + serial.get().onError(new TestException()); + super.onNext(v); + } + }; + SerializedSubscriber sobs = new SerializedSubscriber(ts); + sobs.onSubscribe(new BooleanSubscription()); + serial.set(sobs); - sobs.onNext(1); + sobs.onNext(1); - ts.assertValue(1); - ts.assertError(TestException.class); + ts.assertValue(1); + ts.assertError(TestException.class); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } } @Test @@ -1180,38 +1194,45 @@ public void startOnce() { @Test public void onCompleteOnErrorRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - TestSubscriber ts = new TestSubscriber(); + List errors = TestHelper.trackPluginErrors(); + try { + TestSubscriber ts = new TestSubscriber(); - final SerializedSubscriber so = new SerializedSubscriber(ts); + final SerializedSubscriber so = new SerializedSubscriber(ts); - BooleanSubscription bs = new BooleanSubscription(); + BooleanSubscription bs = new BooleanSubscription(); - so.onSubscribe(bs); + so.onSubscribe(bs); - final Throwable ex = new TestException(); + final Throwable ex = new TestException(); - Runnable r1 = new Runnable() { - @Override - public void run() { - so.onError(ex); - } - }; + Runnable r1 = new Runnable() { + @Override + public void run() { + so.onError(ex); + } + }; - Runnable r2 = new Runnable() { - @Override - public void run() { - so.onComplete(); - } - }; + Runnable r2 = new Runnable() { + @Override + public void run() { + so.onComplete(); + } + }; - TestHelper.race(r1, r2); + TestHelper.race(r1, r2); - ts.awaitDone(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); - if (ts.completions() != 0) { - ts.assertResult(); - } else { - ts.assertFailure(TestException.class).assertError(ex); + if (ts.completions() != 0) { + ts.assertResult(); + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } else { + ts.assertFailure(TestException.class).assertError(ex); + assertTrue("" + errors, errors.isEmpty()); + } + } finally { + RxJavaPlugins.reset(); } } From 3c773caf327f301e81e60bd0743178dcb7e793e8 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 21 Sep 2018 20:13:25 +0200 Subject: [PATCH 077/211] 2.x JavaDocs: Remove unnecessary 's' from ConnectableObservable (#6220) --- .../io/reactivex/observables/ConnectableObservable.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/observables/ConnectableObservable.java b/src/main/java/io/reactivex/observables/ConnectableObservable.java index 1858397e65..b5e54054b1 100644 --- a/src/main/java/io/reactivex/observables/ConnectableObservable.java +++ b/src/main/java/io/reactivex/observables/ConnectableObservable.java @@ -203,7 +203,7 @@ public final Observable refCount(int subscriberCount, long timeout, TimeUnit * during the lifetime of the returned Observable. If this ConnectableObservable * terminates, the connection is never renewed, no matter how Observers come * and go. Use {@link #refCount()} to renew a connection or dispose an active - * connection when all {@code Observers}s have disposed their {@code Disposable}s. + * connection when all {@code Observer}s have disposed their {@code Disposable}s. *

    * This overload does not allow disconnecting the connection established via * {@link #connect(Consumer)}. Use the {@link #autoConnect(int, Consumer)} overload @@ -227,7 +227,7 @@ public Observable autoConnect() { * during the lifetime of the returned Observable. If this ConnectableObservable * terminates, the connection is never renewed, no matter how Observers come * and go. Use {@link #refCount()} to renew a connection or dispose an active - * connection when all {@code Observers}s have disposed their {@code Disposable}s. + * connection when all {@code Observer}s have disposed their {@code Disposable}s. *

    * This overload does not allow disconnecting the connection established via * {@link #connect(Consumer)}. Use the {@link #autoConnect(int, Consumer)} overload @@ -255,7 +255,7 @@ public Observable autoConnect(int numberOfSubscribers) { * during the lifetime of the returned Observable. If this ConnectableObservable * terminates, the connection is never renewed, no matter how Observers come * and go. Use {@link #refCount()} to renew a connection or dispose an active - * connection when all {@code Observers}s have disposed their {@code Disposable}s. + * connection when all {@code Observer}s have disposed their {@code Disposable}s. * * @param numberOfSubscribers the number of subscribers to await before calling connect * on the ConnectableObservable. A non-positive value indicates From fd48d56266bf0664568226160516b182e046a62a Mon Sep 17 00:00:00 2001 From: Raiymbek Kapishev Date: Sun, 23 Sep 2018 16:12:56 +0400 Subject: [PATCH 078/211] Fix typos (#6223) - Add space on README.md page --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92bdf2946f..3fcaf292d2 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ The preparation of dataflows by applying various intermediate operators happens ```java Flowable flow = Flowable.range(1, 5) -.map(v -> v* v) +.map(v -> v * v) .filter(v -> v % 3 == 0) ; ``` From 1ea1e2abfe7f31a95a7a49cb938a8195216426b7 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sun, 30 Sep 2018 11:38:06 +0200 Subject: [PATCH 079/211] 2.x: Cleanup Observable.flatMap drain logic (#6232) --- .../observable/ObservableFlatMap.java | 40 ++++++----------- .../observable/ObservableFlatMapTest.java | 43 ++++++++++++++++++- 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java index 9039aa78a6..551ceba280 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java @@ -338,23 +338,17 @@ void drainLoop() { if (svq != null) { for (;;) { - U o; - for (;;) { - if (checkTerminate()) { - return; - } - - o = svq.poll(); + if (checkTerminate()) { + return; + } - if (o == null) { - break; - } + U o = svq.poll(); - child.onNext(o); - } if (o == null) { break; } + + child.onNext(o); } } @@ -415,17 +409,10 @@ void drainLoop() { @SuppressWarnings("unchecked") InnerObserver is = (InnerObserver)inner[j]; - - for (;;) { - if (checkTerminate()) { - return; - } - SimpleQueue q = is.queue; - if (q == null) { - break; - } - U o; + SimpleQueue q = is.queue; + if (q != null) { for (;;) { + U o; try { o = q.poll(); } catch (Throwable ex) { @@ -437,7 +424,10 @@ void drainLoop() { } removeInner(is); innerCompleted = true; - i++; + j++; + if (j == n) { + j = 0; + } continue sourceLoop; } if (o == null) { @@ -450,10 +440,8 @@ void drainLoop() { return; } } - if (o == null) { - break; - } } + boolean innerDone = is.done; SimpleQueue innerQueue = is.queue; if (innerDone && (innerQueue == null || innerQueue.isEmpty())) { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index 22a6889abc..c0cb65abe9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -26,14 +26,14 @@ import io.reactivex.*; import io.reactivex.Observable; import io.reactivex.Observer; -import io.reactivex.disposables.Disposable; +import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.subjects.*; public class ObservableFlatMapTest { @Test @@ -1006,4 +1006,43 @@ public void onNext(Integer t) { to.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } + + @Test + public void fusedSourceCrashResumeWithNextSource() { + final UnicastSubject fusedSource = UnicastSubject.create(); + TestObserver to = new TestObserver(); + + ObservableFlatMap.MergeObserver merger = + new ObservableFlatMap.MergeObserver(to, new Function>() { + @Override + public Observable apply(Integer t) + throws Exception { + if (t == 0) { + return fusedSource + .map(new Function() { + @Override + public Integer apply(Integer v) + throws Exception { throw new TestException(); } + }) + .compose(TestHelper.observableStripBoundary()); + } + return Observable.range(10 * t, 5); + } + }, true, Integer.MAX_VALUE, 128); + + merger.onSubscribe(Disposables.empty()); + merger.getAndIncrement(); + + merger.onNext(0); + merger.onNext(1); + merger.onNext(2); + + assertTrue(fusedSource.hasObservers()); + + fusedSource.onNext(-1); + + merger.drainLoop(); + + to.assertValuesOnly(10, 11, 12, 13, 14, 20, 21, 22, 23, 24); + } } From 6126752a3a26e084af4cd0e096d77b94ce2a8f94 Mon Sep 17 00:00:00 2001 From: "Artem Zinnatullin :slowpoke" Date: Tue, 2 Oct 2018 00:52:42 -0700 Subject: [PATCH 080/211] Add timeout and unit to TimeoutException message (#6234) * Add timeout and unit to TimeoutException message * New timeout message, add tests --- .../observers/BlockingMultiObserver.java | 4 +- .../internal/observers/FutureObserver.java | 4 +- .../observers/FutureSingleObserver.java | 4 +- .../completable/CompletableTimeout.java | 4 +- .../flowable/FlowableTimeoutTimed.java | 4 +- .../observable/ObservableTimeoutTimed.java | 4 +- .../operators/single/SingleTimeout.java | 14 +++++-- .../subscribers/FutureSubscriber.java | 4 +- .../internal/util/ExceptionHelper.java | 9 +++++ .../observers/BlockingMultiObserverTest.java | 15 ++++++++ .../observers/FutureObserverTest.java | 11 ++++++ .../observers/FutureSingleObserverTest.java | 5 ++- .../completable/CompletableTimeoutTest.java | 3 +- .../flowable/FlowableTimeoutTests.java | 35 ++++++++---------- .../observable/ObservableTimeoutTests.java | 37 ++++++++----------- .../operators/single/SingleTimeoutTest.java | 12 ++++++ .../subscribers/FutureSubscriberTest.java | 11 ++++++ 17 files changed, 125 insertions(+), 55 deletions(-) diff --git a/src/main/java/io/reactivex/internal/observers/BlockingMultiObserver.java b/src/main/java/io/reactivex/internal/observers/BlockingMultiObserver.java index d96f3efa21..2b5f5603e0 100644 --- a/src/main/java/io/reactivex/internal/observers/BlockingMultiObserver.java +++ b/src/main/java/io/reactivex/internal/observers/BlockingMultiObserver.java @@ -19,6 +19,8 @@ import io.reactivex.disposables.Disposable; import io.reactivex.internal.util.*; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; + /** * A combined Observer that awaits the success or error signal via a CountDownLatch. * @param the value type @@ -148,7 +150,7 @@ public Throwable blockingGetError(long timeout, TimeUnit unit) { BlockingHelper.verifyNonBlocking(); if (!await(timeout, unit)) { dispose(); - throw ExceptionHelper.wrapOrThrow(new TimeoutException()); + throw ExceptionHelper.wrapOrThrow(new TimeoutException(timeoutMessage(timeout, unit))); } } catch (InterruptedException ex) { dispose(); diff --git a/src/main/java/io/reactivex/internal/observers/FutureObserver.java b/src/main/java/io/reactivex/internal/observers/FutureObserver.java index b3de7f40b8..9b0d12140a 100644 --- a/src/main/java/io/reactivex/internal/observers/FutureObserver.java +++ b/src/main/java/io/reactivex/internal/observers/FutureObserver.java @@ -23,6 +23,8 @@ import io.reactivex.internal.util.BlockingHelper; import io.reactivex.plugins.RxJavaPlugins; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; + /** * An Observer + Future that expects exactly one upstream value and provides it * via the (blocking) Future API. @@ -92,7 +94,7 @@ public T get(long timeout, TimeUnit unit) throws InterruptedException, Execution if (getCount() != 0) { BlockingHelper.verifyNonBlocking(); if (!await(timeout, unit)) { - throw new TimeoutException(); + throw new TimeoutException(timeoutMessage(timeout, unit)); } } diff --git a/src/main/java/io/reactivex/internal/observers/FutureSingleObserver.java b/src/main/java/io/reactivex/internal/observers/FutureSingleObserver.java index fb3b096855..1ad8242b5c 100644 --- a/src/main/java/io/reactivex/internal/observers/FutureSingleObserver.java +++ b/src/main/java/io/reactivex/internal/observers/FutureSingleObserver.java @@ -22,6 +22,8 @@ import io.reactivex.internal.util.BlockingHelper; import io.reactivex.plugins.RxJavaPlugins; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; + /** * An Observer + Future that expects exactly one upstream value and provides it * via the (blocking) Future API. @@ -91,7 +93,7 @@ public T get(long timeout, TimeUnit unit) throws InterruptedException, Execution if (getCount() != 0) { BlockingHelper.verifyNonBlocking(); if (!await(timeout, unit)) { - throw new TimeoutException(); + throw new TimeoutException(timeoutMessage(timeout, unit)); } } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableTimeout.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableTimeout.java index 90d36ad103..c11daa7342 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableTimeout.java @@ -20,6 +20,8 @@ import io.reactivex.disposables.*; import io.reactivex.plugins.RxJavaPlugins; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; + public final class CompletableTimeout extends Completable { final CompletableSource source; @@ -104,7 +106,7 @@ public void run() { if (once.compareAndSet(false, true)) { set.clear(); if (other == null) { - downstream.onError(new TimeoutException()); + downstream.onError(new TimeoutException(timeoutMessage(timeout, unit))); } else { other.subscribe(new DisposeObserver()); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java index 28f00cfe1b..54a2762dfc 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java @@ -23,6 +23,8 @@ import io.reactivex.internal.subscriptions.*; import io.reactivex.plugins.RxJavaPlugins; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; + public final class FlowableTimeoutTimed extends AbstractFlowableWithUpstream { final long timeout; final TimeUnit unit; @@ -134,7 +136,7 @@ public void onTimeout(long idx) { if (compareAndSet(idx, Long.MAX_VALUE)) { SubscriptionHelper.cancel(upstream); - downstream.onError(new TimeoutException()); + downstream.onError(new TimeoutException(timeoutMessage(timeout, unit))); worker.dispose(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java index 7ceda44b73..9e3cb8a945 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTimeoutTimed.java @@ -21,6 +21,8 @@ import io.reactivex.internal.disposables.*; import io.reactivex.plugins.RxJavaPlugins; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; + public final class ObservableTimeoutTimed extends AbstractObservableWithUpstream { final long timeout; final TimeUnit unit; @@ -129,7 +131,7 @@ public void onTimeout(long idx) { if (compareAndSet(idx, Long.MAX_VALUE)) { DisposableHelper.dispose(upstream); - downstream.onError(new TimeoutException()); + downstream.onError(new TimeoutException(timeoutMessage(timeout, unit))); worker.dispose(); } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java b/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java index 4c97882d62..ea4212f0ec 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleTimeout.java @@ -21,6 +21,8 @@ import io.reactivex.internal.disposables.DisposableHelper; import io.reactivex.plugins.RxJavaPlugins; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; + public final class SingleTimeout extends Single { final SingleSource source; @@ -45,7 +47,7 @@ public SingleTimeout(SingleSource source, long timeout, TimeUnit unit, Schedu @Override protected void subscribeActual(final SingleObserver observer) { - TimeoutMainObserver parent = new TimeoutMainObserver(observer, other); + TimeoutMainObserver parent = new TimeoutMainObserver(observer, other, timeout, unit); observer.onSubscribe(parent); DisposableHelper.replace(parent.task, scheduler.scheduleDirect(parent, timeout, unit)); @@ -66,6 +68,10 @@ static final class TimeoutMainObserver extends AtomicReference SingleSource other; + final long timeout; + + final TimeUnit unit; + static final class TimeoutFallbackObserver extends AtomicReference implements SingleObserver { @@ -92,9 +98,11 @@ public void onError(Throwable e) { } } - TimeoutMainObserver(SingleObserver actual, SingleSource other) { + TimeoutMainObserver(SingleObserver actual, SingleSource other, long timeout, TimeUnit unit) { this.downstream = actual; this.other = other; + this.timeout = timeout; + this.unit = unit; this.task = new AtomicReference(); if (other != null) { this.fallback = new TimeoutFallbackObserver(actual); @@ -112,7 +120,7 @@ public void run() { } SingleSource other = this.other; if (other == null) { - downstream.onError(new TimeoutException()); + downstream.onError(new TimeoutException(timeoutMessage(timeout, unit))); } else { this.other = null; other.subscribe(fallback); diff --git a/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java index 1cc2eb2e09..a559749fb1 100644 --- a/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java @@ -24,6 +24,8 @@ import io.reactivex.internal.util.BlockingHelper; import io.reactivex.plugins.RxJavaPlugins; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; + /** * A Subscriber + Future that expects exactly one upstream value and provides it * via the (blocking) Future API. @@ -93,7 +95,7 @@ public T get(long timeout, TimeUnit unit) throws InterruptedException, Execution if (getCount() != 0) { BlockingHelper.verifyNonBlocking(); if (!await(timeout, unit)) { - throw new TimeoutException(); + throw new TimeoutException(timeoutMessage(timeout, unit)); } } diff --git a/src/main/java/io/reactivex/internal/util/ExceptionHelper.java b/src/main/java/io/reactivex/internal/util/ExceptionHelper.java index 002f2df215..b6fb4e9196 100644 --- a/src/main/java/io/reactivex/internal/util/ExceptionHelper.java +++ b/src/main/java/io/reactivex/internal/util/ExceptionHelper.java @@ -14,6 +14,7 @@ package io.reactivex.internal.util; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import io.reactivex.exceptions.CompositeException; @@ -121,6 +122,14 @@ public static Exception throwIfThrowable(Throwable e) thro throw (E)e; } + public static String timeoutMessage(long timeout, TimeUnit unit) { + return "The source did not signal an event for " + + timeout + + " " + + unit.toString().toLowerCase() + + " and has been terminated."; + } + static final class Termination extends Throwable { private static final long serialVersionUID = -4649703670690200604L; diff --git a/src/test/java/io/reactivex/internal/observers/BlockingMultiObserverTest.java b/src/test/java/io/reactivex/internal/observers/BlockingMultiObserverTest.java index 6b4238f8f6..793253504b 100644 --- a/src/test/java/io/reactivex/internal/observers/BlockingMultiObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/BlockingMultiObserverTest.java @@ -13,9 +13,11 @@ package io.reactivex.internal.observers; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.junit.Test; @@ -132,4 +134,17 @@ public void run() { assertTrue(bmo.blockingGetError(1, TimeUnit.MINUTES) instanceof TestException); } + + @Test + public void blockingGetErrorTimedOut() { + final BlockingMultiObserver bmo = new BlockingMultiObserver(); + + try { + assertNull(bmo.blockingGetError(1, TimeUnit.NANOSECONDS)); + fail("Should have thrown"); + } catch (RuntimeException expected) { + assertEquals(TimeoutException.class, expected.getCause().getClass()); + assertEquals(timeoutMessage(1, TimeUnit.NANOSECONDS), expected.getCause().getMessage()); + } + } } diff --git a/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java b/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java index bf91a78a4e..7ee71945bc 100644 --- a/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java @@ -13,6 +13,7 @@ package io.reactivex.internal.observers; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; import java.util.*; @@ -352,4 +353,14 @@ public void run() { assertEquals(1, fo.get().intValue()); } + + @Test + public void getTimedOut() throws Exception { + try { + fo.get(1, TimeUnit.NANOSECONDS); + fail("Should have thrown"); + } catch (TimeoutException expected) { + assertEquals(timeoutMessage(1, TimeUnit.NANOSECONDS), expected.getMessage()); + } + } } diff --git a/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java b/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java index 1dc0451434..9cafad4569 100644 --- a/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java @@ -13,6 +13,7 @@ package io.reactivex.internal.observers; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; import java.util.concurrent.*; @@ -89,8 +90,8 @@ public void timeout() throws Exception { try { f.get(100, TimeUnit.MILLISECONDS); fail("Should have thrown"); - } catch (TimeoutException ex) { - // expected + } catch (TimeoutException expected) { + assertEquals(timeoutMessage(100, TimeUnit.MILLISECONDS), expected.getMessage()); } } diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableTimeoutTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableTimeoutTest.java index 3df78394f3..a0de2b25aa 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableTimeoutTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableTimeoutTest.java @@ -13,6 +13,7 @@ package io.reactivex.internal.operators.completable; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; import java.util.List; @@ -40,7 +41,7 @@ public void timeoutException() throws Exception { .timeout(100, TimeUnit.MILLISECONDS, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) - .assertFailure(TimeoutException.class); + .assertFailureAndMessage(TimeoutException.class, timeoutMessage(100, TimeUnit.MILLISECONDS)); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java index 8ba33edca7..7e4b97c899 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java @@ -13,6 +13,7 @@ package io.reactivex.internal.operators.flowable; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -82,26 +83,24 @@ public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { @Test public void shouldTimeoutIfOnNextNotWithinTimeout() { - Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(subscriber); + TestSubscriber subscriber = new TestSubscriber(); - withTimeout.subscribe(ts); + withTimeout.subscribe(subscriber); testScheduler.advanceTimeBy(TIMEOUT + 1, TimeUnit.SECONDS); - verify(subscriber).onError(any(TimeoutException.class)); - ts.dispose(); + subscriber.assertFailureAndMessage(TimeoutException.class, timeoutMessage(TIMEOUT, TIME_UNIT)); } @Test public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { - Subscriber subscriber = TestHelper.mockSubscriber(); + TestSubscriber subscriber = new TestSubscriber(); TestSubscriber ts = new TestSubscriber(subscriber); withTimeout.subscribe(subscriber); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); - verify(subscriber).onNext("One"); + subscriber.assertValue("One"); testScheduler.advanceTimeBy(TIMEOUT + 1, TimeUnit.SECONDS); - verify(subscriber).onError(any(TimeoutException.class)); + subscriber.assertFailureAndMessage(TimeoutException.class, timeoutMessage(TIMEOUT, TIME_UNIT), "One"); ts.dispose(); } @@ -235,8 +234,7 @@ public void shouldTimeoutIfSynchronizedFlowableEmitFirstOnNextNotWithinTimeout() final CountDownLatch exit = new CountDownLatch(1); final CountDownLatch timeoutSetuped = new CountDownLatch(1); - final Subscriber subscriber = TestHelper.mockSubscriber(); - final TestSubscriber ts = new TestSubscriber(subscriber); + final TestSubscriber subscriber = new TestSubscriber(); new Thread(new Runnable() { @@ -258,16 +256,14 @@ public void subscribe(Subscriber subscriber) { } }).timeout(1, TimeUnit.SECONDS, testScheduler) - .subscribe(ts); + .subscribe(subscriber); } }).start(); timeoutSetuped.await(); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); - InOrder inOrder = inOrder(subscriber); - inOrder.verify(subscriber, times(1)).onError(isA(TimeoutException.class)); - inOrder.verifyNoMoreInteractions(); + subscriber.assertFailureAndMessage(TimeoutException.class, timeoutMessage(1, TimeUnit.SECONDS)); exit.countDown(); // exit the thread } @@ -287,15 +283,12 @@ public void subscribe(Subscriber subscriber) { TestScheduler testScheduler = new TestScheduler(); Flowable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(subscriber); - observableWithTimeout.subscribe(ts); + TestSubscriber subscriber = new TestSubscriber(); + observableWithTimeout.subscribe(subscriber); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(subscriber); - inOrder.verify(subscriber).onError(isA(TimeoutException.class)); - inOrder.verifyNoMoreInteractions(); + subscriber.assertFailureAndMessage(TimeoutException.class, timeoutMessage(1000, TimeUnit.MILLISECONDS)); verify(s, times(1)).cancel(); } @@ -548,11 +541,13 @@ public void run() { if (ts.valueCount() != 0) { if (ts.errorCount() != 0) { ts.assertFailure(TimeoutException.class, 1); + ts.assertErrorMessage(timeoutMessage(1, TimeUnit.SECONDS)); } else { ts.assertValuesOnly(1); } } else { ts.assertFailure(TimeoutException.class); + ts.assertErrorMessage(timeoutMessage(1, TimeUnit.SECONDS)); } } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java index 21e8caea84..935922b67c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java @@ -13,6 +13,7 @@ package io.reactivex.internal.operators.observable; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -81,27 +82,23 @@ public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { @Test public void shouldTimeoutIfOnNextNotWithinTimeout() { - Observer observer = TestHelper.mockObserver(); - TestObserver to = new TestObserver(observer); + TestObserver observer = new TestObserver(); - withTimeout.subscribe(to); + withTimeout.subscribe(observer); testScheduler.advanceTimeBy(TIMEOUT + 1, TimeUnit.SECONDS); - verify(observer).onError(any(TimeoutException.class)); - to.dispose(); + observer.assertFailureAndMessage(TimeoutException.class, timeoutMessage(TIMEOUT, TIME_UNIT)); } @Test public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { - Observer observer = TestHelper.mockObserver(); - TestObserver to = new TestObserver(observer); + TestObserver observer = new TestObserver(); withTimeout.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); - verify(observer).onNext("One"); + observer.assertValue("One"); testScheduler.advanceTimeBy(TIMEOUT + 1, TimeUnit.SECONDS); - verify(observer).onError(any(TimeoutException.class)); - to.dispose(); + observer.assertFailureAndMessage(TimeoutException.class, timeoutMessage(TIMEOUT, TIME_UNIT), "One"); } @Test @@ -234,8 +231,7 @@ public void shouldTimeoutIfSynchronizedObservableEmitFirstOnNextNotWithinTimeout final CountDownLatch exit = new CountDownLatch(1); final CountDownLatch timeoutSetuped = new CountDownLatch(1); - final Observer observer = TestHelper.mockObserver(); - final TestObserver to = new TestObserver(observer); + final TestObserver observer = new TestObserver(); new Thread(new Runnable() { @@ -257,16 +253,14 @@ public void subscribe(Observer observer) { } }).timeout(1, TimeUnit.SECONDS, testScheduler) - .subscribe(to); + .subscribe(observer); } }).start(); timeoutSetuped.await(); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError(isA(TimeoutException.class)); - inOrder.verifyNoMoreInteractions(); + observer.assertFailureAndMessage(TimeoutException.class, timeoutMessage(1, TimeUnit.SECONDS)); exit.countDown(); // exit the thread } @@ -286,15 +280,12 @@ public void subscribe(Observer observer) { TestScheduler testScheduler = new TestScheduler(); Observable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - Observer observer = TestHelper.mockObserver(); - TestObserver to = new TestObserver(observer); - observableWithTimeout.subscribe(to); + TestObserver observer = new TestObserver(); + observableWithTimeout.subscribe(observer); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer).onError(isA(TimeoutException.class)); - inOrder.verifyNoMoreInteractions(); + observer.assertFailureAndMessage(TimeoutException.class, timeoutMessage(1000, TimeUnit.MILLISECONDS)); verify(upstream, times(1)).dispose(); } @@ -547,11 +538,13 @@ public void run() { if (to.valueCount() != 0) { if (to.errorCount() != 0) { to.assertFailure(TimeoutException.class, 1); + to.assertErrorMessage(timeoutMessage(1, TimeUnit.SECONDS)); } else { to.assertValuesOnly(1); } } else { to.assertFailure(TimeoutException.class); + to.assertErrorMessage(timeoutMessage(1, TimeUnit.SECONDS)); } } } diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleTimeoutTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleTimeoutTest.java index 37077a6dd2..0acbc7a9ef 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleTimeoutTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleTimeoutTest.java @@ -13,10 +13,12 @@ package io.reactivex.internal.operators.single; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.junit.Test; @@ -209,4 +211,14 @@ public void run() { RxJavaPlugins.reset(); } } + + @Test + public void mainTimedOut() { + Single + .never() + .timeout(1, TimeUnit.NANOSECONDS) + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertFailureAndMessage(TimeoutException.class, timeoutMessage(1, TimeUnit.NANOSECONDS)); + } } diff --git a/src/test/java/io/reactivex/internal/subscribers/FutureSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/FutureSubscriberTest.java index baef7a9176..2aa9ec7a25 100644 --- a/src/test/java/io/reactivex/internal/subscribers/FutureSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/FutureSubscriberTest.java @@ -13,6 +13,7 @@ package io.reactivex.internal.subscribers; +import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; import java.util.*; @@ -281,4 +282,14 @@ public void run() { assertEquals(1, fs.get().intValue()); } + + @Test + public void getTimedOut() throws Exception { + try { + fs.get(1, TimeUnit.NANOSECONDS); + fail("Should have thrown"); + } catch (TimeoutException expected) { + assertEquals(timeoutMessage(1, TimeUnit.NANOSECONDS), expected.getMessage()); + } + } } From a04ade55d9a5053de7e5d49dd67edc8e23627db9 Mon Sep 17 00:00:00 2001 From: V Date: Tue, 2 Oct 2018 19:16:15 +0300 Subject: [PATCH 081/211] Fix docs typos (#6235) --- docs/Combining-Observables.md | 12 +++---- docs/Creating-Observables.md | 20 ++++++------ docs/Mathematical-and-Aggregate-Operators.md | 34 ++++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/Combining-Observables.md b/docs/Combining-Observables.md index 0e3796da1f..bcc19f6b0f 100644 --- a/docs/Combining-Observables.md +++ b/docs/Combining-Observables.md @@ -15,7 +15,7 @@ This section explains operators you can use to combine multiple Observables. **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/startwith.html](http://reactivex.io/documentation/operators/startwith.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/startwith.html](http://reactivex.io/documentation/operators/startwith.html) Emit a specified sequence of items before beginning to emit the items from the Observable. @@ -37,7 +37,7 @@ Combines multiple Observables into one. **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/merge.html](http://reactivex.io/documentation/operators/merge.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/merge.html](http://reactivex.io/documentation/operators/merge.html) Combines multiple Observables into one. Any `onError` notifications passed from any of the source observables will immediately be passed through to through to the observers and will terminate the merged `Observable`. @@ -55,7 +55,7 @@ Observable.just(1, 2, 3) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/merge.html](http://reactivex.io/documentation/operators/merge.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/merge.html](http://reactivex.io/documentation/operators/merge.html) Combines multiple Observables into one. Any `onError` notifications passed from any of the source observables will be withheld until all merged Observables complete, and only then will be passed along to the observers. @@ -75,7 +75,7 @@ Observable.mergeDelayError(observable1, observable2) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/zip.html](http://reactivex.io/documentation/operators/zip.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/zip.html](http://reactivex.io/documentation/operators/zip.html) Combines sets of items emitted by two or more Observables together via a specified function and emit items based on the results of this function. @@ -94,7 +94,7 @@ firstNames.zipWith(lastNames, (first, last) -> first + " " + last) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/combinelatest.html](http://reactivex.io/documentation/operators/combinelatest.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/combinelatest.html](http://reactivex.io/documentation/operators/combinelatest.html) When an item is emitted by either of two Observables, combine the latest item emitted by each Observable via a specified function and emit items based on the results of this function. @@ -124,7 +124,7 @@ Observable.combineLatest(newsRefreshes, weatherRefreshes, **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/switch.html](http://reactivex.io/documentation/operators/switch.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/switch.html](http://reactivex.io/documentation/operators/switch.html) Convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently emitted of those Observables. diff --git a/docs/Creating-Observables.md b/docs/Creating-Observables.md index b167c4d866..4d26bbf2b1 100644 --- a/docs/Creating-Observables.md +++ b/docs/Creating-Observables.md @@ -17,7 +17,7 @@ This page shows methods that create reactive sources, such as `Observable`s. **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/just.html](http://reactivex.io/documentation/operators/just.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/just.html](http://reactivex.io/documentation/operators/just.html) Constructs a reactive type by taking a pre-existing object and emitting that specific object to the downstream consumer upon subscription. @@ -46,7 +46,7 @@ Constructs a sequence from a pre-existing source or generator type. *Note: These static methods use the postfix naming convention (i.e., the argument type is repeated in the method name) to avoid overload resolution ambiguities.* -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/from.html](http://reactivex.io/documentation/operators/from.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/from.html](http://reactivex.io/documentation/operators/from.html) ### fromIterable @@ -203,7 +203,7 @@ observable.subscribe( **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/create.html](http://reactivex.io/documentation/operators/create.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/create.html](http://reactivex.io/documentation/operators/create.html) Construct a **safe** reactive type instance which when subscribed to by a consumer, runs an user-provided function and provides a type-specific `Emitter` for this function to generate the signal(s) the designated business logic requires. This method allows bridging the non-reactive, usually listener/callback-style world, with the reactive world. @@ -239,7 +239,7 @@ executor.shutdown(); **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/defer.html](http://reactivex.io/documentation/operators/defer.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/defer.html](http://reactivex.io/documentation/operators/defer.html) Calls an user-provided `java.util.concurrent.Callable` when a consumer subscribes to the reactive type so that the `Callable` can generate the actual reactive instance to relay signals from towards the consumer. `defer` allows: @@ -266,7 +266,7 @@ observable.subscribe(time -> System.out.println(time)); **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/range.html](http://reactivex.io/documentation/operators/range.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/range.html](http://reactivex.io/documentation/operators/range.html) Generates a sequence of values to each individual consumer. The `range()` method generates `Integer`s, the `rangeLong()` generates `Long`s. @@ -287,7 +287,7 @@ characters.subscribe(character -> System.out.print(character), erro -> error.pri **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/interval.html](http://reactivex.io/documentation/operators/interval.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/interval.html](http://reactivex.io/documentation/operators/interval.html) Periodically generates an infinite, ever increasing numbers (of type `Long`). The `intervalRange` variant generates a limited amount of such numbers. @@ -309,7 +309,7 @@ clock.subscribe(time -> { **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/timer.html](http://reactivex.io/documentation/operators/timer.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/timer.html](http://reactivex.io/documentation/operators/timer.html) After the specified time, this reactive source signals a single `0L` (then completes for `Flowable` and `Observable`). @@ -325,7 +325,7 @@ eggTimer.blockingSubscribe(v -> System.out.println("Egg is ready!")); **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/empty-never-throw.html](http://reactivex.io/documentation/operators/empty-never-throw.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/empty-never-throw.html](http://reactivex.io/documentation/operators/empty-never-throw.html) This type of source signals completion immediately upon subscription. @@ -344,7 +344,7 @@ empty.subscribe( **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/empty-never-throw.html](http://reactivex.io/documentation/operators/empty-never-throw.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/empty-never-throw.html](http://reactivex.io/documentation/operators/empty-never-throw.html) This type of source does not signal any `onNext`, `onSuccess`, `onError` or `onComplete`. This type of reactive source is useful in testing or "disabling" certain sources in combinator operators. @@ -363,7 +363,7 @@ never.subscribe( **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/empty-never-throw.html](http://reactivex.io/documentation/operators/empty-never-throw.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/empty-never-throw.html](http://reactivex.io/documentation/operators/empty-never-throw.html) Signal an error, either pre-existing or generated via a `java.util.concurrent.Callable`, to the consumer. diff --git a/docs/Mathematical-and-Aggregate-Operators.md b/docs/Mathematical-and-Aggregate-Operators.md index 574111ad0e..f6bf79019e 100644 --- a/docs/Mathematical-and-Aggregate-Operators.md +++ b/docs/Mathematical-and-Aggregate-Operators.md @@ -39,7 +39,7 @@ import hu.akarnokd.rxjava2.math.MathFlowable; **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/average.html](http://reactivex.io/documentation/operators/average.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/average.html](http://reactivex.io/documentation/operators/average.html) Calculates the average of `Number`s emitted by an `Observable` and emits this average as a `Double`. @@ -56,7 +56,7 @@ MathObservable.averageDouble(numbers).subscribe((Double avg) -> System.out.print **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/average.html](http://reactivex.io/documentation/operators/average.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/average.html](http://reactivex.io/documentation/operators/average.html) Calculates the average of `Number`s emitted by an `Observable` and emits this average as a `Float`. @@ -73,7 +73,7 @@ MathObservable.averageFloat(numbers).subscribe((Float avg) -> System.out.println **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/max.html](http://reactivex.io/documentation/operators/max.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/max.html](http://reactivex.io/documentation/operators/max.html) Emits the maximum value emitted by a source `Observable`. A `Comparator` can be specified that will be used to compare the elements emitted by the `Observable`. @@ -100,7 +100,7 @@ MathObservable.max(names, Comparator.comparingInt(String::length)) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/min.html](http://reactivex.io/documentation/operators/min.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/min.html](http://reactivex.io/documentation/operators/min.html) Emits the minimum value emitted by a source `Observable`. A `Comparator` can be specified that will be used to compare the elements emitted by the `Observable`. @@ -117,7 +117,7 @@ MathObservable.min(numbers).subscribe(System.out::println); **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) Adds the `Double`s emitted by an `Observable` and emits this sum. @@ -134,7 +134,7 @@ MathObservable.sumDouble(numbers).subscribe((Double sum) -> System.out.println(s **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) Adds the `Float`s emitted by an `Observable` and emits this sum. @@ -151,7 +151,7 @@ MathObservable.sumFloat(numbers).subscribe((Float sum) -> System.out.println(sum **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) Adds the `Integer`s emitted by an `Observable` and emits this sum. @@ -168,7 +168,7 @@ MathObservable.sumInt(numbers).subscribe((Integer sum) -> System.out.println(sum **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/sum.html](http://reactivex.io/documentation/operators/sum.html) Adds the `Long`s emitted by an `Observable` and emits this sum. @@ -189,7 +189,7 @@ MathObservable.sumLong(numbers).subscribe((Long sum) -> System.out.println(sum)) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/count.html](http://reactivex.io/documentation/operators/count.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/count.html](http://reactivex.io/documentation/operators/count.html) Counts the number of items emitted by an `Observable` and emits this count as a `Long`. @@ -205,7 +205,7 @@ Observable.just(1, 2, 3).count().subscribe(System.out::println); **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) Apply a function to each emitted item, sequentially, and emit only the final accumulated value. @@ -223,7 +223,7 @@ Observable.range(1, 5) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) Apply a function to each emitted item, sequentially, and emit only the final accumulated value. @@ -245,7 +245,7 @@ Observable.just(1, 2, 2, 3, 4, 4, 4, 5) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) Collect items emitted by the source `Observable` into a single mutable data structure and return an `Observable` that emits this structure. @@ -264,7 +264,7 @@ Observable.just("Kirk", "Spock", "Chekov", "Sulu") **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/reduce.html](http://reactivex.io/documentation/operators/reduce.html) Collect items emitted by the source `Observable` into a single mutable data structure and return an `Observable` that emits this structure. @@ -285,7 +285,7 @@ Observable.just('R', 'x', 'J', 'a', 'v', 'a') **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) Collect all items from an `Observable` and emit them as a single `List`. @@ -303,7 +303,7 @@ Observable.just(2, 1, 3) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) Collect all items from an `Observable` and emit them as a single, sorted `List`. @@ -321,7 +321,7 @@ Observable.just(2, 1, 3) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) Convert the sequence of items emitted by an `Observable` into a `Map` keyed by a specified key function. @@ -345,7 +345,7 @@ Observable.just(1, 2, 3, 4) **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` -**ReactiveX doumentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/to.html](http://reactivex.io/documentation/operators/to.html) Convert the sequence of items emitted by an `Observable` into a `Collection` that is also a `Map` keyed by a specified key function. From 2ad63c4431c71366b4be6b43d59cb7912f7653fa Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 3 Oct 2018 21:57:24 +0200 Subject: [PATCH 082/211] 2.x: Adjust Undeliverable & OnErrorNotImpl message to use full inner (#6236) --- .../io/reactivex/exceptions/OnErrorNotImplementedException.java | 2 +- .../java/io/reactivex/exceptions/UndeliverableException.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java b/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java index 6fdc42aeec..1cfe421916 100644 --- a/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java +++ b/src/main/java/io/reactivex/exceptions/OnErrorNotImplementedException.java @@ -48,6 +48,6 @@ public OnErrorNotImplementedException(String message, @NonNull Throwable e) { * the {@code Throwable} to signal; if null, a NullPointerException is constructed */ public OnErrorNotImplementedException(@NonNull Throwable e) { - this("The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: https://github.com/ReactiveX/RxJava/wiki/Error-Handling | " + (e != null ? e.getMessage() : ""), e); + this("The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: https://github.com/ReactiveX/RxJava/wiki/Error-Handling | " + e, e); } } \ No newline at end of file diff --git a/src/main/java/io/reactivex/exceptions/UndeliverableException.java b/src/main/java/io/reactivex/exceptions/UndeliverableException.java index d8bb99ce5c..d3923e0cdd 100644 --- a/src/main/java/io/reactivex/exceptions/UndeliverableException.java +++ b/src/main/java/io/reactivex/exceptions/UndeliverableException.java @@ -28,6 +28,6 @@ public final class UndeliverableException extends IllegalStateException { * @param cause the cause, not null */ public UndeliverableException(Throwable cause) { - super("The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | " + cause.getMessage(), cause); + super("The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | " + cause, cause); } } From 17f6e840e437ac90e81f2f2d369e25d4bcbde9ff Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 9 Oct 2018 15:01:04 +0200 Subject: [PATCH 083/211] 2.x Wiki: Remove mention of i.r.f.Functions (#6241) The `io.reactivex.functions.Functions` utility method has been made internal a long ago and should not be mentioned. --- docs/What's-different-in-2.0.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/What's-different-in-2.0.md b/docs/What's-different-in-2.0.md index 4dbaea04b1..fac50df56d 100644 --- a/docs/What's-different-in-2.0.md +++ b/docs/What's-different-in-2.0.md @@ -294,8 +294,6 @@ We followed the naming convention of Java 8 by defining `io.reactivex.functions. In addition, operators requiring a predicate no longer use `Func1` but have a separate, primitive-returning type of `Predicate` (allows better inlining due to no autoboxing). -The `io.reactivex.functions.Functions` utility class offers common function sources and conversions to `Function`. - # Subscriber The Reactive-Streams specification has its own Subscriber as an interface. This interface is lightweight and combines request management with cancellation into a single interface `org.reactivestreams.Subscription` instead of having `rx.Producer` and `rx.Subscription` separately. This allows creating stream consumers with less internal state than the quite heavy `rx.Subscriber` of 1.x. @@ -969,4 +967,4 @@ Flowable.just(1, 2, 3) .doFinally(() -> System.out.println("Finally")) .take(2) // cancels the above after 2 elements .subscribe(System.out::println); -``` \ No newline at end of file +``` From a1758c4b9ba1f908b50552b92db0845686dbd6a3 Mon Sep 17 00:00:00 2001 From: Dmitry Fisenko Date: Fri, 12 Oct 2018 20:07:34 +0300 Subject: [PATCH 084/211] Add Nullable annotations for blocking methods in Completable (#6244) --- src/main/java/io/reactivex/Completable.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 704e74c613..9911261911 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -1227,6 +1227,7 @@ public final boolean blockingAwait(long timeout, TimeUnit unit) { * @return the throwable if this terminated with an error, null otherwise * @throws RuntimeException that wraps an InterruptedException if the wait is interrupted */ + @Nullable @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Throwable blockingGet() { @@ -1250,6 +1251,7 @@ public final Throwable blockingGet() { * @throws RuntimeException that wraps an InterruptedException if the wait is interrupted or * TimeoutException if the specified timeout elapsed before it */ + @Nullable @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Throwable blockingGet(long timeout, TimeUnit unit) { From f78bd953e6d09792d2ba2aa1c3fce0f7c9110810 Mon Sep 17 00:00:00 2001 From: soshial Date: Fri, 19 Oct 2018 11:16:04 +0300 Subject: [PATCH 085/211] Add delaySubscription() methods to Completable #5081 (#6242) * Add delaySubscription() methods to Completable #5081 * fix parameter test and documentation for delaySubscription() * add tests to delayCompletable() * remove mocked observer from delaySubscription() tests for Completable --- src/main/java/io/reactivex/Completable.java | 45 ++++++++++++ .../completable/CompletableDelayTest.java | 72 ++++++++++++++++++- .../ParamValidationCheckerTest.java | 4 ++ 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 9911261911..58eddbfed8 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -1390,6 +1390,51 @@ public final Completable delay(final long delay, final TimeUnit unit, final Sche return RxJavaPlugins.onAssembly(new CompletableDelay(this, delay, unit, scheduler, delayError)); } + /** + * Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time. + *

    + *

    + *
    Scheduler:
    + *
    This version of {@code delaySubscription} operates by default on the {@code computation} {@link Scheduler}.
    + *
    + * + * @param delay the time to delay the subscription + * @param unit the time unit of {@code delay} + * @return a Completable that delays the subscription to the source CompletableSource by the given amount + * @since 2.2.3 - experimental + * @see ReactiveX operators documentation: Delay + */ + @CheckReturnValue + @Experimental + @SchedulerSupport(SchedulerSupport.COMPUTATION) + public final Completable delaySubscription(long delay, TimeUnit unit) { + return delaySubscription(delay, unit, Schedulers.computation()); + } + + /** + * Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time, + * both waiting and subscribing on a given Scheduler. + *

    + *

    + *
    Scheduler:
    + *
    You specify which {@link Scheduler} this operator will use.
    + *
    + * + * @param delay the time to delay the subscription + * @param unit the time unit of {@code delay} + * @param scheduler the Scheduler on which the waiting and subscription will happen + * @return a Completable that delays the subscription to the source CompletableSource by a given + * amount, waiting and subscribing on the given Scheduler + * @since 2.2.3 - experimental + * @see ReactiveX operators documentation: Delay + */ + @CheckReturnValue + @Experimental + @SchedulerSupport(SchedulerSupport.CUSTOM) + public final Completable delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) { + return Completable.timer(delay, unit, scheduler).andThen(this); + } + /** * Returns a Completable which calls the given onComplete callback if this Completable completes. *

    diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java index 174a520e0f..ea89a32a5f 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java @@ -20,11 +20,14 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.CompletableSource; +import io.reactivex.TestHelper; +import io.reactivex.Completable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.observers.TestObserver; -import io.reactivex.schedulers.*; +import io.reactivex.schedulers.Schedulers; +import io.reactivex.schedulers.TestScheduler; public class CompletableDelayTest { @@ -120,4 +123,69 @@ public void errorDelayed() { to.assertFailure(TestException.class); } + + @Test + public void errorDelayedSubscription() { + TestScheduler scheduler = new TestScheduler(); + + TestObserver to = Completable.error(new TestException()) + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler) + .test(); + + to.assertEmpty(); + + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + + to.assertEmpty(); + + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + + to.assertFailure(TestException.class); + } + + @Test + public void errorDelayedSubscriptionDisposeBeforeTime() { + TestScheduler scheduler = new TestScheduler(); + + Completable result = Completable.complete() + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + TestObserver to = result.test(); + + to.assertEmpty(); + + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + to.dispose(); + + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + + to.assertEmpty(); + } + + @Test + public void testDelaySubscriptionDisposeBeforeTime() { + TestScheduler scheduler = new TestScheduler(); + + Completable result = Completable.complete() + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + TestObserver to = result.test(); + + to.assertEmpty(); + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + to.dispose(); + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + to.assertEmpty(); + } + + @Test + public void testDelaySubscription() { + TestScheduler scheduler = new TestScheduler(); + Completable result = Completable.complete() + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + TestObserver to = result.test(); + + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + to.assertEmpty(); + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + to.assertResult(); + } } diff --git a/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java b/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java index ac078393e1..2d7a9649b8 100644 --- a/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java +++ b/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java @@ -261,6 +261,10 @@ public void checkParallelFlowable() { addOverride(new ParamOverride(Completable.class, 0, ParamMode.ANY, "delay", Long.TYPE, TimeUnit.class, Scheduler.class)); addOverride(new ParamOverride(Completable.class, 0, ParamMode.ANY, "delay", Long.TYPE, TimeUnit.class, Scheduler.class, Boolean.TYPE)); + // negative time is considered as zero time + addOverride(new ParamOverride(Completable.class, 0, ParamMode.ANY, "delaySubscription", Long.TYPE, TimeUnit.class)); + addOverride(new ParamOverride(Completable.class, 0, ParamMode.ANY, "delaySubscription", Long.TYPE, TimeUnit.class, Scheduler.class)); + // zero repeat is allowed addOverride(new ParamOverride(Completable.class, 0, ParamMode.NON_NEGATIVE, "repeat", Long.TYPE)); From 2fb950427c717d953c0d72f7419ccb4692db6be4 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 19 Oct 2018 10:54:27 +0200 Subject: [PATCH 086/211] 2.x: Expand and fix Completable.delaySubscription tests (#6252) --- .../CompletableDelaySubscriptionTest.java | 169 ++++++++++++++++++ .../completable/CompletableDelayTest.java | 65 ------- 2 files changed, 169 insertions(+), 65 deletions(-) create mode 100644 src/test/java/io/reactivex/internal/operators/completable/CompletableDelaySubscriptionTest.java diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelaySubscriptionTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelaySubscriptionTest.java new file mode 100644 index 0000000000..7148233f9d --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelaySubscriptionTest.java @@ -0,0 +1,169 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.completable; + +import static org.junit.Assert.*; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Test; + +import io.reactivex.Completable; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Action; +import io.reactivex.observers.TestObserver; +import io.reactivex.schedulers.TestScheduler; +import io.reactivex.subjects.CompletableSubject; + +public class CompletableDelaySubscriptionTest { + + @Test + public void normal() { + final AtomicInteger counter = new AtomicInteger(); + + Completable.fromAction(new Action() { + @Override + public void run() throws Exception { + counter.incrementAndGet(); + } + }) + .delaySubscription(100, TimeUnit.MILLISECONDS) + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(); + + assertEquals(1, counter.get()); + } + + @Test + public void error() { + final AtomicInteger counter = new AtomicInteger(); + + Completable.fromAction(new Action() { + @Override + public void run() throws Exception { + counter.incrementAndGet(); + + throw new TestException(); + } + }) + .delaySubscription(100, TimeUnit.MILLISECONDS) + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertFailure(TestException.class); + + assertEquals(1, counter.get()); + } + + @Test + public void disposeBeforeTime() { + TestScheduler scheduler = new TestScheduler(); + + final AtomicInteger counter = new AtomicInteger(); + + Completable result = Completable.fromAction(new Action() { + @Override + public void run() throws Exception { + counter.incrementAndGet(); + } + }) + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + TestObserver to = result.test(); + + to.assertEmpty(); + + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + + to.dispose(); + + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + + to.assertEmpty(); + + assertEquals(0, counter.get()); + } + + @Test + public void timestep() { + TestScheduler scheduler = new TestScheduler(); + final AtomicInteger counter = new AtomicInteger(); + + Completable result = Completable.fromAction(new Action() { + @Override + public void run() throws Exception { + counter.incrementAndGet(); + } + }) + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + + TestObserver to = result.test(); + + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + to.assertEmpty(); + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + to.assertResult(); + + assertEquals(1, counter.get()); + } + + @Test + public void timestepError() { + TestScheduler scheduler = new TestScheduler(); + final AtomicInteger counter = new AtomicInteger(); + + Completable result = Completable.fromAction(new Action() { + @Override + public void run() throws Exception { + counter.incrementAndGet(); + + throw new TestException(); + } + }) + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + + TestObserver to = result.test(); + + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + + to.assertEmpty(); + + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + + to.assertFailure(TestException.class); + + assertEquals(1, counter.get()); + } + + @Test + public void disposeMain() { + CompletableSubject cs = CompletableSubject.create(); + + TestScheduler scheduler = new TestScheduler(); + + TestObserver to = cs + .delaySubscription(1, TimeUnit.SECONDS, scheduler) + .test(); + + assertFalse(cs.hasObservers()); + + scheduler.advanceTimeBy(1, TimeUnit.SECONDS); + + assertTrue(cs.hasObservers()); + + to.dispose(); + + assertFalse(cs.hasObservers()); + } +} diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java index ea89a32a5f..be72ce0ad4 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java @@ -123,69 +123,4 @@ public void errorDelayed() { to.assertFailure(TestException.class); } - - @Test - public void errorDelayedSubscription() { - TestScheduler scheduler = new TestScheduler(); - - TestObserver to = Completable.error(new TestException()) - .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler) - .test(); - - to.assertEmpty(); - - scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); - - to.assertEmpty(); - - scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); - - to.assertFailure(TestException.class); - } - - @Test - public void errorDelayedSubscriptionDisposeBeforeTime() { - TestScheduler scheduler = new TestScheduler(); - - Completable result = Completable.complete() - .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); - TestObserver to = result.test(); - - to.assertEmpty(); - - scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); - to.dispose(); - - scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); - - to.assertEmpty(); - } - - @Test - public void testDelaySubscriptionDisposeBeforeTime() { - TestScheduler scheduler = new TestScheduler(); - - Completable result = Completable.complete() - .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); - TestObserver to = result.test(); - - to.assertEmpty(); - scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); - to.dispose(); - scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); - to.assertEmpty(); - } - - @Test - public void testDelaySubscription() { - TestScheduler scheduler = new TestScheduler(); - Completable result = Completable.complete() - .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); - TestObserver to = result.test(); - - scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); - to.assertEmpty(); - scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); - to.assertResult(); - } } From 8654393d7dc84545cc92077bd635e61a915db32e Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 19 Oct 2018 12:26:00 +0200 Subject: [PATCH 087/211] 2.x: Fix flaky sample() backpressure test, improve coverage (#6254) --- .../flowable/FlowableSampleTest.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java index 12e354cda2..74cbcc24c2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java @@ -13,6 +13,7 @@ package io.reactivex.internal.operators.flowable; +import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -306,11 +307,20 @@ public void backpressureOverflow() { @Test public void backpressureOverflowWithOtherPublisher() { - BehaviorProcessor.createDefault(1) - .sample(Flowable.timer(1, TimeUnit.MILLISECONDS)) - .test(0L) - .awaitDone(5, TimeUnit.SECONDS) - .assertFailure(MissingBackpressureException.class); + PublishProcessor pp1 = PublishProcessor.create(); + PublishProcessor pp2 = PublishProcessor.create(); + + TestSubscriber ts = pp1 + .sample(pp2) + .test(0L); + + pp1.onNext(1); + pp2.onNext(2); + + ts.assertFailure(MissingBackpressureException.class); + + assertFalse(pp1.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); } @Test @@ -455,5 +465,19 @@ public Flowable apply(Flowable f) return f.sample(1, TimeUnit.SECONDS); } }); + + TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { + @Override + public Flowable apply(Flowable f) + throws Exception { + return f.sample(PublishProcessor.create()); + } + }); + } + + @Test + public void badRequest() { + TestHelper.assertBadRequestReported(PublishProcessor.create() + .sample(PublishProcessor.create())); } } From 378cbf92c17db3906d3a1ba5b7dc156280f4632b Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 19 Oct 2018 12:49:01 +0200 Subject: [PATCH 088/211] 2.x: Cleanup code style, commas, spaces, docs (#6255) --- .../io/reactivex/parallel/ParallelPerf.java | 2 +- .../operators/flowable/FlowableGroupBy.java | 4 +-- .../internal/queue/MpscLinkedQueue.java | 2 +- .../internal/queue/SpscArrayQueue.java | 4 +-- .../internal/queue/SpscLinkedArrayQueue.java | 28 +++++++++---------- .../internal/schedulers/IoScheduler.java | 1 + .../internal/schedulers/SingleScheduler.java | 2 ++ .../internal/util/ExceptionHelper.java | 2 +- .../processors/UnicastProcessor.java | 2 +- .../reactivex/exceptions/ExceptionsTest.java | 4 +++ .../flowable/FlowableConversionTest.java | 2 +- .../flowable/FlowableErrorHandlingTests.java | 6 ++-- .../reactivex/flowable/FlowableNullTests.java | 2 +- .../flowable/FlowableSubscriberTest.java | 11 ++++---- .../io/reactivex/flowable/FlowableTests.java | 2 +- .../flowable/FlowableBufferTest.java | 4 +-- .../flowable/FlowableCombineLatestTest.java | 4 +-- .../flowable/FlowableConcatTest.java | 4 +-- .../flowable/FlowableDefaultIfEmptyTest.java | 2 +- .../FlowableDistinctUntilChangedTest.java | 4 +-- .../flowable/FlowableDoOnRequestTest.java | 2 +- .../flowable/FlowableFlatMapMaybeTest.java | 3 +- .../flowable/FlowableFlatMapSingleTest.java | 3 +- .../flowable/FlowableFlatMapTest.java | 2 +- .../flowable/FlowableFromIterableTest.java | 2 +- .../flowable/FlowableGroupByTest.java | 8 +++--- .../operators/flowable/FlowableMergeTest.java | 8 +++--- .../flowable/FlowableObserveOnTest.java | 6 ++-- .../flowable/FlowableReduceTest.java | 12 +++++--- .../flowable/FlowableRefCountTest.java | 2 +- .../flowable/FlowableReplayTest.java | 2 +- .../operators/flowable/FlowableRetryTest.java | 6 ++-- .../FlowableRetryWithPredicateTest.java | 4 +-- .../operators/flowable/FlowableScanTest.java | 6 ++-- .../operators/flowable/FlowableSkipTest.java | 2 +- .../flowable/FlowableSwitchIfEmptyTest.java | 2 +- .../flowable/FlowableTakeLastOneTest.java | 2 +- .../flowable/FlowableTakeLastTest.java | 2 +- .../observable/ObservableBufferTest.java | 4 +-- .../ObservableDistinctUntilChangedTest.java | 4 +-- .../ObservableFlatMapMaybeTest.java | 2 +- .../ObservableFlatMapSingleTest.java | 2 +- .../observable/ObservableFlatMapTest.java | 2 +- .../observable/ObservableMergeTest.java | 4 +-- .../observable/ObservableObserveOnTest.java | 2 +- .../observable/ObservableRefCountTest.java | 2 +- .../observable/ObservableReplayTest.java | 2 +- .../observable/ObservableRetryTest.java | 4 +-- .../ObservableRetryWithPredicateTest.java | 4 +-- .../observable/ObservableScanTest.java | 6 ++-- .../observable/ObservableSkipTest.java | 2 +- .../observable/ObservableTakeLastOneTest.java | 2 +- .../observable/ObservableTakeLastTest.java | 2 +- .../observable/ObservableNullTests.java | 2 +- .../reactivex/observable/ObservableTest.java | 2 +- .../reactivex/plugins/RxJavaPluginsTest.java | 2 +- ...ReplayProcessorBoundedConcurrencyTest.java | 1 + .../ReplayProcessorConcurrencyTest.java | 1 + .../processors/UnicastProcessorTest.java | 2 +- .../AbstractSchedulerConcurrencyTests.java | 1 + .../ReplaySubjectBoundedConcurrencyTest.java | 1 + .../ReplaySubjectConcurrencyTest.java | 1 + 62 files changed, 122 insertions(+), 101 deletions(-) diff --git a/src/jmh/java/io/reactivex/parallel/ParallelPerf.java b/src/jmh/java/io/reactivex/parallel/ParallelPerf.java index 1630e82eef..24a0e85954 100644 --- a/src/jmh/java/io/reactivex/parallel/ParallelPerf.java +++ b/src/jmh/java/io/reactivex/parallel/ParallelPerf.java @@ -28,7 +28,7 @@ @BenchmarkMode(Mode.Throughput) @Warmup(iterations = 5) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) -@Fork(value = 1,jvmArgsAppend = { "-XX:MaxInlineLevel=20" }) +@Fork(value = 1, jvmArgsAppend = { "-XX:MaxInlineLevel=20" }) @OutputTimeUnit(TimeUnit.SECONDS) @State(Scope.Thread) public class ParallelPerf implements Function { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java index 14fbc74b99..719645afe9 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java @@ -430,7 +430,7 @@ public boolean isEmpty() { } } - static final class EvictionAction implements Consumer> { + static final class EvictionAction implements Consumer> { final Queue> evictedGroups; @@ -439,7 +439,7 @@ static final class EvictionAction implements Consumer> } @Override - public void accept(GroupedUnicast value) { + public void accept(GroupedUnicast value) { evictedGroups.offer(value); } } diff --git a/src/main/java/io/reactivex/internal/queue/MpscLinkedQueue.java b/src/main/java/io/reactivex/internal/queue/MpscLinkedQueue.java index eddfb306b4..c33147de06 100644 --- a/src/main/java/io/reactivex/internal/queue/MpscLinkedQueue.java +++ b/src/main/java/io/reactivex/internal/queue/MpscLinkedQueue.java @@ -36,7 +36,7 @@ public MpscLinkedQueue() { consumerNode = new AtomicReference>(); LinkedQueueNode node = new LinkedQueueNode(); spConsumerNode(node); - xchgProducerNode(node);// this ensures correct construction: StoreLoad + xchgProducerNode(node); // this ensures correct construction: StoreLoad } /** diff --git a/src/main/java/io/reactivex/internal/queue/SpscArrayQueue.java b/src/main/java/io/reactivex/internal/queue/SpscArrayQueue.java index 1afa99738f..53ac212600 100644 --- a/src/main/java/io/reactivex/internal/queue/SpscArrayQueue.java +++ b/src/main/java/io/reactivex/internal/queue/SpscArrayQueue.java @@ -89,12 +89,12 @@ public E poll() { final long index = consumerIndex.get(); final int offset = calcElementOffset(index); // local load of field to avoid repeated loads after volatile reads - final E e = lvElement(offset);// LoadLoad + final E e = lvElement(offset); // LoadLoad if (null == e) { return null; } soConsumerIndex(index + 1); // ordered store -> atomic and ordered for size() - soElement(offset, null);// StoreStore + soElement(offset, null); // StoreStore return e; } diff --git a/src/main/java/io/reactivex/internal/queue/SpscLinkedArrayQueue.java b/src/main/java/io/reactivex/internal/queue/SpscLinkedArrayQueue.java index ec874209d0..e5e71e29f4 100644 --- a/src/main/java/io/reactivex/internal/queue/SpscLinkedArrayQueue.java +++ b/src/main/java/io/reactivex/internal/queue/SpscLinkedArrayQueue.java @@ -92,8 +92,8 @@ public boolean offer(final T e) { } private boolean writeToQueue(final AtomicReferenceArray buffer, final T e, final long index, final int offset) { - soElement(buffer, offset, e);// StoreStore - soProducerIndex(index + 1);// this ensures atomic write of long on 32bit platforms + soElement(buffer, offset, e); // StoreStore + soProducerIndex(index + 1); // this ensures atomic write of long on 32bit platforms return true; } @@ -103,11 +103,11 @@ private void resize(final AtomicReferenceArray oldBuffer, final long cur final AtomicReferenceArray newBuffer = new AtomicReferenceArray(capacity); producerBuffer = newBuffer; producerLookAhead = currIndex + mask - 1; - soElement(newBuffer, offset, e);// StoreStore + soElement(newBuffer, offset, e); // StoreStore soNext(oldBuffer, newBuffer); soElement(oldBuffer, offset, HAS_NEXT); // new buffer is visible after element is // inserted - soProducerIndex(currIndex + 1);// this ensures correctness on 32bit platforms + soProducerIndex(currIndex + 1); // this ensures correctness on 32bit platforms } private void soNext(AtomicReferenceArray curr, AtomicReferenceArray next) { @@ -135,11 +135,11 @@ public T poll() { final long index = lpConsumerIndex(); final int mask = consumerMask; final int offset = calcWrappedOffset(index, mask); - final Object e = lvElement(buffer, offset);// LoadLoad + final Object e = lvElement(buffer, offset); // LoadLoad boolean isNextBuffer = e == HAS_NEXT; if (null != e && !isNextBuffer) { - soElement(buffer, offset, null);// StoreStore - soConsumerIndex(index + 1);// this ensures correctness on 32bit platforms + soElement(buffer, offset, null); // StoreStore + soConsumerIndex(index + 1); // this ensures correctness on 32bit platforms return (T) e; } else if (isNextBuffer) { return newBufferPoll(lvNextBufferAndUnlink(buffer, mask + 1), index, mask); @@ -152,10 +152,10 @@ public T poll() { private T newBufferPoll(AtomicReferenceArray nextBuffer, final long index, final int mask) { consumerBuffer = nextBuffer; final int offsetInNew = calcWrappedOffset(index, mask); - final T n = (T) lvElement(nextBuffer, offsetInNew);// LoadLoad + final T n = (T) lvElement(nextBuffer, offsetInNew); // LoadLoad if (null != n) { - soElement(nextBuffer, offsetInNew, null);// StoreStore - soConsumerIndex(index + 1);// this ensures correctness on 32bit platforms + soElement(nextBuffer, offsetInNew, null); // StoreStore + soConsumerIndex(index + 1); // this ensures correctness on 32bit platforms } return n; } @@ -166,7 +166,7 @@ public T peek() { final long index = lpConsumerIndex(); final int mask = consumerMask; final int offset = calcWrappedOffset(index, mask); - final Object e = lvElement(buffer, offset);// LoadLoad + final Object e = lvElement(buffer, offset); // LoadLoad if (e == HAS_NEXT) { return newBufferPeek(lvNextBufferAndUnlink(buffer, mask + 1), index, mask); } @@ -178,7 +178,7 @@ public T peek() { private T newBufferPeek(AtomicReferenceArray nextBuffer, final long index, final int mask) { consumerBuffer = nextBuffer; final int offsetInNew = calcWrappedOffset(index, mask); - return (T) lvElement(nextBuffer, offsetInNew);// LoadLoad + return (T) lvElement(nextBuffer, offsetInNew); // LoadLoad } @Override @@ -277,13 +277,13 @@ public boolean offer(T first, T second) { producerBuffer = newBuffer; pi = calcWrappedOffset(p, m); - soElement(newBuffer, pi + 1, second);// StoreStore + soElement(newBuffer, pi + 1, second); // StoreStore soElement(newBuffer, pi, first); soNext(buffer, newBuffer); soElement(buffer, pi, HAS_NEXT); // new buffer is visible after element is - soProducerIndex(p + 2);// this ensures correctness on 32bit platforms + soProducerIndex(p + 2); // this ensures correctness on 32bit platforms } return true; diff --git a/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java b/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java index 662335ef43..423a47898f 100644 --- a/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java @@ -151,6 +151,7 @@ public IoScheduler() { } /** + * Constructs an IoScheduler with the given thread factory and starts the pool of workers. * @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any * system properties for configuring new thread creation. Cannot be null. */ diff --git a/src/main/java/io/reactivex/internal/schedulers/SingleScheduler.java b/src/main/java/io/reactivex/internal/schedulers/SingleScheduler.java index d65348aa3c..40a7ce0b85 100644 --- a/src/main/java/io/reactivex/internal/schedulers/SingleScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/SingleScheduler.java @@ -53,6 +53,8 @@ public SingleScheduler() { } /** + * Constructs a SingleScheduler with the given ThreadFactory and prepares the + * single scheduler thread. * @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any * system properties for configuring new thread creation. Cannot be null. */ diff --git a/src/main/java/io/reactivex/internal/util/ExceptionHelper.java b/src/main/java/io/reactivex/internal/util/ExceptionHelper.java index b6fb4e9196..ecd970c730 100644 --- a/src/main/java/io/reactivex/internal/util/ExceptionHelper.java +++ b/src/main/java/io/reactivex/internal/util/ExceptionHelper.java @@ -129,7 +129,7 @@ public static String timeoutMessage(long timeout, TimeUnit unit) { + unit.toString().toLowerCase() + " and has been terminated."; } - + static final class Termination extends Throwable { private static final long serialVersionUID = -4649703670690200604L; diff --git a/src/main/java/io/reactivex/processors/UnicastProcessor.java b/src/main/java/io/reactivex/processors/UnicastProcessor.java index 47f02489b4..94547b88fb 100644 --- a/src/main/java/io/reactivex/processors/UnicastProcessor.java +++ b/src/main/java/io/reactivex/processors/UnicastProcessor.java @@ -255,7 +255,7 @@ public static UnicastProcessor create(int capacityHint, Runnable onCancel * @since 2.0 */ UnicastProcessor(int capacityHint) { - this(capacityHint,null, true); + this(capacityHint, null, true); } /** diff --git a/src/test/java/io/reactivex/exceptions/ExceptionsTest.java b/src/test/java/io/reactivex/exceptions/ExceptionsTest.java index 4928f14bf1..e1cff53e29 100644 --- a/src/test/java/io/reactivex/exceptions/ExceptionsTest.java +++ b/src/test/java/io/reactivex/exceptions/ExceptionsTest.java @@ -59,6 +59,7 @@ public void accept(Integer t1) { } /** + * Outdated test: Observer should not suppress errors from onCompleted. * https://github.com/ReactiveX/RxJava/issues/3885 */ @Ignore("v2 components should not throw") @@ -200,6 +201,7 @@ public void onNext(Integer t) { } /** + * Outdated test: throwing from onError handler. * https://github.com/ReactiveX/RxJava/issues/969 */ @Ignore("v2 components should not throw") @@ -237,6 +239,7 @@ public void onNext(Object o) { } /** + * Outdated test: throwing from onError. * https://github.com/ReactiveX/RxJava/issues/2998 * @throws Exception on arbitrary errors */ @@ -276,6 +279,7 @@ public void onNext(GroupedObservable integerIntegerGroupedObse } /** + * Outdated test: throwing from onError. * https://github.com/ReactiveX/RxJava/issues/2998 * @throws Exception on arbitrary errors */ diff --git a/src/test/java/io/reactivex/flowable/FlowableConversionTest.java b/src/test/java/io/reactivex/flowable/FlowableConversionTest.java index a7d908111a..36bcb643f6 100644 --- a/src/test/java/io/reactivex/flowable/FlowableConversionTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableConversionTest.java @@ -206,7 +206,7 @@ public String apply(String a, String n) { public void testConvertToConcurrentQueue() { final AtomicReference thrown = new AtomicReference(null); final AtomicBoolean isFinished = new AtomicBoolean(false); - ConcurrentLinkedQueue queue = Flowable.range(0,5) + ConcurrentLinkedQueue queue = Flowable.range(0, 5) .flatMap(new Function>() { @Override public Publisher apply(final Integer i) { diff --git a/src/test/java/io/reactivex/flowable/FlowableErrorHandlingTests.java b/src/test/java/io/reactivex/flowable/FlowableErrorHandlingTests.java index e86aa39266..21f05aa8d4 100644 --- a/src/test/java/io/reactivex/flowable/FlowableErrorHandlingTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableErrorHandlingTests.java @@ -28,7 +28,8 @@ public class FlowableErrorHandlingTests { /** - * Test that an error from a user provided Observer.onNext is handled and emitted to the onError + * Test that an error from a user provided Observer.onNext + * is handled and emitted to the onError. * @throws InterruptedException if the test is interrupted */ @Test @@ -63,7 +64,8 @@ public void onNext(Long args) { } /** - * Test that an error from a user provided Observer.onNext is handled and emitted to the onError + * Test that an error from a user provided Observer.onNext + * is handled and emitted to the onError. * even when done across thread boundaries with observeOn * @throws InterruptedException if the test is interrupted */ diff --git a/src/test/java/io/reactivex/flowable/FlowableNullTests.java b/src/test/java/io/reactivex/flowable/FlowableNullTests.java index 3e9582363b..a9acc4f061 100644 --- a/src/test/java/io/reactivex/flowable/FlowableNullTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableNullTests.java @@ -466,7 +466,7 @@ public void intervalPeriodSchedulerNull() { @Test(expected = NullPointerException.class) public void intervalRangeUnitNull() { - Flowable.intervalRange(1,1, 1, 1, null); + Flowable.intervalRange(1, 1, 1, 1, null); } @Test(expected = NullPointerException.class) diff --git a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java index e95d5a9ab2..d0a0e1a88e 100644 --- a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java @@ -467,7 +467,7 @@ public void onNext(Integer t) { public void testNegativeRequestThrowsIllegalArgumentException() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference exception = new AtomicReference(); - Flowable.just(1,2,3,4).subscribe(new DefaultSubscriber() { + Flowable.just(1, 2, 3, 4).subscribe(new DefaultSubscriber() { @Override public void onStart() { @@ -498,7 +498,8 @@ public void onNext(Integer t) { @Test public void testOnStartRequestsAreAdditive() { final List list = new ArrayList(); - Flowable.just(1,2,3,4,5).subscribe(new DefaultSubscriber() { + Flowable.just(1, 2, 3, 4, 5) + .subscribe(new DefaultSubscriber() { @Override public void onStart() { request(3); @@ -519,13 +520,13 @@ public void onError(Throwable e) { public void onNext(Integer t) { list.add(t); }}); - assertEquals(Arrays.asList(1,2,3,4,5), list); + assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); } @Test public void testOnStartRequestsAreAdditiveAndOverflowBecomesMaxValue() { final List list = new ArrayList(); - Flowable.just(1,2,3,4,5).subscribe(new DefaultSubscriber() { + Flowable.just(1, 2, 3, 4, 5).subscribe(new DefaultSubscriber() { @Override public void onStart() { request(2); @@ -546,7 +547,7 @@ public void onError(Throwable e) { public void onNext(Integer t) { list.add(t); }}); - assertEquals(Arrays.asList(1,2,3,4,5), list); + assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); } @Test diff --git a/src/test/java/io/reactivex/flowable/FlowableTests.java b/src/test/java/io/reactivex/flowable/FlowableTests.java index 377254f95e..4a700b5aea 100644 --- a/src/test/java/io/reactivex/flowable/FlowableTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableTests.java @@ -1026,7 +1026,7 @@ public void testAmbWith() { public void testTakeWhileToList() { final int expectedCount = 3; final AtomicInteger count = new AtomicInteger(); - for (int i = 0;i < expectedCount; i++) { + for (int i = 0; i < expectedCount; i++) { Flowable .just(Boolean.TRUE, Boolean.FALSE) .takeWhile(new Predicate() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java index 00568da3ec..5060c58253 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java @@ -2130,7 +2130,7 @@ public Integer apply(Integer integer, Long aLong) { return integer; } }) - .buffer(Flowable.interval(0,200, TimeUnit.MILLISECONDS), + .buffer(Flowable.interval(0, 200, TimeUnit.MILLISECONDS), new Function>() { @Override public Publisher apply(Long a) { @@ -2153,7 +2153,7 @@ public Integer apply(Integer integer, Long aLong) { return integer; } }) - .buffer(Flowable.interval(0,100, TimeUnit.MILLISECONDS), + .buffer(Flowable.interval(0, 100, TimeUnit.MILLISECONDS), new Function>() { @Override public Publisher apply(Long a) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java index 1d759a6e44..4443a71759 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java @@ -807,8 +807,8 @@ public Long apply(Long t1, Integer t2) { public void testCombineLatestRequestOverflow() throws InterruptedException { @SuppressWarnings("unchecked") List> sources = Arrays.asList(Flowable.fromArray(1, 2, 3, 4), - Flowable.fromArray(5,6,7,8)); - Flowable f = Flowable.combineLatest(sources,new Function() { + Flowable.fromArray(5, 6, 7, 8)); + Flowable f = Flowable.combineLatest(sources, new Function() { @Override public Integer apply(Object[] args) { return (Integer) args[0]; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java index ed0f556b7f..733f3b7cf3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java @@ -779,8 +779,8 @@ public void onError(Throwable e) { @Test public void testRequestOverflowDoesNotStallStream() { - Flowable f1 = Flowable.just(1,2,3); - Flowable f2 = Flowable.just(4,5,6); + Flowable f1 = Flowable.just(1, 2, 3); + Flowable f2 = Flowable.just(4, 5, 6); final AtomicBoolean completed = new AtomicBoolean(false); f1.concatWith(f2).subscribe(new DefaultSubscriber() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java index fa6b123a15..4c75d500e8 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java @@ -97,7 +97,7 @@ public void testBackpressureEmpty() { @Test public void testBackpressureNonEmpty() { TestSubscriber ts = new TestSubscriber(0L); - Flowable.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/flowable/FlowableDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java index 0502283132..7c5eb993e1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java @@ -234,7 +234,7 @@ public void accept(Throwable t) { @Test public void customComparator() { - Flowable source = Flowable.just("a", "b", "B", "A","a", "C"); + Flowable source = Flowable.just("a", "b", "B", "A", "a", "C"); TestSubscriber ts = TestSubscriber.create(); @@ -253,7 +253,7 @@ public boolean test(String a, String b) { @Test public void customComparatorThrows() { - Flowable source = Flowable.just("a", "b", "B", "A","a", "C"); + Flowable source = Flowable.just("a", "b", "B", "A", "a", "C"); TestSubscriber ts = TestSubscriber.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnRequestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnRequestTest.java index 1d30f4663c..4502206206 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnRequestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnRequestTest.java @@ -83,7 +83,7 @@ public void onNext(Integer t) { request(t); } }); - assertEquals(Arrays.asList(3L,1L,2L,3L,4L,5L), requests); + assertEquals(Arrays.asList(3L, 1L, 2L, 3L, 4L, 5L), requests); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java index eac6c0503f..aab0940c46 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java @@ -261,7 +261,8 @@ public MaybeSource apply(Integer v) throws Exception { @Test public void middleError() { - Flowable.fromArray(new String[]{"1","a","2"}).flatMapMaybe(new Function>() { + Flowable.fromArray(new String[]{"1", "a", "2"}) + .flatMapMaybe(new Function>() { @Override public MaybeSource apply(final String s) throws NumberFormatException { //return Maybe.just(Integer.valueOf(s)); //This works diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java index 381d210070..ac137d6c3d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java @@ -248,7 +248,8 @@ public SingleSource apply(Integer v) throws Exception { @Test public void middleError() { - Flowable.fromArray(new String[]{"1","a","2"}).flatMapSingle(new Function>() { + Flowable.fromArray(new String[]{"1", "a", "2"}) + .flatMapSingle(new Function>() { @Override public SingleSource apply(final String s) throws NumberFormatException { //return Single.just(Integer.valueOf(s)); //This works diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java index b05b847c90..bb525b2ddb 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java @@ -522,7 +522,7 @@ public Flowable apply(Integer t) { @Test public void flatMapIntPassthruAsync() { - for (int i = 0;i < 1000; i++) { + for (int i = 0; i < 1000; i++) { TestSubscriber ts = new TestSubscriber(); Flowable.range(1, 1000).flatMap(new Function>() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java index fdedc6577c..e33556cb4e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java @@ -172,7 +172,7 @@ public void testSubscribeMultipleTimes() { @Test public void testFromIterableRequestOverflow() throws InterruptedException { - Flowable f = Flowable.fromIterable(Arrays.asList(1,2,3,4)); + Flowable f = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4)); final int expectedCount = 4; final CountDownLatch latch = new CountDownLatch(expectedCount); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java index 9b2ae32416..97a0a5ca23 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java @@ -2069,10 +2069,10 @@ public Publisher apply(GroupedFlowable g) th } //not thread safe - private static final class SingleThreadEvictingHashMap implements Map { + private static final class SingleThreadEvictingHashMap implements Map { private final List list = new ArrayList(); - private final Map map = new HashMap(); + private final Map map = new HashMap(); private final int maxSize; private final Consumer evictedListener; @@ -2175,7 +2175,7 @@ public Map apply(final Consumer notify) throws Exceptio .maximumSize(maxSize) // .removalListener(new RemovalListener() { @Override - public void onRemoval(RemovalNotification notification) { + public void onRemoval(RemovalNotification notification) { try { notify.accept(notification.getValue()); } catch (Exception e) { @@ -2194,7 +2194,7 @@ private static Function, Map> createEvictingMa @Override public Map apply(final Consumer notify) throws Exception { - return new SingleThreadEvictingHashMap(maxSize, new Consumer() { + return new SingleThreadEvictingHashMap(maxSize, new Consumer() { @Override public void accept(Object object) { try { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java index fc09bd1dc5..010da8bd69 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java @@ -335,8 +335,8 @@ public void testError2() { // we are using synchronous execution to test this exactly rather than non-deterministic concurrent behavior final Flowable f1 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", "three")); final Flowable f2 = Flowable.unsafeCreate(new TestErrorFlowable("four", null, "six")); // we expect to lose "six" - final Flowable f3 = Flowable.unsafeCreate(new TestErrorFlowable("seven", "eight", null));// we expect to lose all of these since o2 is done first and fails - final Flowable f4 = Flowable.unsafeCreate(new TestErrorFlowable("nine"));// we expect to lose all of these since o2 is done first and fails + final Flowable f3 = Flowable.unsafeCreate(new TestErrorFlowable("seven", "eight", null)); // we expect to lose all of these since o2 is done first and fails + final Flowable f4 = Flowable.unsafeCreate(new TestErrorFlowable("nine")); // we expect to lose all of these since o2 is done first and fails Flowable m = Flowable.merge(f1, f2, f3, f4); m.subscribe(stringSubscriber); @@ -1269,8 +1269,8 @@ 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 - Flowable f = Flowable.fromIterable(Arrays.asList(1,2)) - .mergeWith(Flowable.fromIterable(Arrays.asList(3,4))); + Flowable f = Flowable.fromIterable(Arrays.asList(1, 2)) + .mergeWith(Flowable.fromIterable(Arrays.asList(3, 4))); final int expectedCount = 4; final CountDownLatch latch = new CountDownLatch(expectedCount); f.subscribeOn(Schedulers.computation()).subscribe(new DefaultSubscriber() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java index d4fdbe15db..ca4bd28986 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java @@ -799,7 +799,7 @@ public void onNext(Integer t) { public void testErrorDelayed() { TestScheduler s = new TestScheduler(); - Flowable source = Flowable.just(1, 2 ,3) + Flowable source = Flowable.just(1, 2, 3) .concatWith(Flowable.error(new TestException())); TestSubscriber ts = TestSubscriber.create(0); @@ -833,7 +833,7 @@ public void testErrorDelayed() { @Test public void testErrorDelayedAsync() { - Flowable source = Flowable.just(1, 2 ,3) + Flowable source = Flowable.just(1, 2, 3) .concatWith(Flowable.error(new TestException())); TestSubscriber ts = TestSubscriber.create(); @@ -1862,7 +1862,7 @@ public void workerNotDisposedPrematurelyAsyncInNormalOut() { static final class TestSubscriberFusedCanceling extends TestSubscriber { - public TestSubscriberFusedCanceling() { + TestSubscriberFusedCanceling() { super(); initialFusionMode = QueueFuseable.ANY; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java index e6103b5a7b..37d7012065 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java @@ -388,7 +388,8 @@ public Integer apply(Integer a, Integer b) throws Exception { } /** - * https://gist.github.com/jurna/353a2bd8ff83f0b24f0b5bc772077d61 + * Make sure an asynchronous reduce with flatMap works. + * Original Reactor-Core test case: https://gist.github.com/jurna/353a2bd8ff83f0b24f0b5bc772077d61 */ @Test public void shouldReduceTo10Events() { @@ -414,7 +415,8 @@ public String apply(String l, String r) throws Exception { @Override public void accept(String s) throws Exception { count.incrementAndGet(); - System.out.println("Completed with " + s);} + System.out.println("Completed with " + s); + } }) .toFlowable(); } @@ -425,7 +427,8 @@ public void accept(String s) throws Exception { } /** - * https://gist.github.com/jurna/353a2bd8ff83f0b24f0b5bc772077d61 + * Make sure an asynchronous reduce with flatMap works. + * Original Reactor-Core test case: https://gist.github.com/jurna/353a2bd8ff83f0b24f0b5bc772077d61 */ @Test public void shouldReduceTo10EventsFlowable() { @@ -452,7 +455,8 @@ public String apply(String l, String r) throws Exception { @Override public void accept(String s) throws Exception { count.incrementAndGet(); - System.out.println("Completed with " + s);} + System.out.println("Completed with " + s); + } }) ; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java index 6bd46295e3..289170b254 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java @@ -537,7 +537,7 @@ public void testUpstreamErrorAllowsRetry() throws InterruptedException { try { final AtomicInteger intervalSubscribed = new AtomicInteger(); Flowable interval = - Flowable.interval(200,TimeUnit.MILLISECONDS) + Flowable.interval(200, TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java index e20c417da9..0cc39b5c03 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java @@ -520,7 +520,7 @@ public void testIssue2191_UnsubscribeSource() throws Exception { Subscriber spiedSubscriberAfterConnect = TestHelper.mockSubscriber(); // Flowable under test - Flowable source = Flowable.just(1,2); + Flowable source = Flowable.just(1, 2); ConnectableFlowable replay = source .doOnNext(sourceNext) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java index 8b35cb37f9..8a0a29f8dd 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java @@ -708,7 +708,7 @@ public void testTimeoutWithRetry() { @Test//(timeout = 15000) public void testRetryWithBackpressure() throws InterruptedException { final int NUM_LOOPS = 1; - for (int j = 0;j < NUM_LOOPS; j++) { + for (int j = 0; j < NUM_LOOPS; j++) { final int numRetries = Flowable.bufferSize() * 2; for (int i = 0; i < 400; i++) { Subscriber subscriber = TestHelper.mockSubscriber(); @@ -852,7 +852,7 @@ public String apply(String t1) { return t1; } }) - .flatMap(new Function, Flowable>() { + .flatMap(new Function, Flowable>() { @Override public Flowable apply(GroupedFlowable t1) { return t1.take(1); @@ -897,7 +897,7 @@ public String apply(String t1) { return t1; } }) - .flatMap(new Function, Flowable>() { + .flatMap(new Function, Flowable>() { @Override public Flowable apply(GroupedFlowable t1) { return t1.take(1); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java index f25c276ece..54346a73c0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java @@ -335,7 +335,7 @@ public void accept(Long t) { System.out.println(t); list.add(t); }}); - assertEquals(Arrays.asList(1L,1L,2L,3L), list); + assertEquals(Arrays.asList(1L, 1L, 2L, 3L), list); } @Test @@ -359,7 +359,7 @@ public void accept(Long t) { System.out.println(t); list.add(t); }}); - assertEquals(Arrays.asList(1L,1L,2L,3L), list); + assertEquals(Arrays.asList(1L, 1L, 2L, 3L), list); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java index d12476cf4e..7e761ca53f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java @@ -553,7 +553,7 @@ public Integer apply(Integer n1, Integer n2) throws Exception { @Test public void testScanWithSeedCompletesNormally() { - Flowable.just(1,2,3).scan(0, SUM) + Flowable.just(1, 2, 3).scan(0, SUM) .test() .assertValues(0, 1, 3, 6) .assertComplete(); @@ -562,7 +562,7 @@ public void testScanWithSeedCompletesNormally() { @Test public void testScanWithSeedWhenScanSeedProviderThrows() { final RuntimeException e = new RuntimeException(); - Flowable.just(1,2,3).scanWith(throwingCallable(e), + Flowable.just(1, 2, 3).scanWith(throwingCallable(e), SUM) .test() .assertError(e) @@ -631,7 +631,7 @@ public Integer apply(Integer n1, Integer n2) throws Exception { assertEquals(1, count.get()); } - private static BiFunction throwingBiFunction(final RuntimeException e) { + private static BiFunction throwingBiFunction(final RuntimeException e) { return new BiFunction() { @Override public Integer apply(Integer n1, Integer n2) throws Exception { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java index 25d902310b..c2f8c2f40f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java @@ -167,7 +167,7 @@ public void testRequestOverflowDoesNotOccur() { ts.assertTerminated(); ts.assertComplete(); ts.assertNoErrors(); - assertEquals(Arrays.asList(6,7,8,9,10), ts.values()); + assertEquals(Arrays.asList(6, 7, 8, 9, 10), ts.values()); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java index 2ab9d75bfd..99ecaaac43 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java @@ -166,7 +166,7 @@ public void testBackpressureNoRequest() { @Test public void testBackpressureOnFirstObservable() { TestSubscriber ts = new TestSubscriber(0L); - Flowable.just(1,2,3).switchIfEmpty(Flowable.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(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java index 5da9f37c50..5a94904936 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java @@ -91,7 +91,7 @@ public void testLastWithBackpressure() { public void testTakeLastZeroProcessesAllItemsButIgnoresThem() { final AtomicInteger upstreamCount = new AtomicInteger(); final int num = 10; - long count = Flowable.range(1,num).doOnNext(new Consumer() { + long count = Flowable.range(1, num).doOnNext(new Consumer() { @Override public void accept(Integer t) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java index 37f5ee0d1f..b0d1af43c7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java @@ -292,7 +292,7 @@ public void onNext(Integer integer) { cancel(); } }); - assertEquals(1,count.get()); + assertEquals(1, count.get()); } @Test(timeout = 10000) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java index 961bb7bfed..43612b228d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java @@ -1557,7 +1557,7 @@ public Integer apply(Integer integer, Long aLong) { return integer; } }) - .buffer(Observable.interval(0,200, TimeUnit.MILLISECONDS), + .buffer(Observable.interval(0, 200, TimeUnit.MILLISECONDS), new Function>() { @Override public Observable apply(Long a) { @@ -1580,7 +1580,7 @@ public Integer apply(Integer integer, Long aLong) { return integer; } }) - .buffer(Observable.interval(0,100, TimeUnit.MILLISECONDS), + .buffer(Observable.interval(0, 100, TimeUnit.MILLISECONDS), new Function>() { @Override public Observable apply(Long a) { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java index 83ba70675b..b0ba634354 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java @@ -140,7 +140,7 @@ public void testDistinctUntilChangedOfSourceWithExceptionsFromKeySelector() { @Test public void customComparator() { - Observable source = Observable.just("a", "b", "B", "A","a", "C"); + Observable source = Observable.just("a", "b", "B", "A", "a", "C"); TestObserver to = TestObserver.create(); @@ -159,7 +159,7 @@ public boolean test(String a, String b) { @Test public void customComparatorThrows() { - Observable source = Observable.just("a", "b", "B", "A","a", "C"); + Observable source = Observable.just("a", "b", "B", "A", "a", "C"); TestObserver to = TestObserver.create(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybeTest.java index d2f77576a3..56ecedc02b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybeTest.java @@ -188,7 +188,7 @@ public MaybeSource apply(Integer v) throws Exception { @Test public void middleError() { - Observable.fromArray(new String[]{"1","a","2"}).flatMapMaybe(new Function>() { + Observable.fromArray(new String[]{"1", "a", "2"}).flatMapMaybe(new Function>() { @Override public MaybeSource apply(final String s) throws NumberFormatException { //return Single.just(Integer.valueOf(s)); //This works diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingleTest.java index 4a56c61795..5226fc594c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingleTest.java @@ -175,7 +175,7 @@ public SingleSource apply(Integer v) throws Exception { @Test public void middleError() { - Observable.fromArray(new String[]{"1","a","2"}).flatMapSingle(new Function>() { + Observable.fromArray(new String[]{"1", "a", "2"}).flatMapSingle(new Function>() { @Override public SingleSource apply(final String s) throws NumberFormatException { //return Single.just(Integer.valueOf(s)); //This works diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index c0cb65abe9..efee97f33a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -515,7 +515,7 @@ public Observable apply(Integer t) { @Test public void flatMapIntPassthruAsync() { - for (int i = 0;i < 1000; i++) { + for (int i = 0; i < 1000; i++) { TestObserver to = new TestObserver(); Observable.range(1, 1000).flatMap(new Function>() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java index fb50ae0f0a..8b69ef593b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java @@ -317,8 +317,8 @@ public void testError2() { // we are using synchronous execution to test this exactly rather than non-deterministic concurrent behavior final Observable o1 = Observable.unsafeCreate(new TestErrorObservable("one", "two", "three")); final Observable o2 = Observable.unsafeCreate(new TestErrorObservable("four", null, "six")); // we expect to lose "six" - final Observable o3 = Observable.unsafeCreate(new TestErrorObservable("seven", "eight", null));// we expect to lose all of these since o2 is done first and fails - final Observable o4 = Observable.unsafeCreate(new TestErrorObservable("nine"));// we expect to lose all of these since o2 is done first and fails + final Observable o3 = Observable.unsafeCreate(new TestErrorObservable("seven", "eight", null)); // we expect to lose all of these since o2 is done first and fails + final Observable o4 = Observable.unsafeCreate(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); m.subscribe(stringObserver); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java index 70f047a005..8d948b2592 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java @@ -791,7 +791,7 @@ public void workerNotDisposedPrematurelyAsyncInNormalOut() { static final class TestObserverFusedCanceling extends TestObserver { - public TestObserverFusedCanceling() { + TestObserverFusedCanceling() { super(); initialFusionMode = QueueFuseable.ANY; } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index d75498bc69..ea69a1d500 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -516,7 +516,7 @@ public Integer apply(Integer t1, Integer t2) { public void testUpstreamErrorAllowsRetry() throws InterruptedException { final AtomicInteger intervalSubscribed = new AtomicInteger(); Observable interval = - Observable.interval(200,TimeUnit.MILLISECONDS) + Observable.interval(200, TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable d) { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java index c480a3b1df..5b06f031a2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java @@ -520,7 +520,7 @@ public void testIssue2191_UnsubscribeSource() throws Exception { Observer spiedSubscriberAfterConnect = TestHelper.mockObserver(); // Observable under test - Observable source = Observable.just(1,2); + Observable source = Observable.just(1, 2); ConnectableObservable replay = source .doOnNext(sourceNext) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java index 010b618c34..5c1cbe0041 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java @@ -801,7 +801,7 @@ public String apply(String t1) { return t1; } }) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Observable>() { @Override public Observable apply(GroupedObservable t1) { return t1.take(1); @@ -846,7 +846,7 @@ public String apply(String t1) { return t1; } }) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Observable>() { @Override public Observable apply(GroupedObservable t1) { return t1.take(1); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java index bd03c8874b..72981f705e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java @@ -334,7 +334,7 @@ public void accept(Long t) { System.out.println(t); list.add(t); }}); - assertEquals(Arrays.asList(1L,1L,2L,3L), list); + assertEquals(Arrays.asList(1L, 1L, 2L, 3L), list); } @Test @@ -358,7 +358,7 @@ public void accept(Long t) { System.out.println(t); list.add(t); }}); - assertEquals(Arrays.asList(1L,1L,2L,3L), list); + assertEquals(Arrays.asList(1L, 1L, 2L, 3L), list); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java index 8cd3aa75b6..35df1a462e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java @@ -326,7 +326,7 @@ public void subscribe(Observer o) { o.onNext(2); o.onError(err2); }}) - .scan(new BiFunction() { + .scan(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) throws Exception { throw err; @@ -351,7 +351,7 @@ public void subscribe(Observer o) { o.onNext(2); o.onComplete(); }}) - .scan(new BiFunction() { + .scan(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) throws Exception { throw err; @@ -374,7 +374,7 @@ public void subscribe(Observer o) { o.onNext(2); o.onNext(3); }}) - .scan(new BiFunction() { + .scan(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) throws Exception { count.incrementAndGet(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTest.java index d787de26bf..9b1de8ab4e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTest.java @@ -142,7 +142,7 @@ public void testRequestOverflowDoesNotOccur() { to.assertTerminated(); to.assertComplete(); to.assertNoErrors(); - assertEquals(Arrays.asList(6,7,8,9,10), to.values()); + assertEquals(Arrays.asList(6, 7, 8, 9, 10), to.values()); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java index 859e311a2d..7dc3a1cf39 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java @@ -82,7 +82,7 @@ public void run() { public void testTakeLastZeroProcessesAllItemsButIgnoresThem() { final AtomicInteger upstreamCount = new AtomicInteger(); final int num = 10; - long count = Observable.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/observable/ObservableTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java index 27327bffcf..34ab87312b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java @@ -179,7 +179,7 @@ public void onNext(Integer integer) { cancel(); } }); - assertEquals(1,count.get()); + assertEquals(1, count.get()); } @Test diff --git a/src/test/java/io/reactivex/observable/ObservableNullTests.java b/src/test/java/io/reactivex/observable/ObservableNullTests.java index 847b7c0422..d4142b34af 100644 --- a/src/test/java/io/reactivex/observable/ObservableNullTests.java +++ b/src/test/java/io/reactivex/observable/ObservableNullTests.java @@ -546,7 +546,7 @@ public void intervalPeriodSchedulerNull() { @Test(expected = NullPointerException.class) public void intervalRangeUnitNull() { - Observable.intervalRange(1,1, 1, 1, null); + Observable.intervalRange(1, 1, 1, 1, null); } @Test(expected = NullPointerException.class) diff --git a/src/test/java/io/reactivex/observable/ObservableTest.java b/src/test/java/io/reactivex/observable/ObservableTest.java index 1d754c5e68..660c57d49a 100644 --- a/src/test/java/io/reactivex/observable/ObservableTest.java +++ b/src/test/java/io/reactivex/observable/ObservableTest.java @@ -1048,7 +1048,7 @@ public void testAmbWith() { public void testTakeWhileToList() { final int expectedCount = 3; final AtomicInteger count = new AtomicInteger(); - for (int i = 0;i < expectedCount; i++) { + for (int i = 0; i < expectedCount; i++) { Observable .just(Boolean.TRUE, Boolean.FALSE) .takeWhile(new Predicate() { diff --git a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java index cd66ce7b7e..efd4642d7e 100644 --- a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java +++ b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java @@ -269,7 +269,7 @@ public boolean getAsBoolean() throws Exception { fail("Should have thrown InvocationTargetException(IllegalStateException)"); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof IllegalStateException) { - assertEquals("Plugins can't be changed anymore",ex.getCause().getMessage()); + assertEquals("Plugins can't be changed anymore", ex.getCause().getMessage()); } else { fail("Should have thrown InvocationTargetException(IllegalStateException)"); } diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java index 8a26d4d80d..0258488d52 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java @@ -284,6 +284,7 @@ public void run() { } /** + * Make sure emission-subscription races are handled correctly. * https://github.com/ReactiveX/RxJava/issues/1147 */ @Test diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java index 6161c484fa..978c86ebe4 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java @@ -284,6 +284,7 @@ public void run() { } /** + * Make sure emission-subscription races are handled correctly. * https://github.com/ReactiveX/RxJava/issues/1147 */ @Test diff --git a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java index b058d51e16..5bbe6dca75 100644 --- a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java +++ b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java @@ -110,7 +110,7 @@ public void threeArgsFactory() { public void run() { } }; - UnicastProcessor ap = UnicastProcessor.create(16, noop,false); + UnicastProcessor ap = UnicastProcessor.create(16, noop, false); ap.onNext(1); ap.onError(new RuntimeException()); diff --git a/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java b/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java index 120dee09d7..3605c74679 100644 --- a/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java +++ b/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java @@ -36,6 +36,7 @@ public abstract class AbstractSchedulerConcurrencyTests extends AbstractSchedulerTests { /** + * Make sure canceling through {@code subscribeOn} works. * Bug report: https://github.com/ReactiveX/RxJava/issues/431 * @throws InterruptedException if the test is interrupted */ diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java index 9379e0059f..693fd9a6ee 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java @@ -288,6 +288,7 @@ public void run() { } /** + * Make sure emission-subscription races are handled correctly. * https://github.com/ReactiveX/RxJava/issues/1147 */ @Test diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java index bec6a10b2d..67120c49bc 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java @@ -288,6 +288,7 @@ public void run() { } /** + * Make sure emission-subscription races are handled correctly. * https://github.com/ReactiveX/RxJava/issues/1147 */ @Test From c35874145070eddf6a9b4dd5559e7c8df9490512 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 19 Oct 2018 22:16:32 +0200 Subject: [PATCH 089/211] 2.x: Add C.delaySubscription marble, fix some javadoc (#6257) --- src/main/java/io/reactivex/Completable.java | 2 ++ .../io/reactivex/internal/fuseable/ConditionalSubscriber.java | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 58eddbfed8..486562b483 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -1393,6 +1393,7 @@ public final Completable delay(final long delay, final TimeUnit unit, final Sche /** * Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time. *

    + * *

    *
    Scheduler:
    *
    This version of {@code delaySubscription} operates by default on the {@code computation} {@link Scheduler}.
    @@ -1415,6 +1416,7 @@ public final Completable delaySubscription(long delay, TimeUnit unit) { * Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time, * both waiting and subscribing on a given Scheduler. *

    + * *

    *
    Scheduler:
    *
    You specify which {@link Scheduler} this operator will use.
    diff --git a/src/main/java/io/reactivex/internal/fuseable/ConditionalSubscriber.java b/src/main/java/io/reactivex/internal/fuseable/ConditionalSubscriber.java index 086e696571..4535b9c18d 100644 --- a/src/main/java/io/reactivex/internal/fuseable/ConditionalSubscriber.java +++ b/src/main/java/io/reactivex/internal/fuseable/ConditionalSubscriber.java @@ -16,7 +16,7 @@ import io.reactivex.FlowableSubscriber; /** - * A Subscriber with an additional onNextIf(T) method that + * A Subscriber with an additional {@link #tryOnNext(Object)} method that * tells the caller the specified value has been accepted or * not. * @@ -30,6 +30,7 @@ public interface ConditionalSubscriber extends FlowableSubscriber { * Conditionally takes the value. * @param t the value to deliver * @return true if the value has been accepted, false if the value has been rejected + * and the next value can be sent immediately */ boolean tryOnNext(T t); } From be0353cc6334fbb60a285f2f4f4ba88150f099e6 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 23 Oct 2018 11:11:52 +0200 Subject: [PATCH 090/211] Release 2.2.3 --- CHANGES.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 308c8e606b..6c888f8d3a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,24 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.3 - October 23, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.3%7C)) + +#### API changes + + - [Pull 6242](https://github.com/ReactiveX/RxJava/pull/6242): Add timed `Completable.delaySubscription()` operator. + +#### Documentation changes + + - [Pull 6220](https://github.com/ReactiveX/RxJava/pull/6220): Remove unnecessary 's' from `ConnectableObservable`. + - [Pull 6241](https://github.com/ReactiveX/RxJava/pull/6241): Remove mention of `io.reactivex.functions.Functions` nonexistent utility class. + +#### Other changes + + - [Pull 6232](https://github.com/ReactiveX/RxJava/pull/6232): Cleanup `Observable.flatMap` drain logic. + - [Pull 6234](https://github.com/ReactiveX/RxJava/pull/6234): Add timeout and unit to `TimeoutException` message in the `timeout` operators. + - [Pull 6236](https://github.com/ReactiveX/RxJava/pull/6236): Adjust `UndeliverableException` and `OnErrorNotImplementedException` message to use the full inner exception. + - [Pull 6244](https://github.com/ReactiveX/RxJava/pull/6244): Add `@Nullable` annotations for blocking methods in `Completable`. + ### Version 2.2.2 - September 6, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.2%7C)) #### Bugfixes From 9181cbc54e80f686a41037ad43605389d4f0741d Mon Sep 17 00:00:00 2001 From: Elijah Verdoorn Date: Fri, 26 Oct 2018 00:32:26 -0700 Subject: [PATCH 091/211] Add generate examples to Creating-Observables.md in Wiki (#6260) Add documentation and example to the wiki for generate. --- docs/Creating-Observables.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/Creating-Observables.md b/docs/Creating-Observables.md index 4d26bbf2b1..9e0c3b96cd 100644 --- a/docs/Creating-Observables.md +++ b/docs/Creating-Observables.md @@ -199,6 +199,27 @@ observable.subscribe( () -> System.out.println("Done")); ``` +## generate + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/create.html](http://reactivex.io/documentation/operators/create.html) + +Creates a cold, synchronous and stateful generator of values. + +#### generate example: + +```java +int startValue = 1; +int incrementValue = 1; +Flowable flowable = Flowable.generate(() -> startValue, (s, emitter) -> { + int nextValue = s + incrementValue; + emitter.onNext(nextValue); + return nextValue; +}); +flowable.subscribe(value -> System.out.println(value)); +``` + ## create **Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` From 1406637753003342f26cec628a9ba5e14b4d5882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Quentin?= Date: Fri, 26 Oct 2018 16:01:52 +0200 Subject: [PATCH 092/211] =?UTF-8?q?Use=20JUnit's=20assert=20format=20for?= =?UTF-8?q?=20assert=20messages=20to=20enable=20better=20suppor=E2=80=A6?= =?UTF-8?q?=20(#6262)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use JUnit's assert format for assert messages to enable better support in IDEs * remove unnecessary < and > since it's not matched by IntelliJ's regex --- .../reactivex/observers/BaseTestConsumer.java | 18 +++++++++--------- .../reactivex/observers/TestObserverTest.java | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/reactivex/observers/BaseTestConsumer.java b/src/main/java/io/reactivex/observers/BaseTestConsumer.java index 2bb9285787..61db5a2356 100644 --- a/src/main/java/io/reactivex/observers/BaseTestConsumer.java +++ b/src/main/java/io/reactivex/observers/BaseTestConsumer.java @@ -351,11 +351,11 @@ public final U assertError(Predicate errorPredicate) { public final U assertValue(T value) { int s = values.size(); if (s != 1) { - throw fail("Expected: " + valueAndClass(value) + ", Actual: " + values); + throw fail("expected: " + valueAndClass(value) + " but was: " + values); } T v = values.get(0); if (!ObjectHelper.equals(value, v)) { - throw fail("Expected: " + valueAndClass(value) + ", Actual: " + valueAndClass(v)); + throw fail("expected: " + valueAndClass(value) + " but was: " + valueAndClass(v)); } return (U)this; } @@ -450,7 +450,7 @@ public final U assertValueAt(int index, T value) { T v = values.get(index); if (!ObjectHelper.equals(value, v)) { - throw fail("Expected: " + valueAndClass(value) + ", Actual: " + valueAndClass(v)); + throw fail("expected: " + valueAndClass(value) + " but was: " + valueAndClass(v)); } return (U)this; } @@ -512,7 +512,7 @@ public static String valueAndClass(Object o) { public final U assertValueCount(int count) { int s = values.size(); if (s != count) { - throw fail("Value counts differ; Expected: " + count + ", Actual: " + s); + throw fail("Value counts differ; expected: " + count + " but was: " + s); } return (U)this; } @@ -535,14 +535,14 @@ public final U assertNoValues() { public final U assertValues(T... values) { int s = this.values.size(); if (s != values.length) { - throw fail("Value count differs; Expected: " + values.length + " " + Arrays.toString(values) - + ", Actual: " + s + " " + this.values); + throw fail("Value count differs; expected: " + values.length + " " + Arrays.toString(values) + + " but was: " + s + " " + this.values); } for (int i = 0; i < s; i++) { T v = this.values.get(i); T u = values[i]; if (!ObjectHelper.equals(u, v)) { - throw fail("Values at position " + i + " differ; Expected: " + valueAndClass(u) + ", Actual: " + valueAndClass(v)); + throw fail("Values at position " + i + " differ; expected: " + valueAndClass(u) + " but was: " + valueAndClass(v)); } } return (U)this; @@ -628,7 +628,7 @@ public final U assertValueSequence(Iterable sequence) { T v = actualIterator.next(); if (!ObjectHelper.equals(u, v)) { - throw fail("Values at position " + i + " differ; Expected: " + valueAndClass(u) + ", Actual: " + valueAndClass(v)); + throw fail("Values at position " + i + " differ; expected: " + valueAndClass(u) + " but was: " + valueAndClass(v)); } i++; } @@ -738,7 +738,7 @@ public final U assertErrorMessage(String message) { Throwable e = errors.get(0); String errorMessage = e.getMessage(); if (!ObjectHelper.equals(message, errorMessage)) { - throw fail("Error message differs; Expected: " + message + ", Actual: " + errorMessage); + throw fail("Error message differs; exptected: " + message + " but was: " + errorMessage); } } else { throw fail("Multiple errors"); diff --git a/src/test/java/io/reactivex/observers/TestObserverTest.java b/src/test/java/io/reactivex/observers/TestObserverTest.java index 2258d15779..d2d81dc77c 100644 --- a/src/test/java/io/reactivex/observers/TestObserverTest.java +++ b/src/test/java/io/reactivex/observers/TestObserverTest.java @@ -1407,7 +1407,7 @@ public void assertValueAtIndexNoMatch() { Observable.just("a", "b", "c").subscribe(to); thrown.expect(AssertionError.class); - thrown.expectMessage("Expected: b (class: String), Actual: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)"); + thrown.expectMessage("expected: b (class: String) but was: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)"); to.assertValueAt(2, "b"); } From 1a774e6d775d381937ae360296a88610353fefe6 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sat, 27 Oct 2018 23:08:08 +0200 Subject: [PATCH 093/211] 2.x: Fix cancel/dispose upon upstream switch for some operators (#6258) * 2.x: Fix cancel/dispose upon upstream switch for some operators * Restore star imports --- .../flowable/FlowableConcatArray.java | 1 + .../operators/flowable/FlowableConcatMap.java | 1 + .../FlowableDelaySubscriptionOther.java | 119 +++++----- .../flowable/FlowableOnErrorNext.java | 1 + .../operators/flowable/FlowableRepeat.java | 2 +- .../flowable/FlowableRepeatUntil.java | 2 +- .../flowable/FlowableRepeatWhen.java | 2 + .../flowable/FlowableRetryBiPredicate.java | 2 +- .../flowable/FlowableRetryPredicate.java | 2 +- .../flowable/FlowableSwitchIfEmpty.java | 2 +- .../operators/flowable/FlowableTimeout.java | 1 + .../flowable/FlowableTimeoutTimed.java | 1 + .../observable/ObservableConcatMap.java | 2 +- .../observable/ObservableRepeatWhen.java | 3 +- .../ObservableRetryBiPredicate.java | 2 +- .../observable/ObservableRetryPredicate.java | 2 +- .../observable/ObservableRetryWhen.java | 1 + .../subscriptions/SubscriptionArbiter.java | 11 +- .../flowable/FlowableConcatMapTest.java | 27 ++- .../flowable/FlowableConcatTest.java | 40 +++- .../flowable/FlowableRepeatTest.java | 73 ++++++ .../operators/flowable/FlowableRetryTest.java | 218 +++++++++++++++++- .../FlowableRetryWithPredicateTest.java | 4 +- .../flowable/FlowableSwitchIfEmptyTest.java | 4 +- .../observable/ObservableConcatMapTest.java | 27 ++- .../observable/ObservableConcatTest.java | 39 ++++ .../observable/ObservableRepeatTest.java | 73 ++++++ .../observable/ObservableRetryTest.java | 208 ++++++++++++++++- .../ObservableRetryWithPredicateTest.java | 4 +- .../SubscriptionArbiterTest.java | 144 +++++++++++- 30 files changed, 920 insertions(+), 98 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatArray.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatArray.java index c06cffa80a..4d7cd06c5b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatArray.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatArray.java @@ -59,6 +59,7 @@ static final class ConcatArraySubscriber extends SubscriptionArbiter implemen long produced; ConcatArraySubscriber(Publisher[] sources, boolean delayError, Subscriber downstream) { + super(false); this.downstream = downstream; this.sources = sources; this.delayError = delayError; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java index edde82442e..2dc316d1e9 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java @@ -571,6 +571,7 @@ static final class ConcatMapInner long produced; ConcatMapInner(ConcatMapSupport parent) { + super(false); this.parent = parent; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOther.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOther.java index a98892a01c..ea52987d59 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOther.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOther.java @@ -12,10 +12,12 @@ */ package io.reactivex.internal.operators.flowable; +import java.util.concurrent.atomic.*; + import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.internal.subscriptions.SubscriptionArbiter; +import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; /** @@ -35,94 +37,105 @@ public FlowableDelaySubscriptionOther(Publisher main, Publisher @Override public void subscribeActual(final Subscriber child) { - final SubscriptionArbiter serial = new SubscriptionArbiter(); - child.onSubscribe(serial); + MainSubscriber parent = new MainSubscriber(child, main); + child.onSubscribe(parent); + other.subscribe(parent.other); + } - FlowableSubscriber otherSubscriber = new DelaySubscriber(serial, child); + static final class MainSubscriber extends AtomicLong implements FlowableSubscriber, Subscription { - other.subscribe(otherSubscriber); - } + private static final long serialVersionUID = 2259811067697317255L; + + final Subscriber downstream; - final class DelaySubscriber implements FlowableSubscriber { - final SubscriptionArbiter serial; - final Subscriber child; - boolean done; + final Publisher main; - DelaySubscriber(SubscriptionArbiter serial, Subscriber child) { - this.serial = serial; - this.child = child; + final OtherSubscriber other; + + final AtomicReference upstream; + + MainSubscriber(Subscriber downstream, Publisher main) { + this.downstream = downstream; + this.main = main; + this.other = new OtherSubscriber(); + this.upstream = new AtomicReference(); } - @Override - public void onSubscribe(final Subscription s) { - serial.setSubscription(new DelaySubscription(s)); - s.request(Long.MAX_VALUE); + void next() { + main.subscribe(this); } @Override - public void onNext(U t) { - onComplete(); + public void onNext(T t) { + downstream.onNext(t); } @Override - public void onError(Throwable e) { - if (done) { - RxJavaPlugins.onError(e); - return; - } - done = true; - child.onError(e); + public void onError(Throwable t) { + downstream.onError(t); } @Override public void onComplete() { - if (done) { - return; - } - done = true; - - main.subscribe(new OnCompleteSubscriber()); + downstream.onComplete(); } - final class DelaySubscription implements Subscription { - - final Subscription upstream; - - DelaySubscription(Subscription s) { - this.upstream = s; + @Override + public void request(long n) { + if (SubscriptionHelper.validate(n)) { + SubscriptionHelper.deferredRequest(upstream, this, n); } + } - @Override - public void request(long n) { - // ignored - } + @Override + public void cancel() { + SubscriptionHelper.cancel(other); + SubscriptionHelper.cancel(upstream); + } - @Override - public void cancel() { - upstream.cancel(); - } + @Override + public void onSubscribe(Subscription s) { + SubscriptionHelper.deferredSetOnce(upstream, this, s); } - final class OnCompleteSubscriber implements FlowableSubscriber { + final class OtherSubscriber extends AtomicReference implements FlowableSubscriber { + + private static final long serialVersionUID = -3892798459447644106L; + @Override public void onSubscribe(Subscription s) { - serial.setSubscription(s); + if (SubscriptionHelper.setOnce(this, s)) { + s.request(Long.MAX_VALUE); + } } @Override - public void onNext(T t) { - child.onNext(t); + public void onNext(Object t) { + Subscription s = get(); + if (s != SubscriptionHelper.CANCELLED) { + lazySet(SubscriptionHelper.CANCELLED); + s.cancel(); + next(); + } } @Override public void onError(Throwable t) { - child.onError(t); + Subscription s = get(); + if (s != SubscriptionHelper.CANCELLED) { + downstream.onError(t); + } else { + RxJavaPlugins.onError(t); + } } @Override public void onComplete() { - child.onComplete(); + Subscription s = get(); + if (s != SubscriptionHelper.CANCELLED) { + next(); + } } } - } +} } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java index 4d5b86c880..7110d086e0 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnErrorNext.java @@ -58,6 +58,7 @@ static final class OnErrorNextSubscriber long produced; OnErrorNextSubscriber(Subscriber actual, Function> nextSupplier, boolean allowFatal) { + super(false); this.downstream = actual; this.nextSupplier = nextSupplier; this.allowFatal = allowFatal; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java index f99bc48a20..1bbdd7cd5c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeat.java @@ -29,7 +29,7 @@ public FlowableRepeat(Flowable source, long count) { @Override public void subscribeActual(Subscriber s) { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(false); s.onSubscribe(sa); RepeatSubscriber rs = new RepeatSubscriber(s, count != Long.MAX_VALUE ? count - 1 : Long.MAX_VALUE, sa, source); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java index d373a3865d..9c7057af59 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatUntil.java @@ -31,7 +31,7 @@ public FlowableRepeatUntil(Flowable source, BooleanSupplier until) { @Override public void subscribeActual(Subscriber s) { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(false); s.onSubscribe(sa); RepeatSubscriber rs = new RepeatSubscriber(s, until, sa, source); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java index c5fac022ad..45f8bfbb1e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java @@ -143,6 +143,7 @@ abstract static class WhenSourceSubscriber extends SubscriptionArbiter imp WhenSourceSubscriber(Subscriber actual, FlowableProcessor processor, Subscription receiver) { + super(false); this.downstream = actual; this.processor = processor; this.receiver = receiver; @@ -160,6 +161,7 @@ public final void onNext(T t) { } protected final void again(U signal) { + setSubscription(EmptySubscription.INSTANCE); long p = produced; if (p != 0L) { produced = 0L; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryBiPredicate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryBiPredicate.java index 662ddb694c..8bc9ba27d0 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryBiPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryBiPredicate.java @@ -33,7 +33,7 @@ public FlowableRetryBiPredicate( @Override public void subscribeActual(Subscriber s) { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(false); s.onSubscribe(sa); RetryBiSubscriber rs = new RetryBiSubscriber(s, predicate, sa, source); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java index 47a8e3d878..8d035aaf95 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRetryPredicate.java @@ -35,7 +35,7 @@ public FlowableRetryPredicate(Flowable source, @Override public void subscribeActual(Subscriber s) { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(false); s.onSubscribe(sa); RetrySubscriber rs = new RetrySubscriber(s, count, predicate, sa, source); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmpty.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmpty.java index f9fc7ebc4c..be8febdf17 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmpty.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmpty.java @@ -43,7 +43,7 @@ static final class SwitchIfEmptySubscriber implements FlowableSubscriber { this.downstream = actual; this.other = other; this.empty = true; - this.arbiter = new SubscriptionArbiter(); + this.arbiter = new SubscriptionArbiter(false); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java index 6d8300f234..eec781bcc3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java @@ -208,6 +208,7 @@ static final class TimeoutFallbackSubscriber extends SubscriptionArbiter TimeoutFallbackSubscriber(Subscriber actual, Function> itemTimeoutIndicator, Publisher fallback) { + super(true); this.downstream = actual; this.itemTimeoutIndicator = itemTimeoutIndicator; this.task = new SequentialDisposable(); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java index 54a2762dfc..d25acdc3e3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTimed.java @@ -196,6 +196,7 @@ static final class TimeoutFallbackSubscriber extends SubscriptionArbiter TimeoutFallbackSubscriber(Subscriber actual, long timeout, TimeUnit unit, Scheduler.Worker worker, Publisher fallback) { + super(true); this.downstream = actual; this.timeout = timeout; this.unit = unit; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java index 831cfd1c55..a59841d501 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMap.java @@ -244,7 +244,7 @@ static final class InnerObserver extends AtomicReference implemen @Override public void onSubscribe(Disposable d) { - DisposableHelper.set(this, d); + DisposableHelper.replace(this, d); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java index 4b8e194973..af27f2f6d0 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java @@ -92,7 +92,7 @@ static final class RepeatWhenObserver extends AtomicInteger implements Observ @Override public void onSubscribe(Disposable d) { - DisposableHelper.replace(this.upstream, d); + DisposableHelper.setOnce(this.upstream, d); } @Override @@ -109,6 +109,7 @@ public void onError(Throwable e) { @Override public void onComplete() { active = false; + DisposableHelper.replace(upstream, null); signaller.onNext(0); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java index c9be2c75ca..f762142f0b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryBiPredicate.java @@ -58,7 +58,7 @@ static final class RetryBiObserver extends AtomicInteger implements Observer< @Override public void onSubscribe(Disposable d) { - upstream.update(d); + upstream.replace(d); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java index 6fb5d7b665..ee5e074f58 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRetryPredicate.java @@ -61,7 +61,7 @@ static final class RepeatObserver extends AtomicInteger implements Observer(); missedRequested = new AtomicLong(); missedProduced = new AtomicLong(); @@ -80,7 +83,7 @@ public final void setSubscription(Subscription s) { if (get() == 0 && compareAndSet(0, 1)) { Subscription a = actual; - if (a != null) { + if (a != null && cancelOnReplace) { a.cancel(); } @@ -100,7 +103,7 @@ public final void setSubscription(Subscription s) { } Subscription a = missedSubscription.getAndSet(s); - if (a != null) { + if (a != null && cancelOnReplace) { a.cancel(); } drain(); @@ -240,7 +243,7 @@ final void drainLoop() { } if (ms != null) { - if (a != null) { + if (a != null && cancelOnReplace) { a.cancel(); } actual = ms; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java index ac5c573910..eba09e564f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java @@ -13,14 +13,17 @@ package io.reactivex.internal.operators.flowable; +import static org.junit.Assert.assertEquals; + import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; import org.reactivestreams.Publisher; import io.reactivex.*; import io.reactivex.exceptions.TestException; -import io.reactivex.functions.Function; +import io.reactivex.functions.*; import io.reactivex.internal.operators.flowable.FlowableConcatMap.WeakScalarSubscription; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; @@ -143,4 +146,26 @@ public Publisher apply(Integer v) .test() .assertFailure(TestException.class); } + + @Test + public void noCancelPrevious() { + final AtomicInteger counter = new AtomicInteger(); + + Flowable.range(1, 5) + .concatMap(new Function>() { + @Override + public Flowable apply(Integer v) throws Exception { + return Flowable.just(v).doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + } + }) + .test() + .assertResult(1, 2, 3, 4, 5); + + assertEquals(0, counter.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java index 733f3b7cf3..772f559733 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java @@ -29,7 +29,7 @@ import io.reactivex.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; -import io.reactivex.functions.Function; +import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; @@ -1627,4 +1627,42 @@ public void subscribe(FlowableEmitter s) throws Exception { assertEquals(1, calls[0]); } + + @SuppressWarnings("unchecked") + @Test + public void noCancelPreviousArray() { + final AtomicInteger counter = new AtomicInteger(); + + Flowable source = Flowable.just(1).doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + Flowable.concatArray(source, source, source, source, source) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } + + @SuppressWarnings("unchecked") + @Test + public void noCancelPreviousIterable() { + final AtomicInteger counter = new AtomicInteger(); + + Flowable source = Flowable.just(1).doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + Flowable.concat(Arrays.asList(source, source, source, source, source)) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java index 82cec69233..51376bc594 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java @@ -368,4 +368,77 @@ public Flowable apply(Flowable handler) throws Exception { .test() .assertResult(1, 2, 3, 1, 2, 3); } + + @Test + public void noCancelPreviousRepeat() { + final AtomicInteger counter = new AtomicInteger(); + + Flowable source = Flowable.just(1).doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.repeat(5) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRepeatUntil() { + final AtomicInteger counter = new AtomicInteger(); + + Flowable source = Flowable.just(1).doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + final AtomicInteger times = new AtomicInteger(); + + source.repeatUntil(new BooleanSupplier() { + @Override + public boolean getAsBoolean() throws Exception { + return times.getAndIncrement() == 4; + } + }) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRepeatWhen() { + final AtomicInteger counter = new AtomicInteger(); + + Flowable source = Flowable.just(1).doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + final AtomicInteger times = new AtomicInteger(); + + source.repeatWhen(new Function, Flowable>() { + @Override + public Flowable apply(Flowable e) throws Exception { + return e.takeWhile(new Predicate() { + @Override + public boolean test(Object v) throws Exception { + return times.getAndIncrement() < 4; + } + }); + } + }) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java index 8a0a29f8dd..a5dd4918ab 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java @@ -30,6 +30,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.flowables.GroupedFlowable; import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; @@ -355,7 +356,7 @@ public void testRetrySubscribesAgainAfterError() throws Exception { Consumer throwException = mock(Consumer.class); doThrow(new RuntimeException()).when(throwException).accept(Mockito.anyInt()); - // create a retrying observable based on a PublishProcessor + // create a retrying Flowable based on a PublishProcessor PublishProcessor processor = PublishProcessor.create(); processor // record item @@ -492,7 +493,7 @@ public void cancel() { } @Test - public void testSourceObservableCallsUnsubscribe() throws InterruptedException { + public void testSourceFlowableCallsUnsubscribe() throws InterruptedException { final AtomicInteger subsCount = new AtomicInteger(0); final TestSubscriber ts = new TestSubscriber(); @@ -523,7 +524,7 @@ public void subscribe(Subscriber s) { } @Test - public void testSourceObservableRetry1() throws InterruptedException { + public void testSourceFlowableRetry1() throws InterruptedException { final AtomicInteger subsCount = new AtomicInteger(0); final TestSubscriber ts = new TestSubscriber(); @@ -542,7 +543,7 @@ public void subscribe(Subscriber s) { } @Test - public void testSourceObservableRetry0() throws InterruptedException { + public void testSourceFlowableRetry0() throws InterruptedException { final AtomicInteger subsCount = new AtomicInteger(0); final TestSubscriber ts = new TestSubscriber(); @@ -566,12 +567,14 @@ static final class SlowFlowable implements Publisher { final AtomicInteger active = new AtomicInteger(0); final AtomicInteger maxActive = new AtomicInteger(0); final AtomicInteger nextBeforeFailure; + final String context; private final int emitDelay; - SlowFlowable(int emitDelay, int countNext) { + SlowFlowable(int emitDelay, int countNext, String context) { this.emitDelay = emitDelay; this.nextBeforeFailure = new AtomicInteger(countNext); + this.context = context; } @Override @@ -593,7 +596,7 @@ public void cancel() { efforts.getAndIncrement(); active.getAndIncrement(); maxActive.set(Math.max(active.get(), maxActive.get())); - final Thread thread = new Thread() { + final Thread thread = new Thread(context) { @Override public void run() { long nr = 0; @@ -603,7 +606,9 @@ public void run() { if (nextBeforeFailure.getAndDecrement() > 0) { subscriber.onNext(nr++); } else { + active.decrementAndGet(); subscriber.onError(new RuntimeException("expected-failed")); + break; } } } catch (InterruptedException t) { @@ -664,7 +669,7 @@ public void testUnsubscribeAfterError() { Subscriber subscriber = TestHelper.mockSubscriber(); // Flowable that always fails after 100ms - SlowFlowable so = new SlowFlowable(100, 0); + SlowFlowable so = new SlowFlowable(100, 0, "testUnsubscribeAfterError"); Flowable f = Flowable.unsafeCreate(so).retry(5); AsyncSubscriber async = new AsyncSubscriber(subscriber); @@ -688,7 +693,7 @@ public void testTimeoutWithRetry() { Subscriber subscriber = TestHelper.mockSubscriber(); // Flowable that sends every 100ms (timeout fails instead) - SlowFlowable sf = new SlowFlowable(100, 10); + SlowFlowable sf = new SlowFlowable(100, 10, "testTimeoutWithRetry"); Flowable f = Flowable.unsafeCreate(sf).timeout(80, TimeUnit.MILLISECONDS).retry(5); AsyncSubscriber async = new AsyncSubscriber(subscriber); @@ -1001,7 +1006,7 @@ public boolean getAsBoolean() throws Exception { } @Test - public void shouldDisposeInnerObservable() { + public void shouldDisposeInnerFlowable() { final PublishProcessor processor = PublishProcessor.create(); final Disposable disposable = Flowable.error(new RuntimeException("Leak")) .retryWhen(new Function, Flowable>() { @@ -1021,4 +1026,199 @@ public Flowable apply(Throwable ignore) throws Exception { disposable.dispose(); assertFalse(processor.hasSubscribers()); } + + @Test + public void noCancelPreviousRetry() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Flowable source = Flowable.defer(new Callable>() { + @Override + public Flowable call() throws Exception { + if (times.getAndIncrement() < 4) { + return Flowable.error(new TestException()); + } + return Flowable.just(1); + } + }) + .doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retry(5) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRetryWhile() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Flowable source = Flowable.defer(new Callable>() { + @Override + public Flowable call() throws Exception { + if (times.getAndIncrement() < 4) { + return Flowable.error(new TestException()); + } + return Flowable.just(1); + } + }) + .doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retry(5, Functions.alwaysTrue()) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRetryWhile2() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Flowable source = Flowable.defer(new Callable>() { + @Override + public Flowable call() throws Exception { + if (times.getAndIncrement() < 4) { + return Flowable.error(new TestException()); + } + return Flowable.just(1); + } + }) + .doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retry(new BiPredicate() { + @Override + public boolean test(Integer a, Throwable b) throws Exception { + return a < 5; + } + }) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRetryUntil() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Flowable source = Flowable.defer(new Callable>() { + @Override + public Flowable call() throws Exception { + if (times.getAndIncrement() < 4) { + return Flowable.error(new TestException()); + } + return Flowable.just(1); + } + }) + .doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retryUntil(new BooleanSupplier() { + @Override + public boolean getAsBoolean() throws Exception { + return false; + } + }) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRepeatWhen() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Flowable source = Flowable.defer(new Callable>() { + @Override + public Flowable call() throws Exception { + if (times.get() < 4) { + return Flowable.error(new TestException()); + } + return Flowable.just(1); + } + }).doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retryWhen(new Function, Flowable>() { + @Override + public Flowable apply(Flowable e) throws Exception { + return e.takeWhile(new Predicate() { + @Override + public boolean test(Object v) throws Exception { + return times.getAndIncrement() < 4; + } + }); + } + }) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRepeatWhen2() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Flowable source = Flowable.error(new TestException()) + .doOnCancel(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retryWhen(new Function, Flowable>() { + @Override + public Flowable apply(Flowable e) throws Exception { + return e.takeWhile(new Predicate() { + @Override + public boolean test(Object v) throws Exception { + return times.getAndIncrement() < 4; + } + }); + } + }) + .test() + .assertResult(); + + assertEquals(0, counter.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java index 54346a73c0..de31e283a4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java @@ -230,7 +230,7 @@ public void testUnsubscribeAfterError() { Subscriber subscriber = TestHelper.mockSubscriber(); // Flowable that always fails after 100ms - FlowableRetryTest.SlowFlowable so = new FlowableRetryTest.SlowFlowable(100, 0); + FlowableRetryTest.SlowFlowable so = new FlowableRetryTest.SlowFlowable(100, 0, "testUnsubscribeAfterError"); Flowable f = Flowable .unsafeCreate(so) .retry(retry5); @@ -256,7 +256,7 @@ public void testTimeoutWithRetry() { Subscriber subscriber = TestHelper.mockSubscriber(); // Flowable that sends every 100ms (timeout fails instead) - FlowableRetryTest.SlowFlowable so = new FlowableRetryTest.SlowFlowable(100, 10); + FlowableRetryTest.SlowFlowable so = new FlowableRetryTest.SlowFlowable(100, 10, "testTimeoutWithRetry"); Flowable f = Flowable .unsafeCreate(so) .timeout(80, TimeUnit.MILLISECONDS) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java index 99ecaaac43..f429d8e172 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java @@ -127,7 +127,7 @@ public void onNext(Long aLong) { } @Test - public void testSwitchShouldTriggerUnsubscribe() { + public void testSwitchShouldNotTriggerUnsubscribe() { final BooleanSubscription bs = new BooleanSubscription(); Flowable.unsafeCreate(new Publisher() { @@ -137,7 +137,7 @@ public void subscribe(final Subscriber subscriber) { subscriber.onComplete(); } }).switchIfEmpty(Flowable.never()).subscribe(); - assertTrue(bs.isCancelled()); + assertFalse(bs.isCancelled()); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapTest.java index 5c2681a79d..4940d6c857 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapTest.java @@ -13,17 +13,18 @@ package io.reactivex.internal.operators.observable; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.List; import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; import io.reactivex.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; -import io.reactivex.functions.Function; +import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; @@ -498,4 +499,26 @@ public void onNext(Integer t) { to.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } + + @Test + public void noCancelPrevious() { + final AtomicInteger counter = new AtomicInteger(); + + Observable.range(1, 5) + .concatMap(new Function>() { + @Override + public ObservableSource apply(Integer v) throws Exception { + return Observable.just(v).doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + } + }) + .test() + .assertResult(1, 2, 3, 4, 5); + + assertEquals(0, counter.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java index fc2a01619b..d47c684cfc 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java @@ -28,6 +28,7 @@ import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Action; import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; import io.reactivex.observers.*; @@ -1155,4 +1156,42 @@ public void onComplete() { assertTrue(disposable[0].isDisposed()); } + + @SuppressWarnings("unchecked") + @Test + public void noCancelPreviousArray() { + final AtomicInteger counter = new AtomicInteger(); + + Observable source = Observable.just(1).doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + Observable.concatArray(source, source, source, source, source) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } + + @SuppressWarnings("unchecked") + @Test + public void noCancelPreviousIterable() { + final AtomicInteger counter = new AtomicInteger(); + + Observable source = Observable.just(1).doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + Observable.concat(Arrays.asList(source, source, source, source, source)) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java index 3616ef729f..3afc1f1cc7 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java @@ -324,4 +324,77 @@ public Object apply(Object w) throws Exception { .test() .assertFailure(TestException.class, 1, 2, 3); } + + @Test + public void noCancelPreviousRepeat() { + final AtomicInteger counter = new AtomicInteger(); + + Observable source = Observable.just(1).doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.repeat(5) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRepeatUntil() { + final AtomicInteger counter = new AtomicInteger(); + + Observable source = Observable.just(1).doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + final AtomicInteger times = new AtomicInteger(); + + source.repeatUntil(new BooleanSupplier() { + @Override + public boolean getAsBoolean() throws Exception { + return times.getAndIncrement() == 4; + } + }) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRepeatWhen() { + final AtomicInteger counter = new AtomicInteger(); + + Observable source = Observable.just(1).doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + final AtomicInteger times = new AtomicInteger(); + + source.repeatWhen(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable e) throws Exception { + return e.takeWhile(new Predicate() { + @Override + public boolean test(Object v) throws Exception { + return times.getAndIncrement() < 4; + } + }); + } + }) + .test() + .assertResult(1, 1, 1, 1, 1); + + assertEquals(0, counter.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java index 5c1cbe0041..e576479921 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; @@ -29,6 +30,7 @@ import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.observables.GroupedObservable; import io.reactivex.observers.*; @@ -522,11 +524,14 @@ static final class SlowObservable implements ObservableSource { final AtomicInteger active = new AtomicInteger(0), maxActive = new AtomicInteger(0); final AtomicInteger nextBeforeFailure; + final String context; + private final int emitDelay; - SlowObservable(int emitDelay, int countNext) { + SlowObservable(int emitDelay, int countNext, String context) { this.emitDelay = emitDelay; this.nextBeforeFailure = new AtomicInteger(countNext); + this.context = context; } @Override @@ -542,7 +547,7 @@ public void run() { efforts.getAndIncrement(); active.getAndIncrement(); maxActive.set(Math.max(active.get(), maxActive.get())); - final Thread thread = new Thread() { + final Thread thread = new Thread(context) { @Override public void run() { long nr = 0; @@ -552,7 +557,9 @@ public void run() { if (nextBeforeFailure.getAndDecrement() > 0) { observer.onNext(nr++); } else { + active.decrementAndGet(); observer.onError(new RuntimeException("expected-failed")); + break; } } } catch (InterruptedException t) { @@ -613,7 +620,7 @@ public void testUnsubscribeAfterError() { Observer observer = TestHelper.mockObserver(); // Observable that always fails after 100ms - SlowObservable so = new SlowObservable(100, 0); + SlowObservable so = new SlowObservable(100, 0, "testUnsubscribeAfterError"); Observable o = Observable.unsafeCreate(so).retry(5); AsyncObserver async = new AsyncObserver(observer); @@ -637,7 +644,7 @@ public void testTimeoutWithRetry() { Observer observer = TestHelper.mockObserver(); // Observable that sends every 100ms (timeout fails instead) - SlowObservable so = new SlowObservable(100, 10); + SlowObservable so = new SlowObservable(100, 10, "testTimeoutWithRetry"); Observable o = Observable.unsafeCreate(so).timeout(80, TimeUnit.MILLISECONDS).retry(5); AsyncObserver async = new AsyncObserver(observer); @@ -931,4 +938,197 @@ public ObservableSource apply(Throwable ignore) throws Exception { assertFalse(subject.hasObservers()); } + @Test + public void noCancelPreviousRetry() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Observable source = Observable.defer(new Callable>() { + @Override + public ObservableSource call() throws Exception { + if (times.getAndIncrement() < 4) { + return Observable.error(new TestException()); + } + return Observable.just(1); + } + }) + .doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retry(5) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRetryWhile() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Observable source = Observable.defer(new Callable>() { + @Override + public ObservableSource call() throws Exception { + if (times.getAndIncrement() < 4) { + return Observable.error(new TestException()); + } + return Observable.just(1); + } + }) + .doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retry(5, Functions.alwaysTrue()) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRetryWhile2() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Observable source = Observable.defer(new Callable>() { + @Override + public ObservableSource call() throws Exception { + if (times.getAndIncrement() < 4) { + return Observable.error(new TestException()); + } + return Observable.just(1); + } + }) + .doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retry(new BiPredicate() { + @Override + public boolean test(Integer a, Throwable b) throws Exception { + return a < 5; + } + }) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRetryUntil() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Observable source = Observable.defer(new Callable>() { + @Override + public ObservableSource call() throws Exception { + if (times.getAndIncrement() < 4) { + return Observable.error(new TestException()); + } + return Observable.just(1); + } + }) + .doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retryUntil(new BooleanSupplier() { + @Override + public boolean getAsBoolean() throws Exception { + return false; + } + }) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRepeatWhen() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Observable source = Observable.defer(new Callable>() { + @Override + public ObservableSource call() throws Exception { + if (times.get() < 4) { + return Observable.error(new TestException()); + } + return Observable.just(1); + } + }).doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retryWhen(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable e) throws Exception { + return e.takeWhile(new Predicate() { + @Override + public boolean test(Object v) throws Exception { + return times.getAndIncrement() < 4; + } + }); + } + }) + .test() + .assertResult(1); + + assertEquals(0, counter.get()); + } + + @Test + public void noCancelPreviousRepeatWhen2() { + final AtomicInteger counter = new AtomicInteger(); + + final AtomicInteger times = new AtomicInteger(); + + Observable source = Observable.error(new TestException()).doOnDispose(new Action() { + @Override + public void run() throws Exception { + counter.getAndIncrement(); + } + }); + + source.retryWhen(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable e) throws Exception { + return e.takeWhile(new Predicate() { + @Override + public boolean test(Object v) throws Exception { + return times.getAndIncrement() < 4; + } + }); + } + }) + .test() + .assertResult(); + + assertEquals(0, counter.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java index 72981f705e..7b0322ab87 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java @@ -229,7 +229,7 @@ public void testUnsubscribeAfterError() { Observer observer = TestHelper.mockObserver(); // Observable that always fails after 100ms - ObservableRetryTest.SlowObservable so = new ObservableRetryTest.SlowObservable(100, 0); + ObservableRetryTest.SlowObservable so = new ObservableRetryTest.SlowObservable(100, 0, "testUnsubscribeAfterError"); Observable o = Observable .unsafeCreate(so) .retry(retry5); @@ -255,7 +255,7 @@ public void testTimeoutWithRetry() { Observer observer = TestHelper.mockObserver(); // Observable that sends every 100ms (timeout fails instead) - ObservableRetryTest.SlowObservable so = new ObservableRetryTest.SlowObservable(100, 10); + ObservableRetryTest.SlowObservable so = new ObservableRetryTest.SlowObservable(100, 10, "testTimeoutWithRetry"); Observable o = Observable .unsafeCreate(so) .timeout(80, TimeUnit.MILLISECONDS) diff --git a/src/test/java/io/reactivex/internal/subscriptions/SubscriptionArbiterTest.java b/src/test/java/io/reactivex/internal/subscriptions/SubscriptionArbiterTest.java index 02d7d30c0a..426d1779e1 100644 --- a/src/test/java/io/reactivex/internal/subscriptions/SubscriptionArbiterTest.java +++ b/src/test/java/io/reactivex/internal/subscriptions/SubscriptionArbiterTest.java @@ -26,7 +26,7 @@ public class SubscriptionArbiterTest { @Test public void setSubscriptionMissed() { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(true); sa.getAndIncrement(); @@ -45,7 +45,7 @@ public void setSubscriptionMissed() { @Test public void invalidDeferredRequest() { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(true); List errors = TestHelper.trackPluginErrors(); try { @@ -59,7 +59,7 @@ public void invalidDeferredRequest() { @Test public void unbounded() { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(true); sa.request(Long.MAX_VALUE); @@ -86,7 +86,7 @@ public void unbounded() { @Test public void cancelled() { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(true); sa.cancelled = true; BooleanSubscription bs1 = new BooleanSubscription(); @@ -102,7 +102,7 @@ public void cancelled() { @Test public void drainUnbounded() { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(true); sa.getAndIncrement(); @@ -113,7 +113,7 @@ public void drainUnbounded() { @Test public void drainMissedRequested() { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(true); sa.getAndIncrement(); @@ -128,7 +128,7 @@ public void drainMissedRequested() { @Test public void drainMissedRequestedProduced() { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(true); sa.getAndIncrement(); @@ -147,7 +147,7 @@ public void drainMissedRequestedProduced() { public void drainMissedRequestedMoreProduced() { List errors = TestHelper.trackPluginErrors(); try { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(true); sa.getAndIncrement(); @@ -169,7 +169,7 @@ public void drainMissedRequestedMoreProduced() { @Test public void missedSubscriptionNoPrior() { - SubscriptionArbiter sa = new SubscriptionArbiter(); + SubscriptionArbiter sa = new SubscriptionArbiter(true); sa.getAndIncrement(); @@ -181,4 +181,130 @@ public void missedSubscriptionNoPrior() { assertSame(bs1, sa.actual); } + + @Test + public void noCancelFastPath() { + SubscriptionArbiter sa = new SubscriptionArbiter(false); + + BooleanSubscription bs1 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); + + sa.setSubscription(bs1); + sa.setSubscription(bs2); + + assertFalse(bs1.isCancelled()); + assertFalse(bs2.isCancelled()); + } + + @Test + public void cancelFastPath() { + SubscriptionArbiter sa = new SubscriptionArbiter(true); + + BooleanSubscription bs1 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); + + sa.setSubscription(bs1); + sa.setSubscription(bs2); + + assertTrue(bs1.isCancelled()); + assertFalse(bs2.isCancelled()); + } + + @Test + public void noCancelSlowPathReplace() { + SubscriptionArbiter sa = new SubscriptionArbiter(false); + + BooleanSubscription bs1 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); + BooleanSubscription bs3 = new BooleanSubscription(); + + sa.setSubscription(bs1); + + sa.getAndIncrement(); + + sa.setSubscription(bs2); + sa.setSubscription(bs3); + + sa.drainLoop(); + + assertFalse(bs1.isCancelled()); + assertFalse(bs2.isCancelled()); + assertFalse(bs3.isCancelled()); + } + + @Test + public void cancelSlowPathReplace() { + SubscriptionArbiter sa = new SubscriptionArbiter(true); + + BooleanSubscription bs1 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); + BooleanSubscription bs3 = new BooleanSubscription(); + + sa.setSubscription(bs1); + + sa.getAndIncrement(); + + sa.setSubscription(bs2); + sa.setSubscription(bs3); + + sa.drainLoop(); + + assertTrue(bs1.isCancelled()); + assertTrue(bs2.isCancelled()); + assertFalse(bs3.isCancelled()); + } + + @Test + public void noCancelSlowPath() { + SubscriptionArbiter sa = new SubscriptionArbiter(false); + + BooleanSubscription bs1 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); + + sa.setSubscription(bs1); + + sa.getAndIncrement(); + + sa.setSubscription(bs2); + + sa.drainLoop(); + + assertFalse(bs1.isCancelled()); + assertFalse(bs2.isCancelled()); + } + + @Test + public void cancelSlowPath() { + SubscriptionArbiter sa = new SubscriptionArbiter(true); + + BooleanSubscription bs1 = new BooleanSubscription(); + BooleanSubscription bs2 = new BooleanSubscription(); + + sa.setSubscription(bs1); + + sa.getAndIncrement(); + + sa.setSubscription(bs2); + + sa.drainLoop(); + + assertTrue(bs1.isCancelled()); + assertFalse(bs2.isCancelled()); + } + + @Test + public void moreProducedViolationFastPath() { + List errors = TestHelper.trackPluginErrors(); + try { + SubscriptionArbiter sa = new SubscriptionArbiter(true); + + sa.produced(2); + + assertEquals(0, sa.requested); + + TestHelper.assertError(errors, 0, IllegalStateException.class, "More produced than requested: -2"); + } finally { + RxJavaPlugins.reset(); + } + } } From 7849fc9f48f91129a3fb511943ea834d7f5a170b Mon Sep 17 00:00:00 2001 From: "Artem Zinnatullin :slowpoke" Date: Sun, 28 Oct 2018 03:06:45 -0700 Subject: [PATCH 094/211] Inline SubscriptionHelper.isCancelled() (#6263) --- .../operators/flowable/BlockingFlowableIterable.java | 2 +- .../internal/operators/flowable/FlowableGroupJoin.java | 4 ++-- .../operators/flowable/FlowablePublishMulticast.java | 2 +- .../internal/operators/flowable/FlowableRepeatWhen.java | 2 +- .../operators/flowable/FlowableSequenceEqualSingle.java | 2 +- .../internal/operators/flowable/FlowableTimeout.java | 2 +- .../operators/flowable/FlowableWithLatestFromMany.java | 2 +- .../operators/maybe/MaybeDelayOtherPublisher.java | 2 +- .../internal/subscribers/ForEachWhileSubscriber.java | 2 +- .../reactivex/internal/subscribers/FutureSubscriber.java | 2 +- .../internal/subscriptions/SubscriptionHelper.java | 8 -------- .../java/io/reactivex/subscribers/ResourceSubscriber.java | 2 +- 12 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableIterable.java b/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableIterable.java index 2eaaa5ffd3..af6613b224 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableIterable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableIterable.java @@ -179,7 +179,7 @@ public void dispose() { @Override public boolean isDisposed() { - return SubscriptionHelper.isCancelled(get()); + return get() == SubscriptionHelper.CANCELLED; } } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java index c9a2b69adb..7cf3adb7b8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupJoin.java @@ -411,7 +411,7 @@ public void dispose() { @Override public boolean isDisposed() { - return SubscriptionHelper.isCancelled(get()); + return get() == SubscriptionHelper.CANCELLED; } @Override @@ -462,7 +462,7 @@ public void dispose() { @Override public boolean isDisposed() { - return SubscriptionHelper.isCancelled(get()); + return get() == SubscriptionHelper.CANCELLED; } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticast.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticast.java index b68e4cf711..46a2dbd7e3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticast.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticast.java @@ -205,7 +205,7 @@ public void dispose() { @Override public boolean isDisposed() { - return SubscriptionHelper.isCancelled(upstream.get()); + return upstream.get() == SubscriptionHelper.CANCELLED; } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java index 45f8bfbb1e..b62254185d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRepeatWhen.java @@ -93,7 +93,7 @@ public void onSubscribe(Subscription s) { public void onNext(Object t) { if (getAndIncrement() == 0) { for (;;) { - if (SubscriptionHelper.isCancelled(upstream.get())) { + if (upstream.get() == SubscriptionHelper.CANCELLED) { return; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java index c37bd0bac9..bcda903c85 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualSingle.java @@ -98,7 +98,7 @@ public void dispose() { @Override public boolean isDisposed() { - return SubscriptionHelper.isCancelled(first.get()); + return first.get() == SubscriptionHelper.CANCELLED; } void cancelAndClear() { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java index eec781bcc3..8363a5d0cb 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableTimeout.java @@ -382,7 +382,7 @@ public void dispose() { @Override public boolean isDisposed() { - return SubscriptionHelper.isCancelled(this.get()); + return this.get() == SubscriptionHelper.CANCELLED; } } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java index d3014113ed..6d6b949c33 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromMany.java @@ -133,7 +133,7 @@ void subscribe(Publisher[] others, int n) { WithLatestInnerSubscriber[] subscribers = this.subscribers; AtomicReference upstream = this.upstream; for (int i = 0; i < n; i++) { - if (SubscriptionHelper.isCancelled(upstream.get())) { + if (upstream.get() == SubscriptionHelper.CANCELLED) { return; } others[i].subscribe(subscribers[i]); diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherPublisher.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherPublisher.java index 55049d5c95..d3a0f783e2 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherPublisher.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherPublisher.java @@ -65,7 +65,7 @@ public void dispose() { @Override public boolean isDisposed() { - return SubscriptionHelper.isCancelled(other.get()); + return other.get() == SubscriptionHelper.CANCELLED; } @Override diff --git a/src/main/java/io/reactivex/internal/subscribers/ForEachWhileSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/ForEachWhileSubscriber.java index ebf47f12a6..5e15bea285 100644 --- a/src/main/java/io/reactivex/internal/subscribers/ForEachWhileSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/ForEachWhileSubscriber.java @@ -108,6 +108,6 @@ public void dispose() { @Override public boolean isDisposed() { - return SubscriptionHelper.isCancelled(this.get()); + return this.get() == SubscriptionHelper.CANCELLED; } } diff --git a/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java index a559749fb1..4b2c329c97 100644 --- a/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/FutureSubscriber.java @@ -65,7 +65,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { @Override public boolean isCancelled() { - return SubscriptionHelper.isCancelled(upstream.get()); + return upstream.get() == SubscriptionHelper.CANCELLED; } @Override diff --git a/src/main/java/io/reactivex/internal/subscriptions/SubscriptionHelper.java b/src/main/java/io/reactivex/internal/subscriptions/SubscriptionHelper.java index cddd53b8d1..ca19d0d4a3 100644 --- a/src/main/java/io/reactivex/internal/subscriptions/SubscriptionHelper.java +++ b/src/main/java/io/reactivex/internal/subscriptions/SubscriptionHelper.java @@ -92,14 +92,6 @@ public static boolean validate(long n) { public static void reportMoreProduced(long n) { RxJavaPlugins.onError(new ProtocolViolationException("More produced than requested: " + n)); } - /** - * Check if the given subscription is the common cancelled subscription. - * @param s the subscription to check - * @return true if the subscription is the common cancelled subscription - */ - public static boolean isCancelled(Subscription s) { - return s == CANCELLED; - } /** * Atomically sets the subscription on the field and cancels the diff --git a/src/main/java/io/reactivex/subscribers/ResourceSubscriber.java b/src/main/java/io/reactivex/subscribers/ResourceSubscriber.java index daa37a024b..220fafd191 100644 --- a/src/main/java/io/reactivex/subscribers/ResourceSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/ResourceSubscriber.java @@ -167,6 +167,6 @@ public final void dispose() { */ @Override public final boolean isDisposed() { - return SubscriptionHelper.isCancelled(upstream.get()); + return upstream.get() == SubscriptionHelper.CANCELLED; } } From 45c0d98105de88bbf73ced44b73acfc3761a6dd1 Mon Sep 17 00:00:00 2001 From: lorenzpahl Date: Mon, 29 Oct 2018 13:30:46 +0100 Subject: [PATCH 095/211] 2.x: Update Creating Observables docs (#6267) * Add "generate" section to the outline * Fix(image link broken) --- docs/Creating-Observables.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/Creating-Observables.md b/docs/Creating-Observables.md index 9e0c3b96cd..8e31a56528 100644 --- a/docs/Creating-Observables.md +++ b/docs/Creating-Observables.md @@ -7,6 +7,7 @@ This page shows methods that create reactive sources, such as `Observable`s. - [`empty`](#empty) - [`error`](#error) - [`from`](#from) +- [`generate`](#generate) - [`interval`](#interval) - [`just`](#just) - [`never`](#never) @@ -201,7 +202,7 @@ observable.subscribe( ## generate -**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` **ReactiveX documentation:** [http://reactivex.io/documentation/operators/create.html](http://reactivex.io/documentation/operators/create.html) From 76abb7beef3aa0b808cdbe193fd96ef04a5f0903 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 29 Oct 2018 18:17:12 +0100 Subject: [PATCH 096/211] 2.x: Call the doOn{Dispose|Cancel} handler at most once (#6269) --- src/main/java/io/reactivex/Observable.java | 2 +- .../observers/DisposableLambdaObserver.java | 18 ++++++++++------ .../flowable/FlowableDoOnLifecycle.java | 16 ++++++++------ .../flowable/FlowableDoOnLifecycleTest.java | 2 +- .../flowable/FlowableDoOnUnsubscribeTest.java | 21 +++++++++++++++++++ .../observable/ObservableCacheTest.java | 2 +- .../ObservableDoOnUnsubscribeTest.java | 21 +++++++++++++++++++ .../observable/ObservableReplayTest.java | 4 ++-- 8 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index ef3c5ed450..89468cec2b 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -8046,7 +8046,7 @@ public final Observable doOnError(Consumer onError) { /** * Calls the appropriate onXXX method (shared between all Observer) for the lifecycle events of - * the sequence (subscription, disposal, requesting). + * the sequence (subscription, disposal). *

    * *

    diff --git a/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java b/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java index 7e3941e260..59d7fac2bc 100644 --- a/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java +++ b/src/main/java/io/reactivex/internal/observers/DisposableLambdaObserver.java @@ -61,6 +61,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (upstream != DisposableHelper.DISPOSED) { + upstream = DisposableHelper.DISPOSED; downstream.onError(t); } else { RxJavaPlugins.onError(t); @@ -70,19 +71,24 @@ public void onError(Throwable t) { @Override public void onComplete() { if (upstream != DisposableHelper.DISPOSED) { + upstream = DisposableHelper.DISPOSED; downstream.onComplete(); } } @Override public void dispose() { - try { - onDispose.run(); - } catch (Throwable e) { - Exceptions.throwIfFatal(e); - RxJavaPlugins.onError(e); + Disposable d = upstream; + if (d != DisposableHelper.DISPOSED) { + upstream = DisposableHelper.DISPOSED; + try { + onDispose.run(); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + RxJavaPlugins.onError(e); + } + d.dispose(); } - upstream.dispose(); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycle.java index f0d233881d..0c979d2918 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycle.java @@ -108,13 +108,17 @@ public void request(long n) { @Override public void cancel() { - try { - onCancel.run(); - } catch (Throwable e) { - Exceptions.throwIfFatal(e); - RxJavaPlugins.onError(e); + Subscription s = upstream; + if (s != SubscriptionHelper.CANCELLED) { + upstream = SubscriptionHelper.CANCELLED; + try { + onCancel.run(); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + RxJavaPlugins.onError(e); + } + s.cancel(); } - upstream.cancel(); } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java index 3d23930aaa..34578bbfee 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java @@ -87,7 +87,7 @@ public void run() throws Exception { ); assertEquals(1, calls[0]); - assertEquals(2, calls[1]); + assertEquals(1, calls[1]); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnUnsubscribeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnUnsubscribeTest.java index 2987102666..de1bd0d57a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnUnsubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnUnsubscribeTest.java @@ -24,6 +24,7 @@ import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.functions.*; +import io.reactivex.processors.BehaviorProcessor; import io.reactivex.subscribers.TestSubscriber; public class FlowableDoOnUnsubscribeTest { @@ -148,4 +149,24 @@ public void run() { assertEquals("There should exactly 1 un-subscription events for upper stream", 1, upperCount.get()); assertEquals("There should exactly 1 un-subscription events for lower stream", 1, lowerCount.get()); } + + @Test + public void noReentrantDispose() { + + final AtomicInteger cancelCalled = new AtomicInteger(); + + final BehaviorProcessor p = BehaviorProcessor.create(); + p.doOnCancel(new Action() { + @Override + public void run() throws Exception { + cancelCalled.incrementAndGet(); + p.onNext(2); + } + }) + .firstOrError() + .subscribe() + .dispose(); + + assertEquals(1, cancelCalled.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java index 9629946ecb..e2aeb6a3f5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java @@ -113,7 +113,7 @@ public void testUnsubscribeSource() throws Exception { o.subscribe(); o.subscribe(); o.subscribe(); - verify(unsubscribe, times(1)).run(); + verify(unsubscribe, never()).run(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnUnsubscribeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnUnsubscribeTest.java index 9d2c84db3c..b7df811bac 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnUnsubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnUnsubscribeTest.java @@ -25,6 +25,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.functions.*; import io.reactivex.observers.TestObserver; +import io.reactivex.subjects.BehaviorSubject; public class ObservableDoOnUnsubscribeTest { @@ -152,4 +153,24 @@ public void run() { assertEquals("There should exactly 1 un-subscription events for upper stream", 1, upperCount.get()); assertEquals("There should exactly 1 un-subscription events for lower stream", 1, lowerCount.get()); } + + @Test + public void noReentrantDispose() { + + final AtomicInteger disposeCalled = new AtomicInteger(); + + final BehaviorSubject s = BehaviorSubject.create(); + s.doOnDispose(new Action() { + @Override + public void run() throws Exception { + disposeCalled.incrementAndGet(); + s.onNext(2); + } + }) + .firstOrError() + .subscribe() + .dispose(); + + assertEquals(1, disposeCalled.get()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java index 5b06f031a2..2592361cd6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java @@ -938,11 +938,11 @@ public void accept(String v) { @Test public void testUnsubscribeSource() throws Exception { Action unsubscribe = mock(Action.class); - Observable o = Observable.just(1).doOnDispose(unsubscribe).cache(); + Observable o = Observable.just(1).doOnDispose(unsubscribe).replay().autoConnect(); o.subscribe(); o.subscribe(); o.subscribe(); - verify(unsubscribe, times(1)).run(); + verify(unsubscribe, never()).run(); } @Test From feb6db71433893244de853bbe9f977c09e6840ef Mon Sep 17 00:00:00 2001 From: OH JAE HWAN Date: Tue, 30 Oct 2018 23:44:24 +0900 Subject: [PATCH 097/211] Fix broken markdown (#6273) --- docs/How-to-Contribute.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/How-to-Contribute.md b/docs/How-to-Contribute.md index 1b63812764..d7c4a3ceb7 100644 --- a/docs/How-to-Contribute.md +++ b/docs/How-to-Contribute.md @@ -1,18 +1,18 @@ -RxJava is still a work in progress and has a long list of work documented in the [[Issues|https://github.com/ReactiveX/RxJava/issues]]. +RxJava is still a work in progress and has a long list of work documented in the [Issues](https://github.com/ReactiveX/RxJava/issues). If you wish to contribute we would ask that you: -- read [[Rx Design Guidelines|http://blogs.msdn.com/b/rxteam/archive/2010/10/28/rx-design-guidelines.aspx]] +- read [Rx Design Guidelines](http://blogs.msdn.com/b/rxteam/archive/2010/10/28/rx-design-guidelines.aspx) - review existing code and comply with existing patterns and idioms - include unit tests - stick to Rx contracts as defined by the Rx.Net implementation when porting operators (each issue attempts to reference the correct documentation from MSDN) -Information about licensing can be found at: [[CONTRIBUTING|https://github.com/ReactiveX/RxJava/blob/1.x/CONTRIBUTING.md]]. +Information about licensing can be found at: [CONTRIBUTING](https://github.com/ReactiveX/RxJava/blob/2.x/CONTRIBUTING.md). ## How to import the project into Eclipse Two options below: -###Import as Eclipse project +### Import as Eclipse project ./gradlew eclipse @@ -23,7 +23,7 @@ In Eclipse * Right click on the project in Package Explorer, select Properties - Java Compiler - Errors/Warnings - click Enable project specific settings. * Still in Errors/Warnings, go to Deprecated and restricted API and set Forbidden reference (access-rules) to Warning. -###Import as Gradle project +### Import as Gradle project You need the Gradle plugin for Eclipse installed. From fba8b61b08f3f11e588ed2e7f7b3c183eb71eab8 Mon Sep 17 00:00:00 2001 From: lorenzpahl Date: Tue, 30 Oct 2018 16:20:47 +0100 Subject: [PATCH 098/211] 2.x: Update Error Handling Operators docs (#6266) * Change document structure; update operator list * Add examples * Clarify which handler is invoked * Use consistent wording in the descriptions * Cleanup --- docs/Error-Handling-Operators.md | 284 ++++++++++++++++++++++++++++++- 1 file changed, 277 insertions(+), 7 deletions(-) diff --git a/docs/Error-Handling-Operators.md b/docs/Error-Handling-Operators.md index 8acae59787..0b2eace61f 100644 --- a/docs/Error-Handling-Operators.md +++ b/docs/Error-Handling-Operators.md @@ -1,14 +1,284 @@ -There are a variety of operators that you can use to react to or recover from `onError` notifications from Observables. For example, you might: +There are a variety of operators that you can use to react to or recover from `onError` notifications from reactive sources, such as `Observable`s. For example, you might: 1. swallow the error and switch over to a backup Observable to continue the sequence 1. swallow the error and emit a default item 1. swallow the error and immediately try to restart the failed Observable 1. swallow the error and try to restart the failed Observable after some back-off interval -The following pages explain these operators. +# Outline -* [**`onErrorResumeNext( )`**](http://reactivex.io/documentation/operators/catch.html) — instructs an Observable to emit a sequence of items if it encounters an error -* [**`onErrorReturn( )`**](http://reactivex.io/documentation/operators/catch.html) — instructs an Observable to emit a particular item when it encounters an error -* [**`onExceptionResumeNext( )`**](http://reactivex.io/documentation/operators/catch.html) — instructs an Observable to continue emitting items after it encounters an exception (but not another variety of throwable) -* [**`retry( )`**](http://reactivex.io/documentation/operators/retry.html) — if a source Observable emits an error, resubscribe to it in the hopes that it will complete without error -* [**`retryWhen( )`**](http://reactivex.io/documentation/operators/retry.html) — if a source Observable emits an error, pass that error to another Observable to determine whether to resubscribe to the source \ No newline at end of file +- [`doOnError`](#doonerror) +- [`onErrorComplete`](#onerrorcomplete) +- [`onErrorResumeNext`](#onerrorresumenext) +- [`onErrorReturn`](#onerrorreturn) +- [`onErrorReturnItem`](#onerrorreturnitem) +- [`onExceptionResumeNext`](#onexceptionresumenext) +- [`retry`](#retry) +- [`retryUntil`](#retryuntil) +- [`retryWhen`](#retrywhen) + +## doOnError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/do.html](http://reactivex.io/documentation/operators/do.html) + +Instructs a reactive type to invoke the given `io.reactivex.functions.Consumer` when it encounters an error. + +### doOnError example + +```java +Observable.error(new IOException("Something went wrong")) + .doOnError(error -> System.err.println("The error message is: " + error.getMessage())) + .subscribe( + x -> System.out.println("onNext should never be printed!"), + Throwable::printStackTrace, + () -> System.out.println("onComplete should never be printed!")); +``` + +## onErrorComplete + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/catch.html](http://reactivex.io/documentation/operators/catch.html) + +Instructs a reactive type to swallow an error event and replace it by a completion event. + +Optionally, a `io.reactivex.functions.Predicate` can be specified that gives more control over when an error event should be replaced by a completion event, and when not. + +### onErrorComplete example + +```java +Completable.fromAction(() -> { + throw new IOException(); +}).onErrorComplete(error -> { + // Only ignore errors of type java.io.IOException. + return error instanceof IOException; +}).subscribe( + () -> System.out.println("IOException was ignored"), + error -> System.err.println("onError should not be printed!")); +``` + +## onErrorResumeNext + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/catch.html](http://reactivex.io/documentation/operators/catch.html) + +Instructs a reactive type to emit a sequence of items if it encounters an error. + +### onErrorResumeNext example + +```java + Observable numbers = Observable.generate(() -> 1, (state, emitter) -> { + emitter.onNext(state); + + return state + 1; +}); + +numbers.scan(Math::multiplyExact) + .onErrorResumeNext(Observable.empty()) + .subscribe( + System.out::println, + error -> System.err.println("onError should not be printed!")); + +// prints: +// 1 +// 2 +// 6 +// 24 +// 120 +// 720 +// 5040 +// 40320 +// 362880 +// 3628800 +// 39916800 +// 479001600 +``` + +## onErrorReturn + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/catch.html](http://reactivex.io/documentation/operators/catch.html) + +Instructs a reactive type to emit the item returned by the specified `io.reactivex.functions.Function` when it encounters an error. + +### onErrorReturn example + +```java +Single.just("2A") + .map(v -> Integer.parseInt(v, 10)) + .onErrorReturn(error -> { + if (error instanceof NumberFormatException) return 0; + else throw new IllegalArgumentException(); + }) + .subscribe( + System.out::println, + error -> System.err.println("onError should not be printed!")); + +// prints 0 +``` + +## onErrorReturnItem + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/catch.html](http://reactivex.io/documentation/operators/catch.html) + +Instructs a reactive type to emit a particular item when it encounters an error. + +### onErrorReturnItem example + +```java +Single.just("2A") + .map(v -> Integer.parseInt(v, 10)) + .onErrorReturnItem(0) + .subscribe( + System.out::println, + error -> System.err.println("onError should not be printed!")); + +// prints 0 +``` + +## onExceptionResumeNext + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/catch.html](http://reactivex.io/documentation/operators/catch.html) + +Instructs a reactive type to continue emitting items after it encounters an `java.lang.Exception`. Unlike [`onErrorResumeNext`](#onerrorresumenext), this one lets other types of `Throwable` continue through. + +### onExceptionResumeNext example + +```java +Observable exception = Observable.error(IOException::new) + .onExceptionResumeNext(Observable.just("This value will be used to recover from the IOException")); + +Observable error = Observable.error(Error::new) + .onExceptionResumeNext(Observable.just("This value will not be used")); + +Observable.concat(exception, error) + .subscribe( + message -> System.out.println("onNext: " + message), + err -> System.err.println("onError: " + err)); + +// prints: +// onNext: This value will be used to recover from the IOException +// onError: java.lang.Error +``` + +## retry + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/retry.html](http://reactivex.io/documentation/operators/retry.html) + +Instructs a reactive type to resubscribe to the source reactive type if it encounters an error in the hopes that it will complete without error. + +### retry example + +```java +Observable source = Observable.interval(0, 1, TimeUnit.SECONDS) + .flatMap(x -> { + if (x >= 2) return Observable.error(new IOException("Something went wrong!")); + else return Observable.just(x); + }); + +source.retry((retryCount, error) -> retryCount < 3) + .blockingSubscribe( + x -> System.out.println("onNext: " + x), + error -> System.err.println("onError: " + error.getMessage())); + +// prints: +// onNext: 0 +// onNext: 1 +// onNext: 0 +// onNext: 1 +// onNext: 0 +// onNext: 1 +// onError: Something went wrong! +``` + +## retryUntil + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/retry.html](http://reactivex.io/documentation/operators/retry.html) + +Instructs a reactive type to resubscribe to the source reactive type if it encounters an error until the given `io.reactivex.functions.BooleanSupplier` returns `true`. + +### retryUntil example + +```java +LongAdder errorCounter = new LongAdder(); +Observable source = Observable.interval(0, 1, TimeUnit.SECONDS) + .flatMap(x -> { + if (x >= 2) return Observable.error(new IOException("Something went wrong!")); + else return Observable.just(x); + }) + .doOnError((error) -> errorCounter.increment()); + +source.retryUntil(() -> errorCounter.intValue() >= 3) + .blockingSubscribe( + x -> System.out.println("onNext: " + x), + error -> System.err.println("onError: " + error.getMessage())); + +// prints: +// onNext: 0 +// onNext: 1 +// onNext: 0 +// onNext: 1 +// onNext: 0 +// onNext: 1 +// onError: Something went wrong! +``` + +## retryWhen + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/retry.html](http://reactivex.io/documentation/operators/retry.html) + +Instructs a reactive type to pass any error to another `Observable` or `Flowable` to determine whether to resubscribe to the source. + +### retryWhen example + +```java +Observable source = Observable.interval(0, 1, TimeUnit.SECONDS) + .flatMap(x -> { + if (x >= 2) return Observable.error(new IOException("Something went wrong!")); + else return Observable.just(x); + }); + +source.retryWhen(errors -> { + return errors.map(error -> 1) + + // Count the number of errors. + .scan(Math::addExact) + + .doOnNext(errorCount -> System.out.println("No. of errors: " + errorCount)) + + // Limit the maximum number of retries. + .takeWhile(errorCount -> errorCount < 3) + + // Signal resubscribe event after some delay. + .flatMapSingle(errorCount -> Single.timer(errorCount, TimeUnit.SECONDS)); +}).blockingSubscribe( + x -> System.out.println("onNext: " + x), + Throwable::printStackTrace, + () -> System.out.println("onComplete")); + +// prints: +// onNext: 0 +// onNext: 1 +// No. of errors: 1 +// onNext: 0 +// onNext: 1 +// No. of errors: 2 +// onNext: 0 +// onNext: 1 +// No. of errors: 3 +// onComplete +``` From c3cfb5ac774a6e08e0d1fdd42dd8c483329f4f23 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 1 Nov 2018 07:31:31 +0100 Subject: [PATCH 099/211] 2.x: Improve the Observable/Flowable cache() operators (#6275) * 2.x: Improve the Observable/Flowable cache() operators * Remove unnecessary casting. * Remove another unnecessary cast. --- src/main/java/io/reactivex/Observable.java | 5 +- .../operators/flowable/FlowableCache.java | 567 +++++++++--------- .../operators/observable/ObservableCache.java | 558 ++++++++--------- .../operators/flowable/FlowableCacheTest.java | 2 +- .../flowable/FlowableReplayTest.java | 4 +- .../observable/ObservableCacheTest.java | 27 +- 6 files changed, 615 insertions(+), 548 deletions(-) diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 89468cec2b..c80e8be95d 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -6164,7 +6164,7 @@ public final > Observable buffer(Callable< @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable cache() { - return ObservableCache.from(this); + return cacheWithInitialCapacity(16); } /** @@ -6222,7 +6222,8 @@ public final Observable cache() { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable cacheWithInitialCapacity(int initialCapacity) { - return ObservableCache.from(this, initialCapacity); + ObjectHelper.verifyPositive(initialCapacity, "initialCapacity"); + return RxJavaPlugins.onAssembly(new ObservableCache(this, initialCapacity)); } /** diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java index db4ccecfa1..830b0984ac 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java @@ -19,7 +19,7 @@ import io.reactivex.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; +import io.reactivex.internal.util.BackpressureHelper; import io.reactivex.plugins.RxJavaPlugins; /** @@ -28,45 +28,93 @@ * * @param the source element type */ -public final class FlowableCache extends AbstractFlowableWithUpstream { - /** The cache and replay state. */ - final CacheState state; +public final class FlowableCache extends AbstractFlowableWithUpstream +implements FlowableSubscriber { + /** + * The subscription to the source should happen at most once. + */ final AtomicBoolean once; /** - * Private constructor because state needs to be shared between the Observable body and - * the onSubscribe function. - * @param source the upstream source whose signals to cache - * @param capacityHint the capacity hint + * The number of items per cached nodes. + */ + final int capacityHint; + + /** + * The current known array of subscriber state to notify. + */ + final AtomicReference[]> subscribers; + + /** + * A shared instance of an empty array of subscribers to avoid creating + * a new empty array when all subscribers cancel. + */ + @SuppressWarnings("rawtypes") + static final CacheSubscription[] EMPTY = new CacheSubscription[0]; + /** + * A shared instance indicating the source has no more events and there + * is no need to remember subscribers anymore. + */ + @SuppressWarnings("rawtypes") + static final CacheSubscription[] TERMINATED = new CacheSubscription[0]; + + /** + * The total number of elements in the list available for reads. + */ + volatile long size; + + /** + * The starting point of the cached items. */ + final Node head; + + /** + * The current tail of the linked structure holding the items. + */ + Node tail; + + /** + * How many items have been put into the tail node so far. + */ + int tailOffset; + + /** + * If {@link #subscribers} is {@link #TERMINATED}, this holds the terminal error if not null. + */ + Throwable error; + + /** + * True if the source has terminated. + */ + volatile boolean done; + + /** + * Constructs an empty, non-connected cache. + * @param source the source to subscribe to for the first incoming subscriber + * @param capacityHint the number of items expected (reduce allocation frequency) + */ + @SuppressWarnings("unchecked") public FlowableCache(Flowable source, int capacityHint) { super(source); - this.state = new CacheState(source, capacityHint); + this.capacityHint = capacityHint; this.once = new AtomicBoolean(); + Node n = new Node(capacityHint); + this.head = n; + this.tail = n; + this.subscribers = new AtomicReference[]>(EMPTY); } @Override protected void subscribeActual(Subscriber t) { - // we can connect first because we replay everything anyway - ReplaySubscription rp = new ReplaySubscription(t, state); - t.onSubscribe(rp); - - boolean doReplay = true; - if (state.addChild(rp)) { - if (rp.requested.get() == ReplaySubscription.CANCELLED) { - state.removeChild(rp); - doReplay = false; - } - } + CacheSubscription consumer = new CacheSubscription(t, this); + t.onSubscribe(consumer); + add(consumer); - // we ensure a single connection here to save an instance field of AtomicBoolean in state. if (!once.get() && once.compareAndSet(false, true)) { - state.connect(); - } - - if (doReplay) { - rp.replay(); + source.subscribe(this); + } else { + replay(consumer); } } @@ -75,7 +123,7 @@ protected void subscribeActual(Subscriber t) { * @return true if already connected */ /* public */boolean isConnected() { - return state.isConnected; + return once.get(); } /** @@ -83,208 +131,248 @@ protected void subscribeActual(Subscriber t) { * @return true if the cache has Subscribers */ /* public */ boolean hasSubscribers() { - return state.subscribers.get().length != 0; + return subscribers.get().length != 0; } /** * Returns the number of events currently cached. * @return the number of currently cached event count */ - /* public */ int cachedEventCount() { - return state.size(); + /* public */ long cachedEventCount() { + return size; } /** - * Contains the active child subscribers and the values to replay. - * - * @param the value type of the cached items + * Atomically adds the consumer to the {@link #subscribers} copy-on-write array + * if the source has not yet terminated. + * @param consumer the consumer to add */ - static final class CacheState extends LinkedArrayList implements FlowableSubscriber { - /** The source observable to connect to. */ - final Flowable source; - /** Holds onto the subscriber connected to source. */ - final AtomicReference connection = new AtomicReference(); - /** Guarded by connection (not this). */ - final AtomicReference[]> subscribers; - /** The default empty array of subscribers. */ - @SuppressWarnings("rawtypes") - static final ReplaySubscription[] EMPTY = new ReplaySubscription[0]; - /** The default empty array of subscribers. */ - @SuppressWarnings("rawtypes") - static final ReplaySubscription[] TERMINATED = new ReplaySubscription[0]; - - /** Set to true after connection. */ - volatile boolean isConnected; - /** - * Indicates that the source has completed emitting values or the - * Observable was forcefully terminated. - */ - boolean sourceDone; + void add(CacheSubscription consumer) { + for (;;) { + CacheSubscription[] current = subscribers.get(); + if (current == TERMINATED) { + return; + } + int n = current.length; - @SuppressWarnings("unchecked") - CacheState(Flowable source, int capacityHint) { - super(capacityHint); - this.source = source; - this.subscribers = new AtomicReference[]>(EMPTY); + @SuppressWarnings("unchecked") + CacheSubscription[] next = new CacheSubscription[n + 1]; + System.arraycopy(current, 0, next, 0, n); + next[n] = consumer; + + if (subscribers.compareAndSet(current, next)) { + return; + } } - /** - * Adds a ReplaySubscription to the subscribers array atomically. - * @param p the target ReplaySubscription wrapping a downstream Subscriber with state - * @return true if the ReplaySubscription was added or false if the cache is already terminated - */ - public boolean addChild(ReplaySubscription p) { - // guarding by connection to save on allocating another object - // thus there are two distinct locks guarding the value-addition and child come-and-go - for (;;) { - ReplaySubscription[] a = subscribers.get(); - if (a == TERMINATED) { - return false; - } - int n = a.length; - @SuppressWarnings("unchecked") - ReplaySubscription[] b = new ReplaySubscription[n + 1]; - System.arraycopy(a, 0, b, 0, n); - b[n] = p; - if (subscribers.compareAndSet(a, b)) { - return true; + } + + /** + * Atomically removes the consumer from the {@link #subscribers} copy-on-write array. + * @param consumer the consumer to remove + */ + @SuppressWarnings("unchecked") + void remove(CacheSubscription consumer) { + for (;;) { + CacheSubscription[] current = subscribers.get(); + int n = current.length; + if (n == 0) { + return; + } + + int j = -1; + for (int i = 0; i < n; i++) { + if (current[i] == consumer) { + j = i; + break; } } + + if (j < 0) { + return; + } + CacheSubscription[] next; + + if (n == 1) { + next = EMPTY; + } else { + next = new CacheSubscription[n - 1]; + System.arraycopy(current, 0, next, 0, j); + System.arraycopy(current, j + 1, next, j, n - j - 1); + } + + if (subscribers.compareAndSet(current, next)) { + return; + } + } + } + + /** + * Replays the contents of this cache to the given consumer based on its + * current state and number of items requested by it. + * @param consumer the consumer to continue replaying items to + */ + void replay(CacheSubscription consumer) { + // make sure there is only one replay going on at a time + if (consumer.getAndIncrement() != 0) { + return; } - /** - * Removes the ReplaySubscription (if present) from the subscribers array atomically. - * @param p the target ReplaySubscription wrapping a downstream Subscriber with state - */ - @SuppressWarnings("unchecked") - public void removeChild(ReplaySubscription p) { - for (;;) { - ReplaySubscription[] a = subscribers.get(); - int n = a.length; - if (n == 0) { - return; - } - int j = -1; - for (int i = 0; i < n; i++) { - if (a[i].equals(p)) { - j = i; - break; - } - } - if (j < 0) { - return; - } - ReplaySubscription[] b; - if (n == 1) { - b = EMPTY; + // see if there were more replay request in the meantime + int missed = 1; + // read out state into locals upfront to avoid being re-read due to volatile reads + long index = consumer.index; + int offset = consumer.offset; + Node node = consumer.node; + AtomicLong requested = consumer.requested; + Subscriber downstream = consumer.downstream; + int capacity = capacityHint; + + for (;;) { + // first see if the source has terminated, read order matters! + boolean sourceDone = done; + // and if the number of items is the same as this consumer has received + boolean empty = size == index; + + // if the source is done and we have all items so far, terminate the consumer + if (sourceDone && empty) { + // release the node object to avoid leaks through retained consumers + consumer.node = null; + // if error is not null then the source failed + Throwable ex = error; + if (ex != null) { + downstream.onError(ex); } else { - b = new ReplaySubscription[n - 1]; - System.arraycopy(a, 0, b, 0, j); - System.arraycopy(a, j + 1, b, j, n - j - 1); + downstream.onComplete(); } - if (subscribers.compareAndSet(a, b)) { + return; + } + + // there are still items not sent to the consumer + if (!empty) { + // see how many items the consumer has requested in total so far + long consumerRequested = requested.get(); + // MIN_VALUE indicates a cancelled consumer, we stop replaying + if (consumerRequested == Long.MIN_VALUE) { + // release the node object to avoid leaks through retained consumers + consumer.node = null; return; } - } - } + // if the consumer has requested more and there is more, we will emit an item + if (consumerRequested != index) { + + // if the offset in the current node has reached the node capacity + if (offset == capacity) { + // switch to the subsequent node + node = node.next; + // reset the in-node offset + offset = 0; + } - @Override - public void onSubscribe(Subscription s) { - SubscriptionHelper.setOnce(connection, s, Long.MAX_VALUE); - } + // emit the cached item + downstream.onNext(node.values[offset]); - /** - * Connects the cache to the source. - * Make sure this is called only once. - */ - public void connect() { - source.subscribe(this); - isConnected = true; - } + // move the node offset forward + offset++; + // move the total consumed item count forward + index++; - @Override - public void onNext(T t) { - if (!sourceDone) { - Object o = NotificationLite.next(t); - add(o); - for (ReplaySubscription rp : subscribers.get()) { - rp.replay(); + // retry for the next item/terminal event if any + continue; } } - } - @SuppressWarnings("unchecked") - @Override - public void onError(Throwable e) { - if (!sourceDone) { - sourceDone = true; - Object o = NotificationLite.error(e); - add(o); - SubscriptionHelper.cancel(connection); - for (ReplaySubscription rp : subscribers.getAndSet(TERMINATED)) { - rp.replay(); - } - } else { - RxJavaPlugins.onError(e); + // commit the changed references back + consumer.index = index; + consumer.offset = offset; + consumer.node = node; + // release the changes and see if there were more replay request in the meantime + missed = consumer.addAndGet(-missed); + if (missed == 0) { + break; } } + } - @SuppressWarnings("unchecked") - @Override - public void onComplete() { - if (!sourceDone) { - sourceDone = true; - Object o = NotificationLite.complete(); - add(o); - SubscriptionHelper.cancel(connection); - for (ReplaySubscription rp : subscribers.getAndSet(TERMINATED)) { - rp.replay(); - } - } + @Override + public void onSubscribe(Subscription s) { + s.request(Long.MAX_VALUE); + } + + @Override + public void onNext(T t) { + int tailOffset = this.tailOffset; + // if the current tail node is full, create a fresh node + if (tailOffset == capacityHint) { + Node n = new Node(tailOffset); + n.values[0] = t; + this.tailOffset = 1; + tail.next = n; + tail = n; + } else { + tail.values[tailOffset] = t; + this.tailOffset = tailOffset + 1; + } + size++; + for (CacheSubscription consumer : subscribers.get()) { + replay(consumer); + } + } + + @SuppressWarnings("unchecked") + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + error = t; + done = true; + for (CacheSubscription consumer : subscribers.getAndSet(TERMINATED)) { + replay(consumer); + } + } + + @SuppressWarnings("unchecked") + @Override + public void onComplete() { + done = true; + for (CacheSubscription consumer : subscribers.getAndSet(TERMINATED)) { + replay(consumer); } } /** - * Keeps track of the current request amount and the replay position for a child Subscriber. - * - * @param + * Hosts the downstream consumer and its current requested and replay states. + * {@code this} holds the work-in-progress counter for the serialized replay. + * @param the value type */ - static final class ReplaySubscription - extends AtomicInteger implements Subscription { + static final class CacheSubscription extends AtomicInteger + implements Subscription { - private static final long serialVersionUID = -2557562030197141021L; - private static final long CANCELLED = Long.MIN_VALUE; - /** The actual child subscriber. */ - final Subscriber child; - /** The cache state object. */ - final CacheState state; + private static final long serialVersionUID = 6770240836423125754L; + + final Subscriber downstream; + + final FlowableCache parent; - /** - * Number of items requested and also the cancelled indicator if - * it contains {@link #CANCELLED}. - */ final AtomicLong requested; - /** - * Contains the reference to the buffer segment in replay. - * Accessed after reading state.size() and when emitting == true. - */ - Object[] currentBuffer; - /** - * Contains the index into the currentBuffer where the next value is expected. - * Accessed after reading state.size() and when emitting == true. - */ - int currentIndexInBuffer; - /** - * Contains the absolute index up until the values have been replayed so far. - */ - int index; + Node node; - /** Number of items emitted so far. */ - long emitted; + int offset; - ReplaySubscription(Subscriber child, CacheState state) { - this.child = child; - this.state = state; + long index; + + /** + * Constructs a new instance with the actual downstream consumer and + * the parent cache object. + * @param downstream the actual consumer + * @param parent the parent that holds onto the cached items + */ + CacheSubscription(Subscriber downstream, FlowableCache parent) { + this.downstream = downstream; + this.parent = parent; + this.node = parent.head; this.requested = new AtomicLong(); } @@ -292,99 +380,38 @@ static final class ReplaySubscription public void request(long n) { if (SubscriptionHelper.validate(n)) { BackpressureHelper.addCancel(requested, n); - replay(); + parent.replay(this); } } @Override public void cancel() { - if (requested.getAndSet(CANCELLED) != CANCELLED) { - state.removeChild(this); + if (requested.getAndSet(Long.MIN_VALUE) != Long.MIN_VALUE) { + parent.remove(this); } } + } + + /** + * Represents a segment of the cached item list as + * part of a linked-node-list structure. + * @param the element type + */ + static final class Node { /** - * Continue replaying available values if there are requests for them. + * The array of values held by this node. */ - public void replay() { - if (getAndIncrement() != 0) { - return; - } - - int missed = 1; - final Subscriber child = this.child; - AtomicLong rq = requested; - long e = emitted; - - for (;;) { + final T[] values; - long r = rq.get(); - - if (r == CANCELLED) { - return; - } - - // read the size, if it is non-zero, we can safely read the head and - // read values up to the given absolute index - int s = state.size(); - if (s != 0) { - Object[] b = currentBuffer; - - // latch onto the very first buffer now that it is available. - if (b == null) { - b = state.head(); - currentBuffer = b; - } - final int n = b.length - 1; - int j = index; - int k = currentIndexInBuffer; - - while (j < s && e != r) { - if (rq.get() == CANCELLED) { - return; - } - if (k == n) { - b = (Object[])b[n]; - k = 0; - } - Object o = b[k]; - - if (NotificationLite.accept(o, child)) { - return; - } - - k++; - j++; - e++; - } - - if (rq.get() == CANCELLED) { - return; - } - - if (r == e) { - Object o = b[k]; - if (NotificationLite.isComplete(o)) { - child.onComplete(); - return; - } else - if (NotificationLite.isError(o)) { - child.onError(NotificationLite.getError(o)); - return; - } - } - - index = j; - currentIndexInBuffer = k; - currentBuffer = b; - } + /** + * The next node if not null. + */ + volatile Node next; - emitted = e; - missed = addAndGet(-missed); - if (missed == 0) { - break; - } - } + @SuppressWarnings("unchecked") + Node(int capacityHint) { + this.values = (T[])new Object[capacityHint]; } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java index 3bfe796efc..fdc3477b75 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCache.java @@ -17,10 +17,6 @@ import io.reactivex.*; import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.SequentialDisposable; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; /** * An observable which auto-connects to another observable, caches the elements @@ -28,61 +24,94 @@ * * @param the source element type */ -public final class ObservableCache extends AbstractObservableWithUpstream { - /** The cache and replay state. */ - final CacheState state; +public final class ObservableCache extends AbstractObservableWithUpstream +implements Observer { + /** + * The subscription to the source should happen at most once. + */ final AtomicBoolean once; /** - * Creates a cached Observable with a default capacity hint of 16. - * @param the value type - * @param source the source Observable to cache - * @return the CachedObservable instance + * The number of items per cached nodes. */ - public static Observable from(Observable source) { - return from(source, 16); - } + final int capacityHint; /** - * Creates a cached Observable with the given capacity hint. - * @param the value type - * @param source the source Observable to cache - * @param capacityHint the hint for the internal buffer size - * @return the CachedObservable instance + * The current known array of observer state to notify. */ - public static Observable from(Observable source, int capacityHint) { - ObjectHelper.verifyPositive(capacityHint, "capacityHint"); - CacheState state = new CacheState(source, capacityHint); - return RxJavaPlugins.onAssembly(new ObservableCache(source, state)); - } + final AtomicReference[]> observers; + + /** + * A shared instance of an empty array of observers to avoid creating + * a new empty array when all observers dispose. + */ + @SuppressWarnings("rawtypes") + static final CacheDisposable[] EMPTY = new CacheDisposable[0]; + /** + * A shared instance indicating the source has no more events and there + * is no need to remember observers anymore. + */ + @SuppressWarnings("rawtypes") + static final CacheDisposable[] TERMINATED = new CacheDisposable[0]; + + /** + * The total number of elements in the list available for reads. + */ + volatile long size; + + /** + * The starting point of the cached items. + */ + final Node head; + + /** + * The current tail of the linked structure holding the items. + */ + Node tail; + + /** + * How many items have been put into the tail node so far. + */ + int tailOffset; + + /** + * If {@link #observers} is {@link #TERMINATED}, this holds the terminal error if not null. + */ + Throwable error; + + /** + * True if the source has terminated. + */ + volatile boolean done; /** - * Private constructor because state needs to be shared between the Observable body and - * the onSubscribe function. - * @param source the source Observable to cache - * @param state the cache state object + * Constructs an empty, non-connected cache. + * @param source the source to subscribe to for the first incoming observer + * @param capacityHint the number of items expected (reduce allocation frequency) */ - private ObservableCache(Observable source, CacheState state) { + @SuppressWarnings("unchecked") + public ObservableCache(Observable source, int capacityHint) { super(source); - this.state = state; + this.capacityHint = capacityHint; this.once = new AtomicBoolean(); + Node n = new Node(capacityHint); + this.head = n; + this.tail = n; + this.observers = new AtomicReference[]>(EMPTY); } @Override protected void subscribeActual(Observer t) { - // we can connect first because we replay everything anyway - ReplayDisposable rp = new ReplayDisposable(t, state); - t.onSubscribe(rp); - - state.addChild(rp); + CacheDisposable consumer = new CacheDisposable(t, this); + t.onSubscribe(consumer); + add(consumer); - // we ensure a single connection here to save an instance field of AtomicBoolean in state. if (!once.get() && once.compareAndSet(false, true)) { - state.connect(); + source.subscribe(this); + } else { + replay(consumer); } - - rp.replay(); } /** @@ -90,290 +119,281 @@ protected void subscribeActual(Observer t) { * @return true if already connected */ /* public */boolean isConnected() { - return state.isConnected; + return once.get(); } /** * Returns true if there are observers subscribed to this observable. - * @return true if the cache has downstream Observers + * @return true if the cache has observers */ /* public */ boolean hasObservers() { - return state.observers.get().length != 0; + return observers.get().length != 0; } /** * Returns the number of events currently cached. - * @return the current number of elements in the cache + * @return the number of currently cached event count */ - /* public */ int cachedEventCount() { - return state.size(); + /* public */ long cachedEventCount() { + return size; } /** - * Contains the active child observers and the values to replay. - * - * @param + * Atomically adds the consumer to the {@link #observers} copy-on-write array + * if the source has not yet terminated. + * @param consumer the consumer to add */ - static final class CacheState extends LinkedArrayList implements Observer { - /** The source observable to connect to. */ - final Observable source; - /** Holds onto the subscriber connected to source. */ - final SequentialDisposable connection; - /** Guarded by connection (not this). */ - final AtomicReference[]> observers; - /** The default empty array of observers. */ - @SuppressWarnings("rawtypes") - static final ReplayDisposable[] EMPTY = new ReplayDisposable[0]; - /** The default empty array of observers. */ - @SuppressWarnings("rawtypes") - static final ReplayDisposable[] TERMINATED = new ReplayDisposable[0]; - - /** Set to true after connection. */ - volatile boolean isConnected; - /** - * Indicates that the source has completed emitting values or the - * Observable was forcefully terminated. - */ - boolean sourceDone; + void add(CacheDisposable consumer) { + for (;;) { + CacheDisposable[] current = observers.get(); + if (current == TERMINATED) { + return; + } + int n = current.length; - @SuppressWarnings("unchecked") - CacheState(Observable source, int capacityHint) { - super(capacityHint); - this.source = source; - this.observers = new AtomicReference[]>(EMPTY); - this.connection = new SequentialDisposable(); - } - /** - * Adds a ReplayDisposable to the observers array atomically. - * @param p the target ReplayDisposable wrapping a downstream Observer with additional state - * @return true if the disposable was added, false otherwise - */ - public boolean addChild(ReplayDisposable p) { - // guarding by connection to save on allocating another object - // thus there are two distinct locks guarding the value-addition and child come-and-go - for (;;) { - ReplayDisposable[] a = observers.get(); - if (a == TERMINATED) { - return false; - } - int n = a.length; - - @SuppressWarnings("unchecked") - ReplayDisposable[] b = new ReplayDisposable[n + 1]; - System.arraycopy(a, 0, b, 0, n); - b[n] = p; - if (observers.compareAndSet(a, b)) { - return true; - } + @SuppressWarnings("unchecked") + CacheDisposable[] next = new CacheDisposable[n + 1]; + System.arraycopy(current, 0, next, 0, n); + next[n] = consumer; + + if (observers.compareAndSet(current, next)) { + return; } } - /** - * Removes the ReplayDisposable (if present) from the observers array atomically. - * @param p the target ReplayDisposable wrapping a downstream Observer with additional state - */ - @SuppressWarnings("unchecked") - public void removeChild(ReplayDisposable p) { - for (;;) { - ReplayDisposable[] a = observers.get(); - int n = a.length; - if (n == 0) { - return; - } - int j = -1; - for (int i = 0; i < n; i++) { - if (a[i].equals(p)) { - j = i; - break; - } - } - if (j < 0) { - return; - } - ReplayDisposable[] b; - if (n == 1) { - b = EMPTY; - } else { - b = new ReplayDisposable[n - 1]; - System.arraycopy(a, 0, b, 0, j); - System.arraycopy(a, j + 1, b, j, n - j - 1); - } - if (observers.compareAndSet(a, b)) { - return; + } + + /** + * Atomically removes the consumer from the {@link #observers} copy-on-write array. + * @param consumer the consumer to remove + */ + @SuppressWarnings("unchecked") + void remove(CacheDisposable consumer) { + for (;;) { + CacheDisposable[] current = observers.get(); + int n = current.length; + if (n == 0) { + return; + } + + int j = -1; + for (int i = 0; i < n; i++) { + if (current[i] == consumer) { + j = i; + break; } } - } - @Override - public void onSubscribe(Disposable d) { - connection.update(d); + if (j < 0) { + return; + } + CacheDisposable[] next; + + if (n == 1) { + next = EMPTY; + } else { + next = new CacheDisposable[n - 1]; + System.arraycopy(current, 0, next, 0, j); + System.arraycopy(current, j + 1, next, j, n - j - 1); + } + + if (observers.compareAndSet(current, next)) { + return; + } } + } - /** - * Connects the cache to the source. - * Make sure this is called only once. - */ - public void connect() { - source.subscribe(this); - isConnected = true; + /** + * Replays the contents of this cache to the given consumer based on its + * current state and number of items requested by it. + * @param consumer the consumer to continue replaying items to + */ + void replay(CacheDisposable consumer) { + // make sure there is only one replay going on at a time + if (consumer.getAndIncrement() != 0) { + return; } - @Override - public void onNext(T t) { - if (!sourceDone) { - Object o = NotificationLite.next(t); - add(o); - for (ReplayDisposable rp : observers.get()) { - rp.replay(); - } + // see if there were more replay request in the meantime + int missed = 1; + // read out state into locals upfront to avoid being re-read due to volatile reads + long index = consumer.index; + int offset = consumer.offset; + Node node = consumer.node; + Observer downstream = consumer.downstream; + int capacity = capacityHint; + + for (;;) { + // if the consumer got disposed, clear the node and quit + if (consumer.disposed) { + consumer.node = null; + return; } - } - @SuppressWarnings("unchecked") - @Override - public void onError(Throwable e) { - if (!sourceDone) { - sourceDone = true; - Object o = NotificationLite.error(e); - add(o); - connection.dispose(); - for (ReplayDisposable rp : observers.getAndSet(TERMINATED)) { - rp.replay(); + // first see if the source has terminated, read order matters! + boolean sourceDone = done; + // and if the number of items is the same as this consumer has received + boolean empty = size == index; + + // if the source is done and we have all items so far, terminate the consumer + if (sourceDone && empty) { + // release the node object to avoid leaks through retained consumers + consumer.node = null; + // if error is not null then the source failed + Throwable ex = error; + if (ex != null) { + downstream.onError(ex); + } else { + downstream.onComplete(); } + return; } - } - @SuppressWarnings("unchecked") - @Override - public void onComplete() { - if (!sourceDone) { - sourceDone = true; - Object o = NotificationLite.complete(); - add(o); - connection.dispose(); - for (ReplayDisposable rp : observers.getAndSet(TERMINATED)) { - rp.replay(); + // there are still items not sent to the consumer + if (!empty) { + // if the offset in the current node has reached the node capacity + if (offset == capacity) { + // switch to the subsequent node + node = node.next; + // reset the in-node offset + offset = 0; } + + // emit the cached item + downstream.onNext(node.values[offset]); + + // move the node offset forward + offset++; + // move the total consumed item count forward + index++; + + // retry for the next item/terminal event if any + continue; + } + + // commit the changed references back + consumer.index = index; + consumer.offset = offset; + consumer.node = node; + // release the changes and see if there were more replay request in the meantime + missed = consumer.addAndGet(-missed); + if (missed == 0) { + break; } } } + @Override + public void onSubscribe(Disposable d) { + // we can't do much with the upstream disposable + } + + @Override + public void onNext(T t) { + int tailOffset = this.tailOffset; + // if the current tail node is full, create a fresh node + if (tailOffset == capacityHint) { + Node n = new Node(tailOffset); + n.values[0] = t; + this.tailOffset = 1; + tail.next = n; + tail = n; + } else { + tail.values[tailOffset] = t; + this.tailOffset = tailOffset + 1; + } + size++; + for (CacheDisposable consumer : observers.get()) { + replay(consumer); + } + } + + @SuppressWarnings("unchecked") + @Override + public void onError(Throwable t) { + error = t; + done = true; + for (CacheDisposable consumer : observers.getAndSet(TERMINATED)) { + replay(consumer); + } + } + + @SuppressWarnings("unchecked") + @Override + public void onComplete() { + done = true; + for (CacheDisposable consumer : observers.getAndSet(TERMINATED)) { + replay(consumer); + } + } + /** - * Keeps track of the current request amount and the replay position for a child Observer. - * - * @param + * Hosts the downstream consumer and its current requested and replay states. + * {@code this} holds the work-in-progress counter for the serialized replay. + * @param the value type */ - static final class ReplayDisposable - extends AtomicInteger + static final class CacheDisposable extends AtomicInteger implements Disposable { - private static final long serialVersionUID = 7058506693698832024L; - /** The actual child subscriber. */ - final Observer child; - /** The cache state object. */ - final CacheState state; + private static final long serialVersionUID = 6770240836423125754L; - /** - * Contains the reference to the buffer segment in replay. - * Accessed after reading state.size() and when emitting == true. - */ - Object[] currentBuffer; - /** - * Contains the index into the currentBuffer where the next value is expected. - * Accessed after reading state.size() and when emitting == true. - */ - int currentIndexInBuffer; - /** - * Contains the absolute index up until the values have been replayed so far. - */ - int index; + final Observer downstream; - /** Set if the ReplayDisposable has been cancelled/disposed. */ - volatile boolean cancelled; + final ObservableCache parent; - ReplayDisposable(Observer child, CacheState state) { - this.child = child; - this.state = state; - } + Node node; - @Override - public boolean isDisposed() { - return cancelled; + int offset; + + long index; + + volatile boolean disposed; + + /** + * Constructs a new instance with the actual downstream consumer and + * the parent cache object. + * @param downstream the actual consumer + * @param parent the parent that holds onto the cached items + */ + CacheDisposable(Observer downstream, ObservableCache parent) { + this.downstream = downstream; + this.parent = parent; + this.node = parent.head; } @Override public void dispose() { - if (!cancelled) { - cancelled = true; - state.removeChild(this); + if (!disposed) { + disposed = true; + parent.remove(this); } } - /** - * Continue replaying available values if there are requests for them. - */ - public void replay() { - // make sure there is only a single thread emitting - if (getAndIncrement() != 0) { - return; - } - - final Observer child = this.child; - int missed = 1; - - for (;;) { + @Override + public boolean isDisposed() { + return disposed; + } + } - if (cancelled) { - return; - } + /** + * Represents a segment of the cached item list as + * part of a linked-node-list structure. + * @param the element type + */ + static final class Node { - // read the size, if it is non-zero, we can safely read the head and - // read values up to the given absolute index - int s = state.size(); - if (s != 0) { - Object[] b = currentBuffer; - - // latch onto the very first buffer now that it is available. - if (b == null) { - b = state.head(); - currentBuffer = b; - } - final int n = b.length - 1; - int j = index; - int k = currentIndexInBuffer; - - while (j < s) { - if (cancelled) { - return; - } - if (k == n) { - b = (Object[])b[n]; - k = 0; - } - Object o = b[k]; - - if (NotificationLite.accept(o, child)) { - return; - } - - k++; - j++; - } - - if (cancelled) { - return; - } - - index = j; - currentIndexInBuffer = k; - currentBuffer = b; + /** + * The array of values held by this node. + */ + final T[] values; - } + /** + * The next node if not null. + */ + volatile Node next; - missed = addAndGet(-missed); - if (missed == 0) { - break; - } - } + @SuppressWarnings("unchecked") + Node(int capacityHint) { + this.values = (T[])new Object[capacityHint]; } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java index 6a427124bd..4208b18dec 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java @@ -139,7 +139,7 @@ public void testUnsubscribeSource() throws Exception { f.subscribe(); f.subscribe(); f.subscribe(); - verify(unsubscribe, times(1)).run(); + verify(unsubscribe, never()).run(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java index 0cc39b5c03..dcf7eea347 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java @@ -951,11 +951,11 @@ public void accept(String v) { @Test public void testUnsubscribeSource() throws Exception { Action unsubscribe = mock(Action.class); - Flowable f = Flowable.just(1).doOnCancel(unsubscribe).cache(); + Flowable f = Flowable.just(1).doOnCancel(unsubscribe).replay().autoConnect(); f.subscribe(); f.subscribe(); f.subscribe(); - verify(unsubscribe, times(1)).run(); + verify(unsubscribe, never()).run(); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java index e2aeb6a3f5..989206f156 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java @@ -35,7 +35,7 @@ public class ObservableCacheTest { @Test public void testColdReplayNoBackpressure() { - ObservableCache source = (ObservableCache)ObservableCache.from(Observable.range(0, 1000)); + ObservableCache source = new ObservableCache(Observable.range(0, 1000), 16); assertFalse("Source is connected!", source.isConnected()); @@ -120,7 +120,7 @@ public void testUnsubscribeSource() throws Exception { public void testTake() { TestObserver to = new TestObserver(); - ObservableCache cached = (ObservableCache)ObservableCache.from(Observable.range(1, 100)); + ObservableCache cached = new ObservableCache(Observable.range(1, 1000), 16); cached.take(10).subscribe(to); to.assertNoErrors(); @@ -136,7 +136,7 @@ public void testAsync() { for (int i = 0; i < 100; i++) { TestObserver to1 = new TestObserver(); - ObservableCache cached = (ObservableCache)ObservableCache.from(source); + ObservableCache cached = new ObservableCache(source, 16); cached.observeOn(Schedulers.computation()).subscribe(to1); @@ -160,7 +160,7 @@ public void testAsyncComeAndGo() { Observable source = Observable.interval(1, 1, TimeUnit.MILLISECONDS) .take(1000) .subscribeOn(Schedulers.io()); - ObservableCache cached = (ObservableCache)ObservableCache.from(source); + ObservableCache cached = new ObservableCache(source, 16); Observable output = cached.observeOn(Schedulers.computation()); @@ -351,4 +351,23 @@ public void run() { .assertSubscribed().assertValueCount(500).assertComplete().assertNoErrors(); } } + + @Test + public void cancelledUpFront() { + final AtomicInteger call = new AtomicInteger(); + Observable f = Observable.fromCallable(new Callable() { + @Override + public Object call() throws Exception { + return call.incrementAndGet(); + } + }).concatWith(Observable.never()) + .cache(); + + f.test().assertValuesOnly(1); + + f.test(true) + .assertEmpty(); + + assertEquals(1, call.get()); + } } From caefffa27e7c2e8d1a9f09bc51213f77ad5ae93e Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 2 Nov 2018 10:45:24 +0100 Subject: [PATCH 100/211] 2.x: Improve the package docs of i.r.schedulers (#6280) --- src/main/java/io/reactivex/schedulers/package-info.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/schedulers/package-info.java b/src/main/java/io/reactivex/schedulers/package-info.java index 431ca3e8e5..7ba9d63567 100644 --- a/src/main/java/io/reactivex/schedulers/package-info.java +++ b/src/main/java/io/reactivex/schedulers/package-info.java @@ -14,7 +14,9 @@ * limitations under the License. */ /** - * Scheduler implementations, value+time record class and the standard factory class to - * return standard RxJava schedulers or wrap any Executor-based (thread pool) instances. + * Contains notably the factory class of {@link io.reactivex.schedulers.Schedulers Schedulers} providing methods for + * retrieving the standard scheduler instances, the {@link io.reactivex.schedulers.TestScheduler TestScheduler} for testing flows + * with scheduling in a controlled manner and the class {@link io.reactivex.schedulers.Timed Timed} that can hold + * a value and a timestamp associated with it. */ package io.reactivex.schedulers; From 3281b027c7e46c1f0ab9ec7719b5029285920e37 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 5 Nov 2018 11:34:14 +0100 Subject: [PATCH 101/211] 2.x: Fix Observable.flatMap to sustain concurrency level (#6283) --- .../observable/ObservableFlatMap.java | 24 ++++++----- .../flowable/FlowableFlatMapTest.java | 40 +++++++++++++++++++ .../observable/ObservableFlatMapTest.java | 40 +++++++++++++++++++ 3 files changed, 93 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java index 551ceba280..a4766f389d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java @@ -376,7 +376,7 @@ void drainLoop() { return; } - boolean innerCompleted = false; + int innerCompleted = 0; if (n != 0) { long startId = lastId; int index = lastIndex; @@ -423,7 +423,7 @@ void drainLoop() { return; } removeInner(is); - innerCompleted = true; + innerCompleted++; j++; if (j == n) { j = 0; @@ -449,7 +449,7 @@ void drainLoop() { if (checkTerminate()) { return; } - innerCompleted = true; + innerCompleted++; } j++; @@ -461,17 +461,19 @@ void drainLoop() { lastId = inner[j].id; } - if (innerCompleted) { + if (innerCompleted != 0) { if (maxConcurrency != Integer.MAX_VALUE) { - ObservableSource p; - synchronized (this) { - p = sources.poll(); - if (p == null) { - wip--; - continue; + while (innerCompleted-- != 0) { + ObservableSource p; + synchronized (this) { + p = sources.poll(); + if (p == null) { + wip--; + continue; + } } + subscribeInner(p); } - subscribeInner(p); } continue; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java index bb525b2ddb..4c1441775b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java @@ -1084,4 +1084,44 @@ public void remove() { assertEquals(1, counter.get()); } + + @Test + public void maxConcurrencySustained() { + final PublishProcessor pp1 = PublishProcessor.create(); + final PublishProcessor pp2 = PublishProcessor.create(); + PublishProcessor pp3 = PublishProcessor.create(); + PublishProcessor pp4 = PublishProcessor.create(); + + TestSubscriber ts = Flowable.just(pp1, pp2, pp3, pp4) + .flatMap(new Function, Flowable>() { + @Override + public Flowable apply(PublishProcessor v) throws Exception { + return v; + } + }, 2) + .doOnNext(new Consumer() { + @Override + public void accept(Integer v) throws Exception { + if (v == 1) { + // this will make sure the drain loop detects two completed + // inner sources and replaces them with fresh ones + pp1.onComplete(); + pp2.onComplete(); + } + } + }) + .test(); + + pp1.onNext(1); + + assertFalse(pp1.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); + assertTrue(pp3.hasSubscribers()); + assertTrue(pp4.hasSubscribers()); + + ts.dispose(); + + assertFalse(pp3.hasSubscribers()); + assertFalse(pp4.hasSubscribers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index efee97f33a..960722060a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -1045,4 +1045,44 @@ public Integer apply(Integer v) to.assertValuesOnly(10, 11, 12, 13, 14, 20, 21, 22, 23, 24); } + + @Test + public void maxConcurrencySustained() { + final PublishSubject ps1 = PublishSubject.create(); + final PublishSubject ps2 = PublishSubject.create(); + PublishSubject ps3 = PublishSubject.create(); + PublishSubject ps4 = PublishSubject.create(); + + TestObserver to = Observable.just(ps1, ps2, ps3, ps4) + .flatMap(new Function, ObservableSource>() { + @Override + public ObservableSource apply(PublishSubject v) throws Exception { + return v; + } + }, 2) + .doOnNext(new Consumer() { + @Override + public void accept(Integer v) throws Exception { + if (v == 1) { + // this will make sure the drain loop detects two completed + // inner sources and replaces them with fresh ones + ps1.onComplete(); + ps2.onComplete(); + } + } + }) + .test(); + + ps1.onNext(1); + + assertFalse(ps1.hasObservers()); + assertFalse(ps2.hasObservers()); + assertTrue(ps3.hasObservers()); + assertTrue(ps4.hasObservers()); + + to.dispose(); + + assertFalse(ps3.hasObservers()); + assertFalse(ps4.hasObservers()); + } } From 64783120ef3ba616f03cd3d217310e0dfe788a65 Mon Sep 17 00:00:00 2001 From: pawellozinski Date: Mon, 5 Nov 2018 13:41:00 +0100 Subject: [PATCH 102/211] 2.x: Expose the Keep-Alive value of the IO Scheduler as System property. (#6279) (#6287) --- .../io/reactivex/internal/schedulers/IoScheduler.java | 9 ++++++++- src/main/java/io/reactivex/schedulers/Schedulers.java | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java b/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java index 423a47898f..d806321bf3 100644 --- a/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java @@ -34,7 +34,11 @@ public final class IoScheduler extends Scheduler { private static final String EVICTOR_THREAD_NAME_PREFIX = "RxCachedWorkerPoolEvictor"; static final RxThreadFactory EVICTOR_THREAD_FACTORY; - private static final long KEEP_ALIVE_TIME = 60; + /** The name of the system property for setting the keep-alive time (in seconds) for this Scheduler workers. */ + private static final String KEY_KEEP_ALIVE_TIME = "rx2.io-keep-alive-time"; + public static final long KEEP_ALIVE_TIME_DEFAULT = 60; + + private static final long KEEP_ALIVE_TIME; private static final TimeUnit KEEP_ALIVE_UNIT = TimeUnit.SECONDS; static final ThreadWorker SHUTDOWN_THREAD_WORKER; @@ -45,7 +49,10 @@ public final class IoScheduler extends Scheduler { private static final String KEY_IO_PRIORITY = "rx2.io-priority"; static final CachedWorkerPool NONE; + static { + KEEP_ALIVE_TIME = Long.getLong(KEY_KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_DEFAULT); + SHUTDOWN_THREAD_WORKER = new ThreadWorker(new RxThreadFactory("RxCachedThreadSchedulerShutdown")); SHUTDOWN_THREAD_WORKER.dispose(); diff --git a/src/main/java/io/reactivex/schedulers/Schedulers.java b/src/main/java/io/reactivex/schedulers/Schedulers.java index 1332a3a019..d3febba3ac 100644 --- a/src/main/java/io/reactivex/schedulers/Schedulers.java +++ b/src/main/java/io/reactivex/schedulers/Schedulers.java @@ -29,6 +29,7 @@ *

    * Supported system properties ({@code System.getProperty()}): *

      + *
    • {@code rx2.io-keep-alive-time} (long): sets the keep-alive time of the {@link #io()} Scheduler workers, default is {@link IoScheduler#KEEP_ALIVE_TIME_DEFAULT}
    • *
    • {@code rx2.io-priority} (int): sets the thread priority of the {@link #io()} Scheduler, default is {@link Thread#NORM_PRIORITY}
    • *
    • {@code rx2.computation-threads} (int): sets the number of threads in the {@link #computation()} Scheduler, default is the number of available CPUs
    • *
    • {@code rx2.computation-priority} (int): sets the thread priority of the {@link #computation()} Scheduler, default is {@link Thread#NORM_PRIORITY}
    • @@ -155,6 +156,7 @@ public static Scheduler computation() { * before the {@link Schedulers} class is referenced in your code. *

      Supported system properties ({@code System.getProperty()}): *

        + *
      • {@code rx2.io-keep-alive-time} (long): sets the keep-alive time of the {@link #io()} Scheduler workers, default is {@link IoScheduler#KEEP_ALIVE_TIME_DEFAULT}
      • *
      • {@code rx2.io-priority} (int): sets the thread priority of the {@link #io()} Scheduler, default is {@link Thread#NORM_PRIORITY}
      • *
      *

      From bc9d59441c189ede38b986ba9839017719126f37 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 6 Nov 2018 08:57:05 +0100 Subject: [PATCH 103/211] 2.x: Add materialize() and dematerialize() (#6278) * 2.x: Add materialize() and dematerialize() * Add remaining test cases * Correct dematerialize javadoc * Use dematerialize selector fix some docs --- src/main/java/io/reactivex/Completable.java | 23 +++- src/main/java/io/reactivex/Maybe.java | 20 ++++ src/main/java/io/reactivex/Single.java | 57 ++++++++++ .../completable/CompletableMaterialize.java | 40 +++++++ .../operators/maybe/MaybeMaterialize.java | 40 +++++++ .../mixed/MaterializeSingleObserver.java | 71 ++++++++++++ .../operators/single/SingleDematerialize.java | 105 +++++++++++++++++ .../operators/single/SingleMaterialize.java | 40 +++++++ .../CompletableMaterializeTest.java | 58 ++++++++++ .../operators/maybe/MaybeMaterializeTest.java | 67 +++++++++++ .../single/SingleDematerializeTest.java | 107 ++++++++++++++++++ .../single/SingleMaterializeTest.java | 58 ++++++++++ 12 files changed, 685 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/reactivex/internal/operators/completable/CompletableMaterialize.java create mode 100644 src/main/java/io/reactivex/internal/operators/maybe/MaybeMaterialize.java create mode 100644 src/main/java/io/reactivex/internal/operators/mixed/MaterializeSingleObserver.java create mode 100644 src/main/java/io/reactivex/internal/operators/single/SingleDematerialize.java create mode 100644 src/main/java/io/reactivex/internal/operators/single/SingleMaterialize.java create mode 100644 src/test/java/io/reactivex/internal/operators/completable/CompletableMaterializeTest.java create mode 100644 src/test/java/io/reactivex/internal/operators/maybe/MaybeMaterializeTest.java create mode 100644 src/test/java/io/reactivex/internal/operators/single/SingleDematerializeTest.java create mode 100644 src/test/java/io/reactivex/internal/operators/single/SingleMaterializeTest.java diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 486562b483..948d8aecde 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -26,7 +26,7 @@ import io.reactivex.internal.operators.completable.*; import io.reactivex.internal.operators.maybe.*; import io.reactivex.internal.operators.mixed.*; -import io.reactivex.internal.operators.single.SingleDelayWithCompletable; +import io.reactivex.internal.operators.single.*; import io.reactivex.internal.util.ExceptionHelper; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; @@ -1782,6 +1782,27 @@ public final Completable lift(final CompletableOperator onLift) { return RxJavaPlugins.onAssembly(new CompletableLift(this, onLift)); } + /** + * Maps the signal types of this Completable into a {@link Notification} of the same kind + * and emits it as a single success value to downstream. + *

      + * + *

      + *
      Scheduler:
      + *
      {@code materialize} does not operate by default on a particular {@link Scheduler}.
      + *
      + * @param the intended target element type of the notification + * @return the new Single instance + * @since 2.2.4 - experimental + * @see Single#dematerialize(Function) + */ + @Experimental + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + public final Single> materialize() { + return RxJavaPlugins.onAssembly(new CompletableMaterialize(this)); + } + /** * Returns a Completable which subscribes to this and the other Completable and completes * when both of them complete or one emits an error. diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 346d35e16a..b1d34260f1 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -3377,6 +3377,26 @@ public final Maybe map(Function mapper) { return RxJavaPlugins.onAssembly(new MaybeMap(this, mapper)); } + /** + * Maps the signal types of this Maybe into a {@link Notification} of the same kind + * and emits it as a single success value to downstream. + *

      + * + *

      + *
      Scheduler:
      + *
      {@code materialize} does not operate by default on a particular {@link Scheduler}.
      + *
      + * @return the new Single instance + * @since 2.2.4 - experimental + * @see Single#dematerialize(Function) + */ + @Experimental + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + public final Single> materialize() { + return RxJavaPlugins.onAssembly(new MaybeMaterialize(this)); + } + /** * Flattens this and another Maybe into a single Flowable, without any transformation. *

      diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 8d4013be66..168c9c216a 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -2302,6 +2302,43 @@ public final Single delaySubscription(long time, TimeUnit unit, Scheduler sch return delaySubscription(Observable.timer(time, unit, scheduler)); } + /** + * Maps the {@link Notification} success value of this Single back into normal + * {@code onSuccess}, {@code onError} or {@code onComplete} signals as a + * {@link Maybe} source. + *

      + * The intended use of the {@code selector} function is to perform a + * type-safe identity mapping (see example) on a source that is already of type + * {@code Notification}. The Java language doesn't allow + * limiting instance methods to a certain generic argument shape, therefore, + * a function is used to ensure the conversion remains type safe. + *

      + *
      Scheduler:
      + *
      {@code dematerialize} does not operate by default on a particular {@link Scheduler}.
      + *
      + *

      + * Example: + *

      
      +     * Single.just(Notification.createOnNext(1))
      +     * .dematerialize(notification -> notification)
      +     * .test()
      +     * .assertResult(1);
      +     * 
      + * @param the result type + * @param selector the function called with the success item and should + * return a {@link Notification} instance. + * @return the new Maybe instance + * @since 2.2.4 - experimental + * @see #materialize() + */ + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + @Experimental + public final Maybe dematerialize(Function> selector) { + ObjectHelper.requireNonNull(selector, "selector is null"); + return RxJavaPlugins.onAssembly(new SingleDematerialize(this, selector)); + } + /** * Calls the specified consumer with the success item after this item has been emitted to the downstream. *

      @@ -2871,6 +2908,26 @@ public final Single map(Function mapper) { return RxJavaPlugins.onAssembly(new SingleMap(this, mapper)); } + /** + * Maps the signal types of this Single into a {@link Notification} of the same kind + * and emits it as a single success value to downstream. + *

      + * + *

      + *
      Scheduler:
      + *
      {@code materialize} does not operate by default on a particular {@link Scheduler}.
      + *
      + * @return the new Single instance + * @since 2.2.4 - experimental + * @see #dematerialize(Function) + */ + @Experimental + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + public final Single> materialize() { + return RxJavaPlugins.onAssembly(new SingleMaterialize(this)); + } + /** * Signals true if the current Single signals a success value that is Object-equals with the value * provided. diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableMaterialize.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableMaterialize.java new file mode 100644 index 0000000000..5eda7f6ae2 --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableMaterialize.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.completable; + +import io.reactivex.*; +import io.reactivex.annotations.Experimental; +import io.reactivex.internal.operators.mixed.MaterializeSingleObserver; + +/** + * Turn the signal types of a Completable source into a single Notification of + * equal kind. + * + * @param the element type of the source + * @since 2.2.4 - experimental + */ +@Experimental +public final class CompletableMaterialize extends Single> { + + final Completable source; + + public CompletableMaterialize(Completable source) { + this.source = source; + } + + @Override + protected void subscribeActual(SingleObserver> observer) { + source.subscribe(new MaterializeSingleObserver(observer)); + } +} diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeMaterialize.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMaterialize.java new file mode 100644 index 0000000000..2b74829ba1 --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeMaterialize.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.maybe; + +import io.reactivex.*; +import io.reactivex.annotations.Experimental; +import io.reactivex.internal.operators.mixed.MaterializeSingleObserver; + +/** + * Turn the signal types of a Maybe source into a single Notification of + * equal kind. + * + * @param the element type of the source + * @since 2.2.4 - experimental + */ +@Experimental +public final class MaybeMaterialize extends Single> { + + final Maybe source; + + public MaybeMaterialize(Maybe source) { + this.source = source; + } + + @Override + protected void subscribeActual(SingleObserver> observer) { + source.subscribe(new MaterializeSingleObserver(observer)); + } +} diff --git a/src/main/java/io/reactivex/internal/operators/mixed/MaterializeSingleObserver.java b/src/main/java/io/reactivex/internal/operators/mixed/MaterializeSingleObserver.java new file mode 100644 index 0000000000..ef8a87076d --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/mixed/MaterializeSingleObserver.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.mixed; + +import io.reactivex.*; +import io.reactivex.annotations.Experimental; +import io.reactivex.disposables.Disposable; +import io.reactivex.internal.disposables.DisposableHelper; + +/** + * A consumer that implements the consumer types of Maybe, Single and Completable + * and turns their signals into Notifications for a SingleObserver. + * @param the element type of the source + * @since 2.2.4 - experimental + */ +@Experimental +public final class MaterializeSingleObserver +implements SingleObserver, MaybeObserver, CompletableObserver, Disposable { + + final SingleObserver> downstream; + + Disposable upstream; + + public MaterializeSingleObserver(SingleObserver> downstream) { + this.downstream = downstream; + } + + @Override + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(upstream, d)) { + this.upstream = d; + downstream.onSubscribe(this); + } + } + + @Override + public void onComplete() { + downstream.onSuccess(Notification.createOnComplete()); + } + + @Override + public void onSuccess(T t) { + downstream.onSuccess(Notification.createOnNext(t)); + } + + @Override + public void onError(Throwable e) { + downstream.onSuccess(Notification.createOnError(e)); + } + + @Override + public boolean isDisposed() { + return upstream.isDisposed(); + } + + @Override + public void dispose() { + upstream.dispose(); + } +} diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDematerialize.java b/src/main/java/io/reactivex/internal/operators/single/SingleDematerialize.java new file mode 100644 index 0000000000..2e402b05da --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDematerialize.java @@ -0,0 +1,105 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.single; + +import io.reactivex.*; +import io.reactivex.annotations.Experimental; +import io.reactivex.disposables.Disposable; +import io.reactivex.exceptions.Exceptions; +import io.reactivex.functions.Function; +import io.reactivex.internal.disposables.DisposableHelper; +import io.reactivex.internal.functions.ObjectHelper; + +/** + * Maps the success value of the source to a Notification, then + * maps it back to the corresponding signal type. + * @param the element type of the source + * @param the element type of the Notification and result + * @since 2.2.4 - experimental + */ +@Experimental +public final class SingleDematerialize extends Maybe { + + final Single source; + + final Function> selector; + + public SingleDematerialize(Single source, Function> selector) { + this.source = source; + this.selector = selector; + } + + @Override + protected void subscribeActual(MaybeObserver observer) { + source.subscribe(new DematerializeObserver(observer, selector)); + } + + static final class DematerializeObserver implements SingleObserver, Disposable { + + final MaybeObserver downstream; + + final Function> selector; + + Disposable upstream; + + DematerializeObserver(MaybeObserver downstream, + Function> selector) { + this.downstream = downstream; + this.selector = selector; + } + + @Override + public void dispose() { + upstream.dispose(); + } + + @Override + public boolean isDisposed() { + return upstream.isDisposed(); + } + + @Override + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(upstream, d)) { + upstream = d; + downstream.onSubscribe(this); + } + } + + @Override + public void onSuccess(T t) { + Notification notification; + + try { + notification = ObjectHelper.requireNonNull(selector.apply(t), "The selector returned a null Notification"); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + downstream.onError(ex); + return; + } + if (notification.isOnNext()) { + downstream.onSuccess(notification.getValue()); + } else if (notification.isOnComplete()) { + downstream.onComplete(); + } else { + downstream.onError(notification.getError()); + } + } + + @Override + public void onError(Throwable e) { + downstream.onError(e); + } + } +} diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleMaterialize.java b/src/main/java/io/reactivex/internal/operators/single/SingleMaterialize.java new file mode 100644 index 0000000000..e22b64865d --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/single/SingleMaterialize.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.single; + +import io.reactivex.*; +import io.reactivex.annotations.Experimental; +import io.reactivex.internal.operators.mixed.MaterializeSingleObserver; + +/** + * Turn the signal types of a Single source into a single Notification of + * equal kind. + * + * @param the element type of the source + * @since 2.2.4 - experimental + */ +@Experimental +public final class SingleMaterialize extends Single> { + + final Single source; + + public SingleMaterialize(Single source) { + this.source = source; + } + + @Override + protected void subscribeActual(SingleObserver> observer) { + source.subscribe(new MaterializeSingleObserver(observer)); + } +} diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableMaterializeTest.java new file mode 100644 index 0000000000..aec11e5a61 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableMaterializeTest.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.completable; + +import org.junit.Test; + +import io.reactivex.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Function; +import io.reactivex.subjects.CompletableSubject; + +public class CompletableMaterializeTest { + + @Test + @SuppressWarnings("unchecked") + public void error() { + TestException ex = new TestException(); + Completable.error(ex) + .materialize() + .test() + .assertResult(Notification.createOnError(ex)); + } + + @Test + @SuppressWarnings("unchecked") + public void empty() { + Completable.complete() + .materialize() + .test() + .assertResult(Notification.createOnComplete()); + } + + @Test + public void doubleOnSubscribe() { + TestHelper.checkDoubleOnSubscribeCompletableToSingle(new Function>>() { + @Override + public SingleSource> apply(Completable v) throws Exception { + return v.materialize(); + } + }); + } + + @Test + public void dispose() { + TestHelper.checkDisposed(CompletableSubject.create().materialize()); + } +} diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMaterializeTest.java new file mode 100644 index 0000000000..f429ecddf2 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMaterializeTest.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.maybe; + +import org.junit.Test; + +import io.reactivex.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Function; +import io.reactivex.subjects.MaybeSubject; + +public class MaybeMaterializeTest { + + @Test + @SuppressWarnings("unchecked") + public void success() { + Maybe.just(1) + .materialize() + .test() + .assertResult(Notification.createOnNext(1)); + } + + @Test + @SuppressWarnings("unchecked") + public void error() { + TestException ex = new TestException(); + Maybe.error(ex) + .materialize() + .test() + .assertResult(Notification.createOnError(ex)); + } + + @Test + @SuppressWarnings("unchecked") + public void empty() { + Maybe.empty() + .materialize() + .test() + .assertResult(Notification.createOnComplete()); + } + + @Test + public void doubleOnSubscribe() { + TestHelper.checkDoubleOnSubscribeMaybeToSingle(new Function, SingleSource>>() { + @Override + public SingleSource> apply(Maybe v) throws Exception { + return v.materialize(); + } + }); + } + + @Test + public void dispose() { + TestHelper.checkDisposed(MaybeSubject.create().materialize()); + } +} diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDematerializeTest.java new file mode 100644 index 0000000000..abfbe2151a --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDematerializeTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.single; + +import org.junit.Test; + +import io.reactivex.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Function; +import io.reactivex.internal.functions.Functions; +import io.reactivex.subjects.SingleSubject; + +public class SingleDematerializeTest { + + @Test + public void success() { + Single.just(Notification.createOnNext(1)) + .dematerialize(Functions.>identity()) + .test() + .assertResult(1); + } + + @Test + public void empty() { + Single.just(Notification.createOnComplete()) + .dematerialize(Functions.>identity()) + .test() + .assertResult(); + } + + @Test + public void error() { + Single.>error(new TestException()) + .dematerialize(Functions.>identity()) + .test() + .assertFailure(TestException.class); + } + + @Test + public void errorNotification() { + Single.just(Notification.createOnError(new TestException())) + .dematerialize(Functions.>identity()) + .test() + .assertFailure(TestException.class); + } + + @Test + public void doubleOnSubscribe() { + TestHelper.checkDoubleOnSubscribeSingleToMaybe(new Function, MaybeSource>() { + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public MaybeSource apply(Single v) throws Exception { + return v.dematerialize((Function)Functions.identity()); + } + }); + } + + @Test + public void dispose() { + TestHelper.checkDisposed(SingleSubject.>create().dematerialize(Functions.>identity())); + } + + @Test + public void selectorCrash() { + Single.just(Notification.createOnNext(1)) + .dematerialize(new Function, Notification>() { + @Override + public Notification apply(Notification v) throws Exception { + throw new TestException(); + } + }) + .test() + .assertFailure(TestException.class); + } + + @Test + public void selectorNull() { + Single.just(Notification.createOnNext(1)) + .dematerialize(Functions.justFunction((Notification)null)) + .test() + .assertFailure(NullPointerException.class); + } + + @Test + public void selectorDifferentType() { + Single.just(Notification.createOnNext(1)) + .dematerialize(new Function, Notification>() { + @Override + public Notification apply(Notification v) throws Exception { + return Notification.createOnNext("Value-" + 1); + } + }) + .test() + .assertResult("Value-1"); + } +} diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleMaterializeTest.java new file mode 100644 index 0000000000..3a97155978 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/single/SingleMaterializeTest.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.single; + +import org.junit.Test; + +import io.reactivex.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Function; +import io.reactivex.subjects.SingleSubject; + +public class SingleMaterializeTest { + + @Test + @SuppressWarnings("unchecked") + public void success() { + Single.just(1) + .materialize() + .test() + .assertResult(Notification.createOnNext(1)); + } + + @Test + @SuppressWarnings("unchecked") + public void error() { + TestException ex = new TestException(); + Maybe.error(ex) + .materialize() + .test() + .assertResult(Notification.createOnError(ex)); + } + + @Test + public void doubleOnSubscribe() { + TestHelper.checkDoubleOnSubscribeSingle(new Function, SingleSource>>() { + @Override + public SingleSource> apply(Single v) throws Exception { + return v.materialize(); + } + }); + } + + @Test + public void dispose() { + TestHelper.checkDisposed(SingleSubject.create().materialize()); + } +} From acd5466c4440961da905d0c1c0e78752bda155ef Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 6 Nov 2018 09:17:27 +0100 Subject: [PATCH 104/211] 2.x: Add dematerialize(selector), deprecate old (#6281) * 2.x: Add dematerialize(selector), deprecate old * Restore full coverage * Fix parameter naming --- src/main/java/io/reactivex/Flowable.java | 73 +++++++++++++++++-- src/main/java/io/reactivex/Observable.java | 65 ++++++++++++++++- .../flowable/FlowableDematerialize.java | 51 +++++++++---- .../observable/ObservableDematerialize.java | 51 +++++++++---- .../io/reactivex/flowable/FlowableTests.java | 9 ++- .../flowable/FlowableDematerializeTest.java | 60 +++++++++++++++ .../ObservableDematerializeTest.java | 60 +++++++++++++++ .../reactivex/observable/ObservableTest.java | 7 +- 8 files changed, 335 insertions(+), 41 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 2e9e6c20ba..a45063f506 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -27,7 +27,7 @@ import io.reactivex.internal.fuseable.*; import io.reactivex.internal.operators.flowable.*; import io.reactivex.internal.operators.mixed.*; -import io.reactivex.internal.operators.observable.ObservableFromPublisher; +import io.reactivex.internal.operators.observable.*; import io.reactivex.internal.schedulers.ImmediateThinScheduler; import io.reactivex.internal.subscribers.*; import io.reactivex.internal.util.*; @@ -8484,6 +8484,7 @@ public final Flowable delaySubscription(long delay, TimeUnit unit, Scheduler *
      
            * Flowable.just(createOnNext(1), createOnComplete(), createOnNext(2))
            * .doOnCancel(() -> System.out.println("Cancelled!"));
      +     * .dematerialize()
            * .test()
            * .assertResult(1);
            * 
      @@ -8491,6 +8492,7 @@ public final Flowable delaySubscription(long delay, TimeUnit unit, Scheduler * with the same event. *
      
            * Flowable.just(createOnNext(1), createOnNext(2))
      +     * .dematerialize()
            * .test()
            * .assertResult(1, 2);
            * 
      @@ -8508,14 +8510,74 @@ public final Flowable delaySubscription(long delay, TimeUnit unit, Scheduler * @return a Flowable that emits the items and notifications embedded in the {@link Notification} objects * emitted by the source Publisher * @see ReactiveX operators documentation: Dematerialize + * @see #dematerialize(Function) + * @deprecated in 2.2.4; inherently type-unsafe as it overrides the output generic type. Use {@link #dematerialize(Function)} instead. */ @CheckReturnValue - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @Deprecated + @SuppressWarnings({ "unchecked", "rawtypes" }) public final Flowable dematerialize() { - @SuppressWarnings("unchecked") - Flowable> m = (Flowable>)this; - return RxJavaPlugins.onAssembly(new FlowableDematerialize(m)); + return RxJavaPlugins.onAssembly(new FlowableDematerialize(this, Functions.identity())); + } + + /** + * Returns a Flowable that reverses the effect of {@link #materialize materialize} by transforming the + * {@link Notification} objects extracted from the source items via a selector function + * into their respective {@code Subscriber} signal types. + *

      + * + *

      + * The intended use of the {@code selector} function is to perform a + * type-safe identity mapping (see example) on a source that is already of type + * {@code Notification}. The Java language doesn't allow + * limiting instance methods to a certain generic argument shape, therefore, + * a function is used to ensure the conversion remains type safe. + *

      + * When the upstream signals an {@link Notification#createOnError(Throwable) onError} or + * {@link Notification#createOnComplete() onComplete} item, the + * returned Flowable cancels of the flow and terminates with that type of terminal event: + *

      
      +     * Flowable.just(createOnNext(1), createOnComplete(), createOnNext(2))
      +     * .doOnCancel(() -> System.out.println("Canceled!"));
      +     * .dematerialize(notification -> notification)
      +     * .test()
      +     * .assertResult(1);
      +     * 
      + * If the upstream signals {@code onError} or {@code onComplete} directly, the flow is terminated + * with the same event. + *
      
      +     * Flowable.just(createOnNext(1), createOnNext(2))
      +     * .dematerialize(notification -> notification)
      +     * .test()
      +     * .assertResult(1, 2);
      +     * 
      + * If this behavior is not desired, the completion can be suppressed by applying {@link #concatWith(Publisher)} + * with a {@link #never()} source. + *
      + *
      Backpressure:
      + *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s + * backpressure behavior.
      + *
      Scheduler:
      + *
      {@code dematerialize} does not operate by default on a particular {@link Scheduler}.
      + *
      + * + * @param the output value type + * @param selector function that returns the upstream item and should return a Notification to signal + * the corresponding {@code Subscriber} event to the downstream. + * @return a Flowable that emits the items and notifications embedded in the {@link Notification} objects + * selected from the items emitted by the source Flowable + * @see ReactiveX operators documentation: Dematerialize + * @since 2.2.4 - experimental + */ + @Experimental + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + public final Flowable dematerialize(Function> selector) { + ObjectHelper.requireNonNull(selector, "selector is null"); + return RxJavaPlugins.onAssembly(new FlowableDematerialize(this, selector)); } /** @@ -11069,6 +11131,7 @@ public final Flowable map(Function mapper) { * @return a Flowable that emits items that are the result of materializing the items and notifications * of the source Publisher * @see ReactiveX operators documentation: Materialize + * @see #dematerialize(Function) */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index c80e8be95d..db3530069a 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -7587,6 +7587,7 @@ public final Observable delaySubscription(long delay, TimeUnit unit, Schedule *
      
            * Observable.just(createOnNext(1), createOnComplete(), createOnNext(2))
            * .doOnDispose(() -> System.out.println("Disposed!"));
      +     * .dematerialize()
            * .test()
            * .assertResult(1);
            * 
      @@ -7594,6 +7595,7 @@ public final Observable delaySubscription(long delay, TimeUnit unit, Schedule * with the same event. *
      
            * Observable.just(createOnNext(1), createOnNext(2))
      +     * .dematerialize()
            * .test()
            * .assertResult(1, 2);
            * 
      @@ -7608,13 +7610,69 @@ public final Observable delaySubscription(long delay, TimeUnit unit, Schedule * @return an Observable that emits the items and notifications embedded in the {@link Notification} objects * emitted by the source ObservableSource * @see ReactiveX operators documentation: Dematerialize + * @see #dematerialize(Function) + * @deprecated in 2.2.4; inherently type-unsafe as it overrides the output generic type. Use {@link #dematerialize(Function)} instead. */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) + @Deprecated + @SuppressWarnings({ "unchecked", "rawtypes" }) public final Observable dematerialize() { - @SuppressWarnings("unchecked") - Observable> m = (Observable>)this; - return RxJavaPlugins.onAssembly(new ObservableDematerialize(m)); + return RxJavaPlugins.onAssembly(new ObservableDematerialize(this, Functions.identity())); + } + + /** + * Returns an Observable that reverses the effect of {@link #materialize materialize} by transforming the + * {@link Notification} objects extracted from the source items via a selector function + * into their respective {@code Observer} signal types. + *

      + * + *

      + * The intended use of the {@code selector} function is to perform a + * type-safe identity mapping (see example) on a source that is already of type + * {@code Notification}. The Java language doesn't allow + * limiting instance methods to a certain generic argument shape, therefore, + * a function is used to ensure the conversion remains type safe. + *

      + * When the upstream signals an {@link Notification#createOnError(Throwable) onError} or + * {@link Notification#createOnComplete() onComplete} item, the + * returned Observable disposes of the flow and terminates with that type of terminal event: + *

      
      +     * Observable.just(createOnNext(1), createOnComplete(), createOnNext(2))
      +     * .doOnDispose(() -> System.out.println("Disposed!"));
      +     * .dematerialize(notification -> notification)
      +     * .test()
      +     * .assertResult(1);
      +     * 
      + * If the upstream signals {@code onError} or {@code onComplete} directly, the flow is terminated + * with the same event. + *
      
      +     * Observable.just(createOnNext(1), createOnNext(2))
      +     * .dematerialize(notification -> notification)
      +     * .test()
      +     * .assertResult(1, 2);
      +     * 
      + * If this behavior is not desired, the completion can be suppressed by applying {@link #concatWith(ObservableSource)} + * with a {@link #never()} source. + *
      + *
      Scheduler:
      + *
      {@code dematerialize} does not operate by default on a particular {@link Scheduler}.
      + *
      + * + * @param the output value type + * @param selector function that returns the upstream item and should return a Notification to signal + * the corresponding {@code Observer} event to the downstream. + * @return an Observable that emits the items and notifications embedded in the {@link Notification} objects + * selected from the items emitted by the source ObservableSource + * @see ReactiveX operators documentation: Dematerialize + * @since 2.2.4 - experimental + */ + @Experimental + @CheckReturnValue + @SchedulerSupport(SchedulerSupport.NONE) + public final Observable dematerialize(Function> selector) { + ObjectHelper.requireNonNull(selector, "selector is null"); + return RxJavaPlugins.onAssembly(new ObservableDematerialize(this, selector)); } /** @@ -9620,6 +9678,7 @@ public final Observable map(Function mapper) { * @return an Observable that emits items that are the result of materializing the items and notifications * of the source ObservableSource * @see ReactiveX operators documentation: Materialize + * @see #dematerialize(Function) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java index 930f5aaee6..5fe5211834 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDematerialize.java @@ -16,29 +16,39 @@ import org.reactivestreams.*; import io.reactivex.*; +import io.reactivex.exceptions.Exceptions; +import io.reactivex.functions.Function; +import io.reactivex.internal.functions.ObjectHelper; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; -public final class FlowableDematerialize extends AbstractFlowableWithUpstream, T> { +public final class FlowableDematerialize extends AbstractFlowableWithUpstream { - public FlowableDematerialize(Flowable> source) { + final Function> selector; + + public FlowableDematerialize(Flowable source, Function> selector) { super(source); + this.selector = selector; } @Override - protected void subscribeActual(Subscriber s) { - source.subscribe(new DematerializeSubscriber(s)); + protected void subscribeActual(Subscriber subscriber) { + source.subscribe(new DematerializeSubscriber(subscriber, selector)); } - static final class DematerializeSubscriber implements FlowableSubscriber>, Subscription { - final Subscriber downstream; + static final class DematerializeSubscriber implements FlowableSubscriber, Subscription { + + final Subscriber downstream; + + final Function> selector; boolean done; Subscription upstream; - DematerializeSubscriber(Subscriber downstream) { + DematerializeSubscriber(Subscriber downstream, Function> selector) { this.downstream = downstream; + this.selector = selector; } @Override @@ -50,22 +60,35 @@ public void onSubscribe(Subscription s) { } @Override - public void onNext(Notification t) { + public void onNext(T item) { if (done) { - if (t.isOnError()) { - RxJavaPlugins.onError(t.getError()); + if (item instanceof Notification) { + Notification notification = (Notification)item; + if (notification.isOnError()) { + RxJavaPlugins.onError(notification.getError()); + } } return; } - if (t.isOnError()) { + + Notification notification; + + try { + notification = ObjectHelper.requireNonNull(selector.apply(item), "The selector returned a null Notification"); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); upstream.cancel(); - onError(t.getError()); + onError(ex); + return; } - else if (t.isOnComplete()) { + if (notification.isOnError()) { + upstream.cancel(); + onError(notification.getError()); + } else if (notification.isOnComplete()) { upstream.cancel(); onComplete(); } else { - downstream.onNext(t.getValue()); + downstream.onNext(notification.getValue()); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java index 9e79e8eba4..2f864152ee 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDematerialize.java @@ -15,29 +15,38 @@ import io.reactivex.*; import io.reactivex.disposables.Disposable; +import io.reactivex.exceptions.Exceptions; +import io.reactivex.functions.Function; import io.reactivex.internal.disposables.DisposableHelper; +import io.reactivex.internal.functions.ObjectHelper; import io.reactivex.plugins.RxJavaPlugins; -public final class ObservableDematerialize extends AbstractObservableWithUpstream, T> { +public final class ObservableDematerialize extends AbstractObservableWithUpstream { - public ObservableDematerialize(ObservableSource> source) { + final Function> selector; + + public ObservableDematerialize(ObservableSource source, Function> selector) { super(source); + this.selector = selector; } @Override - public void subscribeActual(Observer t) { - source.subscribe(new DematerializeObserver(t)); + public void subscribeActual(Observer observer) { + source.subscribe(new DematerializeObserver(observer, selector)); } - static final class DematerializeObserver implements Observer>, Disposable { - final Observer downstream; + static final class DematerializeObserver implements Observer, Disposable { + final Observer downstream; + + final Function> selector; boolean done; Disposable upstream; - DematerializeObserver(Observer downstream) { + DematerializeObserver(Observer downstream, Function> selector) { this.downstream = downstream; + this.selector = selector; } @Override @@ -60,22 +69,36 @@ public boolean isDisposed() { } @Override - public void onNext(Notification t) { + public void onNext(T item) { if (done) { - if (t.isOnError()) { - RxJavaPlugins.onError(t.getError()); + if (item instanceof Notification) { + Notification notification = (Notification)item; + if (notification.isOnError()) { + RxJavaPlugins.onError(notification.getError()); + } } return; } - if (t.isOnError()) { + + Notification notification; + + try { + notification = ObjectHelper.requireNonNull(selector.apply(item), "The selector returned a null Notification"); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + upstream.dispose(); + onError(ex); + return; + } + if (notification.isOnError()) { upstream.dispose(); - onError(t.getError()); + onError(notification.getError()); } - else if (t.isOnComplete()) { + else if (notification.isOnComplete()) { upstream.dispose(); onComplete(); } else { - downstream.onNext(t.getValue()); + downstream.onNext(notification.getValue()); } } diff --git a/src/test/java/io/reactivex/flowable/FlowableTests.java b/src/test/java/io/reactivex/flowable/FlowableTests.java index 4a700b5aea..fa8026da6c 100644 --- a/src/test/java/io/reactivex/flowable/FlowableTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableTests.java @@ -14,22 +14,24 @@ package io.reactivex.flowable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import io.reactivex.Observable; import org.junit.*; import org.mockito.InOrder; import org.reactivestreams.*; import io.reactivex.*; +import io.reactivex.Observable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; @@ -341,7 +343,8 @@ public void testOnSubscribeFails() { @Test public void testMaterializeDematerializeChaining() { Flowable obs = Flowable.just(1); - Flowable chained = obs.materialize().dematerialize(); + Flowable chained = obs.materialize() + .dematerialize(Functions.>identity()); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -1076,7 +1079,7 @@ public void testErrorThrownIssue1685() { Flowable.error(new RuntimeException("oops")) .materialize() .delay(1, TimeUnit.SECONDS) - .dematerialize() + .dematerialize(Functions.>identity()) .subscribe(processor); processor.subscribe(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java index f83510f830..66fd932dcc 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java @@ -24,12 +24,57 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; +import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +@SuppressWarnings("deprecation") public class FlowableDematerializeTest { + @Test + public void simpleSelector() { + Flowable> notifications = Flowable.just(1, 2).materialize(); + Flowable dematerialize = notifications.dematerialize(Functions.>identity()); + + Subscriber subscriber = TestHelper.mockSubscriber(); + + dematerialize.subscribe(subscriber); + + verify(subscriber, times(1)).onNext(1); + verify(subscriber, times(1)).onNext(2); + verify(subscriber, times(1)).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + } + + @Test + public void selectorCrash() { + Flowable.just(1, 2) + .materialize() + .dematerialize(new Function, Notification>() { + @Override + public Notification apply(Notification v) throws Exception { + throw new TestException(); + } + }) + .test() + .assertFailure(TestException.class); + } + + @Test + public void selectorNull() { + Flowable.just(1, 2) + .materialize() + .dematerialize(new Function, Notification>() { + @Override + public Notification apply(Notification v) throws Exception { + return null; + } + }) + .test() + .assertFailure(NullPointerException.class); + } + @Test public void testDematerialize1() { Flowable> notifications = Flowable.just(1, 2).materialize(); @@ -176,4 +221,19 @@ protected void subscribeActual(Subscriber subscriber) { RxJavaPlugins.reset(); } } + + @Test + public void nonNotificationInstanceAfterDispose() { + new Flowable() { + @Override + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(Notification.createOnComplete()); + subscriber.onNext(1); + } + } + .dematerialize() + .test() + .assertResult(); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java index a5017c68c4..d815a70ea5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java @@ -24,11 +24,56 @@ import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; +import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +@SuppressWarnings("deprecation") public class ObservableDematerializeTest { + @Test + public void simpleSelector() { + Observable> notifications = Observable.just(1, 2).materialize(); + Observable dematerialize = notifications.dematerialize(Functions.>identity()); + + Observer observer = TestHelper.mockObserver(); + + dematerialize.subscribe(observer); + + verify(observer, times(1)).onNext(1); + verify(observer, times(1)).onNext(2); + verify(observer, times(1)).onComplete(); + verify(observer, never()).onError(any(Throwable.class)); + } + + @Test + public void selectorCrash() { + Observable.just(1, 2) + .materialize() + .dematerialize(new Function, Notification>() { + @Override + public Notification apply(Notification v) throws Exception { + throw new TestException(); + } + }) + .test() + .assertFailure(TestException.class); + } + + @Test + public void selectorNull() { + Observable.just(1, 2) + .materialize() + .dematerialize(new Function, Notification>() { + @Override + public Notification apply(Notification v) throws Exception { + return null; + } + }) + .test() + .assertFailure(NullPointerException.class); + } + @Test public void testDematerialize1() { Observable> notifications = Observable.just(1, 2).materialize(); @@ -175,4 +220,19 @@ protected void subscribeActual(Observer observer) { RxJavaPlugins.reset(); } } + + @Test + public void nonNotificationInstanceAfterDispose() { + new Observable() { + @Override + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(Notification.createOnComplete()); + observer.onNext(1); + } + } + .dematerialize() + .test() + .assertResult(); + } } diff --git a/src/test/java/io/reactivex/observable/ObservableTest.java b/src/test/java/io/reactivex/observable/ObservableTest.java index 660c57d49a..ab915ffa53 100644 --- a/src/test/java/io/reactivex/observable/ObservableTest.java +++ b/src/test/java/io/reactivex/observable/ObservableTest.java @@ -14,6 +14,7 @@ package io.reactivex.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; @@ -28,6 +29,7 @@ import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.observables.ConnectableObservable; import io.reactivex.observers.*; import io.reactivex.schedulers.*; @@ -357,7 +359,8 @@ public void testOnSubscribeFails() { @Test public void testMaterializeDematerializeChaining() { Observable obs = Observable.just(1); - Observable chained = obs.materialize().dematerialize(); + Observable chained = obs.materialize() + .dematerialize(Functions.>identity()); Observer observer = TestHelper.mockObserver(); @@ -1096,7 +1099,7 @@ public void testErrorThrownIssue1685() { Observable.error(new RuntimeException("oops")) .materialize() .delay(1, TimeUnit.SECONDS) - .dematerialize() + .dematerialize(Functions.>identity()) .subscribe(subject); subject.subscribe(); From 55f3bb2a366c5667c682021fe56726479f29bc3b Mon Sep 17 00:00:00 2001 From: Zac Sweers Date: Sun, 11 Nov 2018 04:06:38 -0800 Subject: [PATCH 105/211] Add missing onSubscribe null-checks to NPE docs on Flowable/Observable subscribe (#6301) Happened to notice these today --- src/main/java/io/reactivex/Flowable.java | 3 ++- src/main/java/io/reactivex/Observable.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index a45063f506..ca4ca72b34 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -14461,7 +14461,8 @@ public final Disposable subscribe(Consumer onNext, ConsumerReactiveX operators documentation: Subscribe */ @CheckReturnValue diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index db3530069a..8ab4059642 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -12119,7 +12119,8 @@ public final Disposable subscribe(Consumer onNext, ConsumerReactiveX operators documentation: Subscribe */ @CheckReturnValue From 2334d880a18d95161aa5d07657104e8639b23b3c Mon Sep 17 00:00:00 2001 From: lorenzpahl Date: Sun, 11 Nov 2018 21:58:02 +0100 Subject: [PATCH 106/211] Fix(incorrect image placement) (#6303) --- src/main/java/io/reactivex/Flowable.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index ca4ca72b34..666c7c765d 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -18043,7 +18043,7 @@ public final Flowable zipWith(Iterable other, BiFunctionTo work around this termination property, * use {@link #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion * or cancellation. - * + *

      * *

      *
      Backpressure:
      @@ -18090,7 +18090,7 @@ public final Flowable zipWith(Publisher other, BiFunction *
      To work around this termination property, * use {@link #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion * or cancellation. - * + *

      * *

      *
      Backpressure:
      @@ -18140,7 +18140,7 @@ public final Flowable zipWith(Publisher other, *
      To work around this termination property, * use {@link #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion * or cancellation. - * + *

      * *

      *
      Backpressure:
      From 390b7b0633ddbec364d2f78e624be5312a6ef198 Mon Sep 17 00:00:00 2001 From: lorenzpahl Date: Mon, 12 Nov 2018 09:54:06 +0100 Subject: [PATCH 107/211] 2.x: Update Transforming Observables docs (#6291) * Change document structure; revise descriptions * Add examples * Add more operators --- docs/Transforming-Observables.md | 787 ++++++++++++++++++++++++++++++- 1 file changed, 777 insertions(+), 10 deletions(-) diff --git a/docs/Transforming-Observables.md b/docs/Transforming-Observables.md index aa7b53e89f..3a3d94cd2e 100644 --- a/docs/Transforming-Observables.md +++ b/docs/Transforming-Observables.md @@ -1,10 +1,777 @@ -This page shows operators with which you can transform items that are emitted by an Observable. - -* [**`map( )`**](http://reactivex.io/documentation/operators/map.html) — transform the items emitted by an Observable by applying a function to each of them -* [**`flatMap( )`, `concatMap( )`, and `flatMapIterable( )`**](http://reactivex.io/documentation/operators/flatmap.html) — transform the items emitted by an Observable into Observables (or Iterables), then flatten this into a single Observable -* [**`switchMap( )`**](http://reactivex.io/documentation/operators/flatmap.html) — transform the items emitted by an Observable into Observables, and mirror those items emitted by the most-recently transformed Observable -* [**`scan( )`**](http://reactivex.io/documentation/operators/scan.html) — apply a function to each item emitted by an Observable, sequentially, and emit each successive value -* [**`groupBy( )`**](http://reactivex.io/documentation/operators/groupby.html) — divide an Observable into a set of Observables that emit groups of items from the original Observable, organized by key -* [**`buffer( )`**](http://reactivex.io/documentation/operators/buffer.html) — periodically gather items from an Observable into bundles and emit these bundles rather than emitting the items one at a time -* [**`window( )`**](http://reactivex.io/documentation/operators/window.html) — periodically subdivide items from an Observable into Observable windows and emit these windows rather than emitting the items one at a time -* [**`cast( )`**](http://reactivex.io/documentation/operators/map.html) — cast all items from the source Observable into a particular type before reemitting them \ No newline at end of file +This page shows operators with which you can transform items that are emitted by reactive sources, such as `Observable`s. + +# Outline + +- [`buffer`](#buffer) +- [`cast`](#cast) +- [`concatMap`](#concatmap) +- [`concatMapCompletable`](#concatmapcompletable) +- [`concatMapCompletableDelayError`](#concatmapcompletabledelayerror) +- [`concatMapDelayError`](#concatmapdelayerror) +- [`concatMapEager`](#concatmapeager) +- [`concatMapEagerDelayError`](#concatmapeagerdelayerror) +- [`concatMapIterable`](#concatmapiterable) +- [`concatMapMaybe`](#concatmapmaybe) +- [`concatMapMaybeDelayError`](#concatmapmaybedelayerror) +- [`concatMapSingle`](#concatmapsingle) +- [`concatMapSingleDelayError`](#concatmapsingledelayerror) +- [`flatMap`](#flatmap) +- [`flatMapCompletable`](#flatmapcompletable) +- [`flatMapIterable`](#flatmapiterable) +- [`flatMapMaybe`](#flatmapmaybe) +- [`flatMapObservable`](#flatmapobservable) +- [`flatMapPublisher`](#flatmappublisher) +- [`flatMapSingle`](#flatmapsingle) +- [`flatMapSingleElement`](#flatmapsingleelement) +- [`flattenAsFlowable`](#flattenasflowable) +- [`flattenAsObservable`](#flattenasobservable) +- [`groupBy`](#groupby) +- [`map`](#map) +- [`scan`](#scan) +- [`switchMap`](#switchmap) +- [`window`](#window) + +## buffer + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/buffer.html](http://reactivex.io/documentation/operators/buffer.html) + +Collects the items emitted by a reactive source into buffers, and emits these buffers. + +### buffer example + +```java +Observable.range(0, 10) + .buffer(4) + .subscribe((List buffer) -> System.out.println(buffer)); + +// prints: +// [0, 1, 2, 3] +// [4, 5, 6, 7] +// [8, 9] +``` + +## cast + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/map.html](http://reactivex.io/documentation/operators/map.html) + +Converts each item emitted by a reactive source to the specified type, and emits these items. + +### cast example + +```java +Observable numbers = Observable.just(1, 4.0, 3f, 7, 12, 4.6, 5); + +numbers.filter((Number x) -> Integer.class.isInstance(x)) + .cast(Integer.class) + .subscribe((Integer x) -> System.out.println(x)); + +// prints: +// 1 +// 7 +// 12 +// 5 +``` + +## concatMap + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a reactive source, and emits the items that result from concatenating the results of these function applications. + +### concatMap example + +```java +Observable.range(0, 5) + .concatMap(i -> { + long delay = Math.round(Math.random() * 2); + + return Observable.timer(delay, TimeUnit.SECONDS).map(n -> i); + }) + .blockingSubscribe(System.out::print); + +// prints 01234 +``` + +## concatMapCompletable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `io.reactivex.CompletableSource`, subscribes to them one at a time and returns a `Completable` that completes when all sources completed. + +### concatMapCompletable example + +```java +Observable source = Observable.just(2, 1, 3); +Completable completable = source.concatMapCompletable(x -> { + return Completable.timer(x, TimeUnit.SECONDS) + .doOnComplete(() -> System.out.println("Info: Processing of item \"" + x + "\" completed")); + }); + +completable.doOnComplete(() -> System.out.println("Info: Processing of all items completed")) + .blockingAwait(); + +// prints: +// Info: Processing of item "2" completed +// Info: Processing of item "1" completed +// Info: Processing of item "3" completed +// Info: Processing of all items completed +``` + +## concatMapCompletableDelayError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `io.reactivex.CompletableSource`, subscribes to them one at a time and returns a `Completable` that completes when all sources completed. Any errors from the sources will be delayed until all of them terminate. + +### concatMapCompletableDelayError example + +```java +Observable source = Observable.just(2, 1, 3); +Completable completable = source.concatMapCompletableDelayError(x -> { + if (x.equals(2)) { + return Completable.error(new IOException("Processing of item \"" + x + "\" failed!")); + } else { + return Completable.timer(1, TimeUnit.SECONDS) + .doOnComplete(() -> System.out.println("Info: Processing of item \"" + x + "\" completed")); + } +}); + +completable.doOnError(error -> System.out.println("Error: " + error.getMessage())) + .onErrorComplete() + .blockingAwait(); + +// prints: +// Info: Processing of item "1" completed +// Info: Processing of item "3" completed +// Error: Processing of item "2" failed! +``` + +## concatMapDelayError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a reactive source, and emits the items that result from concatenating the results of these function applications. Any errors from the sources will be delayed until all of them terminate. + +### concatMapDelayError example + +```java +Observable.intervalRange(1, 3, 0, 1, TimeUnit.SECONDS) + .concatMapDelayError(x -> { + if (x.equals(1L)) return Observable.error(new IOException("Something went wrong!")); + else return Observable.just(x, x * x); + }) + .blockingSubscribe( + x -> System.out.println("onNext: " + x), + error -> System.out.println("onError: " + error.getMessage())); + +// prints: +// onNext: 2 +// onNext: 4 +// onNext: 3 +// onNext: 9 +// onError: Something went wrong! +``` + +## concatMapEager + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a reactive source, and emits the items that result from concatenating the results of these function applications. Unlike [`concatMap`](#concatmap), this operator eagerly subscribes to all sources. + +### concatMapEager example + +```java +Observable.range(0, 5) + .concatMapEager(i -> { + long delay = Math.round(Math.random() * 3); + + return Observable.timer(delay, TimeUnit.SECONDS) + .map(n -> i) + .doOnNext(x -> System.out.println("Info: Finished processing item " + x)); + }) + .blockingSubscribe(i -> System.out.println("onNext: " + i)); + +// prints (lines beginning with "Info..." can be displayed in a different order): +// Info: Finished processing item 2 +// Info: Finished processing item 0 +// onNext: 0 +// Info: Finished processing item 1 +// onNext: 1 +// onNext: 2 +// Info: Finished processing item 3 +// Info: Finished processing item 4 +// onNext: 3 +// onNext: 4 +``` + +## concatMapEagerDelayError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a reactive source, and emits the items that result from concatenating the results of these function applications. A `boolean` value must be specified, which if `true` indicates that all errors from all sources will be delayed until the end, otherwise if `false`, an error from the main source will be signalled when the current source terminates. Unlike [concatMapDelayError](#concatmapdelayerror), this operator eagerly subscribes to all sources. + +### concatMapEagerDelayError example + +```java +Observable source = Observable.create(emitter -> { + emitter.onNext(1); + emitter.onNext(2); + emitter.onError(new Error("Fatal error!")); +}); + +source.doOnError(error -> System.out.println("Info: Error from main source " + error.getMessage())) + .concatMapEagerDelayError(x -> { + return Observable.timer(1, TimeUnit.SECONDS).map(n -> x) + .doOnSubscribe(it -> System.out.println("Info: Processing of item \"" + x + "\" started")); + }, true) + .blockingSubscribe( + x -> System.out.println("onNext: " + x), + error -> System.out.println("onError: " + error.getMessage())); + +// prints: +// Info: Processing of item "1" started +// Info: Processing of item "2" started +// Info: Error from main source Fatal error! +// onNext: 1 +// onNext: 2 +// onError: Fatal error! +``` + +## concatMapIterable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `java.lang.Iterable`, and emits the items that result from concatenating the results of these function applications. + +### concatMapIterable example + +```java +Observable.just("A", "B", "C") + .concatMapIterable(item -> List.of(item, item, item)) + .subscribe(System.out::print); + +// prints AAABBBCCC +``` + +## concatMapMaybe + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `io.reactivex.MaybeSource`, and emits the items that result from concatenating these `MaybeSource`s. + +### concatMapMaybe example + +```java +Observable.just("5", "3,14", "2.71", "FF") + .concatMapMaybe(v -> { + return Maybe.fromCallable(() -> Double.parseDouble(v)) + .doOnError(e -> System.out.println("Info: The value \"" + v + "\" could not be parsed.")) + + // Ignore values that can not be parsed. + .onErrorComplete(); + }) + .subscribe(x -> System.out.println("onNext: " + x)); + +// prints: +// onNext: 5.0 +// Info: The value "3,14" could not be parsed. +// onNext: 2.71 +// Info: The value "FF" could not be parsed. +``` + +## concatMapMaybeDelayError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `io.reactivex.MaybeSource`, and emits the items that result from concatenating these `MaybeSource`s. Any errors from the sources will be delayed until all of them terminate. + +### concatMapMaybeDelayError example + +```java +DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd.MM.uuuu"); +Observable.just("04.03.2018", "12-08-2018", "06.10.2018", "01.12.2018") + .concatMapMaybeDelayError(date -> { + return Maybe.fromCallable(() -> LocalDate.parse(date, dateFormatter)); + }) + .subscribe( + localDate -> System.out.println("onNext: " + localDate), + error -> System.out.println("onError: " + error.getMessage())); + +// prints: +// onNext: 2018-03-04 +// onNext: 2018-10-06 +// onNext: 2018-12-01 +// onError: Text '12-08-2018' could not be parsed at index 2 +``` + +## concatMapSingle + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `io.reactivex.SingleSource`, and emits the items that result from concatenating these ``SingleSource`s. + +### concatMapSingle example + +```java +Observable.just("5", "3,14", "2.71", "FF") + .concatMapSingle(v -> { + return Single.fromCallable(() -> Double.parseDouble(v)) + .doOnError(e -> System.out.println("Info: The value \"" + v + "\" could not be parsed.")) + + // Return a default value if the given value can not be parsed. + .onErrorReturnItem(42.0); + }) + .subscribe(x -> System.out.println("onNext: " + x)); + +// prints: +// onNext: 5.0 +// Info: The value "3,14" could not be parsed. +// onNext: 42.0 +// onNext: 2.71 +// Info: The value "FF" could not be parsed. +// onNext: 42.0 +``` + +## concatMapSingleDelayError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `io.reactivex.SingleSource`, and emits the items that result from concatenating the results of these function applications. Any errors from the sources will be delayed until all of them terminate. + +### concatMapSingleDelayError example + +```java +DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd.MM.uuuu"); +Observable.just("24.03.2018", "12-08-2018", "06.10.2018", "01.12.2018") + .concatMapSingleDelayError(date -> { + return Single.fromCallable(() -> LocalDate.parse(date, dateFormatter)); + }) + .subscribe( + localDate -> System.out.println("onNext: " + localDate), + error -> System.out.println("onError: " + error.getMessage())); + +// prints: +// onNext: 2018-03-24 +// onNext: 2018-10-06 +// onNext: 2018-12-01 +// onError: Text '12-08-2018' could not be parsed at index 2 +``` + +## flatMap + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a reactive source, and emits the items that result from merging the results of these function applications. + +### flatMap example + +```java +Observable.just("A", "B", "C") + .flatMap(a -> { + return Observable.intervalRange(1, 3, 0, 1, TimeUnit.SECONDS) + .map(b -> '(' + a + ", " + b + ')'); + }) + .blockingSubscribe(System.out::println); + +// prints (not necessarily in this order): +// (A, 1) +// (C, 1) +// (B, 1) +// (A, 2) +// (C, 2) +// (B, 2) +// (A, 3) +// (C, 3) +// (B, 3) +``` + +## flatMapCompletable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `io.reactivex.CompletableSource`, and returns a `Completable` that completes when all sources completed. + +### flatMapCompletable example + +```java +Observable source = Observable.just(2, 1, 3); +Completable completable = source.flatMapCompletable(x -> { + return Completable.timer(x, TimeUnit.SECONDS) + .doOnComplete(() -> System.out.println("Info: Processing of item \"" + x + "\" completed")); +}); + +completable.doOnComplete(() -> System.out.println("Info: Processing of all items completed")) + .blockingAwait(); + +// prints: +// Info: Processing of item "1" completed +// Info: Processing of item "2" completed +// Info: Processing of item "3" completed +// Info: Processing of all items completed +``` + +## flatMapIterable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `java.lang.Iterable`, and emits the elements from these `Iterable`s. + +### flatMapIterable example + +```java +Observable.just(1, 2, 3, 4) + .flatMapIterable(x -> { + switch (x % 4) { + case 1: + return List.of("A"); + case 2: + return List.of("B", "B"); + case 3: + return List.of("C", "C", "C"); + default: + return List.of(); + } + }) + .subscribe(System.out::println); + +// prints: +// A +// B +// B +// C +// C +// C +``` + +## flatMapMaybe + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `io.reactivex.MaybeSource`, and emits the items that result from merging these `MaybeSource`s. + +### flatMapMaybe example + +```java +Observable.just(9.0, 16.0, -4.0) + .flatMapMaybe(x -> { + if (x.compareTo(0.0) < 0) return Maybe.empty(); + else return Maybe.just(Math.sqrt(x)); + }) + .subscribe( + System.out::println, + Throwable::printStackTrace, + () -> System.out.println("onComplete")); + +// prints: +// 3.0 +// 4.0 +// onComplete +``` + +## flatMapObservable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to the item emitted by a `Maybe` or `Single`, where that function returns an `io.reactivex.ObservableSource`, and returns an `Observable` that emits the items emitted by this `ObservableSource`. + +### flatMapObservable example + +```java +Single source = Single.just("Kirk, Spock, Chekov, Sulu"); +Observable names = source.flatMapObservable(text -> { + return Observable.fromArray(text.split(",")) + .map(String::strip); +}); + +names.subscribe(name -> System.out.println("onNext: " + name)); + +// prints: +// onNext: Kirk +// onNext: Spock +// onNext: Chekov +// onNext: Sulu +``` + +## flatMapPublisher + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to the item emitted by a `Maybe` or `Single`, where that function returns an `org.reactivestreams.Publisher`, and returns a `Flowable` that emits the items emitted by this `Publisher`. + +### flatMapPublisher example + +```java +Single source = Single.just("Kirk, Spock, Chekov, Sulu"); +Flowable names = source.flatMapPublisher(text -> { + return Flowable.fromArray(text.split(",")) + .map(String::strip); +}); + +names.subscribe(name -> System.out.println("onNext: " + name)); + +// prints: +// onNext: Kirk +// onNext: Spock +// onNext: Chekov +// onNext: Sulu +``` + +## flatMapSingle + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a `io.reactivex.SingleSource`, and emits the items that result from merging these `SingleSource`s. + +### flatMapSingle example + +```java +Observable.just(4, 2, 1, 3) + .flatMapSingle(x -> Single.timer(x, TimeUnit.SECONDS).map(i -> x)) + .blockingSubscribe(System.out::print); + +// prints 1234 +``` + +*Note:* `Maybe::flatMapSingle` returns a `Single` that signals an error notification if the `Maybe` source is empty: + +```java +Maybe emptySource = Maybe.empty(); +Single result = emptySource.flatMapSingle(x -> Single.just(x)); +result.subscribe( + x -> System.out.println("onSuccess will not be printed!"), + error -> System.out.println("onError: Source was empty!")); + +// prints: +// onError: Source was empty! +``` + +Use [`Maybe::flatMapSingleElement`](#flatmapsingleelement) -- which returns a `Maybe` -- if you don't want this behaviour. + +## flatMapSingleElement + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to the item emitted by a `Maybe`, where that function returns a `io.reactivex.SingleSource`, and returns a `Maybe` that either emits the item emitted by this `SingleSource` or completes if the source `Maybe` just completes. + +### flatMapSingleElement example + +```java +Maybe source = Maybe.just(-42); +Maybe result = source.flatMapSingleElement(x -> { + return Single.just(Math.abs(x)); +}); + +result.subscribe(System.out::println); + +// prints 42 +``` + +## flattenAsFlowable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to the item emitted by a `Maybe` or `Single`, where that function returns a `java.lang.Iterable`, and returns a `Flowable` that emits the elements from this `Iterable`. + +### flattenAsFlowable example + +```java +Single source = Single.just(2.0); +Flowable flowable = source.flattenAsFlowable(x -> { + return List.of(x, Math.pow(x, 2), Math.pow(x, 3)); +}); + +flowable.subscribe(x -> System.out.println("onNext: " + x)); + +// prints: +// onNext: 2.0 +// onNext: 4.0 +// onNext: 8.0 +``` + +## flattenAsObservable + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to the item emitted by a `Maybe` or `Single`, where that function returns a `java.lang.Iterable`, and returns an `Observable` that emits the elements from this `Iterable`. + +### flattenAsObservable example + +```java +Single source = Single.just(2.0); +Observable observable = source.flattenAsObservable(x -> { + return List.of(x, Math.pow(x, 2), Math.pow(x, 3)); +}); + +observable.subscribe(x -> System.out.println("onNext: " + x)); + +// prints: +// onNext: 2.0 +// onNext: 4.0 +// onNext: 8.0 +``` + +## groupBy + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/groupby.html](http://reactivex.io/documentation/operators/groupby.html) + +Groups the items emitted by a reactive source according to a specified criterion, and emits these grouped items as a `GroupedObservable` or `GroupedFlowable`. + +### groupBy example + +```java +Observable animals = Observable.just( + "Tiger", "Elephant", "Cat", "Chameleon", "Frog", "Fish", "Turtle", "Flamingo"); + +animals.groupBy(animal -> animal.charAt(0), String::toUpperCase) + .concatMapSingle(Observable::toList) + .subscribe(System.out::println); + +// prints: +// [TIGER, TURTLE] +// [ELEPHANT] +// [CAT, CHAMELEON] +// [FROG, FISH, FLAMINGO] +``` + +## map + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/map.html](http://reactivex.io/documentation/operators/map.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source and emits the results of these function applications. + +### map example + +```java +Observable.just(1, 2, 3) + .map(x -> x * x) + .subscribe(System.out::println); + +// prints: +// 1 +// 4 +// 9 +``` + +## scan + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/scan.html](http://reactivex.io/documentation/operators/scan.html) + +Applies the given `io.reactivex.functions.BiFunction` to a seed value and the first item emitted by a reactive source, then feeds the result of that function application along with the second item emitted by the reactive source into the same function, and so on until all items have been emitted by the reactive source, emitting each intermediate result. + +### scan example + +```java +Observable.just(5, 3, 8, 1, 7) + .scan(0, (partialSum, x) -> partialSum + x) + .subscribe(System.out::println); + +// prints: +// 0 +// 5 +// 8 +// 16 +// 17 +// 24 +``` + +## switchMap + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/flatmap.html](http://reactivex.io/documentation/operators/flatmap.html) + +Applies the given `io.reactivex.functions.Function` to each item emitted by a reactive source, where that function returns a reactive source, and emits the items emitted by the most recently projected of these reactive sources. + +### switchMap example + +```java +Observable.interval(0, 1, TimeUnit.SECONDS) + .switchMap(x -> { + return Observable.interval(0, 750, TimeUnit.MILLISECONDS) + .map(y -> x); + }) + .takeWhile(x -> x < 3) + .blockingSubscribe(System.out::print); + +// prints 001122 +``` + +## window + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/window.html](http://reactivex.io/documentation/operators/window.html) + +Collects the items emitted by a reactive source into windows, and emits these windows as a `Flowable` or `Observable`. + +### window example + +```java +Observable.range(1, 10) + + // Create windows containing at most 2 items, and skip 3 items before starting a new window. + .window(2, 3) + .flatMapSingle(window -> { + return window.map(String::valueOf) + .reduce(new StringJoiner(", ", "[", "]"), StringJoiner::add); + }) + .subscribe(System.out::println); + +// prints: +// [1, 2] +// [4, 5] +// [7, 8] +// [10] +``` From 6afd2b8d6c96ae9f76f5dc4802b9e8385c7b12ee Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 12 Nov 2018 10:26:14 +0100 Subject: [PATCH 108/211] 2.x: Fix refCount eager disconnect not resetting the connection (#6297) * 2.x: Fix refCount eager disconnect not resetting the connection * Remove unnecessary comment. --- .../operators/flowable/FlowableRefCount.java | 13 ++++++++++++- .../operators/observable/ObservableRefCount.java | 14 +++++++++++++- .../operators/flowable/FlowableRefCountTest.java | 15 +++++++++++++++ .../observable/ObservableRefCountTest.java | 15 +++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java index f966f01365..bc11aa5425 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java @@ -141,7 +141,11 @@ void timeout(RefConnection rc) { if (source instanceof Disposable) { ((Disposable)source).dispose(); } else if (source instanceof ResettableConnectable) { - ((ResettableConnectable)source).resetIf(connectionObject); + if (connectionObject == null) { + rc.disconnectedEarly = true; + } else { + ((ResettableConnectable)source).resetIf(connectionObject); + } } } } @@ -160,6 +164,8 @@ static final class RefConnection extends AtomicReference boolean connected; + boolean disconnectedEarly; + RefConnection(FlowableRefCount parent) { this.parent = parent; } @@ -172,6 +178,11 @@ public void run() { @Override public void accept(Disposable t) throws Exception { DisposableHelper.replace(this, t); + synchronized (parent) { + if (disconnectedEarly) { + ((ResettableConnectable)parent.source).resetIf(t); + } + } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java index 3dced24de6..5abc174350 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java @@ -135,10 +135,15 @@ void timeout(RefConnection rc) { connection = null; Disposable connectionObject = rc.get(); DisposableHelper.dispose(rc); + if (source instanceof Disposable) { ((Disposable)source).dispose(); } else if (source instanceof ResettableConnectable) { - ((ResettableConnectable)source).resetIf(connectionObject); + if (connectionObject == null) { + rc.disconnectedEarly = true; + } else { + ((ResettableConnectable)source).resetIf(connectionObject); + } } } } @@ -157,6 +162,8 @@ static final class RefConnection extends AtomicReference boolean connected; + boolean disconnectedEarly; + RefConnection(ObservableRefCount parent) { this.parent = parent; } @@ -169,6 +176,11 @@ public void run() { @Override public void accept(Disposable t) throws Exception { DisposableHelper.replace(this, t); + synchronized (parent) { + if (disconnectedEarly) { + ((ResettableConnectable)parent.source).resetIf(t); + } + } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java index 289170b254..673a0f4add 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java @@ -1394,4 +1394,19 @@ public void timeoutDisposesSource() { assertTrue(((Disposable)o.source).isDisposed()); } + + @Test + public void disconnectBeforeConnect() { + BehaviorProcessor processor = BehaviorProcessor.create(); + + Flowable flowable = processor + .replay(1) + .refCount(); + + flowable.takeUntil(Flowable.just(1)).test(); + + processor.onNext(2); + + flowable.take(1).test().assertResult(2); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index ea69a1d500..0f0d930d8d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -1345,4 +1345,19 @@ public void timeoutDisposesSource() { assertTrue(((Disposable)o.source).isDisposed()); } + + @Test + public void disconnectBeforeConnect() { + BehaviorSubject subject = BehaviorSubject.create(); + + Observable observable = subject + .replay(1) + .refCount(); + + observable.takeUntil(Observable.just(1)).test(); + + subject.onNext(2); + + observable.take(1).test().assertResult(2); + } } From e82b82edf874e69ed51896987a4c987d3f5af9f2 Mon Sep 17 00:00:00 2001 From: punitd Date: Tue, 13 Nov 2018 19:46:50 +0530 Subject: [PATCH 109/211] Javadoc : Explain explicitly about non-concurrency for Emitter interface methods (#6305) --- src/main/java/io/reactivex/Emitter.java | 5 +++++ src/main/java/io/reactivex/Flowable.java | 25 ++++++++++++++++++++++ src/main/java/io/reactivex/Observable.java | 25 ++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/src/main/java/io/reactivex/Emitter.java b/src/main/java/io/reactivex/Emitter.java index 2f60f90478..0d95e80dcf 100644 --- a/src/main/java/io/reactivex/Emitter.java +++ b/src/main/java/io/reactivex/Emitter.java @@ -17,6 +17,11 @@ /** * Base interface for emitting signals in a push-fashion in various generator-like source * operators (create, generate). + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently. Calling them from multiple threads is not supported and leads to an + * undefined behavior. * * @param the value type emitted */ diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 666c7c765d..da4f800670 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -2210,6 +2210,11 @@ public static Flowable fromPublisher(final Publisher source) /** * Returns a cold, synchronous, stateless and backpressure-aware generator of values. + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *

      *
      Backpressure:
      *
      The operator honors downstream backpressure.
      @@ -2236,6 +2241,11 @@ public static Flowable generate(final Consumer> generator) { /** * Returns a cold, synchronous, stateful and backpressure-aware generator of values. + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *

      *
      Backpressure:
      *
      The operator honors downstream backpressure.
      @@ -2263,6 +2273,11 @@ public static Flowable generate(Callable initialState, final BiCons /** * Returns a cold, synchronous, stateful and backpressure-aware generator of values. + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *

      *
      Backpressure:
      *
      The operator honors downstream backpressure.
      @@ -2292,6 +2307,11 @@ public static Flowable generate(Callable initialState, final BiCons /** * Returns a cold, synchronous, stateful and backpressure-aware generator of values. + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *

      *
      Backpressure:
      *
      The operator honors downstream backpressure.
      @@ -2318,6 +2338,11 @@ public static Flowable generate(Callable initialState, BiFunction + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *
      *
      Backpressure:
      *
      The operator honors downstream backpressure.
      diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 8ab4059642..c022a0f9fa 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -1992,6 +1992,11 @@ public static Observable fromPublisher(Publisher publisher) * Returns a cold, synchronous and stateless generator of values. *

      * + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *

      *
      Scheduler:
      *
      {@code generate} does not operate by default on a particular {@link Scheduler}.
      @@ -2016,6 +2021,11 @@ public static Observable generate(final Consumer> generator) { * Returns a cold, synchronous and stateful generator of values. *

      * + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *

      *
      Scheduler:
      *
      {@code generate} does not operate by default on a particular {@link Scheduler}.
      @@ -2041,6 +2051,11 @@ public static Observable generate(Callable initialState, final BiCo * Returns a cold, synchronous and stateful generator of values. *

      * + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *

      *
      Scheduler:
      *
      {@code generate} does not operate by default on a particular {@link Scheduler}.
      @@ -2071,6 +2086,11 @@ public static Observable generate( * Returns a cold, synchronous and stateful generator of values. *

      * + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *

      *
      Scheduler:
      *
      {@code generate} does not operate by default on a particular {@link Scheduler}.
      @@ -2096,6 +2116,11 @@ public static Observable generate(Callable initialState, BiFunction * Returns a cold, synchronous and stateful generator of values. *

      * + *

      + * Note that the {@link Emitter#onNext}, {@link Emitter#onError} and + * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance should be called synchronously, + * never concurrently and only while the function body is executing. Calling them from multiple threads + * or outside the function call is not supported and leads to an undefined behavior. *

      *
      Scheduler:
      *
      {@code generate} does not operate by default on a particular {@link Scheduler}.
      From f800b30f044497ea11f23986d3d6260e7ea69f2b Mon Sep 17 00:00:00 2001 From: Purnima Kamath Date: Fri, 16 Nov 2018 21:52:03 +0800 Subject: [PATCH 110/211] Javadoc updates for RXJava Issue 6289 (#6308) * Javadoc updates for RXJava Issue 6289 * With review comments on issue 6289 --- src/main/java/io/reactivex/Flowable.java | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index da4f800670..c3c48e3c95 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -10345,6 +10345,14 @@ public final Disposable forEachWhile(final Predicate onNext, final Co * is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore those * {@code GroupedPublisher}s that do not concern you. Instead, you can signal to them that they may * discard their buffers by applying an operator like {@link #ignoreElements} to them. + *

      + * Note that the {@link GroupedFlowable}s should be subscribed to as soon as possible, otherwise, + * the unconsumed groups may starve other groups due to the internal backpressure + * coordination of the {@code groupBy} operator. Such hangs can be usually avoided by using + * {@link #flatMap(Function, int)} or {@link #concatMapEager(Function, int, int)} and overriding the default maximum concurrency + * value to be greater or equal to the expected number of groups, possibly using + * {@code Integer.MAX_VALUE} if the number of expected groups is unknown. + * *

      *
      Backpressure:
      *
      Both the returned and its inner {@code Publisher}s honor backpressure and the source {@code Publisher} @@ -10385,6 +10393,13 @@ public final Flowable> groupBy(Function + * Note that the {@link GroupedFlowable}s should be subscribed to as soon as possible, otherwise, + * the unconsumed groups may starve other groups due to the internal backpressure + * coordination of the {@code groupBy} operator. Such hangs can be usually avoided by using + * {@link #flatMap(Function, int)} or {@link #concatMapEager(Function, int, int)} and overriding the default maximum concurrency + * value to be greater or equal to the expected number of groups, possibly using + * {@code Integer.MAX_VALUE} if the number of expected groups is unknown. *
      *
      Backpressure:
      *
      Both the returned and its inner {@code Publisher}s honor backpressure and the source {@code Publisher} @@ -10428,6 +10443,14 @@ public final Flowable> groupBy(Function + * Note that the {@link GroupedFlowable}s should be subscribed to as soon as possible, otherwise, + * the unconsumed groups may starve other groups due to the internal backpressure + * coordination of the {@code groupBy} operator. Such hangs can be usually avoided by using + * {@link #flatMap(Function, int)} or {@link #concatMapEager(Function, int, int)} and overriding the default maximum concurrency + * value to be greater or equal to the expected number of groups, possibly using + * {@code Integer.MAX_VALUE} if the number of expected groups is unknown. + * *
      *
      Backpressure:
      *
      Both the returned and its inner {@code Publisher}s honor backpressure and the source {@code Publisher} @@ -10473,6 +10496,14 @@ public final Flowable> groupBy(Function + * Note that the {@link GroupedFlowable}s should be subscribed to as soon as possible, otherwise, + * the unconsumed groups may starve other groups due to the internal backpressure + * coordination of the {@code groupBy} operator. Such hangs can be usually avoided by using + * {@link #flatMap(Function, int)} or {@link #concatMapEager(Function, int, int)} and overriding the default maximum concurrency + * value to be greater or equal to the expected number of groups, possibly using + * {@code Integer.MAX_VALUE} if the number of expected groups is unknown. + * *
      *
      Backpressure:
      *
      Both the returned and its inner {@code Publisher}s honor backpressure and the source {@code Publisher} @@ -10521,6 +10552,14 @@ public final Flowable> groupBy(Function + * Note that the {@link GroupedFlowable}s should be subscribed to as soon as possible, otherwise, + * the unconsumed groups may starve other groups due to the internal backpressure + * coordination of the {@code groupBy} operator. Such hangs can be usually avoided by using + * {@link #flatMap(Function, int)} or {@link #concatMapEager(Function, int, int)} and overriding the default maximum concurrency + * value to be greater or equal to the expected number of groups, possibly using + * {@code Integer.MAX_VALUE} if the number of expected groups is unknown. + * *
      *
      Backpressure:
      *
      Both the returned and its inner {@code Publisher}s honor backpressure and the source {@code Publisher} @@ -10617,6 +10656,14 @@ public final Flowable> groupBy(Function + * Note that the {@link GroupedFlowable}s should be subscribed to as soon as possible, otherwise, + * the unconsumed groups may starve other groups due to the internal backpressure + * coordination of the {@code groupBy} operator. Such hangs can be usually avoided by using + * {@link #flatMap(Function, int)} or {@link #concatMapEager(Function, int, int)} and overriding the default maximum concurrency + * value to be greater or equal to the expected number of groups, possibly using + * {@code Integer.MAX_VALUE} if the number of expected groups is unknown. + * *
      *
      Backpressure:
      *
      Both the returned and its inner {@code GroupedFlowable}s honor backpressure and the source {@code Publisher} From 7058126ad4763a0ba6bcbf8433792f04426f5a77 Mon Sep 17 00:00:00 2001 From: punitd Date: Fri, 16 Nov 2018 22:30:17 +0530 Subject: [PATCH 111/211] Javadoc: explain that distinctUntilChanged requires non-mutating data to work as expected (#6311) * Javadoc : Explain distinctUntilChanged requires non-mutating data type in flow(Observable) Add few tests for scenarios related to mutable data type flow in distinctUntilChanged() methods for Observable * Javadoc : Explain distinctUntilChanged requires non-mutating data type in flow(Flowable) Add few tests for scenarios related to mutable data type flow in distinctUntilChanged() methods for Flowable * Remove tests and fix typo in javadoc --- src/main/java/io/reactivex/Flowable.java | 21 +++++++++++++++++++++ src/main/java/io/reactivex/Observable.java | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index c3c48e3c95..d484f9da69 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -8740,6 +8740,13 @@ public final Flowable distinct(Function keySelector, *

      * Note that the operator always retains the latest item from upstream regardless of the comparison result * and uses it in the next comparison with the next upstream item. + *

      + * Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current + * item may yield unexpected results if the items are mutated externally. Common cases are mutable + * {@code CharSequence}s or {@code List}s where the objects will actually have the same + * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. + * To avoid such situation, it is recommended that mutable data is converted to an immutable one, + * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. *

      *
      Backpressure:
      *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s @@ -8776,6 +8783,13 @@ public final Flowable distinctUntilChanged() { *

      * Note that the operator always retains the latest key from upstream regardless of the comparison result * and uses it in the next comparison with the next key derived from the next upstream item. + *

      + * Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current + * item may yield unexpected results if the items are mutated externally. Common cases are mutable + * {@code CharSequence}s or {@code List}s where the objects will actually have the same + * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. + * To avoid such situation, it is recommended that mutable data is converted to an immutable one, + * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. *

      *
      Backpressure:
      *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s @@ -8808,6 +8822,13 @@ public final Flowable distinctUntilChanged(Function keySele *

      * Note that the operator always retains the latest item from upstream regardless of the comparison result * and uses it in the next comparison with the next upstream item. + *

      + * Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current + * item may yield unexpected results if the items are mutated externally. Common cases are mutable + * {@code CharSequence}s or {@code List}s where the objects will actually have the same + * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. + * To avoid such situation, it is recommended that mutable data is converted to an immutable one, + * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. *

      *
      Backpressure:
      *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index c022a0f9fa..41f10e395f 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -7824,6 +7824,13 @@ public final Observable distinct(Function keySelector, Call *

      * Note that the operator always retains the latest item from upstream regardless of the comparison result * and uses it in the next comparison with the next upstream item. + *

      + * Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current + * item may yield unexpected results if the items are mutated externally. Common cases are mutable + * {@code CharSequence}s or {@code List}s where the objects will actually have the same + * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. + * To avoid such situation, it is recommended that mutable data is converted to an immutable one, + * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. *

      *
      Scheduler:
      *
      {@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
      @@ -7856,6 +7863,13 @@ public final Observable distinctUntilChanged() { *

      * Note that the operator always retains the latest key from upstream regardless of the comparison result * and uses it in the next comparison with the next key derived from the next upstream item. + *

      + * Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current + * item may yield unexpected results if the items are mutated externally. Common cases are mutable + * {@code CharSequence}s or {@code List}s where the objects will actually have the same + * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. + * To avoid such situation, it is recommended that mutable data is converted to an immutable one, + * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. *

      *
      Scheduler:
      *
      {@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
      @@ -7884,6 +7898,13 @@ public final Observable distinctUntilChanged(Function keySe *

      * Note that the operator always retains the latest item from upstream regardless of the comparison result * and uses it in the next comparison with the next upstream item. + *

      + * Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current + * item may yield unexpected results if the items are mutated externally. Common cases are mutable + * {@code CharSequence}s or {@code List}s where the objects will actually have the same + * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. + * To avoid such situation, it is recommended that mutable data is converted to an immutable one, + * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. *

      *
      Scheduler:
      *
      {@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
      From ac3b5b195b8abf6086c21c7601ff5d054e0041d4 Mon Sep 17 00:00:00 2001 From: punitd Date: Mon, 19 Nov 2018 22:07:23 +0530 Subject: [PATCH 112/211] Change javadoc explanation for Mutable List (#6314) --- src/main/java/io/reactivex/Flowable.java | 6 +++--- src/main/java/io/reactivex/Observable.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index d484f9da69..18ed618512 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -8746,7 +8746,7 @@ public final Flowable distinct(Function keySelector, * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. + * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. *
      *
      Backpressure:
      *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s @@ -8789,7 +8789,7 @@ public final Flowable distinctUntilChanged() { * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. + * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. *
      *
      Backpressure:
      *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s @@ -8828,7 +8828,7 @@ public final Flowable distinctUntilChanged(Function keySele * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. + * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. *
      *
      Backpressure:
      *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 41f10e395f..ef177b5c6a 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -7830,7 +7830,7 @@ public final Observable distinct(Function keySelector, Call * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. + * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. *
      *
      Scheduler:
      *
      {@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
      @@ -7869,7 +7869,7 @@ public final Observable distinctUntilChanged() { * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. + * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. *
      *
      Scheduler:
      *
      {@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
      @@ -7904,7 +7904,7 @@ public final Observable distinctUntilChanged(Function keySe * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`. + * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. *
      *
      Scheduler:
      *
      {@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
      From 3e4ae3856f184d5783d34ffc5c468d91e67d77d8 Mon Sep 17 00:00:00 2001 From: Philip Leonard Date: Fri, 23 Nov 2018 08:41:07 +0100 Subject: [PATCH 113/211] Fix Flowable#toObservable backpressure support (#6321) --- src/main/java/io/reactivex/Flowable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 18ed618512..1115eba74e 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -16983,7 +16983,7 @@ public final Single>> toMultimap( * @since 2.0 */ @CheckReturnValue - @BackpressureSupport(BackpressureKind.NONE) + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Observable toObservable() { return RxJavaPlugins.onAssembly(new ObservableFromPublisher(this)); From 6ae765a899969682263acef757480df95b026783 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 23 Nov 2018 08:43:18 +0100 Subject: [PATCH 114/211] Release 2.2.4 --- CHANGES.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6c888f8d3a..dd1266c545 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,46 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.4 - November 23, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.4%7C)) + +#### API changes + + - [Pull 6278](https://github.com/ReactiveX/RxJava/pull/6278): Add `Maybe`/`Single`/`Completable` `materialize` operator, + - [Pull 6278](https://github.com/ReactiveX/RxJava/pull/6278): Add `Single.dematerialize(selector)` operator. + - [Pull 6281](https://github.com/ReactiveX/RxJava/pull/6281): Add `Flowable`/`Observable` `dematerialize(selector)` operator. + +#### Bugfixes + + - [Pull 6258](https://github.com/ReactiveX/RxJava/pull/6258): Fix cancel/dispose upon upstream switch for some operators. + - [Pull 6269](https://github.com/ReactiveX/RxJava/pull/6269): Call the `doOn{Dispose|Cancel}` handler at most once. + - [Pull 6283](https://github.com/ReactiveX/RxJava/pull/6283): Fix `Observable.flatMap` to sustain concurrency level. + - [Pull 6297](https://github.com/ReactiveX/RxJava/pull/6297): Fix refCount eager disconnect not resetting the connection. + +#### Documentation changes + + - [Pull 6280](https://github.com/ReactiveX/RxJava/pull/6280): Improve the package docs of `io.reactivex.schedulers`. + - [Pull 6301](https://github.com/ReactiveX/RxJava/pull/6301): Add missing `onSubscribe` null-checks to NPE docs on `Flowable`/`Observable` `subscribe`. + - [Pull 6303](https://github.com/ReactiveX/RxJava/pull/6303): Fix incorrect image placement in `Flowable.zip` docs. + - [Pull 6305](https://github.com/ReactiveX/RxJava/pull/6305): Explain the non-concurrency requirement of the `Emitter` interface methods. + - [Pull 6308](https://github.com/ReactiveX/RxJava/pull/6308): Explain the need to consume both the group sequence and each group specifically with `Flowable.groupBy`. + - [Pull 6311](https://github.com/ReactiveX/RxJava/pull/6311): Explain that `distinctUntilChanged` requires non-mutating data to work as expected. + +#### Wiki changes + + - [Pull 6260](https://github.com/ReactiveX/RxJava/pull/6260): Add `generate` examples to `Creating-Observables.md`. + - [Pull 6267](https://github.com/ReactiveX/RxJava/pull/6267): Fix `Creating-Observables.md` docs stlye mistake. + - [Pull 6273](https://github.com/ReactiveX/RxJava/pull/6273): Fix broken markdown of `How-to-Contribute.md`. + - [Pull 6266](https://github.com/ReactiveX/RxJava/pull/6266): Update Error Handling Operators docs. + - [Pull 6291](https://github.com/ReactiveX/RxJava/pull/6291): Update Transforming Observables docs. + +#### Other changes + + - [Pull 6262](https://github.com/ReactiveX/RxJava/pull/6262): Use JUnit's assert format for assert messages for better IDE interoperation. + - [Pull 6263](https://github.com/ReactiveX/RxJava/pull/6263): Inline `SubscriptionHelper.isCancelled()`. + - [Pull 6275](https://github.com/ReactiveX/RxJava/pull/6275): Improve the `Observable`/`Flowable` `cache()` operators. + - [Pull 6287](https://github.com/ReactiveX/RxJava/pull/6287): Expose the Keep-Alive value of the IO `Scheduler` as System property. + - [Pull 6321](https://github.com/ReactiveX/RxJava/pull/6321): Fix `Flowable.toObservable` backpressure annotation. + ### Version 2.2.3 - October 23, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.3%7C)) #### API changes From bc40695e4073ee806de460947958d4c6edca632b Mon Sep 17 00:00:00 2001 From: hoangnam2261 <31692990+hoangnam2261@users.noreply.github.com> Date: Mon, 10 Dec 2018 16:18:15 +0700 Subject: [PATCH 115/211] #6323 Java 8 version for Problem-Solving-Examples-in-RxJava (#6324) * #6323 Java 8 version for Project Euler problem * #6323 Java 8 version for Generate the Fibonacci Sequence * #6323 Java 8 version for Project Euler problem - Fix name of variable * #6324 Fixing for code review. --- docs/Problem-Solving-Examples-in-RxJava.md | 62 +++++++++++++++++++--- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/docs/Problem-Solving-Examples-in-RxJava.md b/docs/Problem-Solving-Examples-in-RxJava.md index 1b41c2a122..6b848ae693 100644 --- a/docs/Problem-Solving-Examples-in-RxJava.md +++ b/docs/Problem-Solving-Examples-in-RxJava.md @@ -1,4 +1,4 @@ -This page will present some elementary RxJava puzzles and walk through some solutions (using the Groovy language implementation of RxJava) as a way of introducing you to some of the RxJava operators. +This page will present some elementary RxJava puzzles and walk through some solutions as a way of introducing you to some of the RxJava operators. # Project Euler problem #1 @@ -7,10 +7,22 @@ There used to be a site called "Project Euler" that presented a series of mathem > If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. There are several ways we could go about this with RxJava. We might, for instance, begin by going through all of the natural numbers below 1000 with [`range`](Creating-Observables#range) and then [`filter`](Filtering-Observables#filter) out those that are not a multiple either of 3 or of 5: +### Java +```java +Observable threesAndFives = Observable.range(1, 999).filter(e -> e % 3 == 0 || e % 5 == 0); +``` +### Groovy ````groovy def threesAndFives = Observable.range(1,999).filter({ !((it % 3) && (it % 5)) }); ```` Or, we could generate two Observable sequences, one containing the multiples of three and the other containing the multiples of five (by [`map`](https://github.com/Netflix/RxJava/wiki/Transforming-Observables#map)ping each value onto its appropriate multiple), making sure to only generating new multiples while they are less than 1000 (the [`takeWhile`](Conditional-and-Boolean-Operators#takewhile-and-takewhilewithindex) operator will help here), and then [`merge`](Combining-Observables#merge) these sets: +### Java +```java +Observable threes = Observable.range(1, 999).map(e -> e * 3).takeWhile(e -> e < 1000); +Observable fives = Observable.range(1, 999).map(e -> e * 5).takeWhile(e -> e < 1000); +Observable threesAndFives = Observable.merge(threes, fives).distinct(); +``` +### Groovy ````groovy def threes = Observable.range(1,999).map({it*3}).takeWhile({it<1000}); def fives = Observable.range(1,999).map({it*5}).takeWhile({it<1000}); @@ -21,6 +33,11 @@ Don't forget the [`distinct`](Filtering-Observables#distinct) operator here, oth Next, we want to sum up the numbers in the resulting sequence. If you have installed the optional `rxjava-math` module, this is elementary: just use an operator like [`sumInteger` or `sumLong`](Mathematical-and-Aggregate-Operators#suminteger-sumlong-sumfloat-and-sumdouble) on the `threesAndFives` Observable. But what if you don't have this module? How could you use standard RxJava operators to sum up a sequence and emit that sum? There are a number of operators that reduce a sequence emitted by a source Observable to a single value emitted by the resulting Observable. Most of the ones that are not in the `rxjava-math` module emit boolean evaluations of the sequence; we want something that can emit a number. The [`reduce`](Mathematical-and-Aggregate-Operators#reduce) operator will do the job: +### Java +```java +Single summer = threesAndFives.reduce(0, (a, b) -> a + b); +``` +### Groovy ````groovy def summer = threesAndFives.reduce(0, { a, b -> a+b }); ```` @@ -38,6 +55,12 @@ Here is how `reduce` gets the job done. It starts with 0 as a seed. Then, with e Finally, we want to see the result. This means we must [subscribe](Observable#onnext-oncompleted-and-onerror) to the Observable we have constructed: + +### Java +```java +summer.subscribe(System.out::print); +``` +### Groovy ````groovy summer.subscribe({println(it);}); ```` @@ -47,11 +70,24 @@ summer.subscribe({println(it);}); How could you create an Observable that emits [the Fibonacci sequence](http://en.wikipedia.org/wiki/Fibonacci_number)? The most direct way would be to use the [`create`](Creating-Observables#wiki-create) operator to make an Observable "from scratch," and then use a traditional loop within the closure you pass to that operator to generate the sequence. Something like this: +### Java +```java +Observable fibonacci = Observable.create(emitter -> { + int f1 = 0, f2 = 1, f = 1; + while (!emitter.isDisposed()) { + emitter.onNext(f); + f = f1 + f2; + f1 = f2; + f2 = f; + } +}); +``` +### Groovy ````groovy -def fibonacci = Observable.create({ observer -> - def f1=0; f2=1, f=1; - while(!observer.isUnsubscribed() { - observer.onNext(f); +def fibonacci = Observable.create({ emitter -> + def f1=0, f2=1, f=1; + while(!emitter.isDisposed()) { + emitter.onNext(f); f = f1+f2; f1 = f2; f2 = f; @@ -61,7 +97,16 @@ def fibonacci = Observable.create({ observer -> But this is a little too much like ordinary linear programming. Is there some way we can instead create this sequence by composing together existing Observable operators? Here's an option that does this: -```` +### Java +```java +Observable fibonacci = + Observable.fromArray(0) + .repeat() + .scan(new int[]{0, 1}, (a, b) -> new int[]{a[1], a[0] + a[1]}) + .map(a -> a[1]); +``` +### Groovy +````groovy def fibonacci = Observable.from(0).repeat().scan([0,1], { a,b -> [a[1], a[0]+a[1]] }).map({it[1]}); ```` It's a little [janky](http://www.urbandictionary.com/define.php?term=janky). Let's walk through it: @@ -73,6 +118,11 @@ This has the effect of emitting the following sequence of items: `[0,1], [1,1], The second item in this array describes the Fibonacci sequence. We can use `map` to reduce the sequence to just that item. To print out a portion of this sequence (using either method), you would use code like the following: +### Java +```java +fibonacci.take(15).subscribe(System.out::println); +``` +### Groovy ````groovy fibonnaci.take(15).subscribe({println(it)})]; ```` From 1e4e966e5f848aaf931cb43db77c36a92ab62885 Mon Sep 17 00:00:00 2001 From: lorenzpahl Date: Wed, 19 Dec 2018 10:41:09 +0100 Subject: [PATCH 116/211] 2.x: Update Filtering Observables docs (#6343) * Update operator list; revise descriptions * Add examples --- docs/Filtering-Observables.md | 782 +++++++++++++++++++++++++++++++++- 1 file changed, 760 insertions(+), 22 deletions(-) diff --git a/docs/Filtering-Observables.md b/docs/Filtering-Observables.md index 7e12d91094..620800dc8c 100644 --- a/docs/Filtering-Observables.md +++ b/docs/Filtering-Observables.md @@ -1,22 +1,760 @@ -This page shows operators you can use to filter and select items emitted by Observables. - -* [**`filter( )`**](http://reactivex.io/documentation/operators/filter.html) — filter items emitted by an Observable -* [**`takeLast( )`**](http://reactivex.io/documentation/operators/takelast.html) — only emit the last _n_ items emitted by an Observable -* [**`last( )`**](http://reactivex.io/documentation/operators/last.html) — emit only the last item emitted by an Observable -* [**`lastOrDefault( )`**](http://reactivex.io/documentation/operators/last.html) — emit only the last item emitted by an Observable, or a default value if the source Observable is empty -* [**`takeLastBuffer( )`**](http://reactivex.io/documentation/operators/takelast.html) — emit the last _n_ items emitted by an Observable, as a single list item -* [**`skip( )`**](http://reactivex.io/documentation/operators/skip.html) — ignore the first _n_ items emitted by an Observable -* [**`skipLast( )`**](http://reactivex.io/documentation/operators/skiplast.html) — ignore the last _n_ items emitted by an Observable -* [**`take( )`**](http://reactivex.io/documentation/operators/take.html) — emit only the first _n_ items emitted by an Observable -* [**`first( )` and `takeFirst( )`**](http://reactivex.io/documentation/operators/first.html) — emit only the first item emitted by an Observable, or the first item that meets some condition -* [**`firstOrDefault( )`**](http://reactivex.io/documentation/operators/first.html) — emit only the first item emitted by an Observable, or the first item that meets some condition, or a default value if the source Observable is empty -* [**`elementAt( )`**](http://reactivex.io/documentation/operators/elementat.html) — emit item _n_ emitted by the source Observable -* [**`elementAtOrDefault( )`**](http://reactivex.io/documentation/operators/elementat.html) — emit item _n_ emitted by the source Observable, or a default item if the source Observable emits fewer than _n_ items -* [**`sample( )` or `throttleLast( )`**](http://reactivex.io/documentation/operators/sample.html) — emit the most recent items emitted by an Observable within periodic time intervals -* [**`throttleFirst( )`**](http://reactivex.io/documentation/operators/sample.html) — emit the first items emitted by an Observable within periodic time intervals -* [**`throttleWithTimeout( )` or `debounce( )`**](http://reactivex.io/documentation/operators/debounce.html) — only emit an item from the source Observable after a particular timespan has passed without the Observable emitting any other items -* [**`timeout( )`**](http://reactivex.io/documentation/operators/timeout.html) — emit items from a source Observable, but issue an exception if no item is emitted in a specified timespan -* [**`distinct( )`**](http://reactivex.io/documentation/operators/distinct.html) — suppress duplicate items emitted by the source Observable -* [**`distinctUntilChanged( )`**](http://reactivex.io/documentation/operators/distinct.html) — suppress duplicate consecutive items emitted by the source Observable -* [**`ofType( )`**](http://reactivex.io/documentation/operators/filter.html) — emit only those items from the source Observable that are of a particular class -* [**`ignoreElements( )`**](http://reactivex.io/documentation/operators/ignoreelements.html) — discard the items emitted by the source Observable and only pass through the error or completed notification +This page shows operators you can use to filter and select items emitted by reactive sources, such as `Observable`s. + +# Outline + +- [`debounce`](#debounce) +- [`distinct`](#distinct) +- [`distinctUntilChanged`](#distinctuntilchanged) +- [`elementAt`](#elementat) +- [`elementAtOrError`](#elementatorerror) +- [`filter`](#filter) +- [`first`](#first) +- [`firstElement`](#firstelement) +- [`firstOrError`](#firstorerror) +- [`ignoreElement`](#ignoreelement) +- [`ignoreElements`](#ignoreelements) +- [`last`](#last) +- [`lastElement`](#lastelement) +- [`lastOrError`](#lastorerror) +- [`ofType`](#oftype) +- [`sample`](#sample) +- [`skip`](#skip) +- [`skipLast`](#skiplast) +- [`take`](#take) +- [`takeLast`](#takelast) +- [`throttleFirst`](#throttlefirst) +- [`throttleLast`](#throttlelast) +- [`throttleLatest`](#throttlelatest) +- [`throttleWithTimeout`](#throttlewithtimeout) +- [`timeout`](#timeout) + +## debounce + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/debounce.html](http://reactivex.io/documentation/operators/debounce.html) + +Drops items emitted by a reactive source that are followed by newer items before the given timeout value expires. The timer resets on each emission. + +This operator keeps track of the most recent emitted item, and emits this item only when enough time has passed without the source emitting any other items. + +### debounce example + +```java +// Diagram: +// -A--------------B----C-D-------------------E-|----> +// a---------1s +// b---------1s +// c---------1s +// d---------1s +// e-|----> +// -----------A---------------------D-----------E-|--> + +Observable source = Observable.create(emitter -> { + emitter.onNext("A"); + + Thread.sleep(1_500); + emitter.onNext("B"); + + Thread.sleep(500); + emitter.onNext("C"); + + Thread.sleep(250); + emitter.onNext("D"); + + Thread.sleep(2_000); + emitter.onNext("E"); + emitter.onComplete(); +}); + +source.subscribeOn(Schedulers.io()) + .debounce(1, TimeUnit.SECONDS) + .blockingSubscribe( + item -> System.out.println("onNext: " + item), + Throwable::printStackTrace, + () -> System.out.println("onComplete")); + +// prints: +// onNext: A +// onNext: D +// onNext: E +// onComplete +``` + +## distinct + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/distinct.html](http://reactivex.io/documentation/operators/distinct.html) + +Filters a reactive source by only emitting items that are distinct by comparison from previous items. A `io.reactivex.functions.Function` can be specified that projects each item emitted by the source into a new value that will be used for comparison with previous projected values. + +### distinct example + +```java +Observable.just(2, 3, 4, 4, 2, 1) + .distinct() + .subscribe(System.out::println); + +// prints: +// 2 +// 3 +// 4 +// 1 +``` + +## distinctUntilChanged + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/distinct.html](http://reactivex.io/documentation/operators/distinct.html) + +Filters a reactive source by only emitting items that are distinct by comparison from their immediate predecessors. A `io.reactivex.functions.Function` can be specified that projects each item emitted by the source into a new value that will be used for comparison with previous projected values. Alternatively, a `io.reactivex.functions.BiPredicate` can be specified that is used as the comparator function to compare immediate predecessors with each other. + +### distinctUntilChanged example + +```java +Observable.just(1, 1, 2, 1, 2, 3, 3, 4) + .distinctUntilChanged() + .subscribe(System.out::println); + +// prints: +// 1 +// 2 +// 1 +// 2 +// 3 +// 4 +``` + +## elementAt + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/elementat.html](http://reactivex.io/documentation/operators/elementat.html) + +Emits the single item at the specified zero-based index in a sequence of emissions from a reactive source. A default item can be specified that will be emitted if the specified index is not within the sequence. + +### elementAt example + +```java +Observable source = Observable.generate(() -> 1L, (state, emitter) -> { + emitter.onNext(state); + + return state + 1L; +}).scan((product, x) -> product * x); + +Maybe element = source.elementAt(5); +element.subscribe(System.out::println); + +// prints 720 +``` + +## elementAtOrError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/elementat.html](http://reactivex.io/documentation/operators/elementat.html) + +Emits the single item at the specified zero-based index in a sequence of emissions from a reactive source, or signals a `java.util.NoSuchElementException` if the specified index is not within the sequence. + +### elementAtOrError example + +```java +Observable source = Observable.just("Kirk", "Spock", "Chekov", "Sulu"); +Single element = source.elementAtOrError(4); + +element.subscribe( + name -> System.out.println("onSuccess will not be printed!"), + error -> System.out.println("onError: " + error)); + +// prints: +// onError: java.util.NoSuchElementException +``` + +## filter + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/filter.html](http://reactivex.io/documentation/operators/filter.html) + +Filters items emitted by a reactive source by only emitting those that satisfy a specified predicate. + +### filter example + +```java +Observable.just(1, 2, 3, 4, 5, 6) + .filter(x -> x % 2 == 0) + .subscribe(System.out::println); + +// prints: +// 2 +// 4 +// 6 +``` + +## first + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/first.html](http://reactivex.io/documentation/operators/first.html) + +Emits only the first item emitted by a reactive source, or emits the given default item if the source completes without emitting an item. This differs from [`firstElement`](#firstelement) in that this operator returns a `Single` whereas [`firstElement`](#firstelement) returns a `Maybe`. + +### first example + +```java +Observable source = Observable.just("A", "B", "C"); +Single firstOrDefault = source.first("D"); + +firstOrDefault.subscribe(System.out::println); + +// prints A +``` + +## firstElement + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/first.html](http://reactivex.io/documentation/operators/first.html) + +Emits only the first item emitted by a reactive source, or just completes if the source completes without emitting an item. This differs from [`first`](#first) in that this operator returns a `Maybe` whereas [`first`](#first) returns a `Single`. + +### firstElement example + +```java +Observable source = Observable.just("A", "B", "C"); +Maybe first = source.firstElement(); + +first.subscribe(System.out::println); + +// prints A +``` + +## firstOrError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/first.html](http://reactivex.io/documentation/operators/first.html) + +Emits only the first item emitted by a reactive source, or signals a `java.util.NoSuchElementException` if the source completes without emitting an item. + +### firstOrError example + +```java +Observable emptySource = Observable.empty(); +Single firstOrError = emptySource.firstOrError(); + +firstOrError.subscribe( + element -> System.out.println("onSuccess will not be printed!"), + error -> System.out.println("onError: " + error)); + +// prints: +// onError: java.util.NoSuchElementException +``` + +## ignoreElement + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/ignoreelements.html](http://reactivex.io/documentation/operators/ignoreelements.html) + +Ignores the single item emitted by a `Single` or `Maybe` source, and returns a `Completable` that signals only the error or completion event from the the source. + +### ignoreElement example + +```java +Single source = Single.timer(1, TimeUnit.SECONDS); +Completable completable = source.ignoreElement(); + +completable.doOnComplete(() -> System.out.println("Done!")) + .blockingAwait(); + +// prints (after 1 second): +// Done! +``` + +## ignoreElements + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/ignoreelements.html](http://reactivex.io/documentation/operators/ignoreelements.html) + +Ignores all items from the `Observable` or `Flowable` source, and returns a `Completable` that signals only the error or completion event from the source. + +### ignoreElements example + +```java +Observable source = Observable.intervalRange(1, 5, 1, 1, TimeUnit.SECONDS); +Completable completable = source.ignoreElements(); + +completable.doOnComplete(() -> System.out.println("Done!")) + .blockingAwait(); + +// prints (after 5 seconds): +// Done! +``` + +## last + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/last.html](http://reactivex.io/documentation/operators/last.html) + +Emits only the last item emitted by a reactive source, or emits the given default item if the source completes without emitting an item. This differs from [`lastElement`](#lastelement) in that this operator returns a `Single` whereas [`lastElement`](#lastelement) returns a `Maybe`. + +### last example + +```java +Observable source = Observable.just("A", "B", "C"); +Single lastOrDefault = source.last("D"); + +lastOrDefault.subscribe(System.out::println); + +// prints C +``` + +## lastElement + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/last.html](http://reactivex.io/documentation/operators/last.html) + +Emits only the last item emitted by a reactive source, or just completes if the source completes without emitting an item. This differs from [`last`](#last) in that this operator returns a `Maybe` whereas [`last`](#last) returns a `Single`. + +### lastElement example + +```java +Observable source = Observable.just("A", "B", "C"); +Maybe last = source.lastElement(); + +last.subscribe(System.out::println); + +// prints C +``` + +## lastOrError + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/last.html](http://reactivex.io/documentation/operators/last.html) + +Emits only the last item emitted by a reactive source, or signals a `java.util.NoSuchElementException` if the source completes without emitting an item. + +### lastOrError example + +```java +Observable emptySource = Observable.empty(); +Single lastOrError = emptySource.lastOrError(); + +lastOrError.subscribe( + element -> System.out.println("onSuccess will not be printed!"), + error -> System.out.println("onError: " + error)); + +// prints: +// onError: java.util.NoSuchElementException +``` + +## ofType + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/filter.html](http://reactivex.io/documentation/operators/filter.html) + +Filters items emitted by a reactive source by only emitting those of the specified type. + +### ofType example + +```java +Observable numbers = Observable.just(1, 4.0, 3, 2.71, 2f, 7); +Observable integers = numbers.ofType(Integer.class); + +integers.subscribe((Integer x) -> System.out.println(x)); + +// prints: +// 1 +// 3 +// 7 +``` + +## sample + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/sample.html](http://reactivex.io/documentation/operators/sample.html) + +Filters items emitted by a reactive source by only emitting the most recently emitted item within periodic time intervals. + +### sample example + +```java +// Diagram: +// -A----B-C-------D-----E-|--> +// -0s-----c--1s---d----2s-|--> +// -----------C---------D--|--> + +Observable source = Observable.create(emitter -> { + emitter.onNext("A"); + + Thread.sleep(500); + emitter.onNext("B"); + + Thread.sleep(200); + emitter.onNext("C"); + + Thread.sleep(800); + emitter.onNext("D"); + + Thread.sleep(600); + emitter.onNext("E"); + emitter.onComplete(); +}); + +source.subscribeOn(Schedulers.io()) + .sample(1, TimeUnit.SECONDS) + .blockingSubscribe( + item -> System.out.println("onNext: " + item), + Throwable::printStackTrace, + () -> System.out.println("onComplete")); + +// prints: +// onNext: C +// onNext: D +// onComplete +``` + +## skip + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/skip.html](http://reactivex.io/documentation/operators/skip.html) + +Drops the first *n* items emitted by a reactive source, and emits the remaining items. + +### skip example + +```java +Observable source = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + +source.skip(4) + .subscribe(System.out::println); + +// prints: +// 5 +// 6 +// 7 +// 8 +// 9 +// 10 +``` + +## skipLast + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/skiplast.html](http://reactivex.io/documentation/operators/skiplast.html) + +Drops the last *n* items emitted by a reactive source, and emits the remaining items. + +### skipLast example + +```java +Observable source = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + +source.skipLast(4) + .subscribe(System.out::println); + +// prints: +// 1 +// 2 +// 3 +// 4 +// 5 +// 6 +``` + +## take + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/take.html](http://reactivex.io/documentation/operators/take.html) + +Emits only the first *n* items emitted by a reactive source. + +### take example + +```java +Observable source = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + +source.take(4) + .subscribe(System.out::println); + +// prints: +// 1 +// 2 +// 3 +// 4 +``` + +## takeLast + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/takelast.html](http://reactivex.io/documentation/operators/takelast.html) + +Emits only the last *n* items emitted by a reactive source. + +### takeLast example + +```java +Observable source = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + +source.takeLast(4) + .subscribe(System.out::println); + +// prints: +// 7 +// 8 +// 9 +// 10 +``` + +## throttleFirst + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/sample.html](http://reactivex.io/documentation/operators/sample.html) + +Emits only the first item emitted by a reactive source during sequential time windows of a specified duration. + +### throttleFirst example + +```java +// Diagram: +// -A----B-C-------D-----E-|--> +// a---------1s +// d-------|--> +// -A--------------D-------|--> + +Observable source = Observable.create(emitter -> { + emitter.onNext("A"); + + Thread.sleep(500); + emitter.onNext("B"); + + Thread.sleep(200); + emitter.onNext("C"); + + Thread.sleep(800); + emitter.onNext("D"); + + Thread.sleep(600); + emitter.onNext("E"); + emitter.onComplete(); +}); + +source.subscribeOn(Schedulers.io()) + .throttleFirst(1, TimeUnit.SECONDS) + .blockingSubscribe( + item -> System.out.println("onNext: " + item), + Throwable::printStackTrace, + () -> System.out.println("onComplete")); + +// prints: +// onNext: A +// onNext: D +// onComplete +``` + +## throttleLast + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/sample.html](http://reactivex.io/documentation/operators/sample.html) + +Emits only the last item emitted by a reactive source during sequential time windows of a specified duration. + +### throttleLast example + +```java +// Diagram: +// -A----B-C-------D-----E-|--> +// -0s-----c--1s---d----2s-|--> +// -----------C---------D--|--> + +Observable source = Observable.create(emitter -> { + emitter.onNext("A"); + + Thread.sleep(500); + emitter.onNext("B"); + + Thread.sleep(200); + emitter.onNext("C"); + + Thread.sleep(800); + emitter.onNext("D"); + + Thread.sleep(600); + emitter.onNext("E"); + emitter.onComplete(); +}); + +source.subscribeOn(Schedulers.io()) + .throttleLast(1, TimeUnit.SECONDS) + .blockingSubscribe( + item -> System.out.println("onNext: " + item), + Throwable::printStackTrace, + () -> System.out.println("onComplete")); + +// prints: +// onNext: C +// onNext: D +// onComplete +``` + +## throttleLatest + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/sample.html](http://reactivex.io/documentation/operators/sample.html) + +Emits the next item emitted by a reactive source, then periodically emits the latest item (if any) when the specified timeout elapses between them. + +### throttleLatest example + +```java +// Diagram: +// -A----B-C-------D-----E-|--> +// -a------c--1s +// -----d----1s +// -e-|--> +// -A---------C---------D--|--> + +Observable source = Observable.create(emitter -> { + emitter.onNext("A"); + + Thread.sleep(500); + emitter.onNext("B"); + + Thread.sleep(200); + emitter.onNext("C"); + + Thread.sleep(800); + emitter.onNext("D"); + + Thread.sleep(600); + emitter.onNext("E"); + emitter.onComplete(); +}); + +source.subscribeOn(Schedulers.io()) + .throttleLatest(1, TimeUnit.SECONDS) + .blockingSubscribe( + item -> System.out.println("onNext: " + item), + Throwable::printStackTrace, + () -> System.out.println("onComplete")); + +// prints: +// onNext: A +// onNext: C +// onNext: D +// onComplete +``` + +## throttleWithTimeout + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_off.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/debounce.html](http://reactivex.io/documentation/operators/debounce.html) + +> Alias to [debounce](#debounce) + +Drops items emitted by a reactive source that are followed by newer items before the given timeout value expires. The timer resets on each emission. + +### throttleWithTimeout example + +```java +// Diagram: +// -A--------------B----C-D-------------------E-|----> +// a---------1s +// b---------1s +// c---------1s +// d---------1s +// e-|----> +// -----------A---------------------D-----------E-|--> + +Observable source = Observable.create(emitter -> { + emitter.onNext("A"); + + Thread.sleep(1_500); + emitter.onNext("B"); + + Thread.sleep(500); + emitter.onNext("C"); + + Thread.sleep(250); + emitter.onNext("D"); + + Thread.sleep(2_000); + emitter.onNext("E"); + emitter.onComplete(); +}); + +source.subscribeOn(Schedulers.io()) + .throttleWithTimeout(1, TimeUnit.SECONDS) + .blockingSubscribe( + item -> System.out.println("onNext: " + item), + Throwable::printStackTrace, + () -> System.out.println("onComplete")); + +// prints: +// onNext: A +// onNext: D +// onNext: E +// onComplete +``` + +## timeout + +**Available in:** ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Flowable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Observable`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Maybe`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Single`, ![image](https://raw.github.com/wiki/ReactiveX/RxJava/images/checkmark_on.png) `Completable` + +**ReactiveX documentation:** [http://reactivex.io/documentation/operators/timeout.html](http://reactivex.io/documentation/operators/timeout.html) + +Emits the items from the `Observable` or `Flowable` source, but terminates with a `java.util.concurrent.TimeoutException` if the next item is not emitted within the specified timeout duration starting from the previous item. For `Maybe`, `Single` and `Completable` the specified timeout duration specifies the maximum time to wait for a success or completion event to arrive. If the `Maybe`, `Single` or `Completable` does not complete within the given time a `java.util.concurrent.TimeoutException` will be emitted. + +### timeout example + +```java +// Diagram: +// -A-------B---C-----------D-|--> +// a---------1s +// b---------1s +// c---------1s +// -A-------B---C---------X------> + +Observable source = Observable.create(emitter -> { + emitter.onNext("A"); + + Thread.sleep(800); + emitter.onNext("B"); + + Thread.sleep(400); + emitter.onNext("C"); + + Thread.sleep(1200); + emitter.onNext("D"); + emitter.onComplete(); +}); + +source.timeout(1, TimeUnit.SECONDS) + .subscribe( + item -> System.out.println("onNext: " + item), + error -> System.out.println("onError: " + error), + () -> System.out.println("onComplete will not be printed!")); + +// prints: +// onNext: A +// onNext: B +// onNext: C +// onError: java.util.concurrent.TimeoutException: The source did not signal an event for 1 seconds and has been terminated. +``` From 913e80046194b2f679e4213335c7a17cfa74c1e0 Mon Sep 17 00:00:00 2001 From: lorenzpahl Date: Wed, 19 Dec 2018 10:57:54 +0100 Subject: [PATCH 117/211] Fix: use correct return type in Javadoc documentation (#6344) --- src/main/java/io/reactivex/Flowable.java | 8 ++++---- src/main/java/io/reactivex/Observable.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 1115eba74e..77964b0fad 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -9289,7 +9289,7 @@ public final Maybe elementAt(long index) { } /** - * Returns a Flowable that emits the item found at a specified index in a sequence of emissions from + * Returns a Single that emits the item found at a specified index in a sequence of emissions from * this Flowable, or a default item if that index is out of range. *

      * @@ -9305,7 +9305,7 @@ public final Maybe elementAt(long index) { * the zero-based index of the item to retrieve * @param defaultItem * the default item - * @return a Flowable that emits the item at the specified position in the sequence emitted by the source + * @return a Single that emits the item at the specified position in the sequence emitted by the source * Publisher, or the default item if that index is outside the bounds of the source sequence * @throws IndexOutOfBoundsException * if {@code index} is less than 0 @@ -9323,7 +9323,7 @@ public final Single elementAt(long index, T defaultItem) { } /** - * Returns a Flowable that emits the item found at a specified index in a sequence of emissions from + * Returns a Single that emits the item found at a specified index in a sequence of emissions from * this Flowable or signals a {@link NoSuchElementException} if this Flowable has fewer elements than index. *

      * @@ -9337,7 +9337,7 @@ public final Single elementAt(long index, T defaultItem) { * * @param index * the zero-based index of the item to retrieve - * @return a Flowable that emits the item at the specified position in the sequence emitted by the source + * @return a Single that emits the item at the specified position in the sequence emitted by the source * Publisher, or the default item if that index is outside the bounds of the source sequence * @throws IndexOutOfBoundsException * if {@code index} is less than 0 diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index ef177b5c6a..541c20b1f4 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -9507,7 +9507,7 @@ public final Maybe lastElement() { * * @param defaultItem * the default item to emit if the source ObservableSource is empty - * @return an Observable that emits only the last item emitted by the source ObservableSource, or a default item + * @return a Single that emits only the last item emitted by the source ObservableSource, or a default item * if the source ObservableSource is empty * @see ReactiveX operators documentation: Last */ From 3481ed1eee9bbdda77435d2c5f698c714ea2fea3 Mon Sep 17 00:00:00 2001 From: Abhimithra Karthikeya Date: Wed, 19 Dec 2018 15:53:43 +0530 Subject: [PATCH 118/211] Adding NonNull annotation (#6313) --- src/main/java/io/reactivex/Completable.java | 56 ++++++ src/main/java/io/reactivex/Flowable.java | 210 ++++++++++++++++++++ src/main/java/io/reactivex/Maybe.java | 101 ++++++++++ src/main/java/io/reactivex/Observable.java | 49 +++++ src/main/java/io/reactivex/Single.java | 87 ++++++++ 5 files changed, 503 insertions(+) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 948d8aecde..9d8325e3b6 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -118,6 +118,7 @@ public abstract class Completable implements CompletableSource { * @throws NullPointerException if sources is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable ambArray(final CompletableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -146,6 +147,7 @@ public static Completable ambArray(final CompletableSource... sources) { * @throws NullPointerException if sources is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable amb(final Iterable sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -164,6 +166,7 @@ public static Completable amb(final Iterable source * @return a Completable instance that completes immediately */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable complete() { return RxJavaPlugins.onAssembly(CompletableEmpty.INSTANCE); @@ -182,6 +185,7 @@ public static Completable complete() { * @throws NullPointerException if sources is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable concatArray(CompletableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -207,6 +211,7 @@ public static Completable concatArray(CompletableSource... sources) { * @throws NullPointerException if sources is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable concat(Iterable sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -253,6 +258,7 @@ public static Completable concat(Publisher sources) * @throws NullPointerException if sources is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.FULL) public static Completable concat(Publisher sources, int prefetch) { @@ -297,6 +303,7 @@ public static Completable concat(Publisher sources, * @see Cancellable */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable create(CompletableOnSubscribe source) { ObjectHelper.requireNonNull(source, "source is null"); @@ -319,6 +326,7 @@ public static Completable create(CompletableOnSubscribe source) { * @throws NullPointerException if source is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable unsafeCreate(CompletableSource source) { ObjectHelper.requireNonNull(source, "source is null"); @@ -340,6 +348,7 @@ public static Completable unsafeCreate(CompletableSource source) { * @return the Completable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable defer(final Callable completableSupplier) { ObjectHelper.requireNonNull(completableSupplier, "completableSupplier"); @@ -363,6 +372,7 @@ public static Completable defer(final Callable comp * @throws NullPointerException if errorSupplier is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable error(final Callable errorSupplier) { ObjectHelper.requireNonNull(errorSupplier, "errorSupplier is null"); @@ -382,6 +392,7 @@ public static Completable error(final Callable errorSupplie * @throws NullPointerException if error is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable error(final Throwable error) { ObjectHelper.requireNonNull(error, "error is null"); @@ -409,6 +420,7 @@ public static Completable error(final Throwable error) { * @throws NullPointerException if run is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable fromAction(final Action run) { ObjectHelper.requireNonNull(run, "run is null"); @@ -435,6 +447,7 @@ public static Completable fromAction(final Action run) { * @return the new Completable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable fromCallable(final Callable callable) { ObjectHelper.requireNonNull(callable, "callable is null"); @@ -455,6 +468,7 @@ public static Completable fromCallable(final Callable callable) { * @return the new Completable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable fromFuture(final Future future) { ObjectHelper.requireNonNull(future, "future is null"); @@ -479,6 +493,7 @@ public static Completable fromFuture(final Future future) { * @since 2.2 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable fromMaybe(final MaybeSource maybe) { ObjectHelper.requireNonNull(maybe, "maybe is null"); @@ -499,6 +514,7 @@ public static Completable fromMaybe(final MaybeSource maybe) { * @throws NullPointerException if run is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable fromRunnable(final Runnable run) { ObjectHelper.requireNonNull(run, "run is null"); @@ -520,6 +536,7 @@ public static Completable fromRunnable(final Runnable run) { * @throws NullPointerException if flowable is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable fromObservable(final ObservableSource observable) { ObjectHelper.requireNonNull(observable, "observable is null"); @@ -556,6 +573,7 @@ public static Completable fromObservable(final ObservableSource observabl * @see #create(CompletableOnSubscribe) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public static Completable fromPublisher(final Publisher publisher) { @@ -578,6 +596,7 @@ public static Completable fromPublisher(final Publisher publisher) { * @throws NullPointerException if single is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable fromSingle(final SingleSource single) { ObjectHelper.requireNonNull(single, "single is null"); @@ -612,6 +631,7 @@ public static Completable fromSingle(final SingleSource single) { * @see #mergeArrayDelayError(CompletableSource...) */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable mergeArray(CompletableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -652,6 +672,7 @@ public static Completable mergeArray(CompletableSource... sources) { * @see #mergeDelayError(Iterable) */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable merge(Iterable sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -753,6 +774,7 @@ public static Completable merge(Publisher sources, * @throws IllegalArgumentException if maxConcurrency is less than 1 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.FULL) private static Completable merge0(Publisher sources, int maxConcurrency, boolean delayErrors) { @@ -776,6 +798,7 @@ private static Completable merge0(Publisher sources * @throws NullPointerException if sources is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable mergeArrayDelayError(CompletableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -797,6 +820,7 @@ public static Completable mergeArrayDelayError(CompletableSource... sources) { * @throws NullPointerException if sources is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable mergeDelayError(Iterable sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -902,6 +926,7 @@ public static Completable timer(long delay, TimeUnit unit) { * @return the new Completable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Completable timer(final long delay, final TimeUnit unit, final Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); @@ -968,6 +993,7 @@ public static Completable using(Callable resourceSupplier, * @return the new Completable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable using( final Callable resourceSupplier, @@ -995,6 +1021,7 @@ public static Completable using( * @throws NullPointerException if source is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable wrap(CompletableSource source) { ObjectHelper.requireNonNull(source, "source is null"); @@ -1019,6 +1046,7 @@ public static Completable wrap(CompletableSource source) { * @throws NullPointerException if other is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable ambWith(CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -1042,6 +1070,7 @@ public final Completable ambWith(CompletableSource other) { * @throws NullPointerException if next is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Observable andThen(ObservableSource next) { ObjectHelper.requireNonNull(next, "next is null"); @@ -1068,6 +1097,7 @@ public final Observable andThen(ObservableSource next) { * @throws NullPointerException if next is null */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable andThen(Publisher next) { @@ -1092,6 +1122,7 @@ public final Flowable andThen(Publisher next) { * @return Single that composes this Completable and next */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single andThen(SingleSource next) { ObjectHelper.requireNonNull(next, "next is null"); @@ -1115,6 +1146,7 @@ public final Single andThen(SingleSource next) { * @return Maybe that composes this Completable and next */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe andThen(MaybeSource next) { ObjectHelper.requireNonNull(next, "next is null"); @@ -1207,6 +1239,7 @@ public final void blockingAwait() { * @throws RuntimeException wrapping an InterruptedException if the current thread is interrupted */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final boolean blockingAwait(long timeout, TimeUnit unit) { ObjectHelper.requireNonNull(unit, "unit is null"); @@ -1320,6 +1353,7 @@ public final Completable compose(CompletableTransformer transformer) { * @see #andThen(Publisher) */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable concatWith(CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -1383,6 +1417,7 @@ public final Completable delay(long delay, TimeUnit unit, Scheduler scheduler) { * @throws NullPointerException if unit or scheduler is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Completable delay(final long delay, final TimeUnit unit, final Scheduler scheduler, final boolean delayError) { ObjectHelper.requireNonNull(unit, "unit is null"); @@ -1514,6 +1549,7 @@ public final Completable doOnError(Consumer onError) { * @throws NullPointerException if onEvent is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable doOnEvent(final Consumer onEvent) { ObjectHelper.requireNonNull(onEvent, "onEvent is null"); @@ -1535,6 +1571,7 @@ public final Completable doOnEvent(final Consumer onEvent) { * @return the new Completable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) private Completable doOnLifecycle( final Consumer onSubscribe, @@ -1639,6 +1676,7 @@ public final Completable doAfterTerminate(final Action onAfterTerminate) { * @since 2.1 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable doFinally(Action onFinally) { ObjectHelper.requireNonNull(onFinally, "onFinally is null"); @@ -1776,6 +1814,7 @@ public final Completable doFinally(Action onFinally) { * @see #compose(CompletableTransformer) */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable lift(final CompletableOperator onLift) { ObjectHelper.requireNonNull(onLift, "onLift is null"); @@ -1817,6 +1856,7 @@ public final Single> materialize() { * @throws NullPointerException if other is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable mergeWith(CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -1836,6 +1876,7 @@ public final Completable mergeWith(CompletableSource other) { * @throws NullPointerException if scheduler is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Completable observeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); @@ -1873,6 +1914,7 @@ public final Completable onErrorComplete() { * @return the new Completable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable onErrorComplete(final Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); @@ -1895,6 +1937,7 @@ public final Completable onErrorComplete(final Predicate pred * @return the new Completable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable onErrorResumeNext(final Function errorMapper) { ObjectHelper.requireNonNull(errorMapper, "errorMapper is null"); @@ -2153,6 +2196,7 @@ public final Completable retryWhen(Function, ? exten * @throws NullPointerException if other is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable startWith(CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -2174,6 +2218,7 @@ public final Completable startWith(CompletableSource other) { * @throws NullPointerException if other is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Observable startWith(Observable other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -2197,6 +2242,7 @@ public final Observable startWith(Observable other) { * @throws NullPointerException if other is null */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable startWith(Publisher other) { @@ -2319,6 +2365,7 @@ public final E subscribeWith(E observer) { * @throws NullPointerException if either callback is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(final Action onComplete, final Consumer onError) { ObjectHelper.requireNonNull(onError, "onError is null"); @@ -2346,6 +2393,7 @@ public final Disposable subscribe(final Action onComplete, final Consumer Observable toObservable() { * @throws NullPointerException if completionValueSupplier is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single toSingle(final Callable completionValueSupplier) { ObjectHelper.requireNonNull(completionValueSupplier, "completionValueSupplier is null"); @@ -2646,6 +2700,7 @@ public final Single toSingle(final Callable completionValueS * @throws NullPointerException if completionValue is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single toSingleDefault(final T completionValue) { ObjectHelper.requireNonNull(completionValue, "completionValue is null"); @@ -2666,6 +2721,7 @@ public final Single toSingleDefault(final T completionValue) { * @throws NullPointerException if scheduler is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Completable unsubscribeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 77964b0fad..0b33a191a2 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -87,6 +87,7 @@ public abstract class Flowable implements Publisher { * @see ReactiveX operators documentation: Amb */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable amb(Iterable> sources) { @@ -116,6 +117,7 @@ public static Flowable amb(Iterable> sou * @see ReactiveX operators documentation: Amb */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable ambArray(Publisher... sources) { @@ -269,6 +271,7 @@ public static Flowable combineLatest(Function Flowable combineLatest(Publisher[] sources, Function combiner, int bufferSize) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -366,6 +369,7 @@ public static Flowable combineLatest(Iterable Flowable combineLatest(Iterable> sources, Function combiner, int bufferSize) { @@ -556,6 +560,7 @@ public static Flowable combineLatestDelayError(Function Flowable combineLatestDelayError(Publisher[] sources, Function combiner, int bufferSize) { @@ -747,6 +752,7 @@ public static Flowable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable combineLatest( @@ -799,6 +805,7 @@ public static Flowable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable combineLatest( @@ -855,6 +862,7 @@ public static Flowable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable combineLatest( @@ -916,6 +924,7 @@ public static Flowable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable combineLatest( @@ -981,6 +990,7 @@ public static Flowable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable combineLatest( @@ -1051,6 +1061,7 @@ public static Flowable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable combineLatest( @@ -1125,6 +1136,7 @@ public static Flowable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable combineLatest( @@ -1166,6 +1178,7 @@ public static Flowable combineLatest( */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable concat(Iterable> sources) { @@ -1261,6 +1274,7 @@ public static Flowable concat(Publisher> */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable concat(Publisher source1, Publisher source2) { @@ -1297,6 +1311,7 @@ public static Flowable concat(Publisher source1, Publisher Flowable concat( @@ -1338,6 +1353,7 @@ public static Flowable concat( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable concat( @@ -1470,6 +1486,7 @@ public static Flowable concatArrayEager(Publisher... sources * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -1564,6 +1581,7 @@ public static Flowable concatArrayEagerDelayError(int maxConcurrency, int */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable concatDelayError(Iterable> sources) { @@ -1668,6 +1686,7 @@ public static Flowable concatEager(Publisher Flowable concatEager(Iterable Flowable concatEager(Iterable Flowable create(FlowableOnSubscribe source, BackpressureStrategy mode) { @@ -1820,6 +1841,7 @@ public static Flowable create(FlowableOnSubscribe source, Backpressure * @see ReactiveX operators documentation: Defer */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable defer(Callable> supplier) { @@ -1874,6 +1896,7 @@ public static Flowable empty() { * @see ReactiveX operators documentation: Throw */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable error(Callable supplier) { @@ -1902,6 +1925,7 @@ public static Flowable error(Callable supplier) { * @see ReactiveX operators documentation: Throw */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable error(final Throwable throwable) { @@ -1929,6 +1953,7 @@ public static Flowable error(final Throwable throwable) { * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable fromArray(T... items) { @@ -1974,6 +1999,7 @@ public static Flowable fromArray(T... items) { * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable fromCallable(Callable supplier) { @@ -2010,6 +2036,7 @@ public static Flowable fromCallable(Callable supplier) { * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable fromFuture(Future future) { @@ -2050,6 +2077,7 @@ public static Flowable fromFuture(Future future) { * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable fromFuture(Future future, long timeout, TimeUnit unit) { @@ -2095,6 +2123,7 @@ public static Flowable fromFuture(Future future, long timeou */ @SuppressWarnings({ "unchecked", "cast" }) @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public static Flowable fromFuture(Future future, long timeout, TimeUnit unit, Scheduler scheduler) { @@ -2133,6 +2162,7 @@ public static Flowable fromFuture(Future future, long timeou */ @SuppressWarnings({ "cast", "unchecked" }) @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public static Flowable fromFuture(Future future, Scheduler scheduler) { @@ -2161,6 +2191,7 @@ public static Flowable fromFuture(Future future, Scheduler s * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable fromIterable(Iterable source) { @@ -2196,6 +2227,7 @@ public static Flowable fromIterable(Iterable source) { * @see #create(FlowableOnSubscribe, BackpressureStrategy) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") @@ -2230,6 +2262,7 @@ public static Flowable fromPublisher(final Publisher source) * @return the new Flowable instance */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable generate(final Consumer> generator) { @@ -2263,6 +2296,7 @@ public static Flowable generate(final Consumer> generator) { * @return the new Flowable instance */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable generate(Callable initialState, final BiConsumer> generator) { @@ -2297,6 +2331,7 @@ public static Flowable generate(Callable initialState, final BiCons * @return the new Flowable instance */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable generate(Callable initialState, final BiConsumer> generator, @@ -2363,6 +2398,7 @@ public static Flowable generate(Callable initialState, BiFunction Flowable generate(Callable initialState, BiFunction, S> generator, Consumer disposeState) { @@ -2432,6 +2468,7 @@ public static Flowable interval(long initialDelay, long period, TimeUnit u * @since 1.0.12 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public static Flowable interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { @@ -2539,6 +2576,7 @@ public static Flowable intervalRange(long start, long count, long initialD * @return the new Flowable instance */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public static Flowable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { @@ -2590,6 +2628,7 @@ public static Flowable intervalRange(long start, long count, long initialD * @see #fromIterable(Iterable) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item) { @@ -2619,6 +2658,7 @@ public static Flowable just(T item) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2) { @@ -2652,6 +2692,7 @@ public static Flowable just(T item1, T item2) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3) { @@ -2688,6 +2729,7 @@ public static Flowable just(T item1, T item2, T item3) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4) { @@ -2727,6 +2769,7 @@ public static Flowable just(T item1, T item2, T item3, T item4) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5) { @@ -2769,6 +2812,7 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5) */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6) { @@ -2814,6 +2858,7 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5, */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7) { @@ -2862,6 +2907,7 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5, */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8) { @@ -2913,6 +2959,7 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5, */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9) { @@ -2967,6 +3014,7 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5, */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9, T item10) { @@ -3357,6 +3405,7 @@ public static Flowable mergeArray(Publisher... sources) { */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable merge(Publisher source1, Publisher source2) { @@ -3406,6 +3455,7 @@ public static Flowable merge(Publisher source1, Publisher Flowable merge(Publisher source1, Publisher source2, Publisher source3) { @@ -3458,6 +3508,7 @@ public static Flowable merge(Publisher source1, Publisher Flowable merge( @@ -3767,6 +3818,7 @@ public static Flowable mergeArrayDelayError(Publisher... sou */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable mergeDelayError(Publisher source1, Publisher source2) { @@ -3809,6 +3861,7 @@ public static Flowable mergeDelayError(Publisher source1, Pu */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable mergeDelayError(Publisher source1, Publisher source2, Publisher source3) { @@ -3854,6 +3907,7 @@ public static Flowable mergeDelayError(Publisher source1, Pu */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable mergeDelayError( @@ -4069,6 +4123,7 @@ public static Single sequenceEqual(Publisher source1, * @see ReactiveX operators documentation: SequenceEqual */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Single sequenceEqual(Publisher source1, Publisher source2, @@ -4319,6 +4374,7 @@ public static Flowable timer(long delay, TimeUnit unit) { * @see ReactiveX operators documentation: Timer */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public static Flowable timer(long delay, TimeUnit unit, Scheduler scheduler) { @@ -4347,6 +4403,7 @@ public static Flowable timer(long delay, TimeUnit unit, Scheduler schedule * instead. */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.NONE) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable unsafeCreate(Publisher onSubscribe) { @@ -4420,6 +4477,7 @@ public static Flowable using(Callable resourceSupplier, * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable using(Callable resourceSupplier, @@ -4476,6 +4534,7 @@ public static Flowable using(Callable resourceSupplier, * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip(Iterable> sources, Function zipper) { @@ -4530,6 +4589,7 @@ public static Flowable zip(Iterable> */ @SuppressWarnings({ "rawtypes", "unchecked", "cast" }) @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip(Publisher> sources, @@ -4588,6 +4648,7 @@ public static Flowable zip(Publisher> */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -4649,6 +4710,7 @@ public static Flowable zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -4711,6 +4773,7 @@ public static Flowable zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -4775,6 +4838,7 @@ public static Flowable zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -4843,6 +4907,7 @@ public static Flowable zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -4916,6 +4981,7 @@ public static Flowable zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -4992,6 +5058,7 @@ public static Flowable zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -5072,6 +5139,7 @@ public static Flowable zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -5157,6 +5225,7 @@ public static Flowable zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -5246,6 +5315,7 @@ public static Flowable zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zip( @@ -5316,6 +5386,7 @@ public static Flowable zip( * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zipArray(Function zipper, @@ -5378,6 +5449,7 @@ public static Flowable zipArray(FunctionReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable zipIterable(Iterable> sources, @@ -5413,6 +5485,7 @@ public static Flowable zipIterable(IterableReactiveX operators documentation: All */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single all(Predicate predicate) { @@ -5442,6 +5515,7 @@ public final Single all(Predicate predicate) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable ambWith(Publisher other) { @@ -5473,6 +5547,7 @@ public final Flowable ambWith(Publisher other) { * @see ReactiveX operators documentation: Contains */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single any(Predicate predicate) { @@ -6203,6 +6278,7 @@ public final Flowable> buffer(int count, int skip) { * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final > Flowable buffer(int count, int skip, Callable bufferSupplier) { @@ -6352,6 +6428,7 @@ public final Flowable> buffer(long timespan, long timeskip, TimeUnit uni * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public final > Flowable buffer(long timespan, long timeskip, TimeUnit unit, @@ -6965,6 +7042,7 @@ public final Flowable cacheWithInitialCapacity(int initialCapacity) { * @see ReactiveX operators documentation: Map */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable cast(final Class clazz) { @@ -7002,6 +7080,7 @@ public final Flowable cast(final Class clazz) { * @see ReactiveX operators documentation: Reduce */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single collect(Callable initialItemSupplier, BiConsumer collector) { @@ -7040,6 +7119,7 @@ public final Single collect(Callable initialItemSupplier, Bi * @see ReactiveX operators documentation: Reduce */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single collectInto(final U initialItem, BiConsumer collector) { @@ -7137,6 +7217,7 @@ public final Flowable concatMap(FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable concatMap(Function> mapper, int prefetch) { @@ -7205,6 +7286,7 @@ public final Completable concatMapCompletable(Function mapper, int prefetch) { @@ -7307,6 +7389,7 @@ public final Completable concatMapCompletableDelayError(Function mapper, boolean tillTheEnd, int prefetch) { @@ -7370,6 +7453,7 @@ public final Flowable concatMapDelayError(Function Flowable concatMapDelayError(Function> mapper, @@ -7437,6 +7521,7 @@ public final Flowable concatMapEager(Function Flowable concatMapEager(Function> mapper, @@ -7506,6 +7591,7 @@ public final Flowable concatMapEagerDelayError(Function Flowable concatMapEagerDelayError(Function> mapper, @@ -7570,6 +7656,7 @@ public final Flowable concatMapIterable(FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable concatMapIterable(final Function> mapper, int prefetch) { @@ -7638,6 +7725,7 @@ public final Flowable concatMapMaybe(Function Flowable concatMapMaybe(Function> mapper, int prefetch) { @@ -7748,6 +7836,7 @@ public final Flowable concatMapMaybeDelayError(Function Flowable concatMapMaybeDelayError(Function> mapper, boolean tillTheEnd, int prefetch) { @@ -7816,6 +7905,7 @@ public final Flowable concatMapSingle(Function Flowable concatMapSingle(Function> mapper, int prefetch) { @@ -7926,6 +8016,7 @@ public final Flowable concatMapSingleDelayError(Function Flowable concatMapSingleDelayError(Function> mapper, boolean tillTheEnd, int prefetch) { @@ -7955,6 +8046,7 @@ public final Flowable concatMapSingleDelayError(FunctionReactiveX operators documentation: Concat */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable concatWith(Publisher other) { @@ -8059,6 +8151,7 @@ public final Flowable concatWith(@NonNull CompletableSource other) { * @see ReactiveX operators documentation: Contains */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single contains(final Object item) { @@ -8114,6 +8207,7 @@ public final Single count() { * @see RxJava wiki: Backpressure */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable debounce(Function> debounceIndicator) { @@ -8187,6 +8281,7 @@ public final Flowable debounce(long timeout, TimeUnit unit) { * @see #throttleWithTimeout(long, TimeUnit, Scheduler) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable debounce(long timeout, TimeUnit unit, Scheduler scheduler) { @@ -8217,6 +8312,7 @@ public final Flowable debounce(long timeout, TimeUnit unit, Scheduler schedul * @see ReactiveX operators documentation: DefaultIfEmpty */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable defaultIfEmpty(T defaultItem) { @@ -8252,6 +8348,7 @@ public final Flowable defaultIfEmpty(T defaultItem) { * @see ReactiveX operators documentation: Delay */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable delay(final Function> itemDelayIndicator) { @@ -8367,6 +8464,7 @@ public final Flowable delay(long delay, TimeUnit unit, Scheduler scheduler) { * @see ReactiveX operators documentation: Delay */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable delay(long delay, TimeUnit unit, Scheduler scheduler, boolean delayError) { @@ -8435,6 +8533,7 @@ public final Flowable delay(Publisher subscriptionIndicator, * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable delaySubscription(Publisher subscriptionIndicator) { @@ -8598,6 +8697,7 @@ public final Flowable dematerialize() { */ @Experimental @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.PASS_THROUGH) public final Flowable dematerialize(Function> selector) { @@ -9011,6 +9111,7 @@ public final Flowable doOnComplete(Action onComplete) { * @see ReactiveX operators documentation: Do */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) private Flowable doOnEach(Consumer onNext, Consumer onError, @@ -9040,6 +9141,7 @@ private Flowable doOnEach(Consumer onNext, ConsumerReactiveX operators documentation: Do */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable doOnEach(final Consumer> onNotification) { @@ -9076,6 +9178,7 @@ public final Flowable doOnEach(final Consumer> onNoti * @see ReactiveX operators documentation: Do */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable doOnEach(final Subscriber subscriber) { @@ -9138,6 +9241,7 @@ public final Flowable doOnError(Consumer onError) { * @see ReactiveX operators documentation: Do */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable doOnLifecycle(final Consumer onSubscribe, @@ -9312,6 +9416,7 @@ public final Maybe elementAt(long index) { * @see ReactiveX operators documentation: ElementAt */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single elementAt(long index, T defaultItem) { @@ -9373,6 +9478,7 @@ public final Single elementAtOrError(long index) { * @see ReactiveX operators documentation: Filter */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable filter(Predicate predicate) { @@ -9629,6 +9735,7 @@ public final Flowable flatMap(Function Flowable flatMap(Function> mapper, @@ -9677,6 +9784,7 @@ public final Flowable flatMap(FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable flatMap( @@ -9723,6 +9831,7 @@ public final Flowable flatMap( * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable flatMap( @@ -9893,6 +10002,7 @@ public final Flowable flatMap(Function Flowable flatMap(final Function> mapper, @@ -9981,6 +10091,7 @@ public final Completable flatMapCompletable(Function mapper, boolean delayErrors, int maxConcurrency) { @@ -10045,6 +10156,7 @@ public final Flowable flatMapIterable(final FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable flatMapIterable(final Function> mapper, int bufferSize) { @@ -10081,6 +10193,7 @@ public final Flowable flatMapIterable(final FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable flatMapIterable(final Function> mapper, @@ -10123,6 +10236,7 @@ public final Flowable flatMapIterable(final Function Flowable flatMapIterable(final Function> mapper, @@ -10172,6 +10286,7 @@ public final Flowable flatMapMaybe(Function Flowable flatMapMaybe(Function> mapper, boolean delayErrors, int maxConcurrency) { @@ -10220,6 +10335,7 @@ public final Flowable flatMapSingle(Function Flowable flatMapSingle(Function> mapper, boolean delayErrors, int maxConcurrency) { @@ -10340,6 +10456,7 @@ public final Disposable forEachWhile(Predicate onNext, ConsumerReactiveX operators documentation: Subscribe */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.NONE) @SchedulerSupport(SchedulerSupport.NONE) public final Disposable forEachWhile(final Predicate onNext, final Consumer onError, @@ -10611,6 +10728,7 @@ public final Flowable> groupBy(FunctionReactiveX operators documentation: GroupBy */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable> groupBy(Function keySelector, @@ -10723,6 +10841,7 @@ public final Flowable> groupBy(Function Flowable> groupBy(Function keySelector, @@ -10772,6 +10891,7 @@ public final Flowable> groupBy(FunctionReactiveX operators documentation: Join */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable groupJoin( @@ -10893,6 +11013,7 @@ public final Single isEmpty() { * @see ReactiveX operators documentation: Join */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable join( @@ -10950,6 +11071,7 @@ public final Maybe lastElement() { * @see ReactiveX operators documentation: Last */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single last(T defaultItem) { @@ -11127,6 +11249,7 @@ public final Single lastOrError() { * @see #compose(FlowableTransformer) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable lift(FlowableOperator lifter) { @@ -11201,6 +11324,7 @@ public final Flowable limit(long count) { * @see ReactiveX operators documentation: Map */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable map(Function mapper) { @@ -11254,6 +11378,7 @@ public final Flowable> materialize() { * @see ReactiveX operators documentation: Merge */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable mergeWith(Publisher other) { @@ -11281,6 +11406,7 @@ public final Flowable mergeWith(Publisher other) { * @since 2.2 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable mergeWith(@NonNull SingleSource other) { @@ -11309,6 +11435,7 @@ public final Flowable mergeWith(@NonNull SingleSource other) { * @since 2.2 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable mergeWith(@NonNull MaybeSource other) { @@ -11334,6 +11461,7 @@ public final Flowable mergeWith(@NonNull MaybeSource other) { * @since 2.2 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable mergeWith(@NonNull CompletableSource other) { @@ -11446,6 +11574,7 @@ public final Flowable observeOn(Scheduler scheduler, boolean delayError) { * @see #observeOn(Scheduler, boolean) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable observeOn(Scheduler scheduler, boolean delayError, int bufferSize) { @@ -11473,6 +11602,7 @@ public final Flowable observeOn(Scheduler scheduler, boolean delayError, int * @see ReactiveX operators documentation: Filter */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable ofType(final Class clazz) { @@ -11649,6 +11779,7 @@ public final Flowable onBackpressureBuffer(int capacity, boolean delayError, * @since 1.1.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onBackpressureBuffer(int capacity, boolean delayError, boolean unbounded, @@ -11720,6 +11851,7 @@ public final Flowable onBackpressureBuffer(int capacity, Action onOverflow) { * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onBackpressureBuffer(long capacity, Action onOverflow, BackpressureOverflowStrategy overflowStrategy) { @@ -11776,6 +11908,7 @@ public final Flowable onBackpressureDrop() { * @since 1.1.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onBackpressureDrop(Consumer onDrop) { @@ -11851,6 +11984,7 @@ public final Flowable onBackpressureLatest() { * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onErrorResumeNext(Function> resumeFunction) { @@ -11894,6 +12028,7 @@ public final Flowable onErrorResumeNext(FunctionReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onErrorResumeNext(final Publisher next) { @@ -11933,6 +12068,7 @@ public final Flowable onErrorResumeNext(final Publisher next) { * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onErrorReturn(Function valueSupplier) { @@ -11972,6 +12108,7 @@ public final Flowable onErrorReturn(Function * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onErrorReturnItem(final T item) { @@ -12018,6 +12155,7 @@ public final Flowable onErrorReturnItem(final T item) { * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onExceptionResumeNext(final Publisher next) { @@ -12226,6 +12364,7 @@ public final Flowable publish(Function, ? extends Pub * @see ReactiveX operators documentation: Publish */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable publish(Function, ? extends Publisher> selector, int prefetch) { @@ -12320,6 +12459,7 @@ public final Flowable rebatchRequests(int n) { * @see Wikipedia: Fold (higher-order function) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Maybe reduce(BiFunction reducer) { @@ -12381,6 +12521,7 @@ public final Maybe reduce(BiFunction reducer) { * @see #reduceWith(Callable, BiFunction) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single reduce(R seed, BiFunction reducer) { @@ -12425,6 +12566,7 @@ public final Single reduce(R seed, BiFunction reducer) { * @see Wikipedia: Fold (higher-order function) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single reduceWith(Callable seedSupplier, BiFunction reducer) { @@ -12512,6 +12654,7 @@ public final Flowable repeat(long times) { * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable repeatUntil(BooleanSupplier stop) { @@ -12542,6 +12685,7 @@ public final Flowable repeatUntil(BooleanSupplier stop) { * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable repeatWhen(final Function, ? extends Publisher> handler) { @@ -12600,6 +12744,7 @@ public final ConnectableFlowable replay() { * @see ReactiveX operators documentation: Replay */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable replay(Function, ? extends Publisher> selector) { @@ -12638,6 +12783,7 @@ public final Flowable replay(Function, ? extends Publ * @see ReactiveX operators documentation: Replay */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable replay(Function, ? extends Publisher> selector, final int bufferSize) { @@ -12728,6 +12874,7 @@ public final Flowable replay(Function, ? extends Publ * @see ReactiveX operators documentation: Replay */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable replay(Function, ? extends Publisher> selector, final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { @@ -12772,6 +12919,7 @@ public final Flowable replay(Function, ? extends Publ * @see ReactiveX operators documentation: Replay */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable replay(final Function, ? extends Publisher> selector, final int bufferSize, final Scheduler scheduler) { @@ -12851,6 +12999,7 @@ public final Flowable replay(Function, ? extends Publ * @see ReactiveX operators documentation: Replay */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable replay(Function, ? extends Publisher> selector, final long time, final TimeUnit unit, final Scheduler scheduler) { @@ -12887,6 +13036,7 @@ public final Flowable replay(Function, ? extends Publ * @see ReactiveX operators documentation: Replay */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable replay(final Function, ? extends Publisher> selector, final Scheduler scheduler) { @@ -13195,6 +13345,7 @@ public final Flowable retry() { * @see ReactiveX operators documentation: Retry */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable retry(BiPredicate predicate) { @@ -13252,6 +13403,7 @@ public final Flowable retry(long count) { * @return the new Flowable instance */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable retry(long times, Predicate predicate) { @@ -13296,6 +13448,7 @@ public final Flowable retry(Predicate predicate) { * @return the new Flowable instance */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable retryUntil(final BooleanSupplier stop) { @@ -13381,6 +13534,7 @@ public final Flowable retryUntil(final BooleanSupplier stop) { * @see ReactiveX operators documentation: Retry */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable retryWhen( @@ -13504,6 +13658,7 @@ public final Flowable sample(long period, TimeUnit unit, boolean emitLast) { * @see #throttleLast(long, TimeUnit, Scheduler) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable sample(long period, TimeUnit unit, Scheduler scheduler) { @@ -13544,6 +13699,7 @@ public final Flowable sample(long period, TimeUnit unit, Scheduler scheduler) * @since 2.1 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable sample(long period, TimeUnit unit, Scheduler scheduler, boolean emitLast) { @@ -13575,6 +13731,7 @@ public final Flowable sample(long period, TimeUnit unit, Scheduler scheduler, * @see RxJava wiki: Backpressure */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable sample(Publisher sampler) { @@ -13612,6 +13769,7 @@ public final Flowable sample(Publisher sampler) { * @since 2.1 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable sample(Publisher sampler, boolean emitLast) { @@ -13644,6 +13802,7 @@ public final Flowable sample(Publisher sampler, boolean emitLast) { * @see ReactiveX operators documentation: Scan */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable scan(BiFunction accumulator) { @@ -13697,6 +13856,7 @@ public final Flowable scan(BiFunction accumulator) { * @see ReactiveX operators documentation: Scan */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable scan(final R initialValue, BiFunction accumulator) { @@ -13736,6 +13896,7 @@ public final Flowable scan(final R initialValue, BiFunctionReactiveX operators documentation: Scan */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable scanWith(Callable seedSupplier, BiFunction accumulator) { @@ -13847,6 +14008,7 @@ public final Maybe singleElement() { * @see ReactiveX operators documentation: First */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single single(T defaultItem) { @@ -14168,6 +14330,7 @@ public final Flowable skipLast(long time, TimeUnit unit, Scheduler scheduler, * @see ReactiveX operators documentation: SkipLast */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable skipLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { @@ -14201,6 +14364,7 @@ public final Flowable skipLast(long time, TimeUnit unit, Scheduler scheduler, * @see ReactiveX operators documentation: SkipUntil */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable skipUntil(Publisher other) { @@ -14228,6 +14392,7 @@ public final Flowable skipUntil(Publisher other) { * @see ReactiveX operators documentation: SkipWhile */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable skipWhile(Predicate predicate) { @@ -14283,6 +14448,7 @@ public final Flowable sorted() { * @return a Flowable that emits the items emitted by the source Publisher in sorted order */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable sorted(Comparator sortFunction) { @@ -14340,6 +14506,7 @@ public final Flowable startWith(Iterable items) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable startWith(Publisher other) { @@ -14369,6 +14536,7 @@ public final Flowable startWith(Publisher other) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable startWith(T value) { @@ -14559,6 +14727,7 @@ public final Disposable subscribe(Consumer onNext, ConsumerReactiveX operators documentation: Subscribe */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Consumer onNext, Consumer onError, @@ -14719,6 +14888,7 @@ public final > E subscribeWith(E subscriber) { * @see #subscribeOn(Scheduler, boolean) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable subscribeOn(@NonNull Scheduler scheduler) { @@ -14756,6 +14926,7 @@ public final Flowable subscribeOn(@NonNull Scheduler scheduler) { * @since 2.2 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable subscribeOn(@NonNull Scheduler scheduler, boolean requestOn) { @@ -14786,6 +14957,7 @@ public final Flowable subscribeOn(@NonNull Scheduler scheduler, boolean reque * @since 1.1.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable switchIfEmpty(Publisher other) { @@ -14899,6 +15071,7 @@ public final Flowable switchMap(Function mapper) { @@ -14945,6 +15118,7 @@ public final Completable switchMapCompletable(@NonNull Function mapper) { @@ -15071,6 +15245,7 @@ Flowable switchMap0(Function> * @since 2.2 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable switchMapMaybe(@NonNull Function> mapper) { @@ -15101,6 +15276,7 @@ public final Flowable switchMapMaybe(@NonNull Function Flowable switchMapMaybeDelayError(@NonNull Function> mapper) { @@ -15141,6 +15317,7 @@ public final Flowable switchMapMaybeDelayError(@NonNull Function Flowable switchMapSingle(@NonNull Function> mapper) { @@ -15171,6 +15348,7 @@ public final Flowable switchMapSingle(@NonNull Function Flowable switchMapSingleDelayError(@NonNull Function> mapper) { @@ -15414,6 +15592,7 @@ public final Flowable takeLast(long count, long time, TimeUnit unit, Schedule * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable takeLast(long count, long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { @@ -15625,6 +15804,7 @@ public final Flowable takeLast(long time, TimeUnit unit, Scheduler scheduler, * @since 1.1.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable takeUntil(Predicate stopPredicate) { @@ -15654,6 +15834,7 @@ public final Flowable takeUntil(Predicate stopPredicate) { * @see ReactiveX operators documentation: TakeUntil */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable takeUntil(Publisher other) { @@ -15682,6 +15863,7 @@ public final Flowable takeUntil(Publisher other) { * @see Flowable#takeUntil(Predicate) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable takeWhile(Predicate predicate) { @@ -15746,6 +15928,7 @@ public final Flowable throttleFirst(long windowDuration, TimeUnit unit) { * @see RxJava wiki: Backpressure */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable throttleFirst(long skipDuration, TimeUnit unit, Scheduler scheduler) { @@ -15965,6 +16148,7 @@ public final Flowable throttleLatest(long timeout, TimeUnit unit, Scheduler s * @since 2.2 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable throttleLatest(long timeout, TimeUnit unit, Scheduler scheduler, boolean emitLast) { @@ -16218,6 +16402,7 @@ public final Flowable timeout(Function> * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable timeout(Function> itemTimeoutIndicator, Flowable other) { @@ -16280,6 +16465,7 @@ public final Flowable timeout(long timeout, TimeUnit timeUnit) { * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Flowable timeout(long timeout, TimeUnit timeUnit, Publisher other) { @@ -16316,6 +16502,7 @@ public final Flowable timeout(long timeout, TimeUnit timeUnit, PublisherReactiveX operators documentation: Timeout */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler, Publisher other) { @@ -16387,6 +16574,7 @@ public final Flowable timeout(long timeout, TimeUnit timeUnit, Scheduler sche * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable timeout(Publisher firstTimeoutIndicator, @@ -16432,6 +16620,7 @@ public final Flowable timeout(Publisher firstTimeoutIndicator, * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable timeout( @@ -16556,6 +16745,7 @@ public final Flowable> timestamp(TimeUnit unit) { * @see ReactiveX operators documentation: Timestamp */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps. public final Flowable> timestamp(final TimeUnit unit, final Scheduler scheduler) { @@ -16726,6 +16916,7 @@ public final > Single toList(Callable coll * @see ReactiveX operators documentation: To */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single> toMap(final Function keySelector) { @@ -16764,6 +16955,7 @@ public final Single> toMap(final Function * @see ReactiveX operators documentation: To */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single> toMap(final Function keySelector, final Function valueSelector) { @@ -16802,6 +16994,7 @@ public final Single> toMap(final FunctionReactiveX operators documentation: To */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single> toMap(final Function keySelector, @@ -16915,6 +17108,7 @@ public final Single>> toMultimap(FunctionReactiveX operators documentation: To */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single>> toMultimap( @@ -17046,6 +17240,7 @@ public final Single> toSortedList() { * @see ReactiveX operators documentation: To */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single> toSortedList(final Comparator comparator) { @@ -17081,6 +17276,7 @@ public final Single> toSortedList(final Comparator comparator * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public final Single> toSortedList(final Comparator comparator, int capacityHint) { @@ -17142,6 +17338,7 @@ public final Single> toSortedList(int capacityHint) { * @see ReactiveX operators documentation: SubscribeOn */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable unsubscribeOn(Scheduler scheduler) { @@ -17352,6 +17549,7 @@ public final Flowable> window(long timespan, long timeskip, TimeUnit * @see ReactiveX operators documentation: Window */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable> window(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler, int bufferSize) { @@ -17630,6 +17828,7 @@ public final Flowable> window(long timespan, TimeUnit unit, * @see ReactiveX operators documentation: Window */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.CUSTOM) public final Flowable> window( @@ -17698,6 +17897,7 @@ public final Flowable> window(Publisher boundaryIndicator) { * @see ReactiveX operators documentation: Window */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable> window(Publisher boundaryIndicator, int bufferSize) { @@ -17774,6 +17974,7 @@ public final Flowable> window( * @see ReactiveX operators documentation: Window */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable> window( @@ -17847,6 +18048,7 @@ public final Flowable> window(Callable> b * @see ReactiveX operators documentation: Window */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable> window(Callable> boundaryIndicatorSupplier, int bufferSize) { @@ -17884,6 +18086,7 @@ public final Flowable> window(Callable> b * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable withLatestFrom(Publisher other, @@ -17921,6 +18124,7 @@ public final Flowable withLatestFrom(Publisher other, * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable withLatestFrom(Publisher source1, Publisher source2, @@ -17960,6 +18164,7 @@ public final Flowable withLatestFrom(Publisher source1, Publi * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable withLatestFrom( @@ -18004,6 +18209,7 @@ public final Flowable withLatestFrom( * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable withLatestFrom( @@ -18042,6 +18248,7 @@ public final Flowable withLatestFrom( * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable withLatestFrom(Publisher[] others, Function combiner) { @@ -18074,6 +18281,7 @@ public final Flowable withLatestFrom(Publisher[] others, Function Flowable withLatestFrom(Iterable> others, Function combiner) { @@ -18113,6 +18321,7 @@ public final Flowable withLatestFrom(Iterable> oth * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable zipWith(Iterable other, BiFunction zipper) { @@ -18161,6 +18370,7 @@ public final Flowable zipWith(Iterable other, BiFunctionReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable zipWith(Publisher other, BiFunction zipper) { diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index b1d34260f1..773021a028 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -124,6 +124,7 @@ public abstract class Maybe implements MaybeSource { * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe amb(final Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -174,6 +175,7 @@ public static Maybe ambArray(final MaybeSource... sources) { */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Flowable concat(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -201,6 +203,7 @@ public static Flowable concat(Iterable */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Flowable concat(MaybeSource source1, MaybeSource source2) { @@ -232,6 +235,7 @@ public static Flowable concat(MaybeSource source1, MaybeSour */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Flowable concat( @@ -267,6 +271,7 @@ public static Flowable concat( */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Flowable concat( @@ -322,6 +327,7 @@ public static Flowable concat(Publisher Flowable concat(Publisher> sources, int prefetch) { @@ -346,6 +352,7 @@ public static Flowable concat(Publisher Flowable concatArray(MaybeSource... sources) { @@ -434,6 +441,7 @@ public static Flowable concatArrayEager(MaybeSource... sourc @SuppressWarnings({ "unchecked", "rawtypes" }) @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Flowable concatDelayError(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -557,6 +565,7 @@ public static Flowable concatEager(Publisher Maybe create(MaybeOnSubscribe onSubscribe) { ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); @@ -576,6 +585,7 @@ public static Maybe create(MaybeOnSubscribe onSubscribe) { * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe defer(final Callable> maybeSupplier) { ObjectHelper.requireNonNull(maybeSupplier, "maybeSupplier is null"); @@ -620,6 +630,7 @@ public static Maybe empty() { * @see ReactiveX operators documentation: Throw */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe error(Throwable exception) { ObjectHelper.requireNonNull(exception, "exception is null"); @@ -645,6 +656,7 @@ public static Maybe error(Throwable exception) { * @see ReactiveX operators documentation: Throw */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe error(Callable supplier) { ObjectHelper.requireNonNull(supplier, "errorSupplier is null"); @@ -671,6 +683,7 @@ public static Maybe error(Callable supplier) { * @throws NullPointerException if run is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromAction(final Action run) { ObjectHelper.requireNonNull(run, "run is null"); @@ -690,6 +703,7 @@ public static Maybe fromAction(final Action run) { * @throws NullPointerException if completable is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromCompletable(CompletableSource completableSource) { ObjectHelper.requireNonNull(completableSource, "completableSource is null"); @@ -709,6 +723,7 @@ public static Maybe fromCompletable(CompletableSource completableSource) * @throws NullPointerException if single is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromSingle(SingleSource singleSource) { ObjectHelper.requireNonNull(singleSource, "singleSource is null"); @@ -750,6 +765,7 @@ public static Maybe fromSingle(SingleSource singleSource) { * @return a new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromCallable(@NonNull final Callable callable) { ObjectHelper.requireNonNull(callable, "callable is null"); @@ -783,6 +799,7 @@ public static Maybe fromCallable(@NonNull final Callable cal * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromFuture(Future future) { ObjectHelper.requireNonNull(future, "future is null"); @@ -820,6 +837,7 @@ public static Maybe fromFuture(Future future) { * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromFuture(Future future, long timeout, TimeUnit unit) { ObjectHelper.requireNonNull(future, "future is null"); @@ -840,6 +858,7 @@ public static Maybe fromFuture(Future future, long timeout, * @throws NullPointerException if run is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromRunnable(final Runnable run) { ObjectHelper.requireNonNull(run, "run is null"); @@ -866,6 +885,7 @@ public static Maybe fromRunnable(final Runnable run) { * @see ReactiveX operators documentation: Just */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe just(T item) { ObjectHelper.requireNonNull(item, "item is null"); @@ -970,6 +990,7 @@ public static Flowable merge(Publisher */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) public static Flowable merge(Publisher> sources, int maxConcurrency) { @@ -1002,6 +1023,7 @@ public static Flowable merge(Publisher * @see ReactiveX operators documentation: Merge */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) public static Maybe merge(MaybeSource> source) { @@ -1047,6 +1069,7 @@ public static Maybe merge(MaybeSource> */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Flowable merge( @@ -1097,6 +1120,7 @@ public static Flowable merge( */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Flowable merge( @@ -1151,6 +1175,7 @@ public static Flowable merge( */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Flowable merge( @@ -1193,6 +1218,7 @@ public static Flowable merge( */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Flowable mergeArray(MaybeSource... sources) { @@ -1347,6 +1373,7 @@ public static Flowable mergeDelayError(Publisher Flowable mergeDelayError(Publisher> sources, int maxConcurrency) { ObjectHelper.requireNonNull(sources, "source is null"); @@ -1385,6 +1412,7 @@ public static Flowable mergeDelayError(Publisher Flowable mergeDelayError(MaybeSource source1, MaybeSource source2) { ObjectHelper.requireNonNull(source1, "source1 is null"); @@ -1426,6 +1454,7 @@ public static Flowable mergeDelayError(MaybeSource source1, @SuppressWarnings({ "unchecked" }) @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Flowable mergeDelayError(MaybeSource source1, MaybeSource source2, MaybeSource source3) { @@ -1471,6 +1500,7 @@ public static Flowable mergeDelayError(MaybeSource source1, @SuppressWarnings({ "unchecked" }) @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Flowable mergeDelayError( MaybeSource source1, MaybeSource source2, @@ -1554,6 +1584,7 @@ public static Single sequenceEqual(MaybeSource source1 * @see ReactiveX operators documentation: SequenceEqual */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single sequenceEqual(MaybeSource source1, MaybeSource source2, BiPredicate isEqual) { @@ -1604,6 +1635,7 @@ public static Maybe timer(long delay, TimeUnit unit) { * @see ReactiveX operators documentation: Timer */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Maybe timer(long delay, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); @@ -1624,6 +1656,7 @@ public static Maybe timer(long delay, TimeUnit unit, Scheduler scheduler) * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe unsafeCreate(MaybeSource onSubscribe) { if (onSubscribe instanceof Maybe) { @@ -1690,6 +1723,7 @@ public static Maybe using(Callable resourceSupplier, * @see ReactiveX operators documentation: Using */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe using(Callable resourceSupplier, Function> sourceSupplier, @@ -1712,6 +1746,7 @@ public static Maybe using(Callable resourceSupplier, * @return the Maybe wrapper or the source cast to Maybe (if possible) */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe wrap(MaybeSource source) { if (source instanceof Maybe) { @@ -1749,6 +1784,7 @@ public static Maybe wrap(MaybeSource source) { * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip(Iterable> sources, Function zipper) { ObjectHelper.requireNonNull(zipper, "zipper is null"); @@ -1783,6 +1819,7 @@ public static Maybe zip(Iterable> s */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, @@ -1822,6 +1859,7 @@ public static Maybe zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, @@ -1865,6 +1903,7 @@ public static Maybe zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, @@ -1913,6 +1952,7 @@ public static Maybe zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, @@ -1965,6 +2005,7 @@ public static Maybe zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, @@ -2021,6 +2062,7 @@ public static Maybe zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, @@ -2082,6 +2124,7 @@ public static Maybe zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, @@ -2147,6 +2190,7 @@ public static Maybe zip( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, @@ -2194,6 +2238,7 @@ public static Maybe zip( * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zipArray(Function zipper, MaybeSource... sources) { @@ -2227,6 +2272,7 @@ public static Maybe zipArray(Function z */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe ambWith(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -2335,6 +2381,7 @@ public final Maybe cache() { * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe cast(final Class clazz) { ObjectHelper.requireNonNull(clazz, "clazz is null"); @@ -2383,6 +2430,7 @@ public final Maybe compose(MaybeTransformer trans * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe concatMap(Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2409,6 +2457,7 @@ public final Maybe concatMap(Function concatWith(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -2432,6 +2481,7 @@ public final Flowable concatWith(MaybeSource other) { * @see ReactiveX operators documentation: Contains */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single contains(final Object item) { ObjectHelper.requireNonNull(item, "item is null"); @@ -2480,6 +2530,7 @@ public final Single count() { * @see ReactiveX operators documentation: DefaultIfEmpty */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe defaultIfEmpty(T defaultItem) { ObjectHelper.requireNonNull(defaultItem, "item is null"); @@ -2529,6 +2580,7 @@ public final Maybe delay(long delay, TimeUnit unit) { * @see ReactiveX operators documentation: Delay */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe delay(long delay, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); @@ -2559,6 +2611,7 @@ public final Maybe delay(long delay, TimeUnit unit, Scheduler scheduler) { * @see ReactiveX operators documentation: Delay */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) public final Maybe delay(Publisher delayIndicator) { @@ -2584,6 +2637,7 @@ public final Maybe delay(Publisher delayIndicator) { */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe delaySubscription(Publisher subscriptionIndicator) { ObjectHelper.requireNonNull(subscriptionIndicator, "subscriptionIndicator is null"); @@ -2652,6 +2706,7 @@ public final Maybe delaySubscription(long delay, TimeUnit unit, Scheduler sch * @since 2.1 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doAfterSuccess(Consumer onAfterSuccess) { ObjectHelper.requireNonNull(onAfterSuccess, "doAfterSuccess is null"); @@ -2676,6 +2731,7 @@ public final Maybe doAfterSuccess(Consumer onAfterSuccess) { * @see ReactiveX operators documentation: Do */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doAfterTerminate(Action onAfterTerminate) { return RxJavaPlugins.onAssembly(new MaybePeek(this, @@ -2705,6 +2761,7 @@ public final Maybe doAfterTerminate(Action onAfterTerminate) { * @since 2.1 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doFinally(Action onFinally) { ObjectHelper.requireNonNull(onFinally, "onFinally is null"); @@ -2723,6 +2780,7 @@ public final Maybe doFinally(Action onFinally) { * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnDispose(Action onDispose) { return RxJavaPlugins.onAssembly(new MaybePeek(this, @@ -2750,6 +2808,7 @@ public final Maybe doOnDispose(Action onDispose) { * @see ReactiveX operators documentation: Do */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnComplete(Action onComplete) { return RxJavaPlugins.onAssembly(new MaybePeek(this, @@ -2775,6 +2834,7 @@ public final Maybe doOnComplete(Action onComplete) { * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnError(Consumer onError) { return RxJavaPlugins.onAssembly(new MaybePeek(this, @@ -2819,6 +2879,7 @@ public final Maybe doOnEvent(BiConsumer onEvent * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnSubscribe(Consumer onSubscribe) { return RxJavaPlugins.onAssembly(new MaybePeek(this, @@ -2844,6 +2905,7 @@ public final Maybe doOnSubscribe(Consumer onSubscribe) { * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnSuccess(Consumer onSuccess) { return RxJavaPlugins.onAssembly(new MaybePeek(this, @@ -2874,6 +2936,7 @@ public final Maybe doOnSuccess(Consumer onSuccess) { * @see ReactiveX operators documentation: Filter */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe filter(Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); @@ -2898,6 +2961,7 @@ public final Maybe filter(Predicate predicate) { * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe flatMap(Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2926,6 +2990,7 @@ public final Maybe flatMap(FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe flatMap( Function> onSuccessMapper, @@ -2960,6 +3025,7 @@ public final Maybe flatMap( * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe flatMap(Function> mapper, BiFunction resultSelector) { @@ -2990,6 +3056,7 @@ public final Maybe flatMap(Function Flowable flattenAsFlowable(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -3014,6 +3081,7 @@ public final Flowable flattenAsFlowable(final FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Observable flattenAsObservable(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -3037,6 +3105,7 @@ public final Observable flattenAsObservable(final FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMapObservable(Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -3064,6 +3133,7 @@ public final Observable flatMapObservable(Function Flowable flatMapPublisher(Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -3089,6 +3159,7 @@ public final Flowable flatMapPublisher(FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single flatMapSingle(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -3116,6 +3187,7 @@ public final Single flatMapSingle(final Function Maybe flatMapSingleElement(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -3139,6 +3211,7 @@ public final Maybe flatMapSingleElement(final FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Completable flatMapCompletable(final Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -3348,6 +3421,7 @@ public final Single isEmpty() { * @see #compose(MaybeTransformer) */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe lift(final MaybeOperator lift) { ObjectHelper.requireNonNull(lift, "onLift is null"); @@ -3371,6 +3445,7 @@ public final Maybe lift(final MaybeOperator lift) * @see ReactiveX operators documentation: Map */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe map(Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -3418,6 +3493,7 @@ public final Single> materialize() { */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Flowable mergeWith(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -3443,6 +3519,7 @@ public final Flowable mergeWith(MaybeSource other) { * @see #subscribeOn */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe observeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); @@ -3466,6 +3543,7 @@ public final Maybe observeOn(final Scheduler scheduler) { * @see ReactiveX operators documentation: Filter */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe ofType(final Class clazz) { ObjectHelper.requireNonNull(clazz, "clazz is null"); @@ -3486,6 +3564,7 @@ public final Maybe ofType(final Class clazz) { * @return the value returned by the convert function */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final R to(Function, R> convert) { try { @@ -3549,6 +3628,7 @@ public final Observable toObservable() { * @return the new Single instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single toSingle(T defaultValue) { ObjectHelper.requireNonNull(defaultValue, "defaultValue is null"); @@ -3597,6 +3677,7 @@ public final Maybe onErrorComplete() { * @return the new Completable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorComplete(final Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); @@ -3624,6 +3705,7 @@ public final Maybe onErrorComplete(final Predicate predica * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorResumeNext(final MaybeSource next) { ObjectHelper.requireNonNull(next, "next is null"); @@ -3650,6 +3732,7 @@ public final Maybe onErrorResumeNext(final MaybeSource next) { * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorResumeNext(Function> resumeFunction) { ObjectHelper.requireNonNull(resumeFunction, "resumeFunction is null"); @@ -3676,6 +3759,7 @@ public final Maybe onErrorResumeNext(FunctionReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorReturn(Function valueSupplier) { ObjectHelper.requireNonNull(valueSupplier, "valueSupplier is null"); @@ -3701,6 +3785,7 @@ public final Maybe onErrorReturn(Function val * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorReturnItem(final T item) { ObjectHelper.requireNonNull(item, "item is null"); @@ -3730,6 +3815,7 @@ public final Maybe onErrorReturnItem(final T item) { * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onExceptionResumeNext(final MaybeSource next) { ObjectHelper.requireNonNull(next, "next is null"); @@ -3970,6 +4056,7 @@ public final Maybe retry(Predicate predicate) { * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe retryUntil(final BooleanSupplier stop) { ObjectHelper.requireNonNull(stop, "stop is null"); @@ -4152,6 +4239,7 @@ public final Disposable subscribe(Consumer onSuccess, ConsumerReactiveX operators documentation: Subscribe */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Consumer onSuccess, Consumer onError, Action onComplete) { @@ -4208,6 +4296,7 @@ public final void subscribe(MaybeObserver observer) { * @see #observeOn */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe subscribeOn(Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); @@ -4260,6 +4349,7 @@ public final > E subscribeWith(E observer) { * alternate MaybeSource if the source Maybe is empty. */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe switchIfEmpty(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -4283,6 +4373,7 @@ public final Maybe switchIfEmpty(MaybeSource other) { * @since 2.2 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single switchIfEmpty(SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -4308,6 +4399,7 @@ public final Single switchIfEmpty(SingleSource other) { * @see ReactiveX operators documentation: TakeUntil */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe takeUntil(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -4337,6 +4429,7 @@ public final Maybe takeUntil(MaybeSource other) { */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe takeUntil(Publisher other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -4388,6 +4481,7 @@ public final Maybe timeout(long timeout, TimeUnit timeUnit) { * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Maybe timeout(long timeout, TimeUnit timeUnit, MaybeSource fallback) { ObjectHelper.requireNonNull(fallback, "other is null"); @@ -4417,6 +4511,7 @@ public final Maybe timeout(long timeout, TimeUnit timeUnit, MaybeSourceReactiveX operators documentation: Timeout */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler, MaybeSource fallback) { ObjectHelper.requireNonNull(fallback, "fallback is null"); @@ -4463,6 +4558,7 @@ public final Maybe timeout(long timeout, TimeUnit timeUnit, Scheduler schedul * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe timeout(MaybeSource timeoutIndicator) { ObjectHelper.requireNonNull(timeoutIndicator, "timeoutIndicator is null"); @@ -4484,6 +4580,7 @@ public final Maybe timeout(MaybeSource timeoutIndicator) { * @return the new Maybe instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe timeout(MaybeSource timeoutIndicator, MaybeSource fallback) { ObjectHelper.requireNonNull(timeoutIndicator, "timeoutIndicator is null"); @@ -4508,6 +4605,7 @@ public final Maybe timeout(MaybeSource timeoutIndicator, MaybeSource Maybe timeout(Publisher timeoutIndicator) { ObjectHelper.requireNonNull(timeoutIndicator, "timeoutIndicator is null"); @@ -4533,6 +4631,7 @@ public final Maybe timeout(Publisher timeoutIndicator) { */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe timeout(Publisher timeoutIndicator, MaybeSource fallback) { ObjectHelper.requireNonNull(timeoutIndicator, "timeoutIndicator is null"); @@ -4552,6 +4651,7 @@ public final Maybe timeout(Publisher timeoutIndicator, MaybeSource unsubscribeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); @@ -4585,6 +4685,7 @@ public final Maybe unsubscribeOn(final Scheduler scheduler) { * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe zipWith(MaybeSource other, BiFunction zipper) { ObjectHelper.requireNonNull(other, "other is null"); diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 541c20b1f4..fdd8b29a92 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -116,6 +116,7 @@ public abstract class Observable implements ObservableSource { * @see ReactiveX operators documentation: Amb */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable amb(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -142,6 +143,7 @@ public static Observable amb(Iterable Observable ambArray(ObservableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -289,6 +291,7 @@ public static Observable combineLatest(IterableReactiveX operators documentation: CombineLatest */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest(Iterable> sources, Function combiner, int bufferSize) { @@ -381,6 +384,7 @@ public static Observable combineLatest(ObservableSource[] * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest(ObservableSource[] sources, Function combiner, int bufferSize) { @@ -426,6 +430,7 @@ public static Observable combineLatest(ObservableSource[] */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, @@ -468,6 +473,7 @@ public static Observable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, @@ -515,6 +521,7 @@ public static Observable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, @@ -566,6 +573,7 @@ public static Observable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, @@ -622,6 +630,7 @@ public static Observable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, @@ -682,6 +691,7 @@ public static Observable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, @@ -747,6 +757,7 @@ public static Observable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, @@ -816,6 +827,7 @@ public static Observable combineLatest( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, @@ -962,6 +974,7 @@ public static Observable combineLatestDelayError(FunctionReactiveX operators documentation: CombineLatest */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatestDelayError(ObservableSource[] sources, Function combiner, int bufferSize) { @@ -1057,6 +1070,7 @@ public static Observable combineLatestDelayError(IterableReactiveX operators documentation: CombineLatest */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatestDelayError(Iterable> sources, Function combiner, int bufferSize) { @@ -1084,6 +1098,7 @@ public static Observable combineLatestDelayError(Iterable Observable concat(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -1134,6 +1149,7 @@ public static Observable concat(ObservableSource Observable concat(ObservableSource> sources, int prefetch) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -1162,6 +1178,7 @@ public static Observable concat(ObservableSource Observable concat(ObservableSource source1, ObservableSource source2) { ObjectHelper.requireNonNull(source1, "source1 is null"); @@ -1192,6 +1209,7 @@ public static Observable concat(ObservableSource source1, Ob */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat( ObservableSource source1, ObservableSource source2, @@ -1227,6 +1245,7 @@ public static Observable concat( */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat( ObservableSource source1, ObservableSource source2, @@ -1410,6 +1429,7 @@ public static Observable concatArrayEagerDelayError(int maxConcurrency, i * @return the new ObservableSource with the concatenating behavior */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatDelayError(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -1455,6 +1475,7 @@ public static Observable concatDelayError(ObservableSource Observable concatDelayError(ObservableSource> sources, int prefetch, boolean tillTheEnd) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -1607,6 +1628,7 @@ public static Observable concatEager(Iterable Observable create(ObservableOnSubscribe source) { ObjectHelper.requireNonNull(source, "source is null"); @@ -1638,6 +1660,7 @@ public static Observable create(ObservableOnSubscribe source) { * @see ReactiveX operators documentation: Defer */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable defer(Callable> supplier) { ObjectHelper.requireNonNull(supplier, "supplier is null"); @@ -1686,6 +1709,7 @@ public static Observable empty() { * @see ReactiveX operators documentation: Throw */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable error(Callable errorSupplier) { ObjectHelper.requireNonNull(errorSupplier, "errorSupplier is null"); @@ -1711,6 +1735,7 @@ public static Observable error(Callable errorSupplie * @see ReactiveX operators documentation: Throw */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable error(final Throwable exception) { ObjectHelper.requireNonNull(exception, "e is null"); @@ -1735,6 +1760,7 @@ public static Observable error(final Throwable exception) { */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) + @NonNull public static Observable fromArray(T... items) { ObjectHelper.requireNonNull(items, "items is null"); if (items.length == 0) { @@ -1775,6 +1801,7 @@ public static Observable fromArray(T... items) { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromCallable(Callable supplier) { ObjectHelper.requireNonNull(supplier, "supplier is null"); @@ -1808,6 +1835,7 @@ public static Observable fromCallable(Callable supplier) { * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromFuture(Future future) { ObjectHelper.requireNonNull(future, "future is null"); @@ -1845,6 +1873,7 @@ public static Observable fromFuture(Future future) { * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromFuture(Future future, long timeout, TimeUnit unit) { ObjectHelper.requireNonNull(future, "future is null"); @@ -1886,6 +1915,7 @@ public static Observable fromFuture(Future future, long time * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable fromFuture(Future future, long timeout, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); @@ -1921,6 +1951,7 @@ public static Observable fromFuture(Future future, long time * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable fromFuture(Future future, Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); @@ -1946,6 +1977,7 @@ public static Observable fromFuture(Future future, Scheduler * @see ReactiveX operators documentation: From */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromIterable(Iterable source) { ObjectHelper.requireNonNull(source, "source is null"); @@ -1982,6 +2014,7 @@ public static Observable fromIterable(Iterable source) { */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromPublisher(Publisher publisher) { ObjectHelper.requireNonNull(publisher, "publisher is null"); @@ -2010,6 +2043,7 @@ public static Observable fromPublisher(Publisher publisher) * @return the new Observable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate(final Consumer> generator) { ObjectHelper.requireNonNull(generator, "generator is null"); @@ -2041,6 +2075,7 @@ public static Observable generate(final Consumer> generator) { * @return the new Observable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate(Callable initialState, final BiConsumer> generator) { ObjectHelper.requireNonNull(generator, "generator is null"); @@ -2073,6 +2108,7 @@ public static Observable generate(Callable initialState, final BiCo * @return the new Observable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate( final Callable initialState, @@ -2139,6 +2175,7 @@ public static Observable generate(Callable initialState, BiFunction * @return the new Observable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate(Callable initialState, BiFunction, S> generator, Consumer disposeState) { @@ -2199,6 +2236,7 @@ public static Observable interval(long initialDelay, long period, TimeUnit * @since 1.0.12 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); @@ -2295,6 +2333,7 @@ public static Observable intervalRange(long start, long count, long initia * @return the new Observable instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { if (count < 0) { @@ -2344,6 +2383,7 @@ public static Observable intervalRange(long start, long count, long initia * @see #fromIterable(Iterable) */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item) { ObjectHelper.requireNonNull(item, "The item is null"); @@ -2370,6 +2410,7 @@ public static Observable just(T item) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2) { ObjectHelper.requireNonNull(item1, "The first item is null"); @@ -2400,6 +2441,7 @@ public static Observable just(T item1, T item2) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3) { ObjectHelper.requireNonNull(item1, "The first item is null"); @@ -2433,6 +2475,7 @@ public static Observable just(T item1, T item2, T item3) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4) { ObjectHelper.requireNonNull(item1, "The first item is null"); @@ -2469,6 +2512,7 @@ public static Observable just(T item1, T item2, T item3, T item4) { */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5) { ObjectHelper.requireNonNull(item1, "The first item is null"); @@ -2508,6 +2552,7 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6) { ObjectHelper.requireNonNull(item1, "The first item is null"); @@ -2550,6 +2595,7 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7) { ObjectHelper.requireNonNull(item1, "The first item is null"); @@ -2595,6 +2641,7 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8) { ObjectHelper.requireNonNull(item1, "The first item is null"); @@ -2643,6 +2690,7 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9) { ObjectHelper.requireNonNull(item1, "The first item is null"); @@ -2694,6 +2742,7 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 */ @SuppressWarnings("unchecked") @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9, T item10) { ObjectHelper.requireNonNull(item1, "The first item is null"); diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 168c9c216a..f41d69a80c 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -129,6 +129,7 @@ public abstract class Single implements SingleSource { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single amb(final Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); @@ -180,6 +181,7 @@ public static Single ambArray(final SingleSource... sources) * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.FULL) public static Flowable concat(Iterable> sources) { @@ -201,6 +203,7 @@ public static Flowable concat(Iterable Observable concat(ObservableSource> sources) { @@ -226,6 +229,7 @@ public static Observable concat(ObservableSource Flowable concat(Publisher> sources) { @@ -251,6 +255,7 @@ public static Flowable concat(Publisher Flowable concat(PublisherReactiveX operators documentation: Concat */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") @@ -313,6 +319,7 @@ public static Flowable concat( * @see ReactiveX operators documentation: Concat */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") @@ -350,6 +357,7 @@ public static Flowable concat( * @see ReactiveX operators documentation: Concat */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") @@ -381,6 +389,7 @@ public static Flowable concat( * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -406,6 +415,7 @@ public static Flowable concatArray(SingleSource... sources) */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Flowable concatArrayEager(SingleSource... sources) { return Flowable.fromArray(sources).concatMapEager(SingleInternalHelper.toFlowable()); @@ -433,6 +443,7 @@ public static Flowable concatArrayEager(SingleSource... sour */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Flowable concatEager(Publisher> sources) { return Flowable.fromPublisher(sources).concatMapEager(SingleInternalHelper.toFlowable()); @@ -458,6 +469,7 @@ public static Flowable concatEager(Publisher Flowable concatEager(Iterable> sources) { return Flowable.fromIterable(sources).concatMapEager(SingleInternalHelper.toFlowable()); @@ -500,6 +512,7 @@ public static Flowable concatEager(Iterable Single create(SingleOnSubscribe source) { ObjectHelper.requireNonNull(source, "source is null"); @@ -521,6 +534,7 @@ public static Single create(SingleOnSubscribe source) { * @return the new Single instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single defer(final Callable> singleSupplier) { ObjectHelper.requireNonNull(singleSupplier, "singleSupplier is null"); @@ -541,6 +555,7 @@ public static Single defer(final Callable Single error(final Callable errorSupplier) { ObjectHelper.requireNonNull(errorSupplier, "errorSupplier is null"); @@ -566,6 +581,7 @@ public static Single error(final Callable errorSuppl * @see ReactiveX operators documentation: Throw */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single error(final Throwable exception) { ObjectHelper.requireNonNull(exception, "error is null"); @@ -599,6 +615,7 @@ public static Single error(final Throwable exception) { * @return a {@link Single} whose {@link SingleObserver}s' subscriptions trigger an invocation of the given function. */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single fromCallable(final Callable callable) { ObjectHelper.requireNonNull(callable, "callable is null"); @@ -763,6 +780,7 @@ public static Single fromFuture(Future future, Scheduler sch */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single fromPublisher(final Publisher publisher) { ObjectHelper.requireNonNull(publisher, "publisher is null"); @@ -786,6 +804,7 @@ public static Single fromPublisher(final Publisher publisher * @return the new Single instance */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single fromObservable(ObservableSource observableSource) { ObjectHelper.requireNonNull(observableSource, "observableSource is null"); @@ -813,6 +832,7 @@ public static Single fromObservable(ObservableSource observa */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) + @NonNull public static Single just(final T item) { ObjectHelper.requireNonNull(item, "value is null"); return RxJavaPlugins.onAssembly(new SingleJust(item)); @@ -849,6 +869,7 @@ public static Single just(final T item) { * @see #mergeDelayError(Iterable) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable merge(Iterable> sources) { @@ -886,6 +907,7 @@ public static Flowable merge(Iterable * @since 2.0 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -917,6 +939,7 @@ public static Flowable merge(PublisherReactiveX operators documentation: Merge */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) public static Single merge(SingleSource> source) { @@ -961,6 +984,7 @@ public static Single merge(SingleSource Flowable merge( * @see #mergeDelayError(SingleSource, SingleSource, SingleSource) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") @@ -1065,6 +1090,7 @@ public static Flowable merge( * @see #mergeDelayError(SingleSource, SingleSource, SingleSource, SingleSource) */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") @@ -1096,6 +1122,7 @@ public static Flowable merge( * @since 2.2 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable mergeDelayError(Iterable> sources) { @@ -1119,6 +1146,7 @@ public static Flowable mergeDelayError(Iterable Flowable mergeDelayError(Publisher Flowable mergeDelayError( * @since 2.2 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") @@ -1235,6 +1265,7 @@ public static Flowable mergeDelayError( * @since 2.2 */ @CheckReturnValue + @NonNull @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") @@ -1305,6 +1336,7 @@ public static Single timer(long delay, TimeUnit unit) { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Single timer(final long delay, final TimeUnit unit, final Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); @@ -1327,6 +1359,7 @@ public static Single timer(final long delay, final TimeUnit unit, final Sc * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single equals(final SingleSource first, final SingleSource second) { // NOPMD ObjectHelper.requireNonNull(first, "first is null"); @@ -1350,6 +1383,7 @@ public static Single equals(final SingleSource first, * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single unsafeCreate(SingleSource onSubscribe) { ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); @@ -1409,6 +1443,7 @@ public static Single using(Callable resourceSupplier, * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single using( final Callable resourceSupplier, @@ -1434,6 +1469,7 @@ public static Single using( * @return the Single wrapper or the source cast to Single (if possible) */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single wrap(SingleSource source) { ObjectHelper.requireNonNull(source, "source is null"); @@ -1473,6 +1509,7 @@ public static Single wrap(SingleSource source) { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single zip(final Iterable> sources, Function zipper) { ObjectHelper.requireNonNull(zipper, "zipper is null"); @@ -1504,6 +1541,7 @@ public static Single zip(final IterableReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Single zip( @@ -1542,6 +1580,7 @@ public static Single zip( * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Single zip( @@ -1585,6 +1624,7 @@ public static Single zip( * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Single zip( @@ -1632,6 +1672,7 @@ public static Single zip( * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Single zip( @@ -1684,6 +1725,7 @@ public static Single zip( * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Single zip( @@ -1740,6 +1782,7 @@ public static Single zip( * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Single zip( @@ -1801,6 +1844,7 @@ public static Single zip( * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Single zip( @@ -1866,6 +1910,7 @@ public static Single zip( * @see ReactiveX operators documentation: Zip */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Single zip( @@ -1918,6 +1963,7 @@ public static Single zip( * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single zipArray(Function zipper, SingleSource... sources) { ObjectHelper.requireNonNull(zipper, "zipper is null"); @@ -1942,6 +1988,7 @@ public static Single zipArray(Function * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public final Single ambWith(SingleSource other) { @@ -2048,6 +2095,7 @@ public final Single cache() { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single cast(final Class clazz) { ObjectHelper.requireNonNull(clazz, "clazz is null"); @@ -2166,6 +2214,7 @@ public final Single delay(final long time, final TimeUnit unit, final Schedul * @since 2.2 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Single delay(final long time, final TimeUnit unit, final Scheduler scheduler, boolean delayError) { ObjectHelper.requireNonNull(unit, "unit is null"); @@ -2188,6 +2237,7 @@ public final Single delay(final long time, final TimeUnit unit, final Schedul * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single delaySubscription(CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -2210,6 +2260,7 @@ public final Single delaySubscription(CompletableSource other) { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single delaySubscription(SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -2232,6 +2283,7 @@ public final Single delaySubscription(SingleSource other) { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single delaySubscription(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -2259,6 +2311,7 @@ public final Single delaySubscription(ObservableSource other) { */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single delaySubscription(Publisher other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -2332,6 +2385,7 @@ public final Single delaySubscription(long time, TimeUnit unit, Scheduler sch * @see #materialize() */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) @Experimental public final Maybe dematerialize(Function> selector) { @@ -2356,6 +2410,7 @@ public final Maybe dematerialize(Function> sel * @since 2.1 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single doAfterSuccess(Consumer onAfterSuccess) { ObjectHelper.requireNonNull(onAfterSuccess, "doAfterSuccess is null"); @@ -2384,6 +2439,7 @@ public final Single doAfterSuccess(Consumer onAfterSuccess) { * @since 2.1 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single doAfterTerminate(Action onAfterTerminate) { ObjectHelper.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); @@ -2410,6 +2466,7 @@ public final Single doAfterTerminate(Action onAfterTerminate) { * @since 2.1 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single doFinally(Action onFinally) { ObjectHelper.requireNonNull(onFinally, "onFinally is null"); @@ -2431,6 +2488,7 @@ public final Single doFinally(Action onFinally) { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single doOnSubscribe(final Consumer onSubscribe) { ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); @@ -2452,6 +2510,7 @@ public final Single doOnSubscribe(final Consumer onSubscr * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single doOnSuccess(final Consumer onSuccess) { ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"); @@ -2470,6 +2529,7 @@ public final Single doOnSuccess(final Consumer onSuccess) { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single doOnEvent(final BiConsumer onEvent) { ObjectHelper.requireNonNull(onEvent, "onEvent is null"); @@ -2491,6 +2551,7 @@ public final Single doOnEvent(final BiConsumer * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single doOnError(final Consumer onError) { ObjectHelper.requireNonNull(onError, "onError is null"); @@ -2513,6 +2574,7 @@ public final Single doOnError(final Consumer onError) { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single doOnDispose(final Action onDispose) { ObjectHelper.requireNonNull(onDispose, "onDispose is null"); @@ -2537,6 +2599,7 @@ public final Single doOnDispose(final Action onDispose) { * @see ReactiveX operators documentation: Filter */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe filter(Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); @@ -2560,6 +2623,7 @@ public final Maybe filter(Predicate predicate) { * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single flatMap(Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2583,6 +2647,7 @@ public final Single flatMap(FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe flatMapMaybe(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2611,6 +2676,7 @@ public final Maybe flatMapMaybe(final Function Flowable flatMapPublisher(Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2639,6 +2705,7 @@ public final Flowable flatMapPublisher(Function Flowable flattenAsFlowable(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2663,6 +2730,7 @@ public final Flowable flattenAsFlowable(final FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Observable flattenAsObservable(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2686,6 +2754,7 @@ public final Observable flattenAsObservable(final FunctionReactiveX operators documentation: FlatMap */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMapObservable(Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2710,6 +2779,7 @@ public final Observable flatMapObservable(Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2879,6 +2949,7 @@ public final T blockingGet() { * @see #compose(SingleTransformer) */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single lift(final SingleOperator lift) { ObjectHelper.requireNonNull(lift, "onLift is null"); @@ -2902,6 +2973,7 @@ public final Single lift(final SingleOperator lif * @see ReactiveX operators documentation: Map */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single map(Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); @@ -2959,6 +3031,7 @@ public final Single contains(Object value) { * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single contains(final Object value, final BiPredicate comparer) { ObjectHelper.requireNonNull(value, "value is null"); @@ -3012,6 +3085,7 @@ public final Flowable mergeWith(SingleSource other) { * @see #subscribeOn */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Single observeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); @@ -3045,6 +3119,7 @@ public final Single observeOn(final Scheduler scheduler) { * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single onErrorReturn(final Function resumeFunction) { ObjectHelper.requireNonNull(resumeFunction, "resumeFunction is null"); @@ -3064,6 +3139,7 @@ public final Single onErrorReturn(final Function resu * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single onErrorReturnItem(final T value) { ObjectHelper.requireNonNull(value, "value is null"); @@ -3098,6 +3174,7 @@ public final Single onErrorReturnItem(final T value) { * @see ReactiveX operators documentation: Catch */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single onErrorResumeNext(final Single resumeSingleInCaseOfError) { ObjectHelper.requireNonNull(resumeSingleInCaseOfError, "resumeSingleInCaseOfError is null"); @@ -3133,6 +3210,7 @@ public final Single onErrorResumeNext(final Single resumeSingleI * @since .20 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single onErrorResumeNext( final Function> resumeFunctionInCaseOfError) { @@ -3419,6 +3497,7 @@ public final Disposable subscribe() { * if {@code onCallback} is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(final BiConsumer onCallback) { ObjectHelper.requireNonNull(onCallback, "onCallback is null"); @@ -3472,6 +3551,7 @@ public final Disposable subscribe(Consumer onSuccess) { * if {@code onError} is null */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(final Consumer onSuccess, final Consumer onError) { ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"); @@ -3560,6 +3640,7 @@ public final > E subscribeWith(E observer) { * @see #observeOn */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Single subscribeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); @@ -3584,6 +3665,7 @@ public final Single subscribeOn(final Scheduler scheduler) { * @see ReactiveX operators documentation: TakeUntil */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single takeUntil(final CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -3615,6 +3697,7 @@ public final Single takeUntil(final CompletableSource other) { */ @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single takeUntil(final Publisher other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -3640,6 +3723,7 @@ public final Single takeUntil(final Publisher other) { * @see ReactiveX operators documentation: TakeUntil */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single takeUntil(final SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -3699,6 +3783,7 @@ public final Single timeout(long timeout, TimeUnit unit, Scheduler scheduler) * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Single timeout(long timeout, TimeUnit unit, Scheduler scheduler, SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -3724,6 +3809,7 @@ public final Single timeout(long timeout, TimeUnit unit, Scheduler scheduler, * @since 2.0 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Single timeout(long timeout, TimeUnit unit, SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); @@ -3902,6 +3988,7 @@ public final Observable toObservable() { * @since 2.2 */ @CheckReturnValue + @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public final Single unsubscribeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); From 5278124db4a93b8f59cee4e3baa9e864601637fd Mon Sep 17 00:00:00 2001 From: Igor Suhorukov Date: Wed, 19 Dec 2018 13:42:56 +0300 Subject: [PATCH 119/211] Replace indexed loop with for-each java5 syntax (#6335) * Replace indexed loop with for-each java5 syntax * Restore code as per @akarnokd code review * Keep empty lines as per @akarnokd code review --- .../reactivex/internal/operators/parallel/ParallelJoin.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/parallel/ParallelJoin.java b/src/main/java/io/reactivex/internal/operators/parallel/ParallelJoin.java index b248cde69f..975c151729 100644 --- a/src/main/java/io/reactivex/internal/operators/parallel/ParallelJoin.java +++ b/src/main/java/io/reactivex/internal/operators/parallel/ParallelJoin.java @@ -110,15 +110,13 @@ public void cancel() { } void cancelAll() { - for (int i = 0; i < subscribers.length; i++) { - JoinInnerSubscriber s = subscribers[i]; + for (JoinInnerSubscriber s : subscribers) { s.cancel(); } } void cleanup() { - for (int i = 0; i < subscribers.length; i++) { - JoinInnerSubscriber s = subscribers[i]; + for (JoinInnerSubscriber s : subscribers) { s.queue = null; } } From 5aef7fee1add9bd0d64a38f1f671eeac3abe0db0 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 24 Dec 2018 15:40:50 +0100 Subject: [PATCH 120/211] Javadoc: fix examples using markdown instead of @code (#6346) --- src/main/java/io/reactivex/Flowable.java | 6 +++--- src/main/java/io/reactivex/Observable.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 0b33a191a2..aea0ed9951 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -8846,7 +8846,7 @@ public final Flowable distinct(Function keySelector, * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. + * for example using {@code map(CharSequence::toString)} or {@code map(list -> Collections.unmodifiableList(new ArrayList<>(list)))}. *

      *
      Backpressure:
      *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s @@ -8889,7 +8889,7 @@ public final Flowable distinctUntilChanged() { * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. + * for example using {@code map(CharSequence::toString)} or {@code map(list -> Collections.unmodifiableList(new ArrayList<>(list)))}. *
      *
      Backpressure:
      *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s @@ -8928,7 +8928,7 @@ public final Flowable distinctUntilChanged(Function keySele * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. + * for example using {@code map(CharSequence::toString)} or {@code map(list -> Collections.unmodifiableList(new ArrayList<>(list)))}. *
      *
      Backpressure:
      *
      The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index fdd8b29a92..50060d353d 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -7879,7 +7879,7 @@ public final Observable distinct(Function keySelector, Call * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. + * for example using {@code map(CharSequence::toString)} or {@code map(list -> Collections.unmodifiableList(new ArrayList<>(list)))}. *
      *
      Scheduler:
      *
      {@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
      @@ -7918,7 +7918,7 @@ public final Observable distinctUntilChanged() { * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. + * for example using {@code map(CharSequence::toString)} or {@code map(list -> Collections.unmodifiableList(new ArrayList<>(list)))}. *
      *
      Scheduler:
      *
      {@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
      @@ -7953,7 +7953,7 @@ public final Observable distinctUntilChanged(Function keySe * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, - * for example using `map(CharSequence::toString)` or `map(list -> Collections.unmodifiableList(new ArrayList<>(list)))`. + * for example using {@code map(CharSequence::toString)} or {@code map(list -> Collections.unmodifiableList(new ArrayList<>(list)))}. *
      *
      Scheduler:
      *
      {@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
      From 4f0cdca8ffe6c2700337a20c03e9c09bf5357a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20K=2E=20=C3=96zcan?= Date: Sat, 29 Dec 2018 01:11:52 +0300 Subject: [PATCH 121/211] Update outdated java example in wiki #6331 (#6351) * Update outdated java example in wiki #6331 * update wiki page similar to README * keep the original example --- docs/How-To-Use-RxJava.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/How-To-Use-RxJava.md b/docs/How-To-Use-RxJava.md index d10274d959..16d156caa9 100644 --- a/docs/How-To-Use-RxJava.md +++ b/docs/How-To-Use-RxJava.md @@ -11,15 +11,20 @@ You can find additional code examples in the `/src/examples` folders of each [la ### Java ```java -public static void hello(String... names) { - Observable.from(names).subscribe(new Action1() { - - @Override - public void call(String s) { - System.out.println("Hello " + s + "!"); - } +public static void hello(String... args) { + Flowable.fromArray(args).subscribe(s -> System.out.println("Hello " + s + "!")); +} +``` - }); +If your platform doesn't support Java 8 lambdas (yet), you have to create an inner class of ```Consumer``` manually: +```java +public static void hello(String... args) { + Flowable.fromArray(args).subscribe(new Consumer() { + @Override + public void accept(String s) { + System.out.println("Hello " + s + "!"); + } + }); } ``` @@ -397,4 +402,4 @@ myModifiedObservable = myObservable.onErrorResumeNext({ t -> Throwable myThrowable = myCustomizedThrowableCreator(t); return (Observable.error(myThrowable)); }); -``` \ No newline at end of file +``` From 537fa263233a2a3234bbb8bd052f89b648fad2da Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 31 Dec 2018 10:57:09 +0100 Subject: [PATCH 122/211] Release 2.2.5 --- CHANGES.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index dd1266c545..57b421fc21 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,24 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.5 - December 31, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.5%7C)) + +#### Documentation changes + + - [Pull 6344](https://github.com/ReactiveX/RxJava/pull/6344): Use correct return type in JavaDocs documentation in `elementAtOrDefault`. + - [Pull 6346](https://github.com/ReactiveX/RxJava/pull/6346): Fix JavaDoc examples using markdown instead of `@code`. + +#### Wiki changes + + - [Pull 6324](https://github.com/ReactiveX/RxJava/pull/6324): Java 8 version for [Problem-Solving-Examples-in-RxJava](https://github.com/ReactiveX/RxJava/wiki/Problem-Solving-Examples-in-RxJava). + - [Pull 6343](https://github.com/ReactiveX/RxJava/pull/6343): Update [Filtering Observables](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) docs. + - [Pull 6351](https://github.com/ReactiveX/RxJava/pull/6351): Updated java example in [How-To-Use-RxJava.md](https://github.com/ReactiveX/RxJava/wiki/How-To-Use-RxJava) file with java 8 version. + +#### Other changes + + - [Pull 6313](https://github.com/ReactiveX/RxJava/pull/6313): Adding `@NonNull` annotation factory methods. + - [Pull 6335](https://github.com/ReactiveX/RxJava/pull/6335): Replace indexed loop with for-each java5 syntax. + ### Version 2.2.4 - November 23, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.4%7C)) #### API changes From 2e0c8b585e467f94a0cc47d5792b6eb8e7f51262 Mon Sep 17 00:00:00 2001 From: lorenzpahl Date: Wed, 2 Jan 2019 18:00:44 +0100 Subject: [PATCH 123/211] docs(README): Use 'ignoreElement' to convert Single to Completable (#6353) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fcaf292d2..c29d6d3fc0 100644 --- a/README.md +++ b/README.md @@ -369,7 +369,7 @@ Each reactive base class features operators that can perform such conversions, i |----------|----------|------------|--------|-------|-------------| |**Flowable** | | `toObservable` | `first`, `firstOrError`, `single`, `singleOrError`, `last`, `lastOrError`1 | `firstElement`, `singleElement`, `lastElement` | `ignoreElements` | |**Observable**| `toFlowable`2 | | `first`, `firstOrError`, `single`, `singleOrError`, `last`, `lastOrError`1 | `firstElement`, `singleElement`, `lastElement` | `ignoreElements` | -|**Single** | `toFlowable`3 | `toObservable` | | `toMaybe` | `toCompletable` | +|**Single** | `toFlowable`3 | `toObservable` | | `toMaybe` | `ignoreElement` | |**Maybe** | `toFlowable`3 | `toObservable` | `toSingle` | | `ignoreElement` | |**Completable** | `toFlowable` | `toObservable` | `toSingle` | `toMaybe` | | From 090f99e13534c0e0e9e4665f1187c1c42637c7b0 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sat, 5 Jan 2019 00:39:20 +0100 Subject: [PATCH 124/211] 2.x: Fix the error/race in Obs.repeatWhen due to flooding repeat signal (#6359) --- .../observable/ObservableRepeatWhen.java | 2 +- .../flowable/FlowableRepeatTest.java | 53 ++++++++++++++++ .../operators/flowable/FlowableRetryTest.java | 61 +++++++++++++++++++ .../observable/ObservableRepeatTest.java | 53 ++++++++++++++++ .../observable/ObservableRetryTest.java | 61 +++++++++++++++++++ 5 files changed, 229 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java index af27f2f6d0..24725997d1 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRepeatWhen.java @@ -108,8 +108,8 @@ public void onError(Throwable e) { @Override public void onComplete() { - active = false; DisposableHelper.replace(upstream, null); + active = false; signaller.onNext(0); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java index 51376bc594..fd5061d9ed 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java @@ -29,6 +29,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; @@ -441,4 +442,56 @@ public boolean test(Object v) throws Exception { assertEquals(0, counter.get()); } + + @Test + public void repeatFloodNoSubscriptionError() { + List errors = TestHelper.trackPluginErrors(); + + try { + final PublishProcessor source = PublishProcessor.create(); + final PublishProcessor signaller = PublishProcessor.create(); + + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + TestSubscriber ts = source.take(1) + .repeatWhen(new Function, Flowable>() { + @Override + public Flowable apply(Flowable v) + throws Exception { + return signaller; + } + }).test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + source.onNext(1); + } + } + }; + Runnable r2 = new Runnable() { + @Override + public void run() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + signaller.offer(1); + } + } + }; + + TestHelper.race(r1, r2); + + ts.dispose(); + } + + if (!errors.isEmpty()) { + for (Throwable e : errors) { + e.printStackTrace(); + } + fail(errors + ""); + } + } finally { + RxJavaPlugins.reset(); + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java index a5dd4918ab..a47a5d6eca 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java @@ -32,6 +32,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; @@ -1221,4 +1222,64 @@ public boolean test(Object v) throws Exception { assertEquals(0, counter.get()); } + + @Test + public void repeatFloodNoSubscriptionError() { + List errors = TestHelper.trackPluginErrors(); + + final TestException error = new TestException(); + + try { + final PublishProcessor source = PublishProcessor.create(); + final PublishProcessor signaller = PublishProcessor.create(); + + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + TestSubscriber ts = source.take(1) + .map(new Function() { + @Override + public Integer apply(Integer v) throws Exception { + throw error; + } + }) + .retryWhen(new Function, Flowable>() { + @Override + public Flowable apply(Flowable v) + throws Exception { + return signaller; + } + }).test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + source.onNext(1); + } + } + }; + Runnable r2 = new Runnable() { + @Override + public void run() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + signaller.offer(1); + } + } + }; + + TestHelper.race(r1, r2); + + ts.dispose(); + } + + if (!errors.isEmpty()) { + for (Throwable e : errors) { + e.printStackTrace(); + } + fail(errors + ""); + } + } finally { + RxJavaPlugins.reset(); + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java index 3afc1f1cc7..dbb72e21ef 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java @@ -30,6 +30,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.observers.TestObserver; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; @@ -397,4 +398,56 @@ public boolean test(Object v) throws Exception { assertEquals(0, counter.get()); } + + @Test + public void repeatFloodNoSubscriptionError() { + List errors = TestHelper.trackPluginErrors(); + + try { + final PublishSubject source = PublishSubject.create(); + final PublishSubject signaller = PublishSubject.create(); + + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + TestObserver to = source.take(1) + .repeatWhen(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable v) + throws Exception { + return signaller; + } + }).test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + source.onNext(1); + } + } + }; + Runnable r2 = new Runnable() { + @Override + public void run() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + signaller.onNext(1); + } + } + }; + + TestHelper.race(r1, r2); + + to.dispose(); + } + + if (!errors.isEmpty()) { + for (Throwable e : errors) { + e.printStackTrace(); + } + fail(errors + ""); + } + } finally { + RxJavaPlugins.reset(); + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java index e576479921..0055449ef5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java @@ -34,6 +34,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.observables.GroupedObservable; import io.reactivex.observers.*; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; @@ -1131,4 +1132,64 @@ public boolean test(Object v) throws Exception { assertEquals(0, counter.get()); } + + @Test + public void repeatFloodNoSubscriptionError() { + List errors = TestHelper.trackPluginErrors(); + + final TestException error = new TestException(); + + try { + final PublishSubject source = PublishSubject.create(); + final PublishSubject signaller = PublishSubject.create(); + + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + TestObserver to = source.take(1) + .map(new Function() { + @Override + public Integer apply(Integer v) throws Exception { + throw error; + } + }) + .retryWhen(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable v) + throws Exception { + return signaller; + } + }).test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + source.onNext(1); + } + } + }; + Runnable r2 = new Runnable() { + @Override + public void run() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + signaller.onNext(1); + } + } + }; + + TestHelper.race(r1, r2); + + to.dispose(); + } + + if (!errors.isEmpty()) { + for (Throwable e : errors) { + e.printStackTrace(); + } + fail(errors + ""); + } + } finally { + RxJavaPlugins.reset(); + } + } } From d7d0a33e04e4b409789fc67ec94883bf0e828c64 Mon Sep 17 00:00:00 2001 From: pjastrz Date: Sat, 12 Jan 2019 19:06:23 +0100 Subject: [PATCH 125/211] 2.x: Fix Completable.andThen(Completable) not running on observeOn scheduler. (#6362) * 2.x: Fix Completable.andThen(Completable) not running on scheduler defined with observeOn. * 2.x: Fix Completable.andThen(Completable) not running on scheduler defined with observeOn. * 2.x: Fix Completable.andThen(Completable) not running on scheduler defined with observeOn. --- src/main/java/io/reactivex/Completable.java | 5 +- .../CompletableAndThenCompletable.java | 107 ++++++++++ .../CompletableAndThenCompletableabTest.java | 185 ++++++++++++++++++ .../completable/CompletableAndThenTest.java | 45 +---- 4 files changed, 297 insertions(+), 45 deletions(-) create mode 100644 src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java create mode 100644 src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletableabTest.java diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 9d8325e3b6..7ac7ead344 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -1171,7 +1171,8 @@ public final Maybe andThen(MaybeSource next) { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable andThen(CompletableSource next) { - return concatWith(next); + ObjectHelper.requireNonNull(next, "next is null"); + return RxJavaPlugins.onAssembly(new CompletableAndThenCompletable(this, next)); } /** @@ -1357,7 +1358,7 @@ public final Completable compose(CompletableTransformer transformer) { @SchedulerSupport(SchedulerSupport.NONE) public final Completable concatWith(CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); - return concatArray(this, other); + return RxJavaPlugins.onAssembly(new CompletableAndThenCompletable(this, other)); } /** diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java new file mode 100644 index 0000000000..20d2332214 --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.completable; + +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.*; +import io.reactivex.disposables.Disposable; +import io.reactivex.internal.disposables.DisposableHelper; + +public final class CompletableAndThenCompletable extends Completable { + + final CompletableSource source; + + final CompletableSource next; + + public CompletableAndThenCompletable(CompletableSource source, CompletableSource next) { + this.source = source; + this.next = next; + } + + @Override + protected void subscribeActual(CompletableObserver observer) { + source.subscribe(new SourceObserver(observer, next)); + } + + static final class SourceObserver + extends AtomicReference + implements CompletableObserver, Disposable { + + private static final long serialVersionUID = -4101678820158072998L; + + final CompletableObserver actualObserver; + + final CompletableSource next; + + SourceObserver(CompletableObserver actualObserver, CompletableSource next) { + this.actualObserver = actualObserver; + this.next = next; + } + + @Override + public void onSubscribe(Disposable d) { + if (DisposableHelper.setOnce(this, d)) { + actualObserver.onSubscribe(this); + } + } + + @Override + public void onError(Throwable e) { + actualObserver.onError(e); + } + + @Override + public void onComplete() { + next.subscribe(new NextObserver(this, actualObserver)); + } + + @Override + public void dispose() { + DisposableHelper.dispose(this); + } + + @Override + public boolean isDisposed() { + return DisposableHelper.isDisposed(get()); + } + } + + static final class NextObserver implements CompletableObserver { + + final AtomicReference parent; + + final CompletableObserver downstream; + + public NextObserver(AtomicReference parent, CompletableObserver downstream) { + this.parent = parent; + this.downstream = downstream; + } + + @Override + public void onSubscribe(Disposable d) { + DisposableHelper.replace(parent, d); + } + + @Override + public void onComplete() { + downstream.onComplete(); + } + + @Override + public void onError(Throwable e) { + downstream.onError(e); + } + } +} diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletableabTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletableabTest.java new file mode 100644 index 0000000000..34b9c82436 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletableabTest.java @@ -0,0 +1,185 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.completable; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Test; + +import io.reactivex.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Action; +import io.reactivex.observers.TestObserver; +import io.reactivex.schedulers.Schedulers; + +import static org.junit.Assert.*; + +public class CompletableAndThenCompletableabTest { + @Test(expected = NullPointerException.class) + public void andThenCompletableCompleteNull() { + Completable.complete() + .andThen((Completable) null); + } + + @Test + public void andThenCompletableCompleteComplete() { + Completable.complete() + .andThen(Completable.complete()) + .test() + .assertComplete(); + } + + @Test + public void andThenCompletableCompleteError() { + Completable.complete() + .andThen(Completable.error(new TestException("test"))) + .test() + .assertNotComplete() + .assertNoValues() + .assertError(TestException.class) + .assertErrorMessage("test"); + } + + @Test + public void andThenCompletableCompleteNever() { + Completable.complete() + .andThen(Completable.never()) + .test() + .assertNoValues() + .assertNoErrors() + .assertNotComplete(); + } + + @Test + public void andThenCompletableErrorComplete() { + Completable.error(new TestException("bla")) + .andThen(Completable.complete()) + .test() + .assertNotComplete() + .assertNoValues() + .assertError(TestException.class) + .assertErrorMessage("bla"); + } + + @Test + public void andThenCompletableErrorNever() { + Completable.error(new TestException("bla")) + .andThen(Completable.never()) + .test() + .assertNotComplete() + .assertNoValues() + .assertError(TestException.class) + .assertErrorMessage("bla"); + } + + @Test + public void andThenCompletableErrorError() { + Completable.error(new TestException("error1")) + .andThen(Completable.error(new TestException("error2"))) + .test() + .assertNotComplete() + .assertNoValues() + .assertError(TestException.class) + .assertErrorMessage("error1"); + } + + @Test + public void andThenCanceled() { + final AtomicInteger completableRunCount = new AtomicInteger(); + Completable.fromRunnable(new Runnable() { + @Override + public void run() { + completableRunCount.incrementAndGet(); + } + }) + .andThen(Completable.complete()) + .test(true) + .assertEmpty(); + assertEquals(1, completableRunCount.get()); + } + + @Test + public void andThenFirstCancels() { + final TestObserver to = new TestObserver(); + Completable.fromRunnable(new Runnable() { + @Override + public void run() { + to.cancel(); + } + }) + .andThen(Completable.complete()) + .subscribe(to); + to + .assertNotComplete() + .assertNoErrors(); + } + + @Test + public void andThenSecondCancels() { + final TestObserver to = new TestObserver(); + Completable.complete() + .andThen(Completable.fromRunnable(new Runnable() { + @Override + public void run() { + to.cancel(); + } + })) + .subscribe(to); + to + .assertNotComplete() + .assertNoErrors(); + } + + @Test + public void andThenDisposed() { + TestHelper.checkDisposed(Completable.complete() + .andThen(Completable.complete())); + } + + @Test + public void andThenNoInterrupt() throws InterruptedException { + for (int k = 0; k < 100; k++) { + final int count = 10; + final CountDownLatch latch = new CountDownLatch(count); + final boolean[] interrupted = {false}; + + for (int i = 0; i < count; i++) { + Completable.complete() + .subscribeOn(Schedulers.io()) + .observeOn(Schedulers.io()) + .andThen(Completable.fromAction(new Action() { + @Override + public void run() throws Exception { + try { + Thread.sleep(30); + } catch (InterruptedException e) { + System.out.println("Interrupted! " + Thread.currentThread()); + interrupted[0] = true; + } + } + })) + .subscribe(new Action() { + @Override + public void run() throws Exception { + latch.countDown(); + } + }); + } + + latch.await(); + assertFalse("The second Completable was interrupted!", interrupted[0]); + } + } +} diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenTest.java index a5d9b3a279..c873d5472d 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenTest.java @@ -13,15 +13,9 @@ package io.reactivex.internal.operators.completable; -import io.reactivex.Completable; -import io.reactivex.Maybe; -import io.reactivex.functions.Action; -import io.reactivex.schedulers.Schedulers; - -import java.util.concurrent.CountDownLatch; - import org.junit.Test; -import static org.junit.Assert.*; + +import io.reactivex.*; public class CompletableAndThenTest { @Test(expected = NullPointerException.class) @@ -69,39 +63,4 @@ public void andThenMaybeError() { .assertError(RuntimeException.class) .assertErrorMessage("bla"); } - - @Test - public void andThenNoInterrupt() throws InterruptedException { - for (int k = 0; k < 100; k++) { - final int count = 10; - final CountDownLatch latch = new CountDownLatch(count); - final boolean[] interrupted = { false }; - - for (int i = 0; i < count; i++) { - Completable.complete() - .subscribeOn(Schedulers.io()) - .observeOn(Schedulers.io()) - .andThen(Completable.fromAction(new Action() { - @Override - public void run() throws Exception { - try { - Thread.sleep(30); - } catch (InterruptedException e) { - System.out.println("Interrupted! " + Thread.currentThread()); - interrupted[0] = true; - } - } - })) - .subscribe(new Action() { - @Override - public void run() throws Exception { - latch.countDown(); - } - }); - } - - latch.await(); - assertFalse("The second Completable was interrupted!", interrupted[0]); - } - } } From 2eda9d82f41cef934da4e22a52899b1eed85d729 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 15 Jan 2019 11:37:22 +0100 Subject: [PATCH 126/211] 2.x: Fix publish not requesting upon client change (#6364) * 2.x: Fix publish not requesting upon client change * Add fused test, rename test method --- .../operators/flowable/FlowablePublish.java | 10 +- .../flowable/FlowablePublishTest.java | 130 ++++++++++++++++++ 2 files changed, 139 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java index 0e08551495..7ab84a568b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java @@ -557,12 +557,20 @@ void dispatch() { InnerSubscriber[] freshArray = subscribers.get(); if (subscribersChanged || freshArray != ps) { ps = freshArray; + + // if we did emit at least one element, request more to replenish the queue + if (d != 0) { + if (sourceMode != QueueSubscription.SYNC) { + upstream.get().request(d); + } + } + continue outer; } } // if we did emit at least one element, request more to replenish the queue - if (d > 0) { + if (d != 0) { if (sourceMode != QueueSubscription.SYNC) { upstream.get().request(d); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java index c7c9865f24..eac12749f5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java @@ -1368,4 +1368,134 @@ public String apply(Integer t) throws Exception { public void badRequest() { TestHelper.assertBadRequestReported(Flowable.range(1, 5).publish()); } + + @Test + @SuppressWarnings("unchecked") + public void splitCombineSubscriberChangeAfterOnNext() { + Flowable source = Flowable.range(0, 20) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription v) throws Exception { + System.out.println("Subscribed"); + } + }) + .publish(10) + .refCount() + ; + + Flowable evenNumbers = source.filter(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return v % 2 == 0; + } + }); + + Flowable oddNumbers = source.filter(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return v % 2 != 0; + } + }); + + final Single getNextOdd = oddNumbers.first(0); + + TestSubscriber> ts = evenNumbers.concatMap(new Function>>() { + @Override + public Publisher> apply(Integer v) throws Exception { + return Single.zip( + Single.just(v), getNextOdd, + new BiFunction>() { + @Override + public List apply(Integer a, Integer b) throws Exception { + return Arrays.asList( a, b ); + } + } + ) + .toFlowable(); + } + }) + .takeWhile(new Predicate>() { + @Override + public boolean test(List v) throws Exception { + return v.get(0) < 20; + } + }) + .test(); + + ts + .assertResult( + Arrays.asList(0, 1), + Arrays.asList(2, 3), + Arrays.asList(4, 5), + Arrays.asList(6, 7), + Arrays.asList(8, 9), + Arrays.asList(10, 11), + Arrays.asList(12, 13), + Arrays.asList(14, 15), + Arrays.asList(16, 17), + Arrays.asList(18, 19) + ); + } + + @Test + @SuppressWarnings("unchecked") + public void splitCombineSubscriberChangeAfterOnNextFused() { + Flowable source = Flowable.range(0, 20) + .publish(10) + .refCount() + ; + + Flowable evenNumbers = source.filter(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return v % 2 == 0; + } + }); + + Flowable oddNumbers = source.filter(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return v % 2 != 0; + } + }); + + final Single getNextOdd = oddNumbers.first(0); + + TestSubscriber> ts = evenNumbers.concatMap(new Function>>() { + @Override + public Publisher> apply(Integer v) throws Exception { + return Single.zip( + Single.just(v), getNextOdd, + new BiFunction>() { + @Override + public List apply(Integer a, Integer b) throws Exception { + return Arrays.asList( a, b ); + } + } + ) + .toFlowable(); + } + }) + .takeWhile(new Predicate>() { + @Override + public boolean test(List v) throws Exception { + return v.get(0) < 20; + } + }) + .test(); + + ts + .assertResult( + Arrays.asList(0, 1), + Arrays.asList(2, 3), + Arrays.asList(4, 5), + Arrays.asList(6, 7), + Arrays.asList(8, 9), + Arrays.asList(10, 11), + Arrays.asList(12, 13), + Arrays.asList(14, 15), + Arrays.asList(16, 17), + Arrays.asList(18, 19) + ); + } } From e1b383840d26ebdfbf298ee7f64ac26f697f9495 Mon Sep 17 00:00:00 2001 From: "Artem Zinnatullin :slowpoke" Date: Tue, 15 Jan 2019 03:27:26 -0800 Subject: [PATCH 127/211] Indicate source disposal in timeout(fallback) (#6365) --- src/main/java/io/reactivex/Flowable.java | 5 +++-- src/main/java/io/reactivex/Maybe.java | 5 +++-- src/main/java/io/reactivex/Observable.java | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index aea0ed9951..cba4b69210 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -16442,7 +16442,7 @@ public final Flowable timeout(long timeout, TimeUnit timeUnit) { /** * Returns a Flowable that mirrors the source Publisher but applies a timeout policy for each emitted * item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, - * the resulting Publisher begins instead to mirror a fallback Publisher. + * the source Publisher is disposed and resulting Publisher begins instead to mirror a fallback Publisher. *

      * *

      @@ -16476,7 +16476,8 @@ public final Flowable timeout(long timeout, TimeUnit timeUnit, Publisher * *
      diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 773021a028..147b3f3125 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -4463,7 +4463,7 @@ public final Maybe timeout(long timeout, TimeUnit timeUnit) { /** * Returns a Maybe that mirrors the source Maybe but applies a timeout policy for each emitted * item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, - * the resulting Maybe begins instead to mirror a fallback MaybeSource. + * the source MaybeSource is disposed and resulting Maybe begins instead to mirror a fallback MaybeSource. *

      * *

      @@ -4491,7 +4491,8 @@ public final Maybe timeout(long timeout, TimeUnit timeUnit, MaybeSource * *
      diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 50060d353d..90b96c38fd 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -13617,7 +13617,8 @@ public final Observable timeout(long timeout, TimeUnit timeUnit) { /** * Returns an Observable that mirrors the source ObservableSource but applies a timeout policy for each emitted * item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, - * the resulting ObservableSource begins instead to mirror a fallback ObservableSource. + * the source ObservableSource is disposed and resulting ObservableSource begins instead + * to mirror a fallback ObservableSource. *

      * *

      @@ -13644,7 +13645,8 @@ public final Observable timeout(long timeout, TimeUnit timeUnit, ObservableSo /** * Returns an Observable that mirrors the source ObservableSource but applies a timeout policy for each emitted * item using a specified Scheduler. If the next item isn't emitted within the specified timeout duration - * starting from its predecessor, the resulting ObservableSource begins instead to mirror a fallback ObservableSource. + * starting from its predecessor, the source ObservableSource is disposed and resulting ObservableSource + * begins instead to mirror a fallback ObservableSource. *

      * *

      From a85ddd154087f634c2834851acff87a02d39a061 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 17 Jan 2019 14:41:02 +0100 Subject: [PATCH 128/211] 2.x: Add interruptible mode to Schedulers.from (#6370) --- .../schedulers/ExecutorScheduler.java | 139 +++- .../io/reactivex/schedulers/Schedulers.java | 73 +- .../ExecutorSchedulerInterruptibleTest.java | 664 ++++++++++++++++++ 3 files changed, 861 insertions(+), 15 deletions(-) create mode 100644 src/test/java/io/reactivex/schedulers/ExecutorSchedulerInterruptibleTest.java diff --git a/src/main/java/io/reactivex/internal/schedulers/ExecutorScheduler.java b/src/main/java/io/reactivex/internal/schedulers/ExecutorScheduler.java index 45e3c1850e..75322a8de8 100644 --- a/src/main/java/io/reactivex/internal/schedulers/ExecutorScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/ExecutorScheduler.java @@ -22,7 +22,7 @@ import io.reactivex.internal.disposables.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.schedulers.ExecutorScheduler.ExecutorWorker.BooleanRunnable; +import io.reactivex.internal.schedulers.ExecutorScheduler.ExecutorWorker.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; @@ -31,19 +31,22 @@ */ public final class ExecutorScheduler extends Scheduler { + final boolean interruptibleWorker; + @NonNull final Executor executor; static final Scheduler HELPER = Schedulers.single(); - public ExecutorScheduler(@NonNull Executor executor) { + public ExecutorScheduler(@NonNull Executor executor, boolean interruptibleWorker) { this.executor = executor; + this.interruptibleWorker = interruptibleWorker; } @NonNull @Override public Worker createWorker() { - return new ExecutorWorker(executor); + return new ExecutorWorker(executor, interruptibleWorker); } @NonNull @@ -58,9 +61,15 @@ public Disposable scheduleDirect(@NonNull Runnable run) { return task; } - BooleanRunnable br = new BooleanRunnable(decoratedRun); - executor.execute(br); - return br; + if (interruptibleWorker) { + InterruptibleRunnable interruptibleTask = new InterruptibleRunnable(decoratedRun, null); + executor.execute(interruptibleTask); + return interruptibleTask; + } else { + BooleanRunnable br = new BooleanRunnable(decoratedRun); + executor.execute(br); + return br; + } } catch (RejectedExecutionException ex) { RxJavaPlugins.onError(ex); return EmptyDisposable.INSTANCE; @@ -111,6 +120,9 @@ public Disposable schedulePeriodicallyDirect(@NonNull Runnable run, long initial } /* public: test support. */ public static final class ExecutorWorker extends Scheduler.Worker implements Runnable { + + final boolean interruptibleWorker; + final Executor executor; final MpscLinkedQueue queue; @@ -121,9 +133,10 @@ public static final class ExecutorWorker extends Scheduler.Worker implements Run final CompositeDisposable tasks = new CompositeDisposable(); - public ExecutorWorker(Executor executor) { + public ExecutorWorker(Executor executor, boolean interruptibleWorker) { this.executor = executor; this.queue = new MpscLinkedQueue(); + this.interruptibleWorker = interruptibleWorker; } @NonNull @@ -134,9 +147,24 @@ public Disposable schedule(@NonNull Runnable run) { } Runnable decoratedRun = RxJavaPlugins.onSchedule(run); - BooleanRunnable br = new BooleanRunnable(decoratedRun); - queue.offer(br); + Runnable task; + Disposable disposable; + + if (interruptibleWorker) { + InterruptibleRunnable interruptibleTask = new InterruptibleRunnable(decoratedRun, tasks); + tasks.add(interruptibleTask); + + task = interruptibleTask; + disposable = interruptibleTask; + } else { + BooleanRunnable runnableTask = new BooleanRunnable(decoratedRun); + + task = runnableTask; + disposable = runnableTask; + } + + queue.offer(task); if (wip.getAndIncrement() == 0) { try { @@ -149,7 +177,7 @@ public Disposable schedule(@NonNull Runnable run) { } } - return br; + return disposable; } @NonNull @@ -288,6 +316,97 @@ public void run() { mar.replace(schedule(decoratedRun)); } } + + /** + * Wrapper for a {@link Runnable} with additional logic for handling interruption on + * a shared thread, similar to how Java Executors do it. + */ + static final class InterruptibleRunnable extends AtomicInteger implements Runnable, Disposable { + + private static final long serialVersionUID = -3603436687413320876L; + + final Runnable run; + + final DisposableContainer tasks; + + volatile Thread thread; + + static final int READY = 0; + + static final int RUNNING = 1; + + static final int FINISHED = 2; + + static final int INTERRUPTING = 3; + + static final int INTERRUPTED = 4; + + InterruptibleRunnable(Runnable run, DisposableContainer tasks) { + this.run = run; + this.tasks = tasks; + } + + @Override + public void run() { + if (get() == READY) { + thread = Thread.currentThread(); + if (compareAndSet(READY, RUNNING)) { + try { + run.run(); + } finally { + thread = null; + if (compareAndSet(RUNNING, FINISHED)) { + cleanup(); + } else { + while (get() == INTERRUPTING) { + Thread.yield(); + } + Thread.interrupted(); + } + } + } else { + thread = null; + } + } + } + + @Override + public void dispose() { + for (;;) { + int state = get(); + if (state >= FINISHED) { + break; + } else if (state == READY) { + if (compareAndSet(READY, INTERRUPTED)) { + cleanup(); + break; + } + } else { + if (compareAndSet(RUNNING, INTERRUPTING)) { + Thread t = thread; + if (t != null) { + t.interrupt(); + thread = null; + } + set(INTERRUPTED); + cleanup(); + break; + } + } + } + } + + void cleanup() { + if (tasks != null) { + tasks.delete(this); + } + } + + @Override + public boolean isDisposed() { + return get() >= FINISHED; + } + } } static final class DelayedRunnable extends AtomicReference diff --git a/src/main/java/io/reactivex/schedulers/Schedulers.java b/src/main/java/io/reactivex/schedulers/Schedulers.java index d3febba3ac..4edaf65b1a 100644 --- a/src/main/java/io/reactivex/schedulers/Schedulers.java +++ b/src/main/java/io/reactivex/schedulers/Schedulers.java @@ -13,13 +13,13 @@ package io.reactivex.schedulers; +import java.util.concurrent.*; + import io.reactivex.Scheduler; -import io.reactivex.annotations.NonNull; +import io.reactivex.annotations.*; import io.reactivex.internal.schedulers.*; import io.reactivex.plugins.RxJavaPlugins; -import java.util.concurrent.*; - /** * Static factory methods for returning standard Scheduler instances. *

      @@ -299,6 +299,9 @@ public static Scheduler single() { * a time delay or periodically will use the {@link #single()} scheduler for the timed waiting * before posting the actual task to the given executor. *

      + * Tasks submitted to the {@link Scheduler.Worker} of this {@code Scheduler} are also not interruptible. Use the + * {@link #from(Executor, boolean)} overload to enable task interruption via this wrapper. + *

      * If the provided executor supports the standard Java {@link ExecutorService} API, * cancelling tasks scheduled by this scheduler can be cancelled/interrupted by calling * {@link io.reactivex.disposables.Disposable#dispose()}. In addition, tasks scheduled with @@ -329,7 +332,7 @@ public static Scheduler single() { * } * *

      - * This type of scheduler is less sensitive to leaking {@link io.reactivex.Scheduler.Worker} instances, although + * This type of scheduler is less sensitive to leaking {@link Scheduler.Worker} instances, although * not disposing a worker that has timed/delayed tasks not cancelled by other means may leak resources and/or * execute those tasks "unexpectedly". *

      @@ -340,7 +343,67 @@ public static Scheduler single() { */ @NonNull public static Scheduler from(@NonNull Executor executor) { - return new ExecutorScheduler(executor); + return new ExecutorScheduler(executor, false); + } + + /** + * Wraps an {@link Executor} into a new Scheduler instance and delegates {@code schedule()} + * calls to it. + *

      + * The tasks scheduled by the returned {@link Scheduler} and its {@link Scheduler.Worker} + * can be optionally interrupted. + *

      + * If the provided executor doesn't support any of the more specific standard Java executor + * APIs, tasks scheduled with a time delay or periodically will use the + * {@link #single()} scheduler for the timed waiting + * before posting the actual task to the given executor. + *

      + * If the provided executor supports the standard Java {@link ExecutorService} API, + * canceling tasks scheduled by this scheduler can be cancelled/interrupted by calling + * {@link io.reactivex.disposables.Disposable#dispose()}. In addition, tasks scheduled with + * a time delay or periodically will use the {@link #single()} scheduler for the timed waiting + * before posting the actual task to the given executor. + *

      + * If the provided executor supports the standard Java {@link ScheduledExecutorService} API, + * canceling tasks scheduled by this scheduler can be cancelled/interrupted by calling + * {@link io.reactivex.disposables.Disposable#dispose()}. In addition, tasks scheduled with + * a time delay or periodically will use the provided executor. Note, however, if the provided + * {@code ScheduledExecutorService} instance is not single threaded, tasks scheduled + * with a time delay close to each other may end up executing in different order than + * the original schedule() call was issued. This limitation may be lifted in a future patch. + *

      + * Starting, stopping and restarting this scheduler is not supported (no-op) and the provided + * executor's lifecycle must be managed externally: + *

      
      +     * ExecutorService exec = Executors.newSingleThreadedExecutor();
      +     * try {
      +     *     Scheduler scheduler = Schedulers.from(exec, true);
      +     *     Flowable.just(1)
      +     *        .subscribeOn(scheduler)
      +     *        .map(v -> v + 1)
      +     *        .observeOn(scheduler)
      +     *        .blockingSubscribe(System.out::println);
      +     * } finally {
      +     *     exec.shutdown();
      +     * }
      +     * 
      + *

      + * This type of scheduler is less sensitive to leaking {@link Scheduler.Worker} instances, although + * not disposing a worker that has timed/delayed tasks not cancelled by other means may leak resources and/or + * execute those tasks "unexpectedly". + *

      + * Note that this method returns a new {@link Scheduler} instance, even for the same {@link Executor} instance. + * @param executor + * the executor to wrap + * @param interruptibleWorker if {@code true} the tasks submitted to the {@link Scheduler.Worker} will + * be interrupted when the task is disposed. + * @return the new Scheduler wrapping the Executor + * @since 2.2.6 - experimental + */ + @NonNull + @Experimental + public static Scheduler from(@NonNull Executor executor, boolean interruptibleWorker) { + return new ExecutorScheduler(executor, interruptibleWorker); } /** diff --git a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerInterruptibleTest.java b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerInterruptibleTest.java new file mode 100644 index 0000000000..bccca7524e --- /dev/null +++ b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerInterruptibleTest.java @@ -0,0 +1,664 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.schedulers; + +import static org.junit.Assert.*; + +import java.lang.management.*; +import java.util.List; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import org.junit.*; + +import io.reactivex.*; +import io.reactivex.Scheduler.Worker; +import io.reactivex.disposables.Disposable; +import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.schedulers.*; +import io.reactivex.plugins.RxJavaPlugins; + +public class ExecutorSchedulerInterruptibleTest extends AbstractSchedulerConcurrencyTests { + + static final Executor executor = Executors.newFixedThreadPool(2, new RxThreadFactory("TestCustomPool")); + + @Override + protected Scheduler getScheduler() { + return Schedulers.from(executor, true); + } + + @Test + @Ignore("Unhandled errors are no longer thrown") + public final void testUnhandledErrorIsDeliveredToThreadHandler() throws InterruptedException { + SchedulerTestHelper.testUnhandledErrorIsDeliveredToThreadHandler(getScheduler()); + } + + @Test + public final void testHandledErrorIsNotDeliveredToThreadHandler() throws InterruptedException { + SchedulerTestHelper.testHandledErrorIsNotDeliveredToThreadHandler(getScheduler()); + } + + public static void testCancelledRetention(Scheduler.Worker w, boolean periodic) throws InterruptedException { + System.out.println("Wait before GC"); + Thread.sleep(1000); + + System.out.println("GC"); + System.gc(); + + Thread.sleep(1000); + + MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); + long initial = memHeap.getUsed(); + + System.out.printf("Starting: %.3f MB%n", initial / 1024.0 / 1024.0); + + int n = 100 * 1000; + if (periodic) { + final CountDownLatch cdl = new CountDownLatch(n); + final Runnable action = new Runnable() { + @Override + public void run() { + cdl.countDown(); + } + }; + for (int i = 0; i < n; i++) { + if (i % 50000 == 0) { + System.out.println(" -> still scheduling: " + i); + } + w.schedulePeriodically(action, 0, 1, TimeUnit.DAYS); + } + + System.out.println("Waiting for the first round to finish..."); + cdl.await(); + } else { + for (int i = 0; i < n; i++) { + if (i % 50000 == 0) { + System.out.println(" -> still scheduling: " + i); + } + w.schedule(Functions.EMPTY_RUNNABLE, 1, TimeUnit.DAYS); + } + } + + memHeap = memoryMXBean.getHeapMemoryUsage(); + long after = memHeap.getUsed(); + System.out.printf("Peak: %.3f MB%n", after / 1024.0 / 1024.0); + + w.dispose(); + + System.out.println("Wait before second GC"); + System.out.println("JDK 6 purge is N log N because it removes and shifts one by one"); + int t = (int)(n * Math.log(n) / 100) + SchedulerPoolFactory.PURGE_PERIOD_SECONDS * 1000; + while (t > 0) { + System.out.printf(" >> Waiting for purge: %.2f s remaining%n", t / 1000d); + + System.gc(); + + Thread.sleep(1000); + + t -= 1000; + memHeap = memoryMXBean.getHeapMemoryUsage(); + long finish = memHeap.getUsed(); + System.out.printf("After: %.3f MB%n", finish / 1024.0 / 1024.0); + if (finish <= initial * 5) { + break; + } + } + + System.out.println("Second GC"); + System.gc(); + + Thread.sleep(1000); + + memHeap = memoryMXBean.getHeapMemoryUsage(); + long finish = memHeap.getUsed(); + System.out.printf("After: %.3f MB%n", finish / 1024.0 / 1024.0); + + if (finish > initial * 5) { + fail(String.format("Tasks retained: %.3f -> %.3f -> %.3f", initial / 1024 / 1024.0, after / 1024 / 1024.0, finish / 1024 / 1024d)); + } + } + + @Test(timeout = 60000) + public void testCancelledTaskRetention() throws InterruptedException { + ExecutorService exec = Executors.newSingleThreadExecutor(); + Scheduler s = Schedulers.from(exec, true); + try { + Scheduler.Worker w = s.createWorker(); + try { + testCancelledRetention(w, false); + } finally { + w.dispose(); + } + + w = s.createWorker(); + try { + testCancelledRetention(w, true); + } finally { + w.dispose(); + } + } finally { + exec.shutdownNow(); + } + } + + /** A simple executor which queues tasks and executes them one-by-one if executeOne() is called. */ + static final class TestExecutor implements Executor { + final ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue(); + @Override + public void execute(Runnable command) { + queue.offer(command); + } + public void executeOne() { + Runnable r = queue.poll(); + if (r != null) { + r.run(); + } + } + public void executeAll() { + Runnable r; + while ((r = queue.poll()) != null) { + r.run(); + } + } + } + + @Test + public void testCancelledTasksDontRun() { + final AtomicInteger calls = new AtomicInteger(); + Runnable task = new Runnable() { + @Override + public void run() { + calls.getAndIncrement(); + } + }; + TestExecutor exec = new TestExecutor(); + Scheduler custom = Schedulers.from(exec, true); + Worker w = custom.createWorker(); + try { + Disposable d1 = w.schedule(task); + Disposable d2 = w.schedule(task); + Disposable d3 = w.schedule(task); + + d1.dispose(); + d2.dispose(); + d3.dispose(); + + exec.executeAll(); + + assertEquals(0, calls.get()); + } finally { + w.dispose(); + } + } + + @Test + public void testCancelledWorkerDoesntRunTasks() { + final AtomicInteger calls = new AtomicInteger(); + Runnable task = new Runnable() { + @Override + public void run() { + calls.getAndIncrement(); + } + }; + TestExecutor exec = new TestExecutor(); + Scheduler custom = Schedulers.from(exec, true); + Worker w = custom.createWorker(); + try { + w.schedule(task); + w.schedule(task); + w.schedule(task); + } finally { + w.dispose(); + } + exec.executeAll(); + assertEquals(0, calls.get()); + } + + // FIXME the internal structure changed and these can't be tested +// +// @Test +// public void testNoTimedTaskAfterScheduleRetention() throws InterruptedException { +// Executor e = new Executor() { +// @Override +// public void execute(Runnable command) { +// command.run(); +// } +// }; +// ExecutorWorker w = (ExecutorWorker)Schedulers.from(e, true).createWorker(); +// +// w.schedule(Functions.emptyRunnable(), 50, TimeUnit.MILLISECONDS); +// +// assertTrue(w.tasks.hasSubscriptions()); +// +// Thread.sleep(150); +// +// assertFalse(w.tasks.hasSubscriptions()); +// } +// +// @Test +// public void testNoTimedTaskPartRetention() { +// Executor e = new Executor() { +// @Override +// public void execute(Runnable command) { +// +// } +// }; +// ExecutorWorker w = (ExecutorWorker)Schedulers.from(e, true).createWorker(); +// +// Disposable task = w.schedule(Functions.emptyRunnable(), 1, TimeUnit.DAYS); +// +// assertTrue(w.tasks.hasSubscriptions()); +// +// task.dispose(); +// +// assertFalse(w.tasks.hasSubscriptions()); +// } +// +// @Test +// public void testNoPeriodicTimedTaskPartRetention() throws InterruptedException { +// Executor e = new Executor() { +// @Override +// public void execute(Runnable command) { +// command.run(); +// } +// }; +// ExecutorWorker w = (ExecutorWorker)Schedulers.from(e, true).createWorker(); +// +// final CountDownLatch cdl = new CountDownLatch(1); +// final Runnable action = new Runnable() { +// @Override +// public void run() { +// cdl.countDown(); +// } +// }; +// +// Disposable task = w.schedulePeriodically(action, 0, 1, TimeUnit.DAYS); +// +// assertTrue(w.tasks.hasSubscriptions()); +// +// cdl.await(); +// +// task.dispose(); +// +// assertFalse(w.tasks.hasSubscriptions()); +// } + + @Test + public void plainExecutor() throws Exception { + Scheduler s = Schedulers.from(new Executor() { + @Override + public void execute(Runnable r) { + r.run(); + } + }, true); + + final CountDownLatch cdl = new CountDownLatch(5); + + Runnable r = new Runnable() { + @Override + public void run() { + cdl.countDown(); + } + }; + + s.scheduleDirect(r); + + s.scheduleDirect(r, 50, TimeUnit.MILLISECONDS); + + Disposable d = s.schedulePeriodicallyDirect(r, 10, 10, TimeUnit.MILLISECONDS); + + try { + assertTrue(cdl.await(5, TimeUnit.SECONDS)); + } finally { + d.dispose(); + } + + assertTrue(d.isDisposed()); + } + + @Test + public void rejectingExecutor() { + ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); + exec.shutdown(); + + Scheduler s = Schedulers.from(exec, true); + + List errors = TestHelper.trackPluginErrors(); + + try { + assertSame(EmptyDisposable.INSTANCE, s.scheduleDirect(Functions.EMPTY_RUNNABLE)); + + assertSame(EmptyDisposable.INSTANCE, s.scheduleDirect(Functions.EMPTY_RUNNABLE, 10, TimeUnit.MILLISECONDS)); + + assertSame(EmptyDisposable.INSTANCE, s.schedulePeriodicallyDirect(Functions.EMPTY_RUNNABLE, 10, 10, TimeUnit.MILLISECONDS)); + + TestHelper.assertUndeliverable(errors, 0, RejectedExecutionException.class); + TestHelper.assertUndeliverable(errors, 1, RejectedExecutionException.class); + TestHelper.assertUndeliverable(errors, 2, RejectedExecutionException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void rejectingExecutorWorker() { + ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); + exec.shutdown(); + + List errors = TestHelper.trackPluginErrors(); + + try { + Worker s = Schedulers.from(exec, true).createWorker(); + assertSame(EmptyDisposable.INSTANCE, s.schedule(Functions.EMPTY_RUNNABLE)); + + s = Schedulers.from(exec, true).createWorker(); + assertSame(EmptyDisposable.INSTANCE, s.schedule(Functions.EMPTY_RUNNABLE, 10, TimeUnit.MILLISECONDS)); + + s = Schedulers.from(exec, true).createWorker(); + assertSame(EmptyDisposable.INSTANCE, s.schedulePeriodically(Functions.EMPTY_RUNNABLE, 10, 10, TimeUnit.MILLISECONDS)); + + TestHelper.assertUndeliverable(errors, 0, RejectedExecutionException.class); + TestHelper.assertUndeliverable(errors, 1, RejectedExecutionException.class); + TestHelper.assertUndeliverable(errors, 2, RejectedExecutionException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void reuseScheduledExecutor() throws Exception { + ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); + + try { + Scheduler s = Schedulers.from(exec, true); + + final CountDownLatch cdl = new CountDownLatch(8); + + Runnable r = new Runnable() { + @Override + public void run() { + cdl.countDown(); + } + }; + + s.scheduleDirect(r); + + s.scheduleDirect(r, 10, TimeUnit.MILLISECONDS); + + Disposable d = s.schedulePeriodicallyDirect(r, 10, 10, TimeUnit.MILLISECONDS); + + try { + assertTrue(cdl.await(5, TimeUnit.SECONDS)); + } finally { + d.dispose(); + } + } finally { + exec.shutdown(); + } + } + + @Test + public void reuseScheduledExecutorAsWorker() throws Exception { + ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); + + Worker s = Schedulers.from(exec, true).createWorker(); + + assertFalse(s.isDisposed()); + try { + + final CountDownLatch cdl = new CountDownLatch(8); + + Runnable r = new Runnable() { + @Override + public void run() { + cdl.countDown(); + } + }; + + s.schedule(r); + + s.schedule(r, 10, TimeUnit.MILLISECONDS); + + Disposable d = s.schedulePeriodically(r, 10, 10, TimeUnit.MILLISECONDS); + + try { + assertTrue(cdl.await(5, TimeUnit.SECONDS)); + } finally { + d.dispose(); + } + } finally { + s.dispose(); + exec.shutdown(); + } + + assertTrue(s.isDisposed()); + } + + @Test + public void disposeRace() { + ExecutorService exec = Executors.newSingleThreadExecutor(); + final Scheduler s = Schedulers.from(exec, true); + try { + for (int i = 0; i < 500; i++) { + final Worker w = s.createWorker(); + + final AtomicInteger c = new AtomicInteger(2); + + w.schedule(new Runnable() { + @Override + public void run() { + c.decrementAndGet(); + while (c.get() != 0) { } + } + }); + + c.decrementAndGet(); + while (c.get() != 0) { } + w.dispose(); + } + } finally { + exec.shutdownNow(); + } + } + + @Test + public void runnableDisposed() { + final Scheduler s = Schedulers.from(new Executor() { + @Override + public void execute(Runnable r) { + r.run(); + } + }, true); + Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE); + + assertTrue(d.isDisposed()); + } + + @Test(timeout = 1000) + public void runnableDisposedAsync() throws Exception { + final Scheduler s = Schedulers.from(new Executor() { + @Override + public void execute(Runnable r) { + new Thread(r).start(); + } + }, true); + Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE); + + while (!d.isDisposed()) { + Thread.sleep(1); + } + } + + @Test(timeout = 1000) + public void runnableDisposedAsync2() throws Exception { + final Scheduler s = Schedulers.from(executor, true); + Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE); + + while (!d.isDisposed()) { + Thread.sleep(1); + } + } + + @Test(timeout = 1000) + public void runnableDisposedAsyncCrash() throws Exception { + final Scheduler s = Schedulers.from(new Executor() { + @Override + public void execute(Runnable r) { + new Thread(r).start(); + } + }, true); + Disposable d = s.scheduleDirect(new Runnable() { + @Override + public void run() { + throw new IllegalStateException(); + } + }); + + while (!d.isDisposed()) { + Thread.sleep(1); + } + } + + @Test(timeout = 1000) + public void runnableDisposedAsyncTimed() throws Exception { + final Scheduler s = Schedulers.from(new Executor() { + @Override + public void execute(Runnable r) { + new Thread(r).start(); + } + }, true); + Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS); + + while (!d.isDisposed()) { + Thread.sleep(1); + } + } + + @Test(timeout = 1000) + public void runnableDisposedAsyncTimed2() throws Exception { + ExecutorService executorScheduler = Executors.newScheduledThreadPool(1, new RxThreadFactory("TestCustomPoolTimed")); + try { + final Scheduler s = Schedulers.from(executorScheduler, true); + Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS); + + while (!d.isDisposed()) { + Thread.sleep(1); + } + } finally { + executorScheduler.shutdownNow(); + } + } + + @Test + public void unwrapScheduleDirectTaskAfterDispose() { + Scheduler scheduler = getScheduler(); + final CountDownLatch cdl = new CountDownLatch(1); + Runnable countDownRunnable = new Runnable() { + @Override + public void run() { + cdl.countDown(); + } + }; + Disposable disposable = scheduler.scheduleDirect(countDownRunnable, 100, TimeUnit.MILLISECONDS); + SchedulerRunnableIntrospection wrapper = (SchedulerRunnableIntrospection) disposable; + assertSame(countDownRunnable, wrapper.getWrappedRunnable()); + disposable.dispose(); + + assertSame(Functions.EMPTY_RUNNABLE, wrapper.getWrappedRunnable()); + } + + @Test(timeout = 10000) + public void interruptibleDirectTask() throws Exception { + Scheduler scheduler = getScheduler(); + + final AtomicInteger sync = new AtomicInteger(2); + + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + Disposable d = scheduler.scheduleDirect(new Runnable() { + @Override + public void run() { + if (sync.decrementAndGet() != 0) { + while (sync.get() != 0) { } + } + try { + Thread.sleep(1000); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + } + }); + + if (sync.decrementAndGet() != 0) { + while (sync.get() != 0) { } + } + + Thread.sleep(500); + + d.dispose(); + + int i = 20; + while (i-- > 0 && !isInterrupted.get()) { + Thread.sleep(50); + } + + assertTrue("Interruption did not propagate", isInterrupted.get()); + } + + @Test(timeout = 10000) + public void interruptibleWorkerTask() throws Exception { + Scheduler scheduler = getScheduler(); + + Worker worker = scheduler.createWorker(); + + try { + final AtomicInteger sync = new AtomicInteger(2); + + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + Disposable d = worker.schedule(new Runnable() { + @Override + public void run() { + if (sync.decrementAndGet() != 0) { + while (sync.get() != 0) { } + } + try { + Thread.sleep(1000); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + } + }); + + if (sync.decrementAndGet() != 0) { + while (sync.get() != 0) { } + } + + Thread.sleep(500); + + d.dispose(); + + int i = 20; + while (i-- > 0 && !isInterrupted.get()) { + Thread.sleep(50); + } + + assertTrue("Interruption did not propagate", isInterrupted.get()); + } finally { + worker.dispose(); + } + } +} From 5106a20e0a2aa45763ac5c6726d6ff86a125d665 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 17 Jan 2019 15:02:36 +0100 Subject: [PATCH 129/211] 2.x: Fix bounded replay() memory leak due to bad node retention (#6371) --- .../operators/flowable/FlowableReplay.java | 4 ++ .../observable/ObservableReplay.java | 3 + .../flowable/FlowableReplayTest.java | 64 ++++++++++++++++++ .../observable/ObservableReplayTest.java | 67 ++++++++++++++++++- .../processors/ReplayProcessorTest.java | 65 +++++++++++++++++- .../reactivex/subjects/ReplaySubjectTest.java | 65 +++++++++++++++++- 6 files changed, 260 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java index 21b1b1d39c..7a02482b4b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java @@ -566,6 +566,8 @@ public void dispose() { // the others had non-zero. By removing this 'blocking' child, the others // are now free to receive events parent.manageRequests(); + // make sure the last known node is not retained + index = null; } } /** @@ -824,6 +826,7 @@ public final void replay(InnerSubscription output) { } for (;;) { if (output.isDisposed()) { + output.index = null; return; } @@ -864,6 +867,7 @@ public final void replay(InnerSubscription output) { break; } if (output.isDisposed()) { + output.index = null; return; } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java index 89db184d6b..197ada9706 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java @@ -453,6 +453,8 @@ public void dispose() { cancelled = true; // remove this from the parent parent.remove(this); + // make sure the last known node is not retained + index = null; } } /** @@ -686,6 +688,7 @@ public final void replay(InnerDisposable output) { for (;;) { if (output.isDisposed()) { + output.index = null; return; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java index dcf7eea347..b3bea718bd 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java @@ -17,6 +17,7 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import java.lang.management.*; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; @@ -1976,4 +1977,67 @@ public void currentDisposedWhenConnecting() { assertFalse(fr.current.get().isDisposed()); } + + @Test + public void noBoundedRetentionViaThreadLocal() throws Exception { + Flowable source = Flowable.range(1, 200) + .map(new Function() { + @Override + public byte[] apply(Integer v) throws Exception { + return new byte[1024 * 1024]; + } + }) + .replay(new Function, Publisher>() { + @Override + public Publisher apply(final Flowable f) throws Exception { + return f.take(1) + .concatMap(new Function>() { + @Override + public Publisher apply(byte[] v) throws Exception { + return f; + } + }); + } + }, 1) + .takeLast(1) + ; + + System.out.println("Bounded Replay Leak check: Wait before GC"); + Thread.sleep(1000); + + System.out.println("Bounded Replay Leak check: GC"); + System.gc(); + + Thread.sleep(500); + + final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); + long initial = memHeap.getUsed(); + + System.out.printf("Bounded Replay Leak check: Starting: %.3f MB%n", initial / 1024.0 / 1024.0); + + final AtomicLong after = new AtomicLong(); + + source.subscribe(new Consumer() { + @Override + public void accept(byte[] v) throws Exception { + System.out.println("Bounded Replay Leak check: Wait before GC 2"); + Thread.sleep(1000); + + System.out.println("Bounded Replay Leak check: GC 2"); + System.gc(); + + Thread.sleep(500); + + after.set(memoryMXBean.getHeapMemoryUsage().getUsed()); + } + }); + + System.out.printf("Bounded Replay Leak check: After: %.3f MB%n", after.get() / 1024.0 / 1024.0); + + if (initial + 100 * 1024 * 1024 < after.get()) { + Assert.fail("Bounded Replay Leak check: Memory leak detected: " + (initial / 1024.0 / 1024.0) + + " -> " + after.get() / 1024.0 / 1024.0); + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java index 2592361cd6..40d09f4f33 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java @@ -17,9 +17,10 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import java.lang.management.*; import java.util.*; import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.*; import org.junit.*; import org.mockito.InOrder; @@ -1713,4 +1714,66 @@ public void noHeadRetentionTime() { assertSame(o, buf.get()); } -} + + @Test + public void noBoundedRetentionViaThreadLocal() throws Exception { + Observable source = Observable.range(1, 200) + .map(new Function() { + @Override + public byte[] apply(Integer v) throws Exception { + return new byte[1024 * 1024]; + } + }) + .replay(new Function, Observable>() { + @Override + public Observable apply(final Observable o) throws Exception { + return o.take(1) + .concatMap(new Function>() { + @Override + public Observable apply(byte[] v) throws Exception { + return o; + } + }); + } + }, 1) + .takeLast(1) + ; + + System.out.println("Bounded Replay Leak check: Wait before GC"); + Thread.sleep(1000); + + System.out.println("Bounded Replay Leak check: GC"); + System.gc(); + + Thread.sleep(500); + + final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); + long initial = memHeap.getUsed(); + + System.out.printf("Bounded Replay Leak check: Starting: %.3f MB%n", initial / 1024.0 / 1024.0); + + final AtomicLong after = new AtomicLong(); + + source.subscribe(new Consumer() { + @Override + public void accept(byte[] v) throws Exception { + System.out.println("Bounded Replay Leak check: Wait before GC 2"); + Thread.sleep(1000); + + System.out.println("Bounded Replay Leak check: GC 2"); + System.gc(); + + Thread.sleep(500); + + after.set(memoryMXBean.getHeapMemoryUsage().getUsed()); + } + }); + + System.out.printf("Bounded Replay Leak check: After: %.3f MB%n", after.get() / 1024.0 / 1024.0); + + if (initial + 100 * 1024 * 1024 < after.get()) { + Assert.fail("Bounded Replay Leak check: Memory leak detected: " + (initial / 1024.0 / 1024.0) + + " -> " + after.get() / 1024.0 / 1024.0); + } + }} diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java index 810e80d9e5..cf930b062a 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java @@ -17,18 +17,19 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import java.lang.management.*; import java.util.Arrays; import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.atomic.*; -import org.junit.Test; +import org.junit.*; import org.mockito.*; import org.reactivestreams.*; import io.reactivex.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; -import io.reactivex.functions.Function; +import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.ReplayProcessor.*; import io.reactivex.schedulers.*; @@ -1692,4 +1693,62 @@ public void noHeadRetentionTime() { public void invalidRequest() { TestHelper.assertBadRequestReported(ReplayProcessor.create()); } + + @Test + public void noBoundedRetentionViaThreadLocal() throws Exception { + final ReplayProcessor rp = ReplayProcessor.createWithSize(1); + + Flowable source = rp.take(1) + .concatMap(new Function>() { + @Override + public Publisher apply(byte[] v) throws Exception { + return rp; + } + }) + .takeLast(1) + ; + + System.out.println("Bounded Replay Leak check: Wait before GC"); + Thread.sleep(1000); + + System.out.println("Bounded Replay Leak check: GC"); + System.gc(); + + Thread.sleep(500); + + final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); + long initial = memHeap.getUsed(); + + System.out.printf("Bounded Replay Leak check: Starting: %.3f MB%n", initial / 1024.0 / 1024.0); + + final AtomicLong after = new AtomicLong(); + + source.subscribe(new Consumer() { + @Override + public void accept(byte[] v) throws Exception { + System.out.println("Bounded Replay Leak check: Wait before GC 2"); + Thread.sleep(1000); + + System.out.println("Bounded Replay Leak check: GC 2"); + System.gc(); + + Thread.sleep(500); + + after.set(memoryMXBean.getHeapMemoryUsage().getUsed()); + } + }); + + for (int i = 0; i < 200; i++) { + rp.onNext(new byte[1024 * 1024]); + } + rp.onComplete(); + + System.out.printf("Bounded Replay Leak check: After: %.3f MB%n", after.get() / 1024.0 / 1024.0); + + if (initial + 100 * 1024 * 1024 < after.get()) { + Assert.fail("Bounded Replay Leak check: Memory leak detected: " + (initial / 1024.0 / 1024.0) + + " -> " + after.get() / 1024.0 / 1024.0); + } + } } diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java index 2326241cfd..aa91270226 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java @@ -17,17 +17,18 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import java.lang.management.*; import java.util.Arrays; import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.atomic.*; -import org.junit.Test; +import org.junit.*; import org.mockito.*; import io.reactivex.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; -import io.reactivex.functions.Function; +import io.reactivex.functions.*; import io.reactivex.observers.*; import io.reactivex.schedulers.*; import io.reactivex.subjects.ReplaySubject.*; @@ -1284,4 +1285,62 @@ public void noHeadRetentionTime() { assertSame(o, buf.head); } + + @Test + public void noBoundedRetentionViaThreadLocal() throws Exception { + final ReplaySubject rs = ReplaySubject.createWithSize(1); + + Observable source = rs.take(1) + .concatMap(new Function>() { + @Override + public Observable apply(byte[] v) throws Exception { + return rs; + } + }) + .takeLast(1) + ; + + System.out.println("Bounded Replay Leak check: Wait before GC"); + Thread.sleep(1000); + + System.out.println("Bounded Replay Leak check: GC"); + System.gc(); + + Thread.sleep(500); + + final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); + long initial = memHeap.getUsed(); + + System.out.printf("Bounded Replay Leak check: Starting: %.3f MB%n", initial / 1024.0 / 1024.0); + + final AtomicLong after = new AtomicLong(); + + source.subscribe(new Consumer() { + @Override + public void accept(byte[] v) throws Exception { + System.out.println("Bounded Replay Leak check: Wait before GC 2"); + Thread.sleep(1000); + + System.out.println("Bounded Replay Leak check: GC 2"); + System.gc(); + + Thread.sleep(500); + + after.set(memoryMXBean.getHeapMemoryUsage().getUsed()); + } + }); + + for (int i = 0; i < 200; i++) { + rs.onNext(new byte[1024 * 1024]); + } + rs.onComplete(); + + System.out.printf("Bounded Replay Leak check: After: %.3f MB%n", after.get() / 1024.0 / 1024.0); + + if (initial + 100 * 1024 * 1024 < after.get()) { + Assert.fail("Bounded Replay Leak check: Memory leak detected: " + (initial / 1024.0 / 1024.0) + + " -> " + after.get() / 1024.0 / 1024.0); + } + } } From d40f923efe6b867d71412858b11f4344c1f0883a Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 17 Jan 2019 15:28:30 +0100 Subject: [PATCH 130/211] 2.x: Don't dispose the winner of {Single|Maybe|Completable}.amb() (#6375) * 2.x: Don't dispose the winner of {Single|Maybe|Completable}.amb() * Add null-source test to MaybeAmbTest --- .../operators/completable/CompletableAmb.java | 19 ++- .../internal/operators/maybe/MaybeAmb.java | 56 ++++---- .../internal/operators/single/SingleAmb.java | 26 ++-- .../completable/CompletableAmbTest.java | 55 ++++++++ .../operators/flowable/FlowableAmbTest.java | 84 +++++++++++- .../operators/maybe/MaybeAmbTest.java | 124 ++++++++++++++++++ .../observable/ObservableAmbTest.java | 87 +++++++++++- .../operators/single/SingleAmbTest.java | 61 +++++++++ 8 files changed, 462 insertions(+), 50 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableAmb.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableAmb.java index cc603acbdc..7de1c648e4 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableAmb.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableAmb.java @@ -63,8 +63,6 @@ public void subscribeActual(final CompletableObserver observer) { final AtomicBoolean once = new AtomicBoolean(); - CompletableObserver inner = new Amb(once, set, observer); - for (int i = 0; i < count; i++) { CompletableSource c = sources[i]; if (set.isDisposed()) { @@ -82,7 +80,7 @@ public void subscribeActual(final CompletableObserver observer) { } // no need to have separate subscribers because inner is stateless - c.subscribe(inner); + c.subscribe(new Amb(once, set, observer)); } if (count == 0) { @@ -91,9 +89,14 @@ public void subscribeActual(final CompletableObserver observer) { } static final class Amb implements CompletableObserver { - private final AtomicBoolean once; - private final CompositeDisposable set; - private final CompletableObserver downstream; + + final AtomicBoolean once; + + final CompositeDisposable set; + + final CompletableObserver downstream; + + Disposable upstream; Amb(AtomicBoolean once, CompositeDisposable set, CompletableObserver observer) { this.once = once; @@ -104,6 +107,7 @@ static final class Amb implements CompletableObserver { @Override public void onComplete() { if (once.compareAndSet(false, true)) { + set.delete(upstream); set.dispose(); downstream.onComplete(); } @@ -112,6 +116,7 @@ public void onComplete() { @Override public void onError(Throwable e) { if (once.compareAndSet(false, true)) { + set.delete(upstream); set.dispose(); downstream.onError(e); } else { @@ -121,8 +126,8 @@ public void onError(Throwable e) { @Override public void onSubscribe(Disposable d) { + upstream = d; set.add(d); } - } } diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java index d9c1c6963c..8efc69b24b 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeAmb.java @@ -64,64 +64,63 @@ protected void subscribeActual(MaybeObserver observer) { count = sources.length; } - AmbMaybeObserver parent = new AmbMaybeObserver(observer); - observer.onSubscribe(parent); + CompositeDisposable set = new CompositeDisposable(); + observer.onSubscribe(set); + + AtomicBoolean winner = new AtomicBoolean(); for (int i = 0; i < count; i++) { MaybeSource s = sources[i]; - if (parent.isDisposed()) { + if (set.isDisposed()) { return; } if (s == null) { - parent.onError(new NullPointerException("One of the MaybeSources is null")); + set.dispose(); + NullPointerException ex = new NullPointerException("One of the MaybeSources is null"); + if (winner.compareAndSet(false, true)) { + observer.onError(ex); + } else { + RxJavaPlugins.onError(ex); + } return; } - s.subscribe(parent); + s.subscribe(new AmbMaybeObserver(observer, set, winner)); } if (count == 0) { observer.onComplete(); } - } static final class AmbMaybeObserver - extends AtomicBoolean - implements MaybeObserver, Disposable { - - private static final long serialVersionUID = -7044685185359438206L; + implements MaybeObserver { final MaybeObserver downstream; - final CompositeDisposable set; + final AtomicBoolean winner; - AmbMaybeObserver(MaybeObserver downstream) { - this.downstream = downstream; - this.set = new CompositeDisposable(); - } + final CompositeDisposable set; - @Override - public void dispose() { - if (compareAndSet(false, true)) { - set.dispose(); - } - } + Disposable upstream; - @Override - public boolean isDisposed() { - return get(); + AmbMaybeObserver(MaybeObserver downstream, CompositeDisposable set, AtomicBoolean winner) { + this.downstream = downstream; + this.set = set; + this.winner = winner; } @Override public void onSubscribe(Disposable d) { + upstream = d; set.add(d); } @Override public void onSuccess(T value) { - if (compareAndSet(false, true)) { + if (winner.compareAndSet(false, true)) { + set.delete(upstream); set.dispose(); downstream.onSuccess(value); @@ -130,7 +129,8 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - if (compareAndSet(false, true)) { + if (winner.compareAndSet(false, true)) { + set.delete(upstream); set.dispose(); downstream.onError(e); @@ -141,12 +141,12 @@ public void onError(Throwable e) { @Override public void onComplete() { - if (compareAndSet(false, true)) { + if (winner.compareAndSet(false, true)) { + set.delete(upstream); set.dispose(); downstream.onComplete(); } } - } } diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleAmb.java b/src/main/java/io/reactivex/internal/operators/single/SingleAmb.java index d7508c3a72..2584506b59 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleAmb.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleAmb.java @@ -59,21 +59,21 @@ protected void subscribeActual(final SingleObserver observer) { count = sources.length; } + final AtomicBoolean winner = new AtomicBoolean(); final CompositeDisposable set = new CompositeDisposable(); - AmbSingleObserver shared = new AmbSingleObserver(observer, set); observer.onSubscribe(set); for (int i = 0; i < count; i++) { SingleSource s1 = sources[i]; - if (shared.get()) { + if (set.isDisposed()) { return; } if (s1 == null) { set.dispose(); Throwable e = new NullPointerException("One of the sources is null"); - if (shared.compareAndSet(false, true)) { + if (winner.compareAndSet(false, true)) { observer.onError(e); } else { RxJavaPlugins.onError(e); @@ -81,31 +81,36 @@ protected void subscribeActual(final SingleObserver observer) { return; } - s1.subscribe(shared); + s1.subscribe(new AmbSingleObserver(observer, set, winner)); } } - static final class AmbSingleObserver extends AtomicBoolean implements SingleObserver { - - private static final long serialVersionUID = -1944085461036028108L; + static final class AmbSingleObserver implements SingleObserver { final CompositeDisposable set; final SingleObserver downstream; - AmbSingleObserver(SingleObserver observer, CompositeDisposable set) { + final AtomicBoolean winner; + + Disposable upstream; + + AmbSingleObserver(SingleObserver observer, CompositeDisposable set, AtomicBoolean winner) { this.downstream = observer; this.set = set; + this.winner = winner; } @Override public void onSubscribe(Disposable d) { + this.upstream = d; set.add(d); } @Override public void onSuccess(T value) { - if (compareAndSet(false, true)) { + if (winner.compareAndSet(false, true)) { + set.delete(upstream); set.dispose(); downstream.onSuccess(value); } @@ -113,7 +118,8 @@ public void onSuccess(T value) { @Override public void onError(Throwable e) { - if (compareAndSet(false, true)) { + if (winner.compareAndSet(false, true)) { + set.delete(upstream); set.dispose(); downstream.onError(e); } else { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java index 0e45cd1c1b..f4a8a084b8 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java @@ -16,6 +16,7 @@ import static org.junit.Assert.*; import java.util.*; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; @@ -23,10 +24,13 @@ import io.reactivex.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; +import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.internal.operators.completable.CompletableAmb.Amb; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; public class CompletableAmbTest { @@ -173,6 +177,7 @@ public void ambRace() { CompositeDisposable cd = new CompositeDisposable(); AtomicBoolean once = new AtomicBoolean(); Amb a = new Amb(once, cd, to); + a.onSubscribe(Disposables.empty()); a.onComplete(); a.onComplete(); @@ -259,4 +264,54 @@ public void untilCompletableOtherError() { to.assertFailure(TestException.class); } + @Test + public void noWinnerErrorDispose() throws Exception { + final TestException ex = new TestException(); + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Completable.ambArray( + Completable.error(ex) + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Completable.never() + ) + .subscribe(Functions.EMPTY_ACTION, new Consumer() { + @Override + public void accept(Throwable e) throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + + @Test + public void noWinnerCompleteDispose() throws Exception { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Completable.ambArray( + Completable.complete() + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Completable.never() + ) + .subscribe(new Action() { + @Override + public void run() throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java index a4b03c633c..5b5941fbf4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java @@ -19,8 +19,8 @@ import java.io.IOException; import java.lang.reflect.Method; import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; import org.junit.*; import org.mockito.InOrder; @@ -30,6 +30,7 @@ import io.reactivex.disposables.CompositeDisposable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.internal.util.CrashingMappedIterable; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; @@ -713,4 +714,83 @@ public void ambArrayOrder() { Flowable error = Flowable.error(new RuntimeException()); Flowable.ambArray(Flowable.just(1), error).test().assertValue(1).assertComplete(); } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerSuccessDispose() throws Exception { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Flowable.ambArray( + Flowable.just(1) + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Flowable.never() + ) + .subscribe(new Consumer() { + @Override + public void accept(Object v) throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerErrorDispose() throws Exception { + final TestException ex = new TestException(); + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Flowable.ambArray( + Flowable.error(ex) + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Flowable.never() + ) + .subscribe(Functions.emptyConsumer(), new Consumer() { + @Override + public void accept(Throwable e) throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerCompleteDispose() throws Exception { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Flowable.ambArray( + Flowable.empty() + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Flowable.never() + ) + .subscribe(Functions.emptyConsumer(), Functions.emptyConsumer(), new Action() { + @Override + public void run() throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeAmbTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeAmbTest.java index a50c685233..a701a279ab 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeAmbTest.java @@ -16,15 +16,21 @@ import static org.junit.Assert.*; import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; import io.reactivex.*; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; +import io.reactivex.functions.*; +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.Schedulers; +import io.reactivex.subjects.*; public class MaybeAmbTest { @@ -129,4 +135,122 @@ protected void subscribeActual( to.assertResult(1); } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerSuccessDispose() throws Exception { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Maybe.ambArray( + Maybe.just(1) + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Maybe.never() + ) + .subscribe(new Consumer() { + @Override + public void accept(Object v) throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerErrorDispose() throws Exception { + final TestException ex = new TestException(); + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Maybe.ambArray( + Maybe.error(ex) + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Maybe.never() + ) + .subscribe(Functions.emptyConsumer(), new Consumer() { + @Override + public void accept(Throwable e) throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerCompleteDispose() throws Exception { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Maybe.ambArray( + Maybe.empty() + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Maybe.never() + ) + .subscribe(Functions.emptyConsumer(), Functions.emptyConsumer(), new Action() { + @Override + public void run() throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + + @Test + public void nullSourceSuccessRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + List errors = TestHelper.trackPluginErrors(); + + try { + + final Subject ps = ReplaySubject.create(); + ps.onNext(1); + + @SuppressWarnings("unchecked") + final Maybe source = Maybe.ambArray(ps.singleElement(), + Maybe.never(), Maybe.never(), null); + + Runnable r1 = new Runnable() { + @Override + public void run() { + source.test(); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + ps.onComplete(); + } + }; + + TestHelper.race(r1, r2); + + if (!errors.isEmpty()) { + TestHelper.assertError(errors, 0, NullPointerException.class); + } + } finally { + RxJavaPlugins.reset(); + } + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java index ee4d58adf5..6e2c737f75 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java @@ -18,8 +18,8 @@ import java.io.IOException; import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; import org.junit.*; import org.mockito.InOrder; @@ -29,7 +29,8 @@ import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; -import io.reactivex.functions.Consumer; +import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; @@ -383,4 +384,84 @@ public void ambArrayOrder() { Observable error = Observable.error(new RuntimeException()); Observable.ambArray(Observable.just(1), error).test().assertValue(1).assertComplete(); } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerSuccessDispose() throws Exception { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Observable.ambArray( + Observable.just(1) + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Observable.never() + ) + .subscribe(new Consumer() { + @Override + public void accept(Object v) throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerErrorDispose() throws Exception { + final TestException ex = new TestException(); + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Observable.ambArray( + Observable.error(ex) + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Observable.never() + ) + .subscribe(Functions.emptyConsumer(), new Consumer() { + @Override + public void accept(Throwable e) throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerCompleteDispose() throws Exception { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Observable.ambArray( + Observable.empty() + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Observable.never() + ) + .subscribe(Functions.emptyConsumer(), Functions.emptyConsumer(), new Action() { + @Override + public void run() throws Exception { + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + } diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleAmbTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleAmbTest.java index 1bc00dedd6..18f4f3be65 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleAmbTest.java @@ -16,14 +16,18 @@ import static org.junit.Assert.*; import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.functions.BiConsumer; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; public class SingleAmbTest { @@ -280,4 +284,61 @@ public void ambArrayOrder() { Single error = Single.error(new RuntimeException()); Single.ambArray(Single.just(1), error).test().assertValue(1); } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerSuccessDispose() throws Exception { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Single.ambArray( + Single.just(1) + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Single.never() + ) + .subscribe(new BiConsumer() { + @Override + public void accept(Object v, Throwable e) throws Exception { + assertNotNull(v); + assertNull(e); + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } + + @SuppressWarnings("unchecked") + @Test + public void noWinnerErrorDispose() throws Exception { + final TestException ex = new TestException(); + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final AtomicBoolean interrupted = new AtomicBoolean(); + final CountDownLatch cdl = new CountDownLatch(1); + + Single.ambArray( + Single.error(ex) + .subscribeOn(Schedulers.single()) + .observeOn(Schedulers.computation()), + Single.never() + ) + .subscribe(new BiConsumer() { + @Override + public void accept(Object v, Throwable e) throws Exception { + assertNull(v); + assertNotNull(e); + interrupted.set(Thread.currentThread().isInterrupted()); + cdl.countDown(); + } + }); + + assertTrue(cdl.await(500, TimeUnit.SECONDS)); + assertFalse("Interrupted!", interrupted.get()); + } + } } From 621b8cda977605f91b8620a6e4e34f6c1cc89455 Mon Sep 17 00:00:00 2001 From: Guillermo Calvo Date: Mon, 21 Jan 2019 18:16:34 +0900 Subject: [PATCH 131/211] Fix bug in CompositeException.getRootCause (#6380) * Fix bug in CompositeException.getRootCause The original code use to be `if (root == null || root == e)`, but apparently after some refactoring it ended up as `if (root == null || cause == root)`, which I believe is a bug. This method should probably be `static` (that would have prevented the bug). * Update unit tests for CompositeException.getRootCause --- .../exceptions/CompositeException.java | 2 +- .../exceptions/CompositeExceptionTest.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/exceptions/CompositeException.java b/src/main/java/io/reactivex/exceptions/CompositeException.java index 748b964cf7..4915688379 100644 --- a/src/main/java/io/reactivex/exceptions/CompositeException.java +++ b/src/main/java/io/reactivex/exceptions/CompositeException.java @@ -280,7 +280,7 @@ public int size() { */ /*private */Throwable getRootCause(Throwable e) { Throwable root = e.getCause(); - if (root == null || cause == root) { + if (root == null || e == root) { return e; } while (true) { diff --git a/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java b/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java index 3625aa099a..2737b90712 100644 --- a/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java +++ b/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java @@ -364,7 +364,22 @@ public synchronized Throwable getCause() { } }; CompositeException ex = new CompositeException(throwable); - assertSame(ex, ex.getRootCause(ex)); + assertSame(ex0, ex.getRootCause(ex)); + } + + @Test + public void rootCauseSelf() { + Throwable throwable = new Throwable() { + + private static final long serialVersionUID = -4398003222998914415L; + + @Override + public synchronized Throwable getCause() { + return this; + } + }; + CompositeException tmp = new CompositeException(new TestException()); + assertSame(throwable, tmp.getRootCause(throwable)); } } From 1484106b1889fe981a2bb62862d9c353373f9851 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 23 Jan 2019 10:53:39 +0100 Subject: [PATCH 132/211] Release 2.2.6 --- CHANGES.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 57b421fc21..2dabb3be28 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,29 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.6 - January 23, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.6%7C)) + +#### API enhancements + + - [Pull 6370](https://github.com/ReactiveX/RxJava/pull/6370): Add interruptible mode via the new `Schedulers.from(Executor, boolean)` overload. + +#### Bugfixes + + - [Pull 6359](https://github.com/ReactiveX/RxJava/pull/6359): Fix the error/race in `Observable.repeatWhen` due to flooding repeat signal. + - [Pull 6362 ](https://github.com/ReactiveX/RxJava/pull/6362 ): Fix `Completable.andThen(Completable)` not running on `observeOn`'s `Scheduler`. + - [Pull 6364](https://github.com/ReactiveX/RxJava/pull/6364): Fix `Flowable.publish` not requesting upon client change. + - [Pull 6371](https://github.com/ReactiveX/RxJava/pull/6371): Fix bounded `replay()` memory leak due to bad node retention. + - [Pull 6375](https://github.com/ReactiveX/RxJava/pull/6375): Don't dispose the winner of `{Single|Maybe|Completable}.amb()`. + - [Pull 6380](https://github.com/ReactiveX/RxJava/pull/6380): Fix `CompositeException.getRootCause()` detecting loops in the cause graph. + +#### Documentation changes + + - [Pull 6365](https://github.com/ReactiveX/RxJava/pull/6365): Indicate source disposal in `timeout(fallback)`. + +#### Other changes + + - [Pull 6353](https://github.com/ReactiveX/RxJava/pull/6353): Use `ignoreElement` to convert `Single` to `Completable` in the `README.md`. + ### Version 2.2.5 - December 31, 2018 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.5%7C)) #### Documentation changes From 3fbfcc9c648dc02a064158c3ddb262f95949cbc5 Mon Sep 17 00:00:00 2001 From: Roman Wuattier Date: Wed, 23 Jan 2019 13:33:30 +0100 Subject: [PATCH 133/211] Expand `Observable#debounce` and `Flowable#debounce` javadoc (#6377) Mention that if the processing of a task takes too long and a newer item arrives then the previous task will get disposed interrupting a long running work. Fixes: #6288 --- src/main/java/io/reactivex/Flowable.java | 22 ++++++++++++++++++++++ src/main/java/io/reactivex/Observable.java | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index cba4b69210..79f4251ddd 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -8189,6 +8189,14 @@ public final Single count() { * source Publisher that are followed by another item within a computed debounce duration. *

      * + *

      + * The delivery of the item happens on the thread of the first {@code onNext} or {@code onComplete} + * signal of the generated {@code Publisher} sequence, + * which if takes too long, a newer item may arrive from the upstream, causing the + * generated sequence to get cancelled, which may also interrupt any downstream blocking operation + * (yielding an {@code InterruptedException}). It is recommended processing items + * that may take long time to be moved to another thread via {@link #observeOn} applied after + * {@code debounce} itself. *

      *
      Backpressure:
      *
      This operator does not support backpressure as it uses the {@code debounceSelector} to mark @@ -8224,6 +8232,13 @@ public final Flowable debounce(Function * will be emitted by the resulting Publisher. *

      * + *

      + * Delivery of the item after the grace period happens on the {@code computation} {@code Scheduler}'s + * {@code Worker} which if takes too long, a newer item may arrive from the upstream, causing the + * {@code Worker}'s task to get disposed, which may also interrupt any downstream blocking operation + * (yielding an {@code InterruptedException}). It is recommended processing items + * that may take long time to be moved to another thread via {@link #observeOn} applied after + * {@code debounce} itself. *

      *
      Backpressure:
      *
      This operator does not support backpressure as it uses time to control data flow.
      @@ -8259,6 +8274,13 @@ public final Flowable debounce(long timeout, TimeUnit unit) { * will be emitted by the resulting Publisher. *

      * + *

      + * Delivery of the item after the grace period happens on the given {@code Scheduler}'s + * {@code Worker} which if takes too long, a newer item may arrive from the upstream, causing the + * {@code Worker}'s task to get disposed, which may also interrupt any downstream blocking operation + * (yielding an {@code InterruptedException}). It is recommended processing items + * that may take long time to be moved to another thread via {@link #observeOn} applied after + * {@code debounce} itself. *

      *
      Backpressure:
      *
      This operator does not support backpressure as it uses time to control data flow.
      diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 90b96c38fd..fe2989bae4 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -7297,6 +7297,14 @@ public final Single count() { * source ObservableSource that are followed by another item within a computed debounce duration. *

      * + *

      + * The delivery of the item happens on the thread of the first {@code onNext} or {@code onComplete} + * signal of the generated {@code ObservableSource} sequence, + * which if takes too long, a newer item may arrive from the upstream, causing the + * generated sequence to get disposed, which may also interrupt any downstream blocking operation + * (yielding an {@code InterruptedException}). It is recommended processing items + * that may take long time to be moved to another thread via {@link #observeOn} applied after + * {@code debounce} itself. *

      *
      Scheduler:
      *
      This version of {@code debounce} does not operate by default on a particular {@link Scheduler}.
      @@ -7326,6 +7334,13 @@ public final Observable debounce(Function * + *

      + * Delivery of the item after the grace period happens on the {@code computation} {@code Scheduler}'s + * {@code Worker} which if takes too long, a newer item may arrive from the upstream, causing the + * {@code Worker}'s task to get disposed, which may also interrupt any downstream blocking operation + * (yielding an {@code InterruptedException}). It is recommended processing items + * that may take long time to be moved to another thread via {@link #observeOn} applied after + * {@code debounce} itself. *

      *
      Scheduler:
      *
      {@code debounce} operates by default on the {@code computation} {@link Scheduler}.
      @@ -7357,6 +7372,13 @@ public final Observable debounce(long timeout, TimeUnit unit) { * will be emitted by the resulting ObservableSource. *

      * + *

      + * Delivery of the item after the grace period happens on the given {@code Scheduler}'s + * {@code Worker} which if takes too long, a newer item may arrive from the upstream, causing the + * {@code Worker}'s task to get disposed, which may also interrupt any downstream blocking operation + * (yielding an {@code InterruptedException}). It is recommended processing items + * that may take long time to be moved to another thread via {@link #observeOn} applied after + * {@code debounce} itself. *

      *
      Scheduler:
      *
      You specify which {@link Scheduler} this operator will use.
      From 6e266af1000083f25dcae9defdcfe41e4ea2b97b Mon Sep 17 00:00:00 2001 From: Sergey Kryvets <10011693+skryvets@users.noreply.github.com> Date: Tue, 29 Jan 2019 06:45:37 -0600 Subject: [PATCH 134/211] Add doOnTerminate to Single/Maybe for consistency (#6379) (#6386) --- src/main/java/io/reactivex/Maybe.java | 27 ++++ src/main/java/io/reactivex/Single.java | 27 ++++ .../operators/maybe/MaybeDoOnTerminate.java | 90 +++++++++++++ .../operators/single/SingleDoOnTerminate.java | 78 +++++++++++ .../maybe/MaybeDoOnTerminateTest.java | 124 ++++++++++++++++++ .../single/SingleDoOnTerminateTest.java | 96 ++++++++++++++ 6 files changed, 442 insertions(+) create mode 100644 src/main/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminate.java create mode 100644 src/main/java/io/reactivex/internal/operators/single/SingleDoOnTerminate.java create mode 100644 src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java create mode 100644 src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 147b3f3125..d978d4a9dd 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -2892,6 +2892,33 @@ public final Maybe doOnSubscribe(Consumer onSubscribe) { )); } + /** + * Returns a Maybe instance that calls the given onTerminate callback + * just before this Maybe completes normally or with an exception. + *

      + * + *

      + * This differs from {@code doAfterTerminate} in that this happens before the {@code onComplete} or + * {@code onError} notification. + *

      + *
      Scheduler:
      + *
      {@code doOnTerminate} does not operate by default on a particular {@link Scheduler}.
      + *
      + * @param onTerminate the action to invoke when the consumer calls {@code onComplete} or {@code onError} + * @return the new Maybe instance + * @see ReactiveX operators documentation: Do + * @see #doOnTerminate(Action) + * @since 2.2.7 - experimental + */ + @Experimental + @CheckReturnValue + @NonNull + @SchedulerSupport(SchedulerSupport.NONE) + public final Maybe doOnTerminate(final Action onTerminate) { + ObjectHelper.requireNonNull(onTerminate, "onTerminate is null"); + return RxJavaPlugins.onAssembly(new MaybeDoOnTerminate(this, onTerminate)); + } + /** * Calls the shared consumer with the success value sent via onSuccess for each * MaybeObserver that subscribes to the current Maybe. diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index f41d69a80c..1071fa836b 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -2495,6 +2495,33 @@ public final Single doOnSubscribe(final Consumer onSubscr return RxJavaPlugins.onAssembly(new SingleDoOnSubscribe(this, onSubscribe)); } + /** + * Returns a Single instance that calls the given onTerminate callback + * just before this Single completes normally or with an exception. + *

      + * + *

      + * This differs from {@code doAfterTerminate} in that this happens before the {@code onComplete} or + * {@code onError} notification. + *

      + *
      Scheduler:
      + *
      {@code doOnTerminate} does not operate by default on a particular {@link Scheduler}.
      + *
      + * @param onTerminate the action to invoke when the consumer calls {@code onComplete} or {@code onError} + * @return the new Single instance + * @see ReactiveX operators documentation: Do + * @see #doOnTerminate(Action) + * @since 2.2.7 - experimental + */ + @Experimental + @CheckReturnValue + @NonNull + @SchedulerSupport(SchedulerSupport.NONE) + public final Single doOnTerminate(final Action onTerminate) { + ObjectHelper.requireNonNull(onTerminate, "onTerminate is null"); + return RxJavaPlugins.onAssembly(new SingleDoOnTerminate(this, onTerminate)); + } + /** * Calls the shared consumer with the success value sent via onSuccess for each * SingleObserver that subscribes to the current Single. diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminate.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminate.java new file mode 100644 index 0000000000..81d0d8af34 --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminate.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.maybe; + +import io.reactivex.Maybe; +import io.reactivex.MaybeObserver; +import io.reactivex.MaybeSource; +import io.reactivex.disposables.Disposable; +import io.reactivex.exceptions.CompositeException; +import io.reactivex.exceptions.Exceptions; +import io.reactivex.functions.Action; + +public final class MaybeDoOnTerminate extends Maybe { + + final MaybeSource source; + + final Action onTerminate; + + public MaybeDoOnTerminate(MaybeSource source, Action onTerminate) { + this.source = source; + this.onTerminate = onTerminate; + } + + @Override + protected void subscribeActual(MaybeObserver observer) { + source.subscribe(new DoOnTerminate(observer)); + } + + final class DoOnTerminate implements MaybeObserver { + final MaybeObserver downstream; + + DoOnTerminate(MaybeObserver observer) { + this.downstream = observer; + } + + @Override + public void onSubscribe(Disposable d) { + downstream.onSubscribe(d); + } + + @Override + public void onSuccess(T value) { + try { + onTerminate.run(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + downstream.onError(ex); + return; + } + + downstream.onSuccess(value); + } + + @Override + public void onError(Throwable e) { + try { + onTerminate.run(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + e = new CompositeException(e, ex); + } + + downstream.onError(e); + } + + @Override + public void onComplete() { + try { + onTerminate.run(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + downstream.onError(ex); + return; + } + + downstream.onComplete(); + } + } +} diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleDoOnTerminate.java b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnTerminate.java new file mode 100644 index 0000000000..7497aff902 --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/single/SingleDoOnTerminate.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.single; + +import io.reactivex.Single; +import io.reactivex.SingleObserver; +import io.reactivex.SingleSource; +import io.reactivex.disposables.Disposable; +import io.reactivex.exceptions.CompositeException; +import io.reactivex.exceptions.Exceptions; +import io.reactivex.functions.Action; + +public final class SingleDoOnTerminate extends Single { + + final SingleSource source; + + final Action onTerminate; + + public SingleDoOnTerminate(SingleSource source, Action onTerminate) { + this.source = source; + this.onTerminate = onTerminate; + } + + @Override + protected void subscribeActual(final SingleObserver observer) { + source.subscribe(new DoOnTerminate(observer)); + } + + final class DoOnTerminate implements SingleObserver { + + final SingleObserver downstream; + + DoOnTerminate(SingleObserver observer) { + this.downstream = observer; + } + + @Override + public void onSubscribe(Disposable d) { + downstream.onSubscribe(d); + } + + @Override + public void onSuccess(T value) { + try { + onTerminate.run(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + downstream.onError(ex); + return; + } + + downstream.onSuccess(value); + } + + @Override + public void onError(Throwable e) { + try { + onTerminate.run(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + e = new CompositeException(e, ex); + } + + downstream.onError(e); + } + } +} diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java new file mode 100644 index 0000000000..d442fcc135 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java @@ -0,0 +1,124 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.maybe; + +import io.reactivex.Maybe; +import io.reactivex.TestHelper; +import io.reactivex.exceptions.CompositeException; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Action; +import io.reactivex.observers.TestObserver; +import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.subjects.PublishSubject; +import org.junit.Test; + +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.assertTrue; + +public class MaybeDoOnTerminateTest { + + @Test(expected = NullPointerException.class) + public void doOnTerminate() { + Maybe.just(1).doOnTerminate(null); + } + + @Test + public void doOnTerminateSuccess() { + final AtomicBoolean atomicBoolean = new AtomicBoolean(); + Maybe.just(1).doOnTerminate(new Action() { + @Override + public void run() { + atomicBoolean.set(true); + } + }) + .test() + .assertResult(1); + + assertTrue(atomicBoolean.get()); + } + + @Test + public void doOnTerminateError() { + final AtomicBoolean atomicBoolean = new AtomicBoolean(); + Maybe.error(new TestException()).doOnTerminate(new Action() { + @Override + public void run() { + atomicBoolean.set(true); + } + }) + .test() + .assertFailure(TestException.class); + + assertTrue(atomicBoolean.get()); + } + + @Test + public void doOnTerminateComplete() { + final AtomicBoolean atomicBoolean = new AtomicBoolean(); + Maybe.empty().doOnTerminate(new Action() { + @Override + public void run() { + atomicBoolean.set(true); + } + }) + .test() + .assertResult(); + + assertTrue(atomicBoolean.get()); + } + + @Test + public void doOnTerminateSuccessCrash() { + Maybe.just(1).doOnTerminate(new Action() { + @Override + public void run() { + throw new TestException(); + } + }) + .test() + .assertFailure(TestException.class); + } + + @Test + public void doOnTerminateErrorCrash() { + TestObserver to = Maybe.error(new TestException("Outer")) + .doOnTerminate(new Action() { + @Override + public void run() { + throw new TestException("Inner"); + } + }) + .test() + .assertFailure(CompositeException.class); + + List errors = TestHelper.compositeList(to.errors().get(0)); + TestHelper.assertError(errors, 0, TestException.class, "Outer"); + TestHelper.assertError(errors, 1, TestException.class, "Inner"); + } + + @Test + public void doOnTerminateCompleteCrash() { + Maybe.empty() + .doOnTerminate(new Action() { + @Override + public void run() { + throw new TestException(); + } + }) + .test() + .assertFailure(TestException.class); + } +} diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java new file mode 100644 index 0000000000..ba15f9f71b --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.single; + +import io.reactivex.Single; +import io.reactivex.TestHelper; +import io.reactivex.exceptions.CompositeException; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.Action; +import io.reactivex.observers.TestObserver; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.assertTrue; + +public class SingleDoOnTerminateTest { + + @Test(expected = NullPointerException.class) + public void doOnTerminate() { + Single.just(1).doOnTerminate(null); + } + + @Test + public void doOnTerminateSuccess() { + final AtomicBoolean atomicBoolean = new AtomicBoolean(); + + Single.just(1).doOnTerminate(new Action() { + @Override + public void run() throws Exception { + atomicBoolean.set(true); + } + }) + .test() + .assertResult(1); + + assertTrue(atomicBoolean.get()); + } + + @Test + public void doOnTerminateError() { + final AtomicBoolean atomicBoolean = new AtomicBoolean(); + Single.error(new TestException()).doOnTerminate(new Action() { + @Override + public void run() { + atomicBoolean.set(true); + } + }) + .test() + .assertFailure(TestException.class); + + assertTrue(atomicBoolean.get()); + } + + @Test + public void doOnTerminateSuccessCrash() { + Single.just(1).doOnTerminate(new Action() { + @Override + public void run() throws Exception { + throw new TestException(); + } + }) + .test() + .assertFailure(TestException.class); + } + + @Test + public void doOnTerminateErrorCrash() { + TestObserver to = Single.error(new TestException("Outer")).doOnTerminate(new Action() { + @Override + public void run() { + throw new TestException("Inner"); + } + }) + .test() + .assertFailure(CompositeException.class); + + List errors = TestHelper.compositeList(to.errors().get(0)); + + TestHelper.assertError(errors, 0, TestException.class, "Outer"); + TestHelper.assertError(errors, 1, TestException.class, "Inner"); + } +} From 7fffa00e3139e7c59e2e26e80f084f29d32a5688 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 12 Feb 2019 23:24:46 +0100 Subject: [PATCH 135/211] 2.x: Fix concatEager to dispose sources & clean up properly. (#6405) --- .../flowable/FlowableConcatMapEager.java | 7 +++- .../observable/ObservableConcatMapEager.java | 15 +++++++-- .../flowable/FlowableConcatMapEagerTest.java | 33 +++++++++++++++++++ .../ObservableConcatMapEagerTest.java | 33 +++++++++++++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEager.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEager.java index 87ee235704..8acad8ac69 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEager.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEager.java @@ -176,7 +176,12 @@ void drainAndCancel() { } void cancelAll() { - InnerQueuedSubscriber inner; + InnerQueuedSubscriber inner = current; + current = null; + + if (inner != null) { + inner.cancel(); + } while ((inner = subscribers.poll()) != null) { inner.cancel(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMapEager.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMapEager.java index cb15b10f65..7028fdcf62 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMapEager.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMapEager.java @@ -162,10 +162,21 @@ public void onComplete() { @Override public void dispose() { + if (cancelled) { + return; + } cancelled = true; + upstream.dispose(); + + drainAndDispose(); + } + + void drainAndDispose() { if (getAndIncrement() == 0) { - queue.clear(); - disposeAll(); + do { + queue.clear(); + disposeAll(); + } while (decrementAndGet() != 0); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java index 1e34d2937b..11f12fb4a3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java @@ -1333,4 +1333,37 @@ public void arrayDelayErrorMaxConcurrencyErrorDelayed() { ts.assertFailure(TestException.class, 1, 2); } + + @Test + public void cancelActive() { + PublishProcessor pp1 = PublishProcessor.create(); + PublishProcessor pp2 = PublishProcessor.create(); + + TestSubscriber ts = Flowable + .concatEager(Flowable.just(pp1, pp2)) + .test(); + + assertTrue(pp1.hasSubscribers()); + assertTrue(pp2.hasSubscribers()); + + ts.cancel(); + + assertFalse(pp1.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); + } + + @Test + public void cancelNoInnerYet() { + PublishProcessor> pp1 = PublishProcessor.create(); + + TestSubscriber ts = Flowable + .concatEager(pp1) + .test(); + + assertTrue(pp1.hasSubscribers()); + + ts.cancel(); + + assertFalse(pp1.hasSubscribers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java index 3959fab45e..17e418bab7 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java @@ -1141,4 +1141,37 @@ public void arrayDelayErrorMaxConcurrencyErrorDelayed() { to.assertFailure(TestException.class, 1, 2); } + + @Test + public void cancelActive() { + PublishSubject ps1 = PublishSubject.create(); + PublishSubject ps2 = PublishSubject.create(); + + TestObserver to = Observable + .concatEager(Observable.just(ps1, ps2)) + .test(); + + assertTrue(ps1.hasObservers()); + assertTrue(ps2.hasObservers()); + + to.dispose(); + + assertFalse(ps1.hasObservers()); + assertFalse(ps2.hasObservers()); + } + + @Test + public void cancelNoInnerYet() { + PublishSubject> ps1 = PublishSubject.create(); + + TestObserver to = Observable + .concatEager(ps1) + .test(); + + assertTrue(ps1.hasObservers()); + + to.dispose(); + + assertFalse(ps1.hasObservers()); + } } From 184a17b7da82683e4c17d5c70392e8c5df50017f Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 13 Feb 2019 09:51:08 +0100 Subject: [PATCH 136/211] 2.x: Fix window() with start/end selector not disposing/cancelling properly (#6398) * 2.x: Fix window() with s/e selector not disposing/cancelling properly * Fix cancellation upon backpressure problem/handler crash --- .../FlowableWindowBoundarySelector.java | 18 ++++-- .../ObservableWindowBoundarySelector.java | 18 ++++-- ...lowableWindowWithStartEndFlowableTest.java | 61 ++++++++++++++++++- ...vableWindowWithStartEndObservableTest.java | 39 +++++++++++- 4 files changed, 119 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java index 0e3fe58b83..d9d6ffa517 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowBoundarySelector.java @@ -71,6 +71,8 @@ static final class WindowBoundaryMainSubscriber final AtomicLong windows = new AtomicLong(); + final AtomicBoolean stopWindows = new AtomicBoolean(); + WindowBoundaryMainSubscriber(Subscriber> actual, Publisher open, Function> close, int bufferSize) { super(actual, new MpscLinkedQueue()); @@ -89,14 +91,13 @@ public void onSubscribe(Subscription s) { downstream.onSubscribe(this); - if (cancelled) { + if (stopWindows.get()) { return; } OperatorWindowBoundaryOpenSubscriber os = new OperatorWindowBoundaryOpenSubscriber(this); if (boundary.compareAndSet(null, os)) { - windows.getAndIncrement(); s.request(Long.MAX_VALUE); open.subscribe(os); } @@ -177,7 +178,12 @@ public void request(long n) { @Override public void cancel() { - cancelled = true; + if (stopWindows.compareAndSet(false, true)) { + DisposableHelper.dispose(boundary); + if (windows.decrementAndGet() == 0) { + upstream.cancel(); + } + } } void dispose() { @@ -236,7 +242,7 @@ void drainLoop() { continue; } - if (cancelled) { + if (stopWindows.get()) { continue; } @@ -250,7 +256,7 @@ void drainLoop() { produced(1); } } else { - cancelled = true; + cancel(); a.onError(new MissingBackpressureException("Could not deliver new window due to lack of requests")); continue; } @@ -260,7 +266,7 @@ void drainLoop() { try { p = ObjectHelper.requireNonNull(close.apply(wo.open), "The publisher supplied is null"); } catch (Throwable e) { - cancelled = true; + cancel(); a.onError(e); continue; } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java index 1e2a2ea052..d8e745e213 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowBoundarySelector.java @@ -69,6 +69,8 @@ static final class WindowBoundaryMainObserver final AtomicLong windows = new AtomicLong(); + final AtomicBoolean stopWindows = new AtomicBoolean(); + WindowBoundaryMainObserver(Observer> actual, ObservableSource open, Function> close, int bufferSize) { super(actual, new MpscLinkedQueue()); @@ -87,14 +89,13 @@ public void onSubscribe(Disposable d) { downstream.onSubscribe(this); - if (cancelled) { + if (stopWindows.get()) { return; } OperatorWindowBoundaryOpenObserver os = new OperatorWindowBoundaryOpenObserver(this); if (boundary.compareAndSet(null, os)) { - windows.getAndIncrement(); open.subscribe(os); } } @@ -164,12 +165,17 @@ void error(Throwable t) { @Override public void dispose() { - cancelled = true; + if (stopWindows.compareAndSet(false, true)) { + DisposableHelper.dispose(boundary); + if (windows.decrementAndGet() == 0) { + upstream.dispose(); + } + } } @Override public boolean isDisposed() { - return cancelled; + return stopWindows.get(); } void disposeBoundary() { @@ -229,7 +235,7 @@ void drainLoop() { continue; } - if (cancelled) { + if (stopWindows.get()) { continue; } @@ -244,7 +250,7 @@ void drainLoop() { p = ObjectHelper.requireNonNull(close.apply(wo.open), "The ObservableSource supplied is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); - cancelled = true; + stopWindows.set(true); a.onError(e); continue; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java index c1d825afed..1d27381129 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java @@ -17,12 +17,13 @@ import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicBoolean; import org.junit.*; import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.exceptions.TestException; +import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; @@ -254,8 +255,8 @@ public Flowable apply(Integer t) { ts.dispose(); - // FIXME subject has subscribers because of the open window - assertTrue(open.hasSubscribers()); + // Disposing the outer sequence stops the opening of new windows + assertFalse(open.hasSubscribers()); // FIXME subject has subscribers because of the open window assertTrue(close.hasSubscribers()); } @@ -430,4 +431,58 @@ protected void subscribeActual( RxJavaPlugins.reset(); } } + + static Flowable flowableDisposed(final AtomicBoolean ref) { + return Flowable.just(1).concatWith(Flowable.never()) + .doOnCancel(new Action() { + @Override + public void run() throws Exception { + ref.set(true); + } + }); + } + + @Test + public void mainAndBoundaryDisposeOnNoWindows() { + AtomicBoolean mainDisposed = new AtomicBoolean(); + AtomicBoolean openDisposed = new AtomicBoolean(); + final AtomicBoolean closeDisposed = new AtomicBoolean(); + + flowableDisposed(mainDisposed) + .window(flowableDisposed(openDisposed), new Function>() { + @Override + public Flowable apply(Integer v) throws Exception { + return flowableDisposed(closeDisposed); + } + }) + .test() + .assertSubscribed() + .assertNoErrors() + .assertNotComplete() + .dispose(); + + assertTrue(mainDisposed.get()); + assertTrue(openDisposed.get()); + assertTrue(closeDisposed.get()); + } + + @Test + @SuppressWarnings("unchecked") + public void mainWindowMissingBackpressure() { + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); + + TestSubscriber> ts = source.window(boundary, Functions.justFunction(Flowable.never())) + .test(0L) + ; + + ts.assertEmpty(); + + boundary.onNext(1); + + ts.assertFailure(MissingBackpressureException.class); + + assertFalse(source.hasSubscribers()); + assertFalse(boundary.hasSubscribers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java index d1426a5a61..c4f7fa6409 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java @@ -17,6 +17,7 @@ import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicBoolean; import org.junit.*; @@ -256,8 +257,8 @@ public Observable apply(Integer t) { to.dispose(); - // FIXME subject has subscribers because of the open window - assertTrue(open.hasObservers()); + // Disposing the outer sequence stops the opening of new windows + assertFalse(open.hasObservers()); // FIXME subject has subscribers because of the open window assertTrue(close.hasObservers()); } @@ -423,4 +424,38 @@ protected void subscribeActual( RxJavaPlugins.reset(); } } + + static Observable observableDisposed(final AtomicBoolean ref) { + return Observable.just(1).concatWith(Observable.never()) + .doOnDispose(new Action() { + @Override + public void run() throws Exception { + ref.set(true); + } + }); + } + + @Test + public void mainAndBoundaryDisposeOnNoWindows() { + AtomicBoolean mainDisposed = new AtomicBoolean(); + AtomicBoolean openDisposed = new AtomicBoolean(); + final AtomicBoolean closeDisposed = new AtomicBoolean(); + + observableDisposed(mainDisposed) + .window(observableDisposed(openDisposed), new Function>() { + @Override + public ObservableSource apply(Integer v) throws Exception { + return observableDisposed(closeDisposed); + } + }) + .test() + .assertSubscribed() + .assertNoErrors() + .assertNotComplete() + .dispose(); + + assertTrue(mainDisposed.get()); + assertTrue(openDisposed.get()); + assertTrue(closeDisposed.get()); + } } From add2812a20bda65bb7326c3845f7714b7218a505 Mon Sep 17 00:00:00 2001 From: Thiyagarajan <38608518+thiyagu-7@users.noreply.github.com> Date: Sun, 17 Feb 2019 00:32:31 +0530 Subject: [PATCH 137/211] Improving Javadoc of flattenAsFlowable and flattenAsObservable methods (#6276) (#6408) --- src/main/java/io/reactivex/Maybe.java | 7 ++++--- src/main/java/io/reactivex/Single.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index d978d4a9dd..ab221724eb 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -3062,8 +3062,8 @@ public final Maybe flatMap(Function * *
      @@ -3091,7 +3091,8 @@ public final Flowable flattenAsFlowable(final Function * *
      diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 1071fa836b..d4b5f7aaf4 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -2711,8 +2711,8 @@ public final Flowable flatMapPublisher(Function * *
      @@ -2740,7 +2740,8 @@ public final Flowable flattenAsFlowable(final Function * *
      From 9a74adf5f85ebfe5063e8191665956d547d515e0 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sat, 23 Feb 2019 09:37:49 +0100 Subject: [PATCH 138/211] Release 2.2.7 --- CHANGES.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2dabb3be28..16757d46b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,22 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.7 - February 23, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.7%7C)) + +#### API enhancements + + - [Pull 6386](https://github.com/ReactiveX/RxJava/pull/6386): Add `doOnTerminate` to `Single`/`Maybe` for consistency. + +#### Bugfixes + + - [Pull 6405](https://github.com/ReactiveX/RxJava/pull/6405): Fix concatEager to dispose sources & clean up properly. + - [Pull 6398](https://github.com/ReactiveX/RxJava/pull/6398): Fix `window()` with start/end selector not disposing/cancelling properly. + +#### Documentation changes + + - [Pull 6377](https://github.com/ReactiveX/RxJava/pull/6377): Expand `Observable#debounce` and `Flowable#debounce` javadoc. + - [Pull 6408](https://github.com/ReactiveX/RxJava/pull/6408): Improving Javadoc of `flattenAsFlowable` and `flattenAsObservable` methods. + ### Version 2.2.6 - January 23, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.6%7C)) #### API enhancements From 0bb7b4db47e5af8d7e37b48545b00f70f69a34f1 Mon Sep 17 00:00:00 2001 From: chronvas Date: Fri, 15 Mar 2019 18:21:25 +0000 Subject: [PATCH 139/211] 2.x composite disposable docs (#6432) * 2.x: Improving NPE message in CompositeDisposable add(..) when param is null * 2.x: Improving NPE message in CompositeDisposable addAll(..) when item in vararg param is null * 2.x: Improved in CompositeDisposable: NPE error messages, parameter naming at methods, added @throws javadoc where applicable * 2.x: Applied PR suggestions in javadoc and messages for CompositeDisposable --- .../disposables/CompositeDisposable.java | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/main/java/io/reactivex/disposables/CompositeDisposable.java b/src/main/java/io/reactivex/disposables/CompositeDisposable.java index 5bed43ec77..f7a1bf4a36 100644 --- a/src/main/java/io/reactivex/disposables/CompositeDisposable.java +++ b/src/main/java/io/reactivex/disposables/CompositeDisposable.java @@ -38,26 +38,28 @@ public CompositeDisposable() { /** * Creates a CompositeDisposables with the given array of initial elements. - * @param resources the array of Disposables to start with + * @param disposables the array of Disposables to start with + * @throws NullPointerException if {@code disposables} or any of its array items is null */ - public CompositeDisposable(@NonNull Disposable... resources) { - ObjectHelper.requireNonNull(resources, "resources is null"); - this.resources = new OpenHashSet(resources.length + 1); - for (Disposable d : resources) { - ObjectHelper.requireNonNull(d, "Disposable item is null"); + public CompositeDisposable(@NonNull Disposable... disposables) { + ObjectHelper.requireNonNull(disposables, "disposables is null"); + this.resources = new OpenHashSet(disposables.length + 1); + for (Disposable d : disposables) { + ObjectHelper.requireNonNull(d, "A Disposable in the disposables array is null"); this.resources.add(d); } } /** * Creates a CompositeDisposables with the given Iterable sequence of initial elements. - * @param resources the Iterable sequence of Disposables to start with + * @param disposables the Iterable sequence of Disposables to start with + * @throws NullPointerException if {@code disposables} or any of its items is null */ - public CompositeDisposable(@NonNull Iterable resources) { - ObjectHelper.requireNonNull(resources, "resources is null"); + public CompositeDisposable(@NonNull Iterable disposables) { + ObjectHelper.requireNonNull(disposables, "disposables is null"); this.resources = new OpenHashSet(); - for (Disposable d : resources) { - ObjectHelper.requireNonNull(d, "Disposable item is null"); + for (Disposable d : disposables) { + ObjectHelper.requireNonNull(d, "A Disposable item in the disposables sequence is null"); this.resources.add(d); } } @@ -88,12 +90,13 @@ public boolean isDisposed() { /** * Adds a disposable to this container or disposes it if the * container has been disposed. - * @param d the disposable to add, not null + * @param disposable the disposable to add, not null * @return true if successful, false if this container has been disposed + * @throws NullPointerException if {@code disposable} is null */ @Override - public boolean add(@NonNull Disposable d) { - ObjectHelper.requireNonNull(d, "d is null"); + public boolean add(@NonNull Disposable disposable) { + ObjectHelper.requireNonNull(disposable, "disposable is null"); if (!disposed) { synchronized (this) { if (!disposed) { @@ -102,40 +105,41 @@ public boolean add(@NonNull Disposable d) { set = new OpenHashSet(); resources = set; } - set.add(d); + set.add(disposable); return true; } } } - d.dispose(); + disposable.dispose(); return false; } /** * Atomically adds the given array of Disposables to the container or * disposes them all if the container has been disposed. - * @param ds the array of Disposables + * @param disposables the array of Disposables * @return true if the operation was successful, false if the container has been disposed + * @throws NullPointerException if {@code disposables} or any of its array items is null */ - public boolean addAll(@NonNull Disposable... ds) { - ObjectHelper.requireNonNull(ds, "ds is null"); + public boolean addAll(@NonNull Disposable... disposables) { + ObjectHelper.requireNonNull(disposables, "disposables is null"); if (!disposed) { synchronized (this) { if (!disposed) { OpenHashSet set = resources; if (set == null) { - set = new OpenHashSet(ds.length + 1); + set = new OpenHashSet(disposables.length + 1); resources = set; } - for (Disposable d : ds) { - ObjectHelper.requireNonNull(d, "d is null"); + for (Disposable d : disposables) { + ObjectHelper.requireNonNull(d, "A Disposable in the disposables array is null"); set.add(d); } return true; } } } - for (Disposable d : ds) { + for (Disposable d : disposables) { d.dispose(); } return false; @@ -144,13 +148,13 @@ public boolean addAll(@NonNull Disposable... ds) { /** * Removes and disposes the given disposable if it is part of this * container. - * @param d the disposable to remove and dispose, not null + * @param disposable the disposable to remove and dispose, not null * @return true if the operation was successful */ @Override - public boolean remove(@NonNull Disposable d) { - if (delete(d)) { - d.dispose(); + public boolean remove(@NonNull Disposable disposable) { + if (delete(disposable)) { + disposable.dispose(); return true; } return false; @@ -159,12 +163,13 @@ public boolean remove(@NonNull Disposable d) { /** * Removes (but does not dispose) the given disposable if it is part of this * container. - * @param d the disposable to remove, not null + * @param disposable the disposable to remove, not null * @return true if the operation was successful + * @throws NullPointerException if {@code disposable} is null */ @Override - public boolean delete(@NonNull Disposable d) { - ObjectHelper.requireNonNull(d, "Disposable item is null"); + public boolean delete(@NonNull Disposable disposable) { + ObjectHelper.requireNonNull(disposable, "disposables is null"); if (disposed) { return false; } @@ -174,7 +179,7 @@ public boolean delete(@NonNull Disposable d) { } OpenHashSet set = resources; - if (set == null || !set.remove(d)) { + if (set == null || !set.remove(disposable)) { return false; } } From 0c4f5c11bfe0774888294dbdac75c98829b13374 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 18 Mar 2019 12:33:14 +0100 Subject: [PATCH 140/211] 2.x: Improve subjects and processors package doc (#6434) --- .../io/reactivex/processors/package-info.java | 22 +++++++++++++++++-- .../io/reactivex/subjects/package-info.java | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/processors/package-info.java b/src/main/java/io/reactivex/processors/package-info.java index 64caf9a4c4..1266a74ee1 100644 --- a/src/main/java/io/reactivex/processors/package-info.java +++ b/src/main/java/io/reactivex/processors/package-info.java @@ -15,7 +15,25 @@ */ /** - * Classes extending the Flowable base reactive class and implementing - * the Subscriber interface at the same time (aka hot Flowables). + * Classes representing so-called hot backpressure-aware sources, aka processors, + * that implement the {@link FlowableProcessor} class, + * the Reactive Streams {@link org.reactivestreams.Processor Processor} interface + * to allow forms of multicasting events to one or more subscribers as well as consuming another + * Reactive Streams {@link org.reactivestreams.Publisher Publisher}. + *

      + * Available processor implementations: + *
      + *

        + *
      • {@link io.reactivex.processors.AsyncProcessor AsyncProcessor} - replays the very last item
      • + *
      • {@link io.reactivex.processors.BehaviorProcessor BehaviorProcessor} - remembers the latest item
      • + *
      • {@link io.reactivex.processors.MulticastProcessor MulticastProcessor} - coordinates its source with its consumers
      • + *
      • {@link io.reactivex.processors.PublishProcessor PublishProcessor} - dispatches items to current consumers
      • + *
      • {@link io.reactivex.processors.ReplayProcessor ReplayProcessor} - remembers some or all items and replays them to consumers
      • + *
      • {@link io.reactivex.processors.UnicastProcessor UnicastProcessor} - remembers or relays items to a single consumer
      • + *
      + *

      + * The non-backpressured variants of the {@code FlowableProcessor} class are called + * {@link io.reactivex.Subject}s and reside in the {@code io.reactivex.subjects} package. + * @see io.reactivex.subjects */ package io.reactivex.processors; diff --git a/src/main/java/io/reactivex/subjects/package-info.java b/src/main/java/io/reactivex/subjects/package-info.java index 8bd3b06ac2..091c223445 100644 --- a/src/main/java/io/reactivex/subjects/package-info.java +++ b/src/main/java/io/reactivex/subjects/package-info.java @@ -29,7 +29,7 @@ *
         {@link io.reactivex.subjects.BehaviorSubject BehaviorSubject} *
         {@link io.reactivex.subjects.PublishSubject PublishSubject} *
         {@link io.reactivex.subjects.ReplaySubject ReplaySubject} - *
         {@link io.reactivex.subjects.UnicastSubject UnicastSubjectSubject} + *
         {@link io.reactivex.subjects.UnicastSubject UnicastSubject} * * {@link io.reactivex.Observable Observable} * {@link io.reactivex.Observer Observer} From b3d7f5f2ac25344143ebdf22f4ae23677e41cc8f Mon Sep 17 00:00:00 2001 From: Lorenz Pahl Date: Thu, 21 Mar 2019 14:00:27 +0100 Subject: [PATCH 141/211] Make error messages of parameter checks consistent (#6433) --- src/main/java/io/reactivex/Completable.java | 2 +- src/main/java/io/reactivex/Flowable.java | 126 +++++++++---------- src/main/java/io/reactivex/Maybe.java | 10 +- src/main/java/io/reactivex/Observable.java | 131 ++++++++++---------- src/main/java/io/reactivex/Single.java | 10 +- 5 files changed, 139 insertions(+), 140 deletions(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 7ac7ead344..13364dc1a6 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -2292,7 +2292,7 @@ public final Disposable subscribe() { @SchedulerSupport(SchedulerSupport.NONE) @Override public final void subscribe(CompletableObserver observer) { - ObjectHelper.requireNonNull(observer, "s is null"); + ObjectHelper.requireNonNull(observer, "observer is null"); try { observer = RxJavaPlugins.onSubscribe(this, observer); diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 79f4251ddd..ff85859f99 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -1900,7 +1900,7 @@ public static Flowable empty() { @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable error(Callable supplier) { - ObjectHelper.requireNonNull(supplier, "errorSupplier is null"); + ObjectHelper.requireNonNull(supplier, "supplier is null"); return RxJavaPlugins.onAssembly(new FlowableError(supplier)); } @@ -2235,7 +2235,7 @@ public static Flowable fromPublisher(final Publisher source) if (source instanceof Flowable) { return RxJavaPlugins.onAssembly((Flowable)source); } - ObjectHelper.requireNonNull(source, "publisher is null"); + ObjectHelper.requireNonNull(source, "source is null"); return RxJavaPlugins.onAssembly(new FlowableFromPublisher(source)); } @@ -2662,8 +2662,8 @@ public static Flowable just(T item) { @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); return fromArray(item1, item2); } @@ -2696,9 +2696,9 @@ public static Flowable just(T item1, T item2) { @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); return fromArray(item1, item2, item3); } @@ -2733,10 +2733,10 @@ public static Flowable just(T item1, T item2, T item3) { @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); return fromArray(item1, item2, item3, item4); } @@ -2773,11 +2773,11 @@ public static Flowable just(T item1, T item2, T item3, T item4) { @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); return fromArray(item1, item2, item3, item4, item5); } @@ -2816,12 +2816,12 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5) @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); return fromArray(item1, item2, item3, item4, item5, item6); } @@ -2862,13 +2862,13 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5, @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); - ObjectHelper.requireNonNull(item7, "The seventh item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); + ObjectHelper.requireNonNull(item7, "item7 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7); } @@ -2911,14 +2911,14 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5, @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); - ObjectHelper.requireNonNull(item7, "The seventh item is null"); - ObjectHelper.requireNonNull(item8, "The eighth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); + ObjectHelper.requireNonNull(item7, "item7 is null"); + ObjectHelper.requireNonNull(item8, "item8 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7, item8); } @@ -2963,15 +2963,15 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5, @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); - ObjectHelper.requireNonNull(item7, "The seventh item is null"); - ObjectHelper.requireNonNull(item8, "The eighth item is null"); - ObjectHelper.requireNonNull(item9, "The ninth is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); + ObjectHelper.requireNonNull(item7, "item7 is null"); + ObjectHelper.requireNonNull(item8, "item8 is null"); + ObjectHelper.requireNonNull(item9, "item9 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7, item8, item9); } @@ -3018,16 +3018,16 @@ public static Flowable just(T item1, T item2, T item3, T item4, T item5, @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9, T item10) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); - ObjectHelper.requireNonNull(item7, "The seventh item is null"); - ObjectHelper.requireNonNull(item8, "The eighth item is null"); - ObjectHelper.requireNonNull(item9, "The ninth item is null"); - ObjectHelper.requireNonNull(item10, "The tenth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); + ObjectHelper.requireNonNull(item7, "item7 is null"); + ObjectHelper.requireNonNull(item8, "item8 is null"); + ObjectHelper.requireNonNull(item9, "item9 is null"); + ObjectHelper.requireNonNull(item10, "item10 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7, item8, item9, item10); } @@ -4485,7 +4485,7 @@ public static Flowable using(Callable resourceSupplier, Consumer resourceDisposer, boolean eager) { ObjectHelper.requireNonNull(resourceSupplier, "resourceSupplier is null"); ObjectHelper.requireNonNull(sourceSupplier, "sourceSupplier is null"); - ObjectHelper.requireNonNull(resourceDisposer, "disposer is null"); + ObjectHelper.requireNonNull(resourceDisposer, "resourceDisposer is null"); return RxJavaPlugins.onAssembly(new FlowableUsing(resourceSupplier, sourceSupplier, resourceDisposer, eager)); } @@ -8338,7 +8338,7 @@ public final Flowable debounce(long timeout, TimeUnit unit, Scheduler schedul @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable defaultIfEmpty(T defaultItem) { - ObjectHelper.requireNonNull(defaultItem, "item is null"); + ObjectHelper.requireNonNull(defaultItem, "defaultItem is null"); return switchIfEmpty(just(defaultItem)); } @@ -9167,7 +9167,7 @@ private Flowable doOnEach(Consumer onNext, Consumer doOnEach(final Consumer> onNotification) { - ObjectHelper.requireNonNull(onNotification, "consumer is null"); + ObjectHelper.requireNonNull(onNotification, "onNotification is null"); return doOnEach( Functions.notificationOnNext(onNotification), Functions.notificationOnError(onNotification), @@ -11769,7 +11769,7 @@ public final Flowable onBackpressureBuffer(int capacity, boolean delayError) @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onBackpressureBuffer(int capacity, boolean delayError, boolean unbounded) { - ObjectHelper.verifyPositive(capacity, "bufferSize"); + ObjectHelper.verifyPositive(capacity, "capacity"); return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBuffer(this, capacity, unbounded, delayError, Functions.EMPTY_ACTION)); } @@ -11877,7 +11877,7 @@ public final Flowable onBackpressureBuffer(int capacity, Action onOverflow) { @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable onBackpressureBuffer(long capacity, Action onOverflow, BackpressureOverflowStrategy overflowStrategy) { - ObjectHelper.requireNonNull(overflowStrategy, "strategy is null"); + ObjectHelper.requireNonNull(overflowStrategy, "overflowStrategy is null"); ObjectHelper.verifyPositive(capacity, "capacity"); return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBufferStrategy(this, capacity, onOverflow, overflowStrategy)); } @@ -13882,7 +13882,7 @@ public final Flowable scan(BiFunction accumulator) { @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable scan(final R initialValue, BiFunction accumulator) { - ObjectHelper.requireNonNull(initialValue, "seed is null"); + ObjectHelper.requireNonNull(initialValue, "initialValue is null"); return scanWith(Functions.justCallable(initialValue), accumulator); } @@ -14562,7 +14562,7 @@ public final Flowable startWith(Publisher other) { @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public final Flowable startWith(T value) { - ObjectHelper.requireNonNull(value, "item is null"); + ObjectHelper.requireNonNull(value, "value is null"); return concatArray(just(value), this); } diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index ab221724eb..9fd5f6c810 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -2533,7 +2533,7 @@ public final Single count() { @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe defaultIfEmpty(T defaultItem) { - ObjectHelper.requireNonNull(defaultItem, "item is null"); + ObjectHelper.requireNonNull(defaultItem, "defaultItem is null"); return switchIfEmpty(just(defaultItem)); } @@ -2709,7 +2709,7 @@ public final Maybe delaySubscription(long delay, TimeUnit unit, Scheduler sch @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doAfterSuccess(Consumer onAfterSuccess) { - ObjectHelper.requireNonNull(onAfterSuccess, "doAfterSuccess is null"); + ObjectHelper.requireNonNull(onAfterSuccess, "onAfterSuccess is null"); return RxJavaPlugins.onAssembly(new MaybeDoAfterSuccess(this, onAfterSuccess)); } @@ -2937,7 +2937,7 @@ public final Maybe doOnTerminate(final Action onTerminate) { public final Maybe doOnSuccess(Consumer onSuccess) { return RxJavaPlugins.onAssembly(new MaybePeek(this, Functions.emptyConsumer(), // onSubscribe - ObjectHelper.requireNonNull(onSuccess, "onSubscribe is null"), + ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"), Functions.emptyConsumer(), // onError Functions.EMPTY_ACTION, // onComplete Functions.EMPTY_ACTION, // (onSuccess | onError | onComplete) @@ -3452,7 +3452,7 @@ public final Single isEmpty() { @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Maybe lift(final MaybeOperator lift) { - ObjectHelper.requireNonNull(lift, "onLift is null"); + ObjectHelper.requireNonNull(lift, "lift is null"); return RxJavaPlugins.onAssembly(new MaybeLift(this, lift)); } @@ -4512,7 +4512,7 @@ public final Maybe timeout(long timeout, TimeUnit timeUnit) { @NonNull @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Maybe timeout(long timeout, TimeUnit timeUnit, MaybeSource fallback) { - ObjectHelper.requireNonNull(fallback, "other is null"); + ObjectHelper.requireNonNull(fallback, "fallback is null"); return timeout(timeout, timeUnit, Schedulers.computation(), fallback); } diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index fe2989bae4..148f96c87b 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -1738,7 +1738,7 @@ public static Observable error(Callable errorSupplie @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable error(final Throwable exception) { - ObjectHelper.requireNonNull(exception, "e is null"); + ObjectHelper.requireNonNull(exception, "exception is null"); return error(Functions.justCallable(exception)); } @@ -2046,7 +2046,7 @@ public static Observable fromPublisher(Publisher publisher) @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate(final Consumer> generator) { - ObjectHelper.requireNonNull(generator, "generator is null"); + ObjectHelper.requireNonNull(generator, "generator is null"); return generate(Functions.nullSupplier(), ObservableInternalHelper.simpleGenerator(generator), Functions.emptyConsumer()); } @@ -2078,7 +2078,7 @@ public static Observable generate(final Consumer> generator) { @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate(Callable initialState, final BiConsumer> generator) { - ObjectHelper.requireNonNull(generator, "generator is null"); + ObjectHelper.requireNonNull(generator, "generator is null"); return generate(initialState, ObservableInternalHelper.simpleBiGenerator(generator), Functions.emptyConsumer()); } @@ -2114,7 +2114,7 @@ public static Observable generate( final Callable initialState, final BiConsumer> generator, Consumer disposeState) { - ObjectHelper.requireNonNull(generator, "generator is null"); + ObjectHelper.requireNonNull(generator, "generator is null"); return generate(initialState, ObservableInternalHelper.simpleBiGenerator(generator), disposeState); } @@ -2180,7 +2180,7 @@ public static Observable generate(Callable initialState, BiFunction public static Observable generate(Callable initialState, BiFunction, S> generator, Consumer disposeState) { ObjectHelper.requireNonNull(initialState, "initialState is null"); - ObjectHelper.requireNonNull(generator, "generator is null"); + ObjectHelper.requireNonNull(generator, "generator is null"); ObjectHelper.requireNonNull(disposeState, "disposeState is null"); return RxJavaPlugins.onAssembly(new ObservableGenerate(initialState, generator, disposeState)); } @@ -2386,7 +2386,7 @@ public static Observable intervalRange(long start, long count, long initia @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item) { - ObjectHelper.requireNonNull(item, "The item is null"); + ObjectHelper.requireNonNull(item, "item is null"); return RxJavaPlugins.onAssembly(new ObservableJust(item)); } @@ -2413,8 +2413,8 @@ public static Observable just(T item) { @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); return fromArray(item1, item2); } @@ -2444,9 +2444,9 @@ public static Observable just(T item1, T item2) { @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); return fromArray(item1, item2, item3); } @@ -2478,10 +2478,10 @@ public static Observable just(T item1, T item2, T item3) { @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); return fromArray(item1, item2, item3, item4); } @@ -2515,11 +2515,11 @@ public static Observable just(T item1, T item2, T item3, T item4) { @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); return fromArray(item1, item2, item3, item4, item5); } @@ -2555,12 +2555,12 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); return fromArray(item1, item2, item3, item4, item5, item6); } @@ -2598,13 +2598,13 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); - ObjectHelper.requireNonNull(item7, "The seventh item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); + ObjectHelper.requireNonNull(item7, "item7 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7); } @@ -2644,14 +2644,14 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); - ObjectHelper.requireNonNull(item7, "The seventh item is null"); - ObjectHelper.requireNonNull(item8, "The eighth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); + ObjectHelper.requireNonNull(item7, "item7 is null"); + ObjectHelper.requireNonNull(item8, "item8 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7, item8); } @@ -2693,15 +2693,15 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); - ObjectHelper.requireNonNull(item7, "The seventh item is null"); - ObjectHelper.requireNonNull(item8, "The eighth item is null"); - ObjectHelper.requireNonNull(item9, "The ninth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); + ObjectHelper.requireNonNull(item7, "item7 is null"); + ObjectHelper.requireNonNull(item8, "item8 is null"); + ObjectHelper.requireNonNull(item9, "item9 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7, item8, item9); } @@ -2745,16 +2745,16 @@ public static Observable just(T item1, T item2, T item3, T item4, T item5 @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9, T item10) { - ObjectHelper.requireNonNull(item1, "The first item is null"); - ObjectHelper.requireNonNull(item2, "The second item is null"); - ObjectHelper.requireNonNull(item3, "The third item is null"); - ObjectHelper.requireNonNull(item4, "The fourth item is null"); - ObjectHelper.requireNonNull(item5, "The fifth item is null"); - ObjectHelper.requireNonNull(item6, "The sixth item is null"); - ObjectHelper.requireNonNull(item7, "The seventh item is null"); - ObjectHelper.requireNonNull(item8, "The eighth item is null"); - ObjectHelper.requireNonNull(item9, "The ninth item is null"); - ObjectHelper.requireNonNull(item10, "The tenth item is null"); + ObjectHelper.requireNonNull(item1, "item1 is null"); + ObjectHelper.requireNonNull(item2, "item2 is null"); + ObjectHelper.requireNonNull(item3, "item3 is null"); + ObjectHelper.requireNonNull(item4, "item4 is null"); + ObjectHelper.requireNonNull(item5, "item5 is null"); + ObjectHelper.requireNonNull(item6, "item6 is null"); + ObjectHelper.requireNonNull(item7, "item7 is null"); + ObjectHelper.requireNonNull(item8, "item8 is null"); + ObjectHelper.requireNonNull(item9, "item9 is null"); + ObjectHelper.requireNonNull(item10, "item10 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7, item8, item9, item10); } @@ -3995,7 +3995,6 @@ public static Observable timer(long delay, TimeUnit unit, Scheduler schedu @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable unsafeCreate(ObservableSource onSubscribe) { - ObjectHelper.requireNonNull(onSubscribe, "source is null"); ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); if (onSubscribe instanceof Observable) { throw new IllegalArgumentException("unsafeCreate(Observable) should be upgraded"); @@ -8157,7 +8156,7 @@ private Observable doOnEach(Consumer onNext, Consumer doOnEach(final Consumer> onNotification) { - ObjectHelper.requireNonNull(onNotification, "consumer is null"); + ObjectHelper.requireNonNull(onNotification, "onNotification is null"); return doOnEach( Functions.notificationOnNext(onNotification), Functions.notificationOnError(onNotification), @@ -9754,7 +9753,7 @@ public final Single lastOrError() { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable lift(ObservableOperator lifter) { - ObjectHelper.requireNonNull(lifter, "onLift is null"); + ObjectHelper.requireNonNull(lifter, "lifter is null"); return RxJavaPlugins.onAssembly(new ObservableLift(this, lifter)); } @@ -11240,7 +11239,7 @@ public final Observable retryWhen( */ @SchedulerSupport(SchedulerSupport.NONE) public final void safeSubscribe(Observer observer) { - ObjectHelper.requireNonNull(observer, "s is null"); + ObjectHelper.requireNonNull(observer, "observer is null"); if (observer instanceof SafeObserver) { subscribe(observer); } else { @@ -11499,7 +11498,7 @@ public final Observable scan(BiFunction accumulator) { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable scan(final R initialValue, BiFunction accumulator) { - ObjectHelper.requireNonNull(initialValue, "seed is null"); + ObjectHelper.requireNonNull(initialValue, "initialValue is null"); return scanWith(Functions.justCallable(initialValue), accumulator); } @@ -13122,7 +13121,7 @@ public final Observable takeUntil(ObservableSource other) { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable takeUntil(Predicate stopPredicate) { - ObjectHelper.requireNonNull(stopPredicate, "predicate is null"); + ObjectHelper.requireNonNull(stopPredicate, "stopPredicate is null"); return RxJavaPlugins.onAssembly(new ObservableTakeUntilPredicate(this, stopPredicate)); } diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index d4b5f7aaf4..f7d02b7a99 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -584,7 +584,7 @@ public static Single error(final Callable errorSuppl @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Single error(final Throwable exception) { - ObjectHelper.requireNonNull(exception, "error is null"); + ObjectHelper.requireNonNull(exception, "exception is null"); return error(Functions.justCallable(exception)); } @@ -834,7 +834,7 @@ public static Single fromObservable(ObservableSource observa @SchedulerSupport(SchedulerSupport.NONE) @NonNull public static Single just(final T item) { - ObjectHelper.requireNonNull(item, "value is null"); + ObjectHelper.requireNonNull(item, "item is null"); return RxJavaPlugins.onAssembly(new SingleJust(item)); } @@ -2413,7 +2413,7 @@ public final Maybe dematerialize(Function> sel @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single doAfterSuccess(Consumer onAfterSuccess) { - ObjectHelper.requireNonNull(onAfterSuccess, "doAfterSuccess is null"); + ObjectHelper.requireNonNull(onAfterSuccess, "onAfterSuccess is null"); return RxJavaPlugins.onAssembly(new SingleDoAfterSuccess(this, onAfterSuccess)); } @@ -2980,7 +2980,7 @@ public final T blockingGet() { @NonNull @SchedulerSupport(SchedulerSupport.NONE) public final Single lift(final SingleOperator lift) { - ObjectHelper.requireNonNull(lift, "onLift is null"); + ObjectHelper.requireNonNull(lift, "lift is null"); return RxJavaPlugins.onAssembly(new SingleLift(this, lift)); } @@ -3593,7 +3593,7 @@ public final Disposable subscribe(final Consumer onSuccess, final Con @SchedulerSupport(SchedulerSupport.NONE) @Override public final void subscribe(SingleObserver observer) { - ObjectHelper.requireNonNull(observer, "subscriber is null"); + ObjectHelper.requireNonNull(observer, "observer is null"); observer = RxJavaPlugins.onSubscribe(this, observer); From b0cb174db6088d231f1385606f1907f2fc5f4afc Mon Sep 17 00:00:00 2001 From: vikas kumar Date: Thu, 21 Mar 2019 19:15:52 +0530 Subject: [PATCH 142/211] refactor: improves Creating-Observables wiki doc (#6436) --- docs/Creating-Observables.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/Creating-Observables.md b/docs/Creating-Observables.md index 8e31a56528..360e03ab09 100644 --- a/docs/Creating-Observables.md +++ b/docs/Creating-Observables.md @@ -37,8 +37,8 @@ There exist overloads with 2 to 9 arguments for convenience, which objects (with ```java Observable observable = Observable.just("1", "A", "3.2", "def"); -observable.subscribe(item -> System.out.print(item), error -> error.printStackTrace, - () -> System.out.println()); + observable.subscribe(item -> System.out.print(item), error -> error.printStackTrace(), + () -> System.out.println()); ``` ## From @@ -80,7 +80,7 @@ for (int i = 0; i < array.length; i++) { array[i] = i; } -Observable observable = Observable.fromIterable(array); +Observable observable = Observable.fromArray(array); observable.subscribe(item -> System.out.println(item), error -> error.printStackTrace(), () -> System.out.println("Done")); @@ -155,7 +155,7 @@ Given a pre-existing, already running or already completed `java.util.concurrent #### fromFuture example: ```java -ScheduledExecutorService executor = Executors.newSingleThreadedScheduledExecutor(); +ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); Future future = executor.schedule(() -> "Hello world!", 1, TimeUnit.SECONDS); @@ -298,10 +298,10 @@ String greeting = "Hello World!"; Observable indexes = Observable.range(0, greeting.length()); -Observable characters = indexes +Observable characters = indexes .map(index -> greeting.charAt(index)); -characters.subscribe(character -> System.out.print(character), erro -> error.printStackTrace(), +characters.subscribe(character -> System.out.print(character), error -> error.printStackTrace(), () -> System.out.println()); ``` @@ -396,7 +396,7 @@ Observable error = Observable.error(new IOException()); error.subscribe( v -> System.out.println("This should never be printed!"), - error -> error.printStackTrace(), + e -> e.printStackTrace(), () -> System.out.println("This neither!")); ``` @@ -423,4 +423,4 @@ for (int i = 0; i < 10; i++) { error -> error.printStackTrace(), () -> System.out.println("Done")); } -``` +``` \ No newline at end of file From 0b3558dbf026411b665c581bc39034e27803e5e0 Mon Sep 17 00:00:00 2001 From: mgb Date: Tue, 26 Mar 2019 20:36:21 +0530 Subject: [PATCH 143/211] Undeliverable error handling logic for Completable operators (#6442) * Error handle on Completable.fromAction with RxJavaPlugins * Error handle on Completable.fromRunnable with RxJavaPlugins * Added error handling java docs section to Completable.fromRunnable --- src/main/java/io/reactivex/Completable.java | 7 +++++++ .../operators/completable/CompletableFromAction.java | 3 +++ .../operators/completable/CompletableFromRunnable.java | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 13364dc1a6..fe4d886dcd 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -508,6 +508,13 @@ public static Completable fromMaybe(final MaybeSource maybe) { *
      *
      Scheduler:
      *
      {@code fromRunnable} does not operate by default on a particular {@link Scheduler}.
      + *
      Error handling:
      + *
      If the {@link Runnable} throws an exception, the respective {@link Throwable} is + * delivered to the downstream via {@link CompletableObserver#onError(Throwable)}, + * except when the downstream has disposed this {@code Completable} source. + * In this latter case, the {@code Throwable} is delivered to the global error handler via + * {@link RxJavaPlugins#onError(Throwable)} as an {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}. + *
      *
      * @param run the runnable to run for each subscriber * @return the new Completable instance diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromAction.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromAction.java index 3e49bf0ec6..6722722390 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromAction.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromAction.java @@ -17,6 +17,7 @@ import io.reactivex.disposables.*; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Action; +import io.reactivex.plugins.RxJavaPlugins; public final class CompletableFromAction extends Completable { @@ -36,6 +37,8 @@ protected void subscribeActual(CompletableObserver observer) { Exceptions.throwIfFatal(e); if (!d.isDisposed()) { observer.onError(e); + } else { + RxJavaPlugins.onError(e); } return; } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromRunnable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromRunnable.java index 981e6d1f1f..3ce78a167f 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableFromRunnable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableFromRunnable.java @@ -18,6 +18,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.Exceptions; +import io.reactivex.plugins.RxJavaPlugins; public final class CompletableFromRunnable extends Completable { @@ -37,6 +38,8 @@ protected void subscribeActual(CompletableObserver observer) { Exceptions.throwIfFatal(e); if (!d.isDisposed()) { observer.onError(e); + } else { + RxJavaPlugins.onError(e); } return; } From 4a78cfcbf2f0d7008042c15ea8bb6797fcd2b06e Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 26 Mar 2019 16:08:13 +0100 Subject: [PATCH 144/211] Release 2.2.8 --- CHANGES.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 16757d46b4..8b4d70b96b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,23 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.8 - March 26, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.8%7C)) + +#### Bugfixes + + - [Pull 6442](https://github.com/ReactiveX/RxJava/pull/6442): Add missing undeliverable error handling logic for `Completable.fromRunnable` & `fromAction` operators. + +#### Documentation changes + + - [Pull 6432](https://github.com/ReactiveX/RxJava/pull/6432): Improve the docs of `CompositeDisposable`. + - [Pull 6434](https://github.com/ReactiveX/RxJava/pull/6434): Improve subjects and processors package doc. + - [Pull 6436](https://github.com/ReactiveX/RxJava/pull/6436): Improve `Creating-Observables` wiki doc. + + +#### Other + + - [Pull 6433](https://github.com/ReactiveX/RxJava/pull/6433): Make error messages of parameter checks consistent. + ### Version 2.2.7 - February 23, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.7%7C)) #### API enhancements From 0f565f21eb041540358cf9f5bcd375069bcde188 Mon Sep 17 00:00:00 2001 From: Kuan-Yu Tseng Date: Thu, 4 Apr 2019 11:37:16 -0700 Subject: [PATCH 145/211] Remove dependency of Schedulers from ObservableRefCount (#6452) In the constructor of `ObservableRefCount` that takes `ConnectableObservable source` as the argument, we set `timeout` to `0L`. In that specific use case of `ObservableRefCount`, `scheduler` is never needed. It's only referenced in `cancel()` method but if timeout is 0, it won't be triggered at all because there is early return. This commit removes the need to depend on `Schedulers.trampoline()` and instead passes null to be scheduler when the ref count is not time-based. The reasons for this change are the following: 1. In projects that don't depend on `Schedulers` class, if there is no reference to `Schedulers`, the whole `Schedulers` can be stripped out of the library after optimizations (e.g., proguard). With constructor that references `Schedulers`, the optimizer can't properly strip it out. In our quick test of our Android app, we were able to reduce the RxJava library size dependency from 51KB to 37KB (after optimization but before compression) by simply avoiding access to `Schedulers` in `ObservableRefCount`. 2. In terms of modularity, `ObservableRefCount` is just an operator so it by itself should probably not have dependency on what available pool of schedulers (`Schedulers`) there are. It should just know that there is some `Scheduler` that could be passed to `ObservableRefCount` when `ObservableRefCount` needs it. --- .../internal/operators/flowable/FlowableRefCount.java | 3 +-- .../internal/operators/observable/ObservableRefCount.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java index bc11aa5425..02ed97b462 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java @@ -25,7 +25,6 @@ import io.reactivex.internal.disposables.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; /** * Returns an observable sequence that stays connected to the source as long as @@ -49,7 +48,7 @@ public final class FlowableRefCount extends Flowable { RefConnection connection; public FlowableRefCount(ConnectableFlowable source) { - this(source, 1, 0L, TimeUnit.NANOSECONDS, Schedulers.trampoline()); + this(source, 1, 0L, TimeUnit.NANOSECONDS, null); } public FlowableRefCount(ConnectableFlowable source, int n, long timeout, TimeUnit unit, diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java index 5abc174350..5306f4481d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java @@ -22,7 +22,6 @@ import io.reactivex.internal.disposables.*; import io.reactivex.observables.ConnectableObservable; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; /** * Returns an observable sequence that stays connected to the source as long as @@ -46,7 +45,7 @@ public final class ObservableRefCount extends Observable { RefConnection connection; public ObservableRefCount(ConnectableObservable source) { - this(source, 1, 0L, TimeUnit.NANOSECONDS, Schedulers.trampoline()); + this(source, 1, 0L, TimeUnit.NANOSECONDS, null); } public ObservableRefCount(ConnectableObservable source, int n, long timeout, TimeUnit unit, From 3958d1bd56e49947cf6253a51f982b300b56a145 Mon Sep 17 00:00:00 2001 From: Alexis Munsayac Date: Fri, 5 Apr 2019 02:56:17 +0800 Subject: [PATCH 146/211] Fixed typos for comments (#6453) * Update Maybe.java * Update Single.java --- src/main/java/io/reactivex/Maybe.java | 8 ++++---- src/main/java/io/reactivex/Single.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 9fd5f6c810..e2266c6b50 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -3685,7 +3685,7 @@ public final Single toSingle() { *
      Scheduler:
      *
      {@code onErrorComplete} does not operate by default on a particular {@link Scheduler}.
      * - * @return the new Completable instance + * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @@ -3702,7 +3702,7 @@ public final Maybe onErrorComplete() { * * @param predicate the predicate to call when an Throwable is emitted which should return true * if the Throwable should be swallowed and replaced with an onComplete. - * @return the new Completable instance + * @return the new Maybe instance */ @CheckReturnValue @NonNull @@ -3984,7 +3984,7 @@ public final Flowable repeatWhen(final Function, ? e *
      {@code retry} does not operate by default on a particular {@link Scheduler}.
      * * - * @return the nww Maybe instance + * @return the new Maybe instance * @see ReactiveX operators documentation: Retry */ @CheckReturnValue @@ -4006,7 +4006,7 @@ public final Maybe retry() { * @param predicate * the predicate that determines if a resubscription may happen in case of a specific exception * and retry count - * @return the nww Maybe instance + * @return the new Maybe instance * @see #retry() * @see ReactiveX operators documentation: Retry */ diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index f7d02b7a99..f97f4d22b7 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -476,7 +476,7 @@ public static Flowable concatEager(Iterable * *

      From c04cfb8366534560e045f86201c05991763e1643 Mon Sep 17 00:00:00 2001 From: Roman Wuattier Date: Fri, 12 Apr 2019 14:03:32 +0200 Subject: [PATCH 147/211] Update the Javadoc of the `retry` operator (#6458) Specify that the `times` function parameter describes "the number of times to resubscribe if the current *operator* fails". Also, this commit updates some unit tests to illustrate the Javadoc wording. Solves: #6402 --- src/main/java/io/reactivex/Completable.java | 4 ++-- src/main/java/io/reactivex/Flowable.java | 4 ++-- src/main/java/io/reactivex/Maybe.java | 4 ++-- src/main/java/io/reactivex/Observable.java | 4 ++-- .../io/reactivex/completable/CompletableTest.java | 6 ++++-- .../internal/operators/single/SingleMiscTest.java | 10 ++++++++-- src/test/java/io/reactivex/maybe/MaybeTest.java | 13 +++++++++++++ 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index fe4d886dcd..79fcc9b432 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -2090,7 +2090,7 @@ public final Completable retry(BiPredicate p *

      Scheduler:
      *
      {@code retry} does not operate by default on a particular {@link Scheduler}.
      * - * @param times the number of times the returned Completable should retry this Completable + * @param times the number of times to resubscribe if the current Completable fails * @return the new Completable instance * @throws IllegalArgumentException if times is negative */ @@ -2110,7 +2110,7 @@ public final Completable retry(long times) { *
      {@code retry} does not operate by default on a particular {@link Scheduler}.
      * *

      History: 2.1.8 - experimental - * @param times the number of times the returned Completable should retry this Completable + * @param times the number of times to resubscribe if the current Completable fails * @param predicate the predicate that is called with the latest throwable and should return * true to indicate the returned Completable should resubscribe to this Completable. * @return the new Completable instance diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index ff85859f99..550b2958ce 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -13399,7 +13399,7 @@ public final Flowable retry(BiPredicate p * * * @param count - * number of retry attempts before failing + * the number of times to resubscribe if the current Flowable fails * @return the source Publisher modified with retry logic * @see ReactiveX operators documentation: Retry */ @@ -13420,7 +13420,7 @@ public final Flowable retry(long count) { *

      Scheduler:
      *
      {@code retry} does not operate by default on a particular {@link Scheduler}.
      * - * @param times the number of times to repeat + * @param times the number of times to resubscribe if the current Flowable fails * @param predicate the predicate called with the failure Throwable and should return true to trigger a retry. * @return the new Flowable instance */ diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index e2266c6b50..c123aa2316 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -4031,7 +4031,7 @@ public final Maybe retry(BiPredicate pred * * * @param count - * number of retry attempts before failing + * the number of times to resubscribe if the current Maybe fails * @return the new Maybe instance * @see ReactiveX operators documentation: Retry */ @@ -4048,7 +4048,7 @@ public final Maybe retry(long count) { *
      Scheduler:
      *
      {@code retry} does not operate by default on a particular {@link Scheduler}.
      * - * @param times the number of times to repeat + * @param times the number of times to resubscribe if the current Maybe fails * @param predicate the predicate called with the failure Throwable and should return true to trigger a retry. * @return the new Maybe instance */ diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 148f96c87b..15b453cd45 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -11075,7 +11075,7 @@ public final Observable retry(BiPredicate * * * @param times - * number of retry attempts before failing + * the number of times to resubscribe if the current Observable fails * @return the source ObservableSource modified with retry logic * @see ReactiveX operators documentation: Retry */ @@ -11093,7 +11093,7 @@ public final Observable retry(long times) { *
      Scheduler:
      *
      {@code retry} does not operate by default on a particular {@link Scheduler}.
      * - * @param times the number of times to repeat + * @param times the number of times to resubscribe if the current Observable fails * @param predicate the predicate called with the failure Throwable and should return true to trigger a retry. * @return the new Observable instance */ diff --git a/src/test/java/io/reactivex/completable/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java index 4798973835..80f4b49d5a 100644 --- a/src/test/java/io/reactivex/completable/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -2398,18 +2398,20 @@ public void retryTimes5Error() { @Test(timeout = 5000) public void retryTimes5Normal() { - final AtomicInteger calls = new AtomicInteger(5); + final AtomicInteger calls = new AtomicInteger(); Completable c = Completable.fromAction(new Action() { @Override public void run() { - if (calls.decrementAndGet() != 0) { + if (calls.incrementAndGet() != 6) { throw new TestException(); } } }).retry(5); c.blockingAwait(); + + assertEquals(6, calls.get()); } @Test(expected = IllegalArgumentException.class) diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java index c811291851..7b3a891680 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java @@ -27,7 +27,9 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; @@ -199,11 +201,13 @@ public boolean test(Integer i, Throwable e) throws Exception { @Test public void retryTimes() { + final AtomicInteger calls = new AtomicInteger(); + Single.fromCallable(new Callable() { - int c; + @Override public Object call() throws Exception { - if (++c != 5) { + if (calls.incrementAndGet() != 6) { throw new TestException(); } return 1; @@ -212,6 +216,8 @@ public Object call() throws Exception { .retry(5) .test() .assertResult(1); + + assertEquals(6, calls.get()); } @Test diff --git a/src/test/java/io/reactivex/maybe/MaybeTest.java b/src/test/java/io/reactivex/maybe/MaybeTest.java index 41225a47cc..45b31b0a8a 100644 --- a/src/test/java/io/reactivex/maybe/MaybeTest.java +++ b/src/test/java/io/reactivex/maybe/MaybeTest.java @@ -3185,6 +3185,19 @@ public Publisher apply(Flowable v) throws Exception return (Publisher)v; } }).test().assertResult(1); + + final AtomicInteger calls = new AtomicInteger(); + try { + Maybe.error(new Callable() { + @Override + public Throwable call() { + calls.incrementAndGet(); + return new TestException(); + } + }).retry(5).test(); + } finally { + assertEquals(6, calls.get()); + } } @Test From deeb14150ac21ad8c7b38c1ac692be487375faf5 Mon Sep 17 00:00:00 2001 From: IRuizM <13287486+IRuizM@users.noreply.github.com> Date: Sat, 13 Apr 2019 14:59:19 +0200 Subject: [PATCH 148/211] Change error message in ObservableFromArray (#6461) * Change error message in ObservableFromArray Changed error message from "The $i th element is null" to "The element at index $i is null". Solves #6460 * Change error messages in FlowableFromArray Changed error messages from "array element is null" to "The element at index $i is null". Solves #6460 --- .../internal/operators/flowable/FlowableFromArray.java | 8 ++++---- .../operators/observable/ObservableFromArray.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java index c8c6201daa..d54fb15a21 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFromArray.java @@ -126,7 +126,7 @@ void fastPath() { } T t = arr[i]; if (t == null) { - a.onError(new NullPointerException("array element is null")); + a.onError(new NullPointerException("The element at index " + i + " is null")); return; } else { a.onNext(t); @@ -156,7 +156,7 @@ void slowPath(long r) { T t = arr[i]; if (t == null) { - a.onError(new NullPointerException("array element is null")); + a.onError(new NullPointerException("The element at index " + i + " is null")); return; } else { a.onNext(t); @@ -209,7 +209,7 @@ void fastPath() { } T t = arr[i]; if (t == null) { - a.onError(new NullPointerException("array element is null")); + a.onError(new NullPointerException("The element at index " + i + " is null")); return; } else { a.tryOnNext(t); @@ -239,7 +239,7 @@ void slowPath(long r) { T t = arr[i]; if (t == null) { - a.onError(new NullPointerException("array element is null")); + a.onError(new NullPointerException("The element at index " + i + " is null")); return; } else { if (a.tryOnNext(t)) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java index 11b871ee46..9a04a4fcc3 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFromArray.java @@ -102,7 +102,7 @@ void run() { for (int i = 0; i < n && !isDisposed(); i++) { T value = a[i]; if (value == null) { - downstream.onError(new NullPointerException("The " + i + "th element is null")); + downstream.onError(new NullPointerException("The element at index " + i + " is null")); return; } downstream.onNext(value); From b570c912a507485c5fd8afee1dbd442836db0629 Mon Sep 17 00:00:00 2001 From: Alexis Munsayac Date: Fri, 26 Apr 2019 18:49:27 +0800 Subject: [PATCH 149/211] Remove redundant methods from Sample(Observable) (#6469) * Update Maybe.java * Update Single.java * Update ObservableSampleWithObservable.java * Update FlowableSamplePublisher.java * Update FlowableSamplePublisher.java --- .../flowable/FlowableSamplePublisher.java | 26 ++++--------------- .../ObservableSampleWithObservable.java | 26 ++++--------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSamplePublisher.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSamplePublisher.java index 55439eee69..66b9c48ec3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSamplePublisher.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSamplePublisher.java @@ -90,7 +90,7 @@ public void onError(Throwable t) { @Override public void onComplete() { SubscriptionHelper.cancel(other); - completeMain(); + completion(); } void setOther(Subscription o) { @@ -117,7 +117,7 @@ public void error(Throwable e) { public void complete() { upstream.cancel(); - completeOther(); + completion(); } void emit() { @@ -134,9 +134,7 @@ void emit() { } } - abstract void completeMain(); - - abstract void completeOther(); + abstract void completion(); abstract void run(); } @@ -178,12 +176,7 @@ static final class SampleMainNoLast extends SamplePublisherSubscriber { } @Override - void completeMain() { - downstream.onComplete(); - } - - @Override - void completeOther() { + void completion() { downstream.onComplete(); } @@ -207,16 +200,7 @@ static final class SampleMainEmitLast extends SamplePublisherSubscriber { } @Override - void completeMain() { - done = true; - if (wip.getAndIncrement() == 0) { - emit(); - downstream.onComplete(); - } - } - - @Override - void completeOther() { + void completion() { done = true; if (wip.getAndIncrement() == 0) { emit(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleWithObservable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleWithObservable.java index fcb0f33a00..1d5f8a5fe1 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleWithObservable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSampleWithObservable.java @@ -84,7 +84,7 @@ public void onError(Throwable t) { @Override public void onComplete() { DisposableHelper.dispose(other); - completeMain(); + completion(); } boolean setOther(Disposable o) { @@ -109,7 +109,7 @@ public void error(Throwable e) { public void complete() { upstream.dispose(); - completeOther(); + completion(); } void emit() { @@ -119,9 +119,7 @@ void emit() { } } - abstract void completeMain(); - - abstract void completeOther(); + abstract void completion(); abstract void run(); } @@ -163,12 +161,7 @@ static final class SampleMainNoLast extends SampleMainObserver { } @Override - void completeMain() { - downstream.onComplete(); - } - - @Override - void completeOther() { + void completion() { downstream.onComplete(); } @@ -192,16 +185,7 @@ static final class SampleMainEmitLast extends SampleMainObserver { } @Override - void completeMain() { - done = true; - if (wip.getAndIncrement() == 0) { - emit(); - downstream.onComplete(); - } - } - - @Override - void completeOther() { + void completion() { done = true; if (wip.getAndIncrement() == 0) { emit(); From ac84182aa2bd866b53e01c8e3fe99683b882c60e Mon Sep 17 00:00:00 2001 From: OH JAE HWAN Date: Mon, 29 Apr 2019 04:46:09 +0900 Subject: [PATCH 150/211] remove unused import in Flowable.java (#6470) --- src/main/java/io/reactivex/Flowable.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 550b2958ce..fe27b9bfd3 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -17,7 +17,6 @@ import org.reactivestreams.*; -import io.reactivex.Observable; import io.reactivex.annotations.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; From 1830453000ff04b099074bde1a17fa594b5468aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristiano=20Gavi=C3=A3o?= Date: Sat, 18 May 2019 14:14:17 -0300 Subject: [PATCH 151/211] Update README.md (#6480) fix issue #6479 --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c29d6d3fc0..982f0c393d 100644 --- a/README.md +++ b/README.md @@ -258,12 +258,10 @@ Flowable.range(1, 10) ```java Flowable inventorySource = warehouse.getInventoryAsync(); -inventorySource.flatMap(inventoryItem -> - erp.getDemandAsync(inventoryItem.getId()) - .map(demand - -> System.out.println("Item " + inventoryItem.getName() + " has demand " + demand)); - ) - .subscribe(); +inventorySource + .flatMap(inventoryItem -> erp.getDemandAsync(inventoryItem.getId()) + .map(demand -> "Item " + inventoryItem.getName() + " has demand " + demand)) + .subscribe(System.out::println); ``` ### Continuations From 8f51d2df7dfa4cfbf735a68085e6673aaa4a2856 Mon Sep 17 00:00:00 2001 From: Alexis Munsayac Date: Mon, 20 May 2019 17:01:03 +0800 Subject: [PATCH 152/211] Correction for Maybe.count doc typo (#6483) Resolves #6481 --- src/main/java/io/reactivex/Maybe.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index c123aa2316..aecb501348 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -2489,7 +2489,7 @@ public final Single contains(final Object item) { } /** - * Returns a Maybe that counts the total number of items emitted (0 or 1) by the source Maybe and emits + * Returns a Single that counts the total number of items emitted (0 or 1) by the source Maybe and emits * this count as a 64-bit Long. *

      * From 4ca7a9b91df673801ed6d09a7d79cfeff7699f79 Mon Sep 17 00:00:00 2001 From: Volodymyr Date: Thu, 23 May 2019 20:17:32 +0300 Subject: [PATCH 153/211] remove unused else from the Observable (#6485) * remove unused else from the Observable * fixed MR comments --- src/main/java/io/reactivex/Observable.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 15b453cd45..5bdd940909 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -84,12 +84,12 @@ * System.out.println("Done!"); * } * }); - * + * * Thread.sleep(500); * // the sequence can now be disposed via dispose() * d.dispose(); * - * + * * @param * the type of the items emitted by the Observable * @see Flowable @@ -1278,7 +1278,7 @@ public static Observable concat( public static Observable concatArray(ObservableSource... sources) { if (sources.length == 0) { return empty(); - } else + } if (sources.length == 1) { return wrap((ObservableSource)sources[0]); } @@ -1305,7 +1305,7 @@ public static Observable concatArray(ObservableSource... sou public static Observable concatArrayDelayError(ObservableSource... sources) { if (sources.length == 0) { return empty(); - } else + } if (sources.length == 1) { return (Observable)wrap(sources[0]); } @@ -1765,7 +1765,7 @@ public static Observable fromArray(T... items) { ObjectHelper.requireNonNull(items, "items is null"); if (items.length == 0) { return empty(); - } else + } if (items.length == 1) { return just(items[0]); } @@ -9626,7 +9626,7 @@ public final Single lastOrError() { * Example: *

      
            * // Step 1: Create the consumer type that will be returned by the ObservableOperator.apply():
      -     * 
      +     *
            * public final class CustomObserver<T> implements Observer<T>, Disposable {
            *
            *     // The downstream's Observer that will receive the onXXX events
      @@ -12816,10 +12816,10 @@ public final Observable take(long time, TimeUnit unit, Scheduler scheduler) {
           public final Observable takeLast(int count) {
               if (count < 0) {
                   throw new IndexOutOfBoundsException("count >= 0 required but it was " + count);
      -        } else
      +        }
               if (count == 0) {
                   return RxJavaPlugins.onAssembly(new ObservableIgnoreElements(this));
      -        } else
      +        }
               if (count == 1) {
                   return RxJavaPlugins.onAssembly(new ObservableTakeLastOne(this));
               }
      
      From c415b322614aedddd6a5d6d7e5b838e49f3fde4c Mon Sep 17 00:00:00 2001
      From: David Karnok 
      Date: Mon, 27 May 2019 10:23:32 +0200
      Subject: [PATCH 154/211] 2.x: Fix zip not stopping the subscription upon eager
       error (#6488)
      
      ---
       .../operators/observable/ObservableZip.java   |  4 +++
       .../operators/flowable/FlowableZipTest.java   | 30 +++++++++++++++++++
       .../observable/ObservableZipTest.java         | 30 +++++++++++++++++++
       3 files changed, 64 insertions(+)
      
      diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java
      index a259cd6d56..af465c43c6 100644
      --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java
      +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java
      @@ -179,6 +179,7 @@ public void drain() {
                                   if (z.done && !delayError) {
                                       Throwable ex = z.error;
                                       if (ex != null) {
      +                                    cancelled = true;
                                           cancel();
                                           a.onError(ex);
                                           return;
      @@ -224,6 +225,7 @@ boolean checkTerminated(boolean d, boolean empty, Observer a, boolean
                       if (delayError) {
                           if (empty) {
                               Throwable e = source.error;
      +                        cancelled = true;
                               cancel();
                               if (e != null) {
                                   a.onError(e);
      @@ -235,11 +237,13 @@ boolean checkTerminated(boolean d, boolean empty, Observer a, boolean
                       } else {
                           Throwable e = source.error;
                           if (e != null) {
      +                        cancelled = true;
                               cancel();
                               a.onError(e);
                               return true;
                           } else
                           if (empty) {
      +                        cancelled = true;
                               cancel();
                               a.onComplete();
                               return true;
      diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java
      index ef1223d66a..12f81c33e0 100644
      --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java
      +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java
      @@ -1895,4 +1895,34 @@ public Integer apply(Integer a, Integer b) throws Exception {
       
               ts.assertResult(4);
           }
      +
      +    @Test
      +    public void firstErrorPreventsSecondSubscription() {
      +        final AtomicInteger counter = new AtomicInteger();
      +
      +        List> flowableList = new ArrayList>();
      +        flowableList.add(Flowable.create(new FlowableOnSubscribe() {
      +            @Override
      +            public void subscribe(FlowableEmitter e)
      +                    throws Exception { throw new TestException(); }
      +        }, BackpressureStrategy.MISSING));
      +        flowableList.add(Flowable.create(new FlowableOnSubscribe() {
      +            @Override
      +            public void subscribe(FlowableEmitter e)
      +                    throws Exception { counter.getAndIncrement(); }
      +        }, BackpressureStrategy.MISSING));
      +
      +        Flowable.zip(flowableList,
      +                new Function() {
      +                    @Override
      +                    public Object apply(Object[] a) throws Exception {
      +                        return a;
      +                    }
      +                })
      +        .test()
      +        .assertFailure(TestException.class)
      +        ;
      +
      +        assertEquals(0, counter.get());
      +    }
       }
      diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java
      index 2fc7d7cb52..ba86f16175 100644
      --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java
      +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java
      @@ -1428,4 +1428,34 @@ public Integer apply(Integer t1, Integer t2) throws Exception {
               ps2.onNext(2);
               to.assertResult(3);
           }
      +
      +    @Test
      +    public void firstErrorPreventsSecondSubscription() {
      +        final AtomicInteger counter = new AtomicInteger();
      +
      +        List> observableList = new ArrayList>();
      +        observableList.add(Observable.create(new ObservableOnSubscribe() {
      +            @Override
      +            public void subscribe(ObservableEmitter e)
      +                    throws Exception { throw new TestException(); }
      +        }));
      +        observableList.add(Observable.create(new ObservableOnSubscribe() {
      +            @Override
      +            public void subscribe(ObservableEmitter e)
      +                    throws Exception { counter.getAndIncrement(); }
      +        }));
      +
      +        Observable.zip(observableList,
      +                new Function() {
      +                    @Override
      +                    public Object apply(Object[] a) throws Exception {
      +                        return a;
      +                    }
      +                })
      +        .test()
      +        .assertFailure(TestException.class)
      +        ;
      +
      +        assertEquals(0, counter.get());
      +    }
       }
      
      From 86048e18479daff55aca132098dcfa0f123cc29f Mon Sep 17 00:00:00 2001
      From: David Karnok 
      Date: Thu, 30 May 2019 09:08:32 +0200
      Subject: [PATCH 155/211] Release 2.2.9
      
      ---
       CHANGES.md | 19 +++++++++++++++++++
       1 file changed, 19 insertions(+)
      
      diff --git a/CHANGES.md b/CHANGES.md
      index 8b4d70b96b..7a5a441cea 100644
      --- a/CHANGES.md
      +++ b/CHANGES.md
      @@ -2,6 +2,25 @@
       
       The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md
       
      +### Version 2.2.9 - May 30, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.9%7C))
      +
      +#### Bugfixes
      +
      +  - [Pull 6488](https://github.com/ReactiveX/RxJava/pull/6488): Fix `zip` not stopping the subscription upon eager error.
      +
      +#### Documentation changes
      +
      +  - [Pull 6453](https://github.com/ReactiveX/RxJava/pull/6453): Fixed wrong type referenced in `Maybe` and `Single` JavaDocs.
      +  - [Pull 6458](https://github.com/ReactiveX/RxJava/pull/6458): Update the Javadoc of the `retry` operator.
      +
      +#### Other
      +
      +  - [Pull 6452](https://github.com/ReactiveX/RxJava/pull/6452): Remove dependency of `Schedulers` from `ObservableRefCount`.
      +  - [Pull 6461](https://github.com/ReactiveX/RxJava/pull/6461): Change error message in `ObservableFromArray`.
      +  - [Pull 6469](https://github.com/ReactiveX/RxJava/pull/6469): Remove redundant methods from `sample(Observable)`.
      +  - [Pull 6470](https://github.com/ReactiveX/RxJava/pull/6470): Remove unused import from `Flowable.java`.
      +  - [Pull 6485](https://github.com/ReactiveX/RxJava/pull/6485): Remove unused `else` from the `Observable`.
      +
       ### Version 2.2.8 - March 26, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.8%7C))
       
       #### Bugfixes
      
      From 368e0b422cee3848078e2d15c720d87ab571b8b5 Mon Sep 17 00:00:00 2001
      From: kongngng <51318004+kongngng@users.noreply.github.com>
      Date: Tue, 4 Jun 2019 19:44:42 +0900
      Subject: [PATCH 156/211] Update Additional-Reading.md (#6496)
      
      * Update Additional-Reading.md
      
      #6132
      - 'What is Reactive Programming?' was wrong link, so deleted.
      - First line was edited.
      
      * Update Additional-Reading.md
      
      - add 'What is Reactive Programming?' link.
      ---
       docs/Additional-Reading.md | 4 ++--
       1 file changed, 2 insertions(+), 2 deletions(-)
      
      diff --git a/docs/Additional-Reading.md b/docs/Additional-Reading.md
      index b5a4a2604a..d634e956a6 100644
      --- a/docs/Additional-Reading.md
      +++ b/docs/Additional-Reading.md
      @@ -1,4 +1,4 @@
      -(A more complete and up-to-date list of resources can be found at the reactivex.io site: [[http://reactivex.io/tutorials.html]])
      +A more complete and up-to-date list of resources can be found at the [reactivex.io site](http://reactivex.io/tutorials.html)
       
       # Introducing Reactive Programming
       * [Introduction to Rx](http://www.introtorx.com/): a free, on-line book by Lee Campbell **(1.x)**
      @@ -10,7 +10,7 @@
       * [Your Mouse is a Database](http://queue.acm.org/detail.cfm?id=2169076) by Erik Meijer
       * [A Playful Introduction to Rx](https://www.youtube.com/watch?v=WKore-AkisY) a video lecture by Erik Meijer
       * Wikipedia: [Reactive Programming](http://en.wikipedia.org/wiki/Reactive_programming) and [Functional Reactive Programming](http://en.wikipedia.org/wiki/Functional_reactive_programming)
      -* [What is Reactive Programming?](http://blog.hackhands.com/overview-of-reactive-programming/) a video presentation by Jafar Husain.
      +* [What is Reactive Programming?](https://www.youtube.com/watch?v=-8Y1-lE6NSA) a video presentation by Jafar Husain.
       * [2 minute introduction to Rx](https://medium.com/@andrestaltz/2-minute-introduction-to-rx-24c8ca793877) by André Staltz
       * StackOverflow: [What is (functional) reactive programming?](http://stackoverflow.com/a/1030631/1946802)
       * [The Reactive Manifesto](http://www.reactivemanifesto.org/)
      
      From 68ad8e24ad2ecf13285b3044cbb31c302653a3c0 Mon Sep 17 00:00:00 2001
      From: Kyeonghwan Kong <51318004+khkong@users.noreply.github.com>
      Date: Tue, 4 Jun 2019 23:09:54 +0900
      Subject: [PATCH 157/211] Update Alphabetical-List-of-Observable-Operators.md
       (#6497)
      
      #6132
      * Invalid link edited.
      ---
       ...phabetical-List-of-Observable-Operators.md | 496 +++++++++---------
       1 file changed, 248 insertions(+), 248 deletions(-)
      
      diff --git a/docs/Alphabetical-List-of-Observable-Operators.md b/docs/Alphabetical-List-of-Observable-Operators.md
      index 86495638c0..e5728356bc 100644
      --- a/docs/Alphabetical-List-of-Observable-Operators.md
      +++ b/docs/Alphabetical-List-of-Observable-Operators.md
      @@ -1,250 +1,250 @@
      -* **`aggregate( )`** — _see [**`reduce( )`**](Mathematical-and-Aggregate-Operators#reduce)_
      -* [**`all( )`**](Conditional-and-Boolean-Operators#all) — determine whether all items emitted by an Observable meet some criteria
      -* [**`amb( )`**](Conditional-and-Boolean-Operators#amb) — given two or more source Observables, emits all of the items from the first of these Observables to emit an item
      -* **`ambWith( )`** — _instance version of [**`amb( )`**](Conditional-and-Boolean-Operators#amb)_
      -* [**`and( )`**](Combining-Observables#and-then-and-when) — combine the emissions from two or more source Observables into a `Pattern` (`rxjava-joins`)
      -* **`apply( )`** (scala) — _see [**`create( )`**](Creating-Observables#create)_
      -* **`asObservable( )`** (kotlin) — _see [**`from( )`**](Creating-Observables#from) (et al.)_
      -* [**`asyncAction( )`**](Async-Operators#toasync-or-asyncaction-or-asyncfunc) — convert an Action into an Observable that executes the Action and emits its return value (`rxjava-async`)
      -* [**`asyncFunc( )`**](Async-Operators#toasync-or-asyncaction-or-asyncfunc) — convert a function into an Observable that executes the function and emits its return value (`rxjava-async`)
      -* [**`averageDouble( )`**](Mathematical-and-Aggregate-Operators#averageinteger-averagelong-averagefloat-and-averagedouble) — calculates the average of Doubles emitted by an Observable and emits this average (`rxjava-math`)
      -* [**`averageFloat( )`**](Mathematical-and-Aggregate-Operators#averageinteger-averagelong-averagefloat-and-averagedouble) — calculates the average of Floats emitted by an Observable and emits this average (`rxjava-math`)
      -* [**`averageInteger( )`**](Mathematical-and-Aggregate-Operators#averageinteger-averagelong-averagefloat-and-averagedouble) — calculates the average of Integers emitted by an Observable and emits this average (`rxjava-math`)
      -* [**`averageLong( )`**](Mathematical-and-Aggregate-Operators#averageinteger-averagelong-averagefloat-and-averagedouble) — calculates the average of Longs emitted by an Observable and emits this average (`rxjava-math`)
      -* **`blocking( )`** (clojure) — _see [**`toBlocking( )`**](Blocking-Observable-Operators)_
      -* [**`buffer( )`**](Transforming-Observables#buffer) — periodically gather items from an Observable into bundles and emit these bundles rather than emitting the items one at a time
      -* [**`byLine( )`**](String-Observables#byline) (`StringObservable`) — converts an Observable of Strings into an Observable of Lines by treating the source sequence as a stream and splitting it on line-endings
      -* [**`cache( )`**](Observable-Utility-Operators#cache) — remember the sequence of items emitted by the Observable and emit the same sequence to future Subscribers
      -* [**`cast( )`**](Transforming-Observables#cast) — cast all items from the source Observable into a particular type before reemitting them
      -* **`catch( )`** (clojure) — _see [**`onErrorResumeNext( )`**](Error-Handling-Operators#onerrorresumenext)_
      -* [**`chunkify( )`**](Phantom-Operators#chunkify) — returns an iterable that periodically returns a list of items emitted by the source Observable since the last list (⁇)
      -* [**`collect( )`**](Mathematical-and-Aggregate-Operators#collect) — collects items emitted by the source Observable into a single mutable data structure and returns an Observable that emits this structure
      -* [**`combineLatest( )`**](Combining-Observables#combinelatest) — when an item is emitted by either of two Observables, combine the latest item emitted by each Observable via a specified function and emit items based on the results of this function
      -* **`combineLatestWith( )`** (scala) — _instance version of [**`combineLatest( )`**](Combining-Observables#combinelatest)_
      -* [**`concat( )`**](Mathematical-and-Aggregate-Operators#concat) — concatenate two or more Observables sequentially
      -* [**`concatMap( )`**](Transforming-Observables#flatmap-concatmap-and-flatmapiterable) — transform the items emitted by an Observable into Observables, then flatten this into a single Observable, without interleaving
      -* **`concatWith( )`** — _instance version of [**`concat( )`**](Mathematical-and-Aggregate-Operators#concat)_
      -* [**`connect( )`**](Connectable-Observable-Operators#connectableobservableconnect) — instructs a Connectable Observable to begin emitting items
      -* **`cons( )`** (clojure) — _see [**`concat( )`**](Mathematical-and-Aggregate-Operators#concat)_
      -* [**`contains( )`**](Conditional-and-Boolean-Operators#contains) — determine whether an Observable emits a particular item or not
      -* [**`count( )`**](Mathematical-and-Aggregate-Operators#count-and-countlong) — counts the number of items emitted by an Observable and emits this count
      -* [**`countLong( )`**](Mathematical-and-Aggregate-Operators#count-and-countlong) — counts the number of items emitted by an Observable and emits this count
      -* [**`create( )`**](Creating-Observables#create) — create an Observable from scratch by means of a function
      -* **`cycle( )`** (clojure) — _see [**`repeat( )`**](Creating-Observables#repeat)_
      -* [**`debounce( )`**](Filtering-Observables#throttlewithtimeout-or-debounce) — only emit an item from the source Observable after a particular timespan has passed without the Observable emitting any other items
      -* [**`decode( )`**](String-Observables#decode) (`StringObservable`) — convert a stream of multibyte characters into an Observable that emits byte arrays that respect character boundaries
      -* [**`defaultIfEmpty( )`**](Conditional-and-Boolean-Operators#defaultifempty) — emit items from the source Observable, or emit a default item if the source Observable completes after emitting no items
      -* [**`defer( )`**](Creating-Observables#defer) — do not create the Observable until a Subscriber subscribes; create a fresh Observable on each subscription
      -* [**`deferFuture( )`**](Async-Operators#deferfuture) — convert a Future that returns an Observable into an Observable, but do not attempt to get the Observable that the Future returns until a Subscriber subscribes (`rxjava-async`)
      -* [**`deferCancellableFuture( )`**](Phantom-Operators#fromcancellablefuture-startcancellablefuture-and-defercancellablefuture-) — convert a Future that returns an Observable into an Observable in a way that monitors the subscription status of the Observable to determine whether to halt work on the Future, but do not attempt to get the returned Observable until a Subscriber subscribes (⁇)(`rxjava-async`)
      -* [**`delay( )`**](Observable-Utility-Operators#delay) — shift the emissions from an Observable forward in time by a specified amount
      -* [**`dematerialize( )`**](Observable-Utility-Operators#dematerialize) — convert a materialized Observable back into its non-materialized form
      -* [**`distinct( )`**](Filtering-Observables#distinct) — suppress duplicate items emitted by the source Observable
      -* [**`distinctUntilChanged( )`**](Filtering-Observables#distinctuntilchanged) — suppress duplicate consecutive items emitted by the source Observable
      -* **`do( )`** (clojure) — _see [**`doOnEach( )`**](Observable-Utility-Operators#dooneach)_
      -* [**`doOnCompleted( )`**](Observable-Utility-Operators#dooncompleted) — register an action to take when an Observable completes successfully
      -* [**`doOnEach( )`**](Observable-Utility-Operators#dooneach) — register an action to take whenever an Observable emits an item
      -* [**`doOnError( )`**](Observable-Utility-Operators#doonerror) — register an action to take when an Observable completes with an error
      -* **`doOnNext( )`** — _see [**`doOnEach( )`**](Observable-Utility-Operators#dooneach)_
      +* **`aggregate( )`** — _see [**`reduce( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#reduce)_
      +* [**`all( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#boolean-operators) — determine whether all items emitted by an Observable meet some criteria
      +* [**`amb( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators) — given two or more source Observables, emits all of the items from the first of these Observables to emit an item
      +* **`ambWith( )`** — _instance version of [**`amb( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators)_
      +* [**`and( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#and-then-and-when) — combine the emissions from two or more source Observables into a `Pattern` (`rxjava-joins`)
      +* **`apply( )`** (scala) — _see [**`create( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#create)_
      +* **`asObservable( )`** (kotlin) — _see [**`from( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#from) (et al.)_
      +* [**`asyncAction( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators#toasync-or-asyncaction-or-asyncfunc) — convert an Action into an Observable that executes the Action and emits its return value (`rxjava-async`)
      +* [**`asyncFunc( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators#toasync-or-asyncaction-or-asyncfunc) — convert a function into an Observable that executes the function and emits its return value (`rxjava-async`)
      +* [**`averageDouble( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#averagedouble) — calculates the average of Doubles emitted by an Observable and emits this average (`rxjava-math`)
      +* [**`averageFloat( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#averagefloat) — calculates the average of Floats emitted by an Observable and emits this average (`rxjava-math`)
      +* [**`averageInteger( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators) — calculates the average of Integers emitted by an Observable and emits this average (`rxjava-math`)
      +* [**`averageLong( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators) — calculates the average of Longs emitted by an Observable and emits this average (`rxjava-math`)
      +* **`blocking( )`** (clojure) — _see [**`toBlocking( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators)_
      +* [**`buffer( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#buffer) — periodically gather items from an Observable into bundles and emit these bundles rather than emitting the items one at a time
      +* [**`byLine( )`**](https://github.com/ReactiveX/RxJava/wiki/String-Observables) (`StringObservable`) — converts an Observable of Strings into an Observable of Lines by treating the source sequence as a stream and splitting it on line-endings
      +* [**`cache( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — remember the sequence of items emitted by the Observable and emit the same sequence to future Subscribers
      +* [**`cast( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#cast) — cast all items from the source Observable into a particular type before reemitting them
      +* **`catch( )`** (clojure) — _see [**`onErrorResumeNext( )`**](https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators#onerrorresumenext)_
      +* [**`chunkify( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#chunkify) — returns an iterable that periodically returns a list of items emitted by the source Observable since the last list (⁇)
      +* [**`collect( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#collect) — collects items emitted by the source Observable into a single mutable data structure and returns an Observable that emits this structure
      +* [**`combineLatest( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#combinelatest) — when an item is emitted by either of two Observables, combine the latest item emitted by each Observable via a specified function and emit items based on the results of this function
      +* **`combineLatestWith( )`** (scala) — _instance version of [**`combineLatest( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#combinelatest)_
      +* [**`concat( )`**](http://reactivex.io/documentation/operators/concat.html) — concatenate two or more Observables sequentially
      +* [**`concatMap( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#concatmap) — transform the items emitted by an Observable into Observables, then flatten this into a single Observable, without interleaving
      +* **`concatWith( )`** — _instance version of [**`concat( )`**](http://reactivex.io/documentation/operators/concat.html)_
      +* [**`connect( )`**](https://github.com/ReactiveX/RxJava/wiki/Connectable-Observable-Operators) — instructs a Connectable Observable to begin emitting items
      +* **`cons( )`** (clojure) — _see [**`concat( )`**](http://reactivex.io/documentation/operators/concat.html)_
      +* [**`contains( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#boolean-operators) — determine whether an Observable emits a particular item or not
      +* [**`count( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#count) — counts the number of items emitted by an Observable and emits this count
      +* [**`countLong( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#count) — counts the number of items emitted by an Observable and emits this count
      +* [**`create( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#create) — create an Observable from scratch by means of a function
      +* **`cycle( )`** (clojure) — _see [**`repeat( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables)_
      +* [**`debounce( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#debounce) — only emit an item from the source Observable after a particular timespan has passed without the Observable emitting any other items
      +* [**`decode( )`**](https://github.com/ReactiveX/RxJava/wiki/String-Observables) (`StringObservable`) — convert a stream of multibyte characters into an Observable that emits byte arrays that respect character boundaries
      +* [**`defaultIfEmpty( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators) — emit items from the source Observable, or emit a default item if the source Observable completes after emitting no items
      +* [**`defer( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#defer) — do not create the Observable until a Subscriber subscribes; create a fresh Observable on each subscription
      +* [**`deferFuture( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) — convert a Future that returns an Observable into an Observable, but do not attempt to get the Observable that the Future returns until a Subscriber subscribes (`rxjava-async`)
      +* [**`deferCancellableFuture( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#fromcancellablefuture-startcancellablefuture-and-defercancellablefuture) — convert a Future that returns an Observable into an Observable in a way that monitors the subscription status of the Observable to determine whether to halt work on the Future, but do not attempt to get the returned Observable until a Subscriber subscribes (⁇)(`rxjava-async`)
      +* [**`delay( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — shift the emissions from an Observable forward in time by a specified amount
      +* [**`dematerialize( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — convert a materialized Observable back into its non-materialized form
      +* [**`distinct( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#distinct) — suppress duplicate items emitted by the source Observable
      +* [**`distinctUntilChanged( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#distinctuntilchanged) — suppress duplicate consecutive items emitted by the source Observable
      +* **`do( )`** (clojure) — _see [**`doOnEach( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators)_
      +* [**`doOnCompleted( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — register an action to take when an Observable completes successfully
      +* [**`doOnEach( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — register an action to take whenever an Observable emits an item
      +* [**`doOnError( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — register an action to take when an Observable completes with an error
      +* **`doOnNext( )`** — _see [**`doOnEach( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators)_
       * **`doOnRequest( )`** — register an action to take when items are requested from an Observable via reactive-pull backpressure (⁇)
      -* [**`doOnSubscribe( )`**](Observable-Utility-Operators#doonsubscribe) — register an action to take when an observer subscribes to an Observable
      -* [**`doOnTerminate( )`**](Observable-Utility-Operators#doonterminate) — register an action to take when an Observable completes, either successfully or with an error
      -* [**`doOnUnsubscribe( )`**](Observable-Utility-Operators#doonunsubscribe) — register an action to take when an observer unsubscribes from an Observable
      -* [**`doWhile( )`**](Conditional-and-Boolean-Operators#dowhile) — emit the source Observable's sequence, and then repeat the sequence as long as a condition remains true (`contrib-computation-expressions`)
      -* **`drop( )`** (scala/clojure) — _see [**`skip( )`**](Filtering-Observables#skip)_
      -* **`dropRight( )`** (scala) — _see [**`skipLast( )`**](Filtering-Observables#skiplast)_
      -* **`dropUntil( )`** (scala) — _see [**`skipUntil( )`**](Conditional-and-Boolean-Operators#skipuntil)_
      -* **`dropWhile( )`** (scala) — _see [**`skipWhile( )`**](Conditional-and-Boolean-Operators#skipwhile)_
      -* **`drop-while( )`** (clojure) — _see [**`skipWhile( )`**](Conditional-and-Boolean-Operators#skipwhile)_
      -* [**`elementAt( )`**](Filtering-Observables#elementat) — emit item _n_ emitted by the source Observable
      -* [**`elementAtOrDefault( )`**](Filtering-Observables#elementatordefault) — emit item _n_ emitted by the source Observable, or a default item if the source Observable emits fewer than _n_ items
      -* [**`empty( )`**](Creating-Observables#empty-error-and-never) — create an Observable that emits nothing and then completes
      -* [**`encode( )`**](String-Observables#encode) (`StringObservable`) — transform an Observable that emits strings into an Observable that emits byte arrays that respect character boundaries of multibyte characters in the original strings
      -* [**`error( )`**](Creating-Observables#empty-error-and-never) — create an Observable that emits nothing and then signals an error
      -* **`every( )`** (clojure) — _see [**`all( )`**](Conditional-and-Boolean-Operators#all)_
      -* [**`exists( )`**](Conditional-and-Boolean-Operators#exists-and-isempty) — determine whether an Observable emits any items or not
      -* [**`filter( )`**](Filtering-Observables#filter) — filter items emitted by an Observable
      -* **`finally( )`** (clojure) — _see [**`finallyDo( )`**](Observable-Utility-Operators#finallydo)_
      -* **`filterNot( )`** (scala) — _see [**`filter( )`**](Filtering-Observables#filter)_
      -* [**`finallyDo( )`**](Observable-Utility-Operators#finallydo) — register an action to take when an Observable completes
      -* [**`first( )`**](Filtering-Observables#first-and-takefirst) (`Observable`) — emit only the first item emitted by an Observable, or the first item that meets some condition
      -* [**`first( )`**](Blocking-Observable-Operators#first-and-firstordefault) (`BlockingObservable`) — emit only the first item emitted by an Observable, or the first item that meets some condition
      -* [**`firstOrDefault( )`**](Filtering-Observables#firstordefault) (`Observable`) — emit only the first item emitted by an Observable, or the first item that meets some condition, or a default value if the source Observable is empty
      -* [**`firstOrDefault( )`**](Blocking-Observable-Operators#first-and-firstordefault) (`BlockingObservable`) — emit only the first item emitted by an Observable, or the first item that meets some condition, or a default value if the source Observable is empty
      -* **`firstOrElse( )`** (scala) — _see [**`firstOrDefault( )`**](Filtering-Observables#firstordefault) or [**`firstOrDefault( )`**](Blocking-Observable-Operators#first-and-firstordefault) (`BlockingObservable`)_
      -* [**`flatMap( )`**](Transforming-Observables#flatmap-concatmap-and-flatmapiterable) — transform the items emitted by an Observable into Observables, then flatten this into a single Observable
      -* [**`flatMapIterable( )`**](Transforming-Observables#flatmap-concatmap-and-flatmapiterable) — create Iterables corresponding to each emission from a source Observable and merge the results into a single Observable
      -* **`flatMapIterableWith( )`** (scala) — _instance version of [**`flatMapIterable( )`**](Transforming-Observables#flatmap-concatmap-and-flatmapiterable)_
      -* **`flatMapWith( )`** (scala) — _instance version of [**`flatmap( )`**](Transforming-Observables#flatmap-concatmap-and-flatmapiterable)_
      -* **`flatten( )`** (scala) — _see [**`merge( )`**](Combining-Observables#merge)_
      -* **`flattenDelayError( )`** (scala) — _see [**`mergeDelayError( )`**](Combining-Observables#mergedelayerror)_
      -* **`foldLeft( )`** (scala) — _see [**`reduce( )`**](Mathematical-and-Aggregate-Operators#reduce)_
      -* **`forall( )`** (scala) — _see [**`all( )`**](Conditional-and-Boolean-Operators#all)_
      -* **`forEach( )`** (`Observable`) — _see [**`subscribe( )`**](Observable#onnext-oncompleted-and-onerror)_
      -* [**`forEach( )`**](Blocking-Observable-Operators#foreach) (`BlockingObservable`) — invoke a function on each item emitted by the Observable; block until the Observable completes
      -* [**`forEachFuture( )`**](Async-Operators#foreachfuture) (`Async`) — pass Subscriber methods to an Observable but also have it behave like a Future that blocks until it completes (`rxjava-async`)
      -* [**`forEachFuture( )`**](Phantom-Operators#foreachfuture) (`BlockingObservable`)— create a futureTask that will invoke a specified function on each item emitted by an Observable (⁇)
      -* [**`forIterable( )`**](Phantom-Operators#foriterable) — apply a function to the elements of an Iterable to create Observables which are then concatenated (⁇)
      -* [**`from( )`**](Creating-Observables#from) — convert an Iterable, a Future, or an Array into an Observable
      -* [**`from( )`**](String-Observables#from) (`StringObservable`) — convert a stream of characters or a Reader into an Observable that emits byte arrays or Strings
      -* [**`fromAction( )`**](Async-Operators#fromaction) — convert an Action into an Observable that invokes the action and emits its result when a Subscriber subscribes (`rxjava-async`)
      -* [**`fromCallable( )`**](Async-Operators#fromcallable) — convert a Callable into an Observable that invokes the callable and emits its result or exception when a Subscriber subscribes (`rxjava-async`)
      -* [**`fromCancellableFuture( )`**](Phantom-Operators#fromcancellablefuture-startcancellablefuture-and-defercancellablefuture-) — convert a Future into an Observable in a way that monitors the subscription status of the Observable to determine whether to halt work on the Future, but do not attempt to get the Future's value until a Subscriber subscribes (⁇)(`rxjava-async`)
      -* **`fromFunc0( )`** — _see [**`fromCallable( )`**](Async-Operators#fromcallable) (`rxjava-async`)_
      -* [**`fromFuture( )`**](Phantom-Operators#fromfuture) — convert a Future into an Observable, but do not attempt to get the Future's value until a Subscriber subscribes (⁇)
      -* [**`fromRunnable( )`**](Async-Operators#fromrunnable) — convert a Runnable into an Observable that invokes the runable and emits its result when a Subscriber subscribes (`rxjava-async`)
      -* [**`generate( )`**](Phantom-Operators#generate-and-generateabsolutetime) — create an Observable that emits a sequence of items as generated by a function of your choosing (⁇)
      -* [**`generateAbsoluteTime( )`**](Phantom-Operators#generate-and-generateabsolutetime) — create an Observable that emits a sequence of items as generated by a function of your choosing, with each item emitted at an item-specific time (⁇)
      -* **`generator( )`** (clojure) — _see [**`generate( )`**](Phantom-Operators#generate-and-generateabsolutetime)_
      -* [**`getIterator( )`**](Blocking-Observable-Operators#transformations-tofuture-toiterable-and-getiterator) — convert the sequence emitted by the Observable into an Iterator
      -* [**`groupBy( )`**](Transforming-Observables#groupby) — divide an Observable into a set of Observables that emit groups of items from the original Observable, organized by key
      -* **`group-by( )`** (clojure) — _see [**`groupBy( )`**](Transforming-Observables#groupby)_
      -* [**`groupByUntil( )`**](Phantom-Operators#groupbyuntil) — a variant of the [`groupBy( )`](Transforming-Observables#groupby) operator that closes any open GroupedObservable upon a signal from another Observable (⁇)
      -* [**`groupJoin( )`**](Combining-Observables#join-and-groupjoin) — combine the items emitted by two Observables whenever one item from one Observable falls within a window of duration specified by an item emitted by the other Observable
      -* **`head( )`** (scala) — _see [**`first( )`**](Blocking-Observable-Operators#first-and-firstordefault) (`BlockingObservable`)_
      -* **`headOption( )`** (scala) — _see [**`firstOrDefault( )`**](Filtering-Observables#firstordefault) or [**`firstOrDefault( )`**](Blocking-Observable-Operators#first-and-firstordefault) (`BlockingObservable`)_
      -* **`headOrElse( )`** (scala) — _see [**`firstOrDefault( )`**](Filtering-Observables#firstordefault) or [**`firstOrDefault( )`**](Blocking-Observable-Operators#first-and-firstordefault) (`BlockingObservable`)_
      -* [**`ifThen( )`**](Conditional-and-Boolean-Operators#ifthen) — only emit the source Observable's sequence if a condition is true, otherwise emit an empty or default sequence (`contrib-computation-expressions`)
      -* [**`ignoreElements( )`**](Filtering-Observables#ignoreelements) — discard the items emitted by the source Observable and only pass through the error or completed notification
      -* [**`interval( )`**](Creating-Observables#interval) — create an Observable that emits a sequence of integers spaced by a given time interval
      -* **`into( )`** (clojure) — _see [**`reduce( )`**](Mathematical-and-Aggregate-Operators#reduce)_
      -* [**`isEmpty( )`**](Conditional-and-Boolean-Operators#exists-and-isempty) — determine whether an Observable emits any items or not
      -* **`items( )`** (scala) — _see [**`just( )`**](Creating-Observables#just)_
      -* [**`join( )`**](Combining-Observables#join-and-groupjoin) — combine the items emitted by two Observables whenever one item from one Observable falls within a window of duration specified by an item emitted by the other Observable
      -* [**`join( )`**](String-Observables#join) (`StringObservable`) — converts an Observable that emits a sequence of strings into an Observable that emits a single string that concatenates them all, separating them by a specified string
      -* [**`just( )`**](Creating-Observables#just) — convert an object into an Observable that emits that object
      -* [**`last( )`**](Blocking-Observable-Operators#last-and-lastordefault) (`BlockingObservable`) — block until the Observable completes, then return the last item emitted by the Observable
      -* [**`last( )`**](Filtering-Observables#last) (`Observable`) — emit only the last item emitted by the source Observable
      -* **`lastOption( )`** (scala) — _see [**`lastOrDefault( )`**](Filtering-Observables#lastOrDefault) or [**`lastOrDefault( )`**](Blocking-Observable-Operators#last-and-lastordefault) (`BlockingObservable`)_
      -* [**`lastOrDefault( )`**](Blocking-Observable-Operators#last-and-lastordefault) (`BlockingObservable`) — block until the Observable completes, then return the last item emitted by the Observable or a default item if there is no last item
      -* [**`lastOrDefault( )`**](Filtering-Observables#lastOrDefault) (`Observable`) — emit only the last item emitted by an Observable, or a default value if the source Observable is empty
      -* **`lastOrElse( )`** (scala) — _see [**`lastOrDefault( )`**](Filtering-Observables#lastOrDefault) or [**`lastOrDefault( )`**](Blocking-Observable-Operators#last-and-lastordefault) (`BlockingObservable`)_
      -* [**`latest( )`**](Blocking-Observable-Operators#latest) — returns an iterable that blocks until or unless the Observable emits an item that has not been returned by the iterable, then returns the latest such item
      -* **`length( )`** (scala) — _see [**`count( )`**](Mathematical-and-Aggregate-Operators#count-and-countlong)_
      -* **`limit( )`** — _see [**`take( )`**](Filtering-Observables#take)_
      -* **`longCount( )`** (scala) — _see [**`countLong( )`**](Mathematical-and-Aggregate-Operators#count-and-countlong)_
      -* [**`map( )`**](Transforming-Observables#map) — transform the items emitted by an Observable by applying a function to each of them
      -* **`mapcat( )`** (clojure) — _see [**`concatMap( )`**](Transforming-Observables#flatmap-concatmap-and-flatmapiterable)_
      -* **`mapMany( )`** — _see: [**`flatMap( )`**](Transforming-Observables#flatmap-concatmap-and-flatmapiterable)_
      -* [**`materialize( )`**](Observable-Utility-Operators#materialize) — convert an Observable into a list of Notifications
      -* [**`max( )`**](Mathematical-and-Aggregate-Operators#max) — emits the maximum value emitted by a source Observable (`rxjava-math`)
      -* [**`maxBy( )`**](Mathematical-and-Aggregate-Operators#maxby) — emits the item emitted by the source Observable that has the maximum key value (`rxjava-math`)
      -* [**`merge( )`**](Combining-Observables#merge) — combine multiple Observables into one
      -* [**`mergeDelayError( )`**](Combining-Observables#mergedelayerror) — combine multiple Observables into one, allowing error-free Observables to continue before propagating errors
      -* **`merge-delay-error( )`** (clojure) — _see [**`mergeDelayError( )`**](Combining-Observables#mergedelayerror)_
      -* **`mergeMap( )`** * — _see: [**`flatMap( )`**](Transforming-Observables#flatmap-concatmap-and-flatmapiterable)_
      -* **`mergeMapIterable( )`** — _see: [**`flatMapIterable( )`**](Transforming-Observables#flatmap-concatmap-and-flatmapiterable)_
      -* **`mergeWith( )`** — _instance version of [**`merge( )`**](Combining-Observables#merge)_
      -* [**`min( )`**](Mathematical-and-Aggregate-Operators#min) — emits the minimum value emitted by a source Observable (`rxjava-math`)
      -* [**`minBy( )`**](Mathematical-and-Aggregate-Operators#minby) — emits the item emitted by the source Observable that has the minimum key value (`rxjava-math`)
      -* [**`mostRecent( )`**](Blocking-Observable-Operators#mostrecent) — returns an iterable that always returns the item most recently emitted by the Observable
      -* [**`multicast( )`**](Phantom-Operators#multicast) — represents an Observable as a Connectable Observable
      -* [**`never( )`**](Creating-Observables#empty-error-and-never) — create an Observable that emits nothing at all
      -* [**`next( )`**](Blocking-Observable-Operators#next) — returns an iterable that blocks until the Observable emits another item, then returns that item
      -* **`nonEmpty( )`** (scala) — _see [**`isEmpty( )`**](Conditional-and-Boolean-Operators#exists-and-isempty)_
      -* **`nth( )`** (clojure) — _see [**`elementAt( )`**](Filtering-Observables#elementat) and [**`elementAtOrDefault( )`**](Filtering-Observables#elementatordefault)_
      -* [**`observeOn( )`**](Observable-Utility-Operators#observeon) — specify on which Scheduler a Subscriber should observe the Observable
      -* [**`ofType( )`**](Filtering-Observables#oftype) — emit only those items from the source Observable that are of a particular class
      -* [**`onBackpressureBlock( )`**](Backpressure) — block the Observable's thread until the Observer is ready to accept more items from the Observable (⁇)
      -* [**`onBackpressureBuffer( )`**](Backpressure) — maintain a buffer of all emissions from the source Observable and emit them to downstream Subscribers according to the requests they generate
      -* [**`onBackpressureDrop( )`**](Backpressure) — drop emissions from the source Observable unless there is a pending request from a downstream Subscriber, in which case emit enough items to fulfill the request
      -* [**`onErrorFlatMap( )`**](Phantom-Operators#onerrorflatmap) — instructs an Observable to emit a sequence of items whenever it encounters an error (⁇)
      -* [**`onErrorResumeNext( )`**](Error-Handling-Operators#onerrorresumenext) — instructs an Observable to emit a sequence of items if it encounters an error
      -* [**`onErrorReturn( )`**](Error-Handling-Operators#onerrorreturn) — instructs an Observable to emit a particular item when it encounters an error
      -* [**`onExceptionResumeNext( )`**](Error-Handling-Operators#onexceptionresumenext) — instructs an Observable to continue emitting items after it encounters an exception (but not another variety of throwable)
      -* **`orElse( )`** (scala) — _see [**`defaultIfEmpty( )`**](Conditional-and-Boolean-Operators#defaultifempty)_
      -* [**`parallel( )`**](Phantom-Operators#parallel) — split the work done on the emissions from an Observable into multiple Observables each operating on its own parallel thread (⁇)
      -* [**`parallelMerge( )`**](Phantom-Operators#parallelmerge) — combine multiple Observables into smaller number of Observables (⁇)
      -* [**`pivot( )`**](Phantom-Operators#pivot) — combine multiple sets of grouped observables so that they are arranged primarily by group rather than by set (⁇)
      -* [**`publish( )`**](Connectable-Observable-Operators#observablepublish) — represents an Observable as a Connectable Observable
      -* [**`publishLast( )`**](Phantom-Operators#publishlast) — represent an Observable as a Connectable Observable that emits only the last item emitted by the source Observable (⁇)
      -* [**`range( )`**](Creating-Observables#range) — create an Observable that emits a range of sequential integers
      -* [**`reduce( )`**](Mathematical-and-Aggregate-Operators#reduce) — apply a function to each emitted item, sequentially, and emit only the final accumulated value
      -* **`reductions( )`** (clojure) — _see [**`scan( )`**](Transforming-Observables#scan)_
      -* [**`refCount( )`**](Connectable-Observable-Operators#connectableobservablerefcount) — makes a Connectable Observable behave like an ordinary Observable
      -* [**`repeat( )`**](Creating-Observables#repeat) — create an Observable that emits a particular item or sequence of items repeatedly
      -* [**`repeatWhen( )`**](Creating-Observables#repeatwhen) — create an Observable that emits a particular item or sequence of items repeatedly, depending on the emissions of a second Observable
      -* [**`replay( )`**](Connectable-Observable-Operators#observablereplay) — ensures that all Subscribers see the same sequence of emitted items, even if they subscribe after the Observable begins emitting the items
      -* **`rest( )`** (clojure) — _see [**`next( )`**](Blocking-Observable-Operators#next)_
      -* **`return( )`** (clojure) — _see [**`just( )`**](Creating-Observables#just)_
      -* [**`retry( )`**](Error-Handling-Operators#retry) — if a source Observable emits an error, resubscribe to it in the hopes that it will complete without error
      -* [**`retrywhen( )`**](Error-Handling-Operators#retrywhen) — if a source Observable emits an error, pass that error to another Observable to determine whether to resubscribe to the source
      -* [**`runAsync( )`**](Async-Operators#runasync) — returns a `StoppableObservable` that emits multiple actions as generated by a specified Action on a Scheduler (`rxjava-async`)
      -* [**`sample( )`**](Filtering-Observables#sample-or-throttlelast) — emit the most recent items emitted by an Observable within periodic time intervals
      -* [**`scan( )`**](Transforming-Observables#scan) — apply a function to each item emitted by an Observable, sequentially, and emit each successive value
      -* **`seq( )`** (clojure) — _see [**`getIterator( )`**](Blocking-Observable-Operators#transformations-tofuture-toiterable-and-getiterator)_
      -* [**`sequenceEqual( )`**](Conditional-and-Boolean-Operators#sequenceequal) — test the equality of sequences emitted by two Observables
      -* **`sequenceEqualWith( )`** (scala) — _instance version of [**`sequenceEqual( )`**](Conditional-and-Boolean-Operators#sequenceequal)_
      -* [**`serialize( )`**](Observable-Utility-Operators#serialize) — force an Observable to make serialized calls and to be well-behaved
      -* **`share( )`** — _see [**`refCount( )`**](Connectable-Observable-Operators#connectableobservablerefcount)_
      -* [**`single( )`**](Blocking-Observable-Operators#single-and-singleordefault) (`BlockingObservable`) — if the source Observable completes after emitting a single item, return that item, otherwise throw an exception
      -* [**`single( )`**](Observable-Utility-Operators#single-and-singleordefault) (`Observable`) — if the source Observable completes after emitting a single item, emit that item, otherwise notify of an exception
      -* **`singleOption( )`** (scala) — _see [**`singleOrDefault( )`**](Blocking-Observable-Operators#single-and-singleordefault) (`BlockingObservable`)_
      -* [**`singleOrDefault( )`**](Blocking-Observable-Operators#single-and-singleordefault) (`BlockingObservable`) — if the source Observable completes after emitting a single item, return that item, otherwise return a default item
      -* [**`singleOrDefault( )`**](Observable-Utility-Operators#single-and-singleordefault) (`Observable`) — if the source Observable completes after emitting a single item, emit that item, otherwise emit a default item
      -* **`singleOrElse( )`** (scala) — _see [**`singleOrDefault( )`**](Observable-Utility-Operators#single-and-singleordefault)_
      -* **`size( )`** (scala) — _see [**`count( )`**](Mathematical-and-Aggregate-Operators#count-and-countlong)_
      -* [**`skip( )`**](Filtering-Observables#skip) — ignore the first _n_ items emitted by an Observable
      -* [**`skipLast( )`**](Filtering-Observables#skiplast) — ignore the last _n_ items emitted by an Observable
      -* [**`skipUntil( )`**](Conditional-and-Boolean-Operators#skipuntil) — discard items emitted by a source Observable until a second Observable emits an item, then emit the remainder of the source Observable's items
      -* [**`skipWhile( )`**](Conditional-and-Boolean-Operators#skipwhile) — discard items emitted by an Observable until a specified condition is false, then emit the remainder
      -* **`sliding( )`** (scala) — _see [**`window( )`**](Transforming-Observables#window)_
      -* **`slidingBuffer( )`** (scala) — _see [**`buffer( )`**](Transforming-Observables#buffer)_
      -* [**`split( )`**](String-Observables#split) (`StringObservable`) — converts an Observable of Strings into an Observable of Strings that treats the source sequence as a stream and splits it on a specified regex boundary
      -* [**`start( )`**](Async-Operators#start) — create an Observable that emits the return value of a function (`rxjava-async`)
      -* [**`startCancellableFuture( )`**](Phantom-Operators#fromcancellablefuture-startcancellablefuture-and-defercancellablefuture-) — convert a function that returns Future into an Observable that emits that Future's return value in a way that monitors the subscription status of the Observable to determine whether to halt work on the Future (⁇)(`rxjava-async`)
      -* [**`startFuture( )`**](Async-Operators#startfuture) — convert a function that returns Future into an Observable that emits that Future's return value (`rxjava-async`)
      -* [**`startWith( )`**](Combining-Observables#startwith) — emit a specified sequence of items before beginning to emit the items from the Observable
      -* [**`stringConcat( )`**](String-Observables#stringconcat) (`StringObservable`) — converts an Observable that emits a sequence of strings into an Observable that emits a single string that concatenates them all
      -* [**`subscribeOn( )`**](Observable-Utility-Operators#subscribeon) — specify which Scheduler an Observable should use when its subscription is invoked
      -* [**`sumDouble( )`**](Mathematical-and-Aggregate-Operators#suminteger-sumlong-sumfloat-and-sumdouble) — adds the Doubles emitted by an Observable and emits this sum (`rxjava-math`)
      -* [**`sumFloat( )`**](Mathematical-and-Aggregate-Operators#suminteger-sumlong-sumfloat-and-sumdouble) — adds the Floats emitted by an Observable and emits this sum (`rxjava-math`)
      -* [**`sumInteger( )`**](Mathematical-and-Aggregate-Operators#suminteger-sumlong-sumfloat-and-sumdouble) — adds the Integers emitted by an Observable and emits this sum (`rxjava-math`)
      -* [**`sumLong( )`**](Mathematical-and-Aggregate-Operators#suminteger-sumlong-sumfloat-and-sumdouble) — adds the Longs emitted by an Observable and emits this sum (`rxjava-math`)
      -* **`switch( )`** (scala) — _see [**`switchOnNext( )`**](Combining-Observables#switchonnext)_
      -* [**`switchCase( )`**](Conditional-and-Boolean-Operators#switchcase) — emit the sequence from a particular Observable based on the results of an evaluation (`contrib-computation-expressions`)
      -* [**`switchMap( )`**](Transforming-Observables#switchmap) — transform the items emitted by an Observable into Observables, and mirror those items emitted by the most-recently transformed Observable
      -* [**`switchOnNext( )`**](Combining-Observables#switchonnext) — convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently emitted of those Observables
      -* **`synchronize( )`** — _see [**`serialize( )`**](Observable-Utility-Operators#serialize)_
      -* [**`take( )`**](Filtering-Observables#take) — emit only the first _n_ items emitted by an Observable
      -* [**`takeFirst( )`**](Filtering-Observables#first-and-takefirst) — emit only the first item emitted by an Observable, or the first item that meets some condition
      -* [**`takeLast( )`**](Filtering-Observables#takelast) — only emit the last _n_ items emitted by an Observable
      -* [**`takeLastBuffer( )`**](Filtering-Observables#takelastbuffer) — emit the last _n_ items emitted by an Observable, as a single list item
      -* **`takeRight( )`** (scala) — _see [**`last( )`**](Filtering-Observables#last) (`Observable`) or [**`takeLast( )`**](Filtering-Observables#takelast)_
      -* [**`takeUntil( )`**](Conditional-and-Boolean-Operators#takeuntil) — emits the items from the source Observable until a second Observable emits an item
      -* [**`takeWhile( )`**](Conditional-and-Boolean-Operators#takewhile) — emit items emitted by an Observable as long as a specified condition is true, then skip the remainder
      -* **`take-while( )`** (clojure) — _see [**`takeWhile( )`**](Conditional-and-Boolean-Operators#takewhile)_
      -* [**`then( )`**](Combining-Observables#and-then-and-when) — transform a series of `Pattern` objects via a `Plan` template (`rxjava-joins`)
      -* [**`throttleFirst( )`**](Filtering-Observables#throttlefirst) — emit the first items emitted by an Observable within periodic time intervals
      -* [**`throttleLast( )`**](Filtering-Observables#sample-or-throttlelast) — emit the most recent items emitted by an Observable within periodic time intervals
      -* [**`throttleWithTimeout( )`**](Filtering-Observables#throttlewithtimeout-or-debounce) — only emit an item from the source Observable after a particular timespan has passed without the Observable emitting any other items
      -* **`throw( )`** (clojure) — _see [**`error( )`**](Creating-Observables#empty-error-and-never)_
      -* [**`timeInterval( )`**](Observable-Utility-Operators#timeinterval) — emit the time lapsed between consecutive emissions of a source Observable
      -* [**`timeout( )`**](Filtering-Observables#timeout) — emit items from a source Observable, but issue an exception if no item is emitted in a specified timespan
      -* [**`timer( )`**](Creating-Observables#timer) — create an Observable that emits a single item after a given delay
      -* [**`timestamp( )`**](Observable-Utility-Operators#timestamp) — attach a timestamp to every item emitted by an Observable
      -* [**`toAsync( )`**](Async-Operators#toasync-or-asyncaction-or-asyncfunc) — convert a function or Action into an Observable that executes the function and emits its return value (`rxjava-async`)
      -* [**`toBlocking( )`**](Blocking-Observable-Operators) — transform an Observable into a BlockingObservable
      -* **`toBlockingObservable( )`** - _see [**`toBlocking( )`**](Blocking-Observable-Operators)_
      -* [**`toFuture( )`**](Blocking-Observable-Operators#transformations-tofuture-toiterable-and-getiterator) — convert the Observable into a Future
      -* [**`toIterable( )`**](Blocking-Observable-Operators#transformations-tofuture-toiterable-and-getiterator) — convert the sequence emitted by the Observable into an Iterable
      -* **`toIterator( )`** — _see [**`getIterator( )`**](Blocking-Observable-Operators#transformations-tofuture-toiterable-and-getiterator)_
      -* [**`toList( )`**](Mathematical-and-Aggregate-Operators#tolist) — collect all items from an Observable and emit them as a single List
      -* [**`toMap( )`**](Mathematical-and-Aggregate-Operators#tomap-and-tomultimap) — convert the sequence of items emitted by an Observable into a map keyed by a specified key function
      -* [**`toMultimap( )`**](Mathematical-and-Aggregate-Operators#tomap-and-tomultimap) — convert the sequence of items emitted by an Observable into an ArrayList that is also a map keyed by a specified key function
      -* **`toSeq( )`** (scala) — _see [**`toList( )`**](Mathematical-and-Aggregate-Operators#tolist)_
      -* [**`toSortedList( )`**](Mathematical-and-Aggregate-Operators#tosortedlist) — collect all items from an Observable and emit them as a single, sorted List
      -* **`tumbling( )`** (scala) — _see [**`window( )`**](Transforming-Observables#window)_
      -* **`tumblingBuffer( )`** (scala) — _see [**`buffer( )`**](Transforming-Observables#buffer)_
      -* [**`using( )`**](Observable-Utility-Operators#using) — create a disposable resource that has the same lifespan as an Observable
      -* [**`when( )`**](Combining-Observables#and-then-and-when) — convert a series of `Plan` objects into an Observable (`rxjava-joins`)
      -* **`where( )`** — _see: [**`filter( )`**](Filtering-Observables#filter)_
      -* [**`whileDo( )`**](Conditional-and-Boolean-Operators#whiledo) — if a condition is true, emit the source Observable's sequence and then repeat the sequence as long as the condition remains true (`contrib-computation-expressions`)
      -* [**`window( )`**](Transforming-Observables#window) — periodically subdivide items from an Observable into Observable windows and emit these windows rather than emitting the items one at a time
      -* [**`zip( )`**](Combining-Observables#zip) — combine sets of items emitted by two or more Observables together via a specified function and emit items based on the results of this function
      -* **`zipWith( )`** — _instance version of [**`zip( )`**](Combining-Observables#zip)_
      -* **`zipWithIndex( )`** (scala) — _see [**`zip( )`**](Combining-Observables#zip)_
      -* **`++`** (scala) — _see [**`concat( )`**](Mathematical-and-Aggregate-Operators#concat)_
      -* **`+:`** (scala) — _see [**`startWith( )`**](Combining-Observables#startwith)_
      +* [**`doOnSubscribe( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — register an action to take when an observer subscribes to an Observable
      +* [**`doOnTerminate( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — register an action to take when an Observable completes, either successfully or with an error
      +* [**`doOnUnsubscribe( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — register an action to take when an observer unsubscribes from an Observable
      +* [**`doWhile( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators) — emit the source Observable's sequence, and then repeat the sequence as long as a condition remains true (`contrib-computation-expressions`)
      +* **`drop( )`** (scala/clojure) — _see [**`skip( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#skip)_
      +* **`dropRight( )`** (scala) — _see [**`skipLast( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#skiplast)_
      +* **`dropUntil( )`** (scala) — _see [**`skipUntil( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators)_
      +* **`dropWhile( )`** (scala) — _see [**`skipWhile( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators)_
      +* **`drop-while( )`** (clojure) — _see [**`skipWhile( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#skipwhile)_
      +* [**`elementAt( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#elementat) — emit item _n_ emitted by the source Observable
      +* [**`elementAtOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) — emit item _n_ emitted by the source Observable, or a default item if the source Observable emits fewer than _n_ items
      +* [**`empty( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#empty) — create an Observable that emits nothing and then completes
      +* [**`encode( )`**](https://github.com/ReactiveX/RxJava/wiki/String-Observables) (`StringObservable`) — transform an Observable that emits strings into an Observable that emits byte arrays that respect character boundaries of multibyte characters in the original strings
      +* [**`error( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#error) — create an Observable that emits nothing and then signals an error
      +* **`every( )`** (clojure) — _see [**`all( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#boolean-operators)_
      +* [**`exists( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#boolean-operators) — determine whether an Observable emits any items or not
      +* [**`filter( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#filter) — filter items emitted by an Observable
      +* **`finally( )`** (clojure) — _see [**`finallyDo( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators)_
      +* **`filterNot( )`** (scala) — _see [**`filter( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#filter)_
      +* [**`finallyDo( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — register an action to take when an Observable completes
      +* [**`first( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#first) (`Observable`) — emit only the first item emitted by an Observable, or the first item that meets some condition
      +* [**`first( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`) — emit only the first item emitted by an Observable, or the first item that meets some condition
      +* [**`firstOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) (`Observable`) — emit only the first item emitted by an Observable, or the first item that meets some condition, or a default value if the source Observable is empty
      +* [**`firstOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`) — emit only the first item emitted by an Observable, or the first item that meets some condition, or a default value if the source Observable is empty
      +* **`firstOrElse( )`** (scala) — _see [**`firstOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) or [**`firstOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`)_
      +* [**`flatMap( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#flatmap) — transform the items emitted by an Observable into Observables, then flatten this into a single Observable
      +* [**`flatMapIterable( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#flatmapiterable) — create Iterables corresponding to each emission from a source Observable and merge the results into a single Observable
      +* **`flatMapIterableWith( )`** (scala) — _instance version of [**`flatMapIterable( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#flatmapiterable)_
      +* **`flatMapWith( )`** (scala) — _instance version of [**`flatmap( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#flatmap)_
      +* **`flatten( )`** (scala) — _see [**`merge( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#merge)_
      +* **`flattenDelayError( )`** (scala) — _see [**`mergeDelayError( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#mergedelayerror)_
      +* **`foldLeft( )`** (scala) — _see [**`reduce( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#reduce)_
      +* **`forall( )`** (scala) — _see [**`all( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#boolean-operators)_
      +* **`forEach( )`** (`Observable`) — _see [**`subscribe( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable)_
      +* [**`forEach( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`) — invoke a function on each item emitted by the Observable; block until the Observable completes
      +* [**`forEachFuture( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) (`Async`) — pass Subscriber methods to an Observable but also have it behave like a Future that blocks until it completes (`rxjava-async`)
      +* [**`forEachFuture( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#foreachfuture) (`BlockingObservable`)— create a futureTask that will invoke a specified function on each item emitted by an Observable (⁇)
      +* [**`forIterable( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#foriterable) — apply a function to the elements of an Iterable to create Observables which are then concatenated (⁇)
      +* [**`from( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#from) — convert an Iterable, a Future, or an Array into an Observable
      +* [**`from( )`**](https://github.com/ReactiveX/RxJava/wiki/String-Observables) (`StringObservable`) — convert a stream of characters or a Reader into an Observable that emits byte arrays or Strings
      +* [**`fromAction( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) — convert an Action into an Observable that invokes the action and emits its result when a Subscriber subscribes (`rxjava-async`)
      +* [**`fromCallable( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) — convert a Callable into an Observable that invokes the callable and emits its result or exception when a Subscriber subscribes (`rxjava-async`)
      +* [**`fromCancellableFuture( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#fromcancellablefuture-startcancellablefuture-and-defercancellablefuture) — convert a Future into an Observable in a way that monitors the subscription status of the Observable to determine whether to halt work on the Future, but do not attempt to get the Future's value until a Subscriber subscribes (⁇)(`rxjava-async`)
      +* **`fromFunc0( )`** — _see [**`fromCallable( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) (`rxjava-async`)_
      +* [**`fromFuture( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#fromfuture) — convert a Future into an Observable, but do not attempt to get the Future's value until a Subscriber subscribes (⁇)
      +* [**`fromRunnable( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators#fromrunnable) — convert a Runnable into an Observable that invokes the runable and emits its result when a Subscriber subscribes (`rxjava-async`)
      +* [**`generate( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#generate-and-generateabsolutetime) — create an Observable that emits a sequence of items as generated by a function of your choosing (⁇)
      +* [**`generateAbsoluteTime( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#generate-and-generateabsolutetime) — create an Observable that emits a sequence of items as generated by a function of your choosing, with each item emitted at an item-specific time (⁇)
      +* **`generator( )`** (clojure) — _see [**`generate( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#generate-and-generateabsolutetime)_
      +* [**`getIterator( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) — convert the sequence emitted by the Observable into an Iterator
      +* [**`groupBy( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#groupby) — divide an Observable into a set of Observables that emit groups of items from the original Observable, organized by key
      +* **`group-by( )`** (clojure) — _see [**`groupBy( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#groupby)_
      +* [**`groupByUntil( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators) — a variant of the [`groupBy( )`](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#groupby) operator that closes any open GroupedObservable upon a signal from another Observable (⁇)
      +* [**`groupJoin( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#joins) — combine the items emitted by two Observables whenever one item from one Observable falls within a window of duration specified by an item emitted by the other Observable
      +* **`head( )`** (scala) — _see [**`first( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`)_
      +* **`headOption( )`** (scala) — _see [**`firstOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) or [**`firstOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`)_
      +* **`headOrElse( )`** (scala) — _see [**`firstOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) or [**`firstOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`)_
      +* [**`ifThen( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators) — only emit the source Observable's sequence if a condition is true, otherwise emit an empty or default sequence (`contrib-computation-expressions`)
      +* [**`ignoreElements( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#ignoreelements) — discard the items emitted by the source Observable and only pass through the error or completed notification
      +* [**`interval( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#interval) — create an Observable that emits a sequence of integers spaced by a given time interval
      +* **`into( )`** (clojure) — _see [**`reduce( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#reduce)_
      +* [**`isEmpty( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#boolean-operators) — determine whether an Observable emits any items or not
      +* **`items( )`** (scala) — _see [**`just( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#just)_
      +* [**`join( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#joins) — combine the items emitted by two Observables whenever one item from one Observable falls within a window of duration specified by an item emitted by the other Observable
      +* [**`join( )`**](https://github.com/ReactiveX/RxJava/wiki/String-Observables) (`StringObservable`) — converts an Observable that emits a sequence of strings into an Observable that emits a single string that concatenates them all, separating them by a specified string
      +* [**`just( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#just) — convert an object into an Observable that emits that object
      +* [**`last( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`) — block until the Observable completes, then return the last item emitted by the Observable
      +* [**`last( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#last) (`Observable`) — emit only the last item emitted by the source Observable
      +* **`lastOption( )`** (scala) — _see [**`lastOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) or [**`lastOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`)_
      +* [**`lastOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`) — block until the Observable completes, then return the last item emitted by the Observable or a default item if there is no last item
      +* [**`lastOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) (`Observable`) — emit only the last item emitted by an Observable, or a default value if the source Observable is empty
      +* **`lastOrElse( )`** (scala) — _see [**`lastOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) or [**`lastOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`)_
      +* [**`latest( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) — returns an iterable that blocks until or unless the Observable emits an item that has not been returned by the iterable, then returns the latest such item
      +* **`length( )`** (scala) — _see [**`count( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#count)_
      +* **`limit( )`** — _see [**`take( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#take)_
      +* **`longCount( )`** (scala) — _see [**`countLong( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators)_
      +* [**`map( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#map) — transform the items emitted by an Observable by applying a function to each of them
      +* **`mapcat( )`** (clojure) — _see [**`concatMap( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#concatmap)_
      +* **`mapMany( )`** — _see: [**`flatMap( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#flatmap)_
      +* [**`materialize( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — convert an Observable into a list of Notifications
      +* [**`max( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#max) — emits the maximum value emitted by a source Observable (`rxjava-math`)
      +* [**`maxBy( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators) — emits the item emitted by the source Observable that has the maximum key value (`rxjava-math`)
      +* [**`merge( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#merge) — combine multiple Observables into one
      +* [**`mergeDelayError( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#mergedelayerror) — combine multiple Observables into one, allowing error-free Observables to continue before propagating errors
      +* **`merge-delay-error( )`** (clojure) — _see [**`mergeDelayError( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#mergedelayerror)_
      +* **`mergeMap( )`** * — _see: [**`flatMap( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#flatmap)_
      +* **`mergeMapIterable( )`** — _see: [**`flatMapIterable( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#flatmapiterable)_
      +* **`mergeWith( )`** — _instance version of [**`merge( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#merge)_
      +* [**`min( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#min) — emits the minimum value emitted by a source Observable (`rxjava-math`)
      +* [**`minBy( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators) — emits the item emitted by the source Observable that has the minimum key value (`rxjava-math`)
      +* [**`mostRecent( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) — returns an iterable that always returns the item most recently emitted by the Observable
      +* [**`multicast( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#multicast) — represents an Observable as a Connectable Observable
      +* [**`never( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#never) — create an Observable that emits nothing at all
      +* [**`next( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) — returns an iterable that blocks until the Observable emits another item, then returns that item
      +* **`nonEmpty( )`** (scala) — _see [**`isEmpty( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#boolean-operators)_
      +* **`nth( )`** (clojure) — _see [**`elementAt( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#elementat) and [**`elementAtOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables)_
      +* [**`observeOn( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — specify on which Scheduler a Subscriber should observe the Observable
      +* [**`ofType( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#oftype) — emit only those items from the source Observable that are of a particular class
      +* [**`onBackpressureBlock( )`**](https://github.com/ReactiveX/RxJava/wiki/Backpressure#reactive-pull-backpressure-isnt-magic) — block the Observable's thread until the Observer is ready to accept more items from the Observable (⁇)
      +* [**`onBackpressureBuffer( )`**](https://github.com/ReactiveX/RxJava/wiki/Backpressure#reactive-pull-backpressure-isnt-magic) — maintain a buffer of all emissions from the source Observable and emit them to downstream Subscribers according to the requests they generate
      +* [**`onBackpressureDrop( )`**](https://github.com/ReactiveX/RxJava/wiki/Backpressure#reactive-pull-backpressure-isnt-magic) — drop emissions from the source Observable unless there is a pending request from a downstream Subscriber, in which case emit enough items to fulfill the request
      +* [**`onErrorFlatMap( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#onerrorflatmap) — instructs an Observable to emit a sequence of items whenever it encounters an error (⁇)
      +* [**`onErrorResumeNext( )`**](https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators#onerrorresumenext) — instructs an Observable to emit a sequence of items if it encounters an error
      +* [**`onErrorReturn( )`**](https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators#onerrorreturn) — instructs an Observable to emit a particular item when it encounters an error
      +* [**`onExceptionResumeNext( )`**](https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators#onexceptionresumenext) — instructs an Observable to continue emitting items after it encounters an exception (but not another variety of throwable)
      +* **`orElse( )`** (scala) — _see [**`defaultIfEmpty( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators)_
      +* [**`parallel( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#parallel) — split the work done on the emissions from an Observable into multiple Observables each operating on its own parallel thread (⁇)
      +* [**`parallelMerge( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#parallelmerge) — combine multiple Observables into smaller number of Observables (⁇)
      +* [**`pivot( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#pivot) — combine multiple sets of grouped observables so that they are arranged primarily by group rather than by set (⁇)
      +* [**`publish( )`**](https://github.com/ReactiveX/RxJava/wiki/Connectable-Observable-Operators) — represents an Observable as a Connectable Observable
      +* [**`publishLast( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#publishlast) — represent an Observable as a Connectable Observable that emits only the last item emitted by the source Observable (⁇)
      +* [**`range( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#range) — create an Observable that emits a range of sequential integers
      +* [**`reduce( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#reduce) — apply a function to each emitted item, sequentially, and emit only the final accumulated value
      +* **`reductions( )`** (clojure) — _see [**`scan( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#scan)_
      +* [**`refCount( )`**](https://github.com/ReactiveX/RxJava/wiki/Connectable-Observable-Operators) — makes a Connectable Observable behave like an ordinary Observable
      +* [**`repeat( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables) — create an Observable that emits a particular item or sequence of items repeatedly
      +* [**`repeatWhen( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#repeatwhen) — create an Observable that emits a particular item or sequence of items repeatedly, depending on the emissions of a second Observable
      +* [**`replay( )`**](https://github.com/ReactiveX/RxJava/wiki/Connectable-Observable-Operators#observablereplay) — ensures that all Subscribers see the same sequence of emitted items, even if they subscribe after the Observable begins emitting the items
      +* **`rest( )`** (clojure) — _see [**`next( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#next)_
      +* **`return( )`** (clojure) — _see [**`just( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#just)_
      +* [**`retry( )`**](https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators#retry) — if a source Observable emits an error, resubscribe to it in the hopes that it will complete without error
      +* [**`retrywhen( )`**](https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators#retrywhen) — if a source Observable emits an error, pass that error to another Observable to determine whether to resubscribe to the source
      +* [**`runAsync( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) — returns a `StoppableObservable` that emits multiple actions as generated by a specified Action on a Scheduler (`rxjava-async`)
      +* [**`sample( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#sample) — emit the most recent items emitted by an Observable within periodic time intervals
      +* [**`scan( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#scan) — apply a function to each item emitted by an Observable, sequentially, and emit each successive value
      +* **`seq( )`** (clojure) — _see [**`getIterator( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators)_
      +* [**`sequenceEqual( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators) — test the equality of sequences emitted by two Observables
      +* **`sequenceEqualWith( )`** (scala) — _instance version of [**`sequenceEqual( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators)_
      +* [**`serialize( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators#serialize) — force an Observable to make serialized calls and to be well-behaved
      +* **`share( )`** — _see [**`refCount( )`**](https://github.com/ReactiveX/RxJava/wiki/Connectable-Observable-Operators)_
      +* [**`single( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`) — if the source Observable completes after emitting a single item, return that item, otherwise throw an exception
      +* [**`single( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) (`Observable`) — if the source Observable completes after emitting a single item, emit that item, otherwise notify of an exception
      +* **`singleOption( )`** (scala) — _see [**`singleOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#single-and-singleordefault) (`BlockingObservable`)_
      +* [**`singleOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) (`BlockingObservable`) — if the source Observable completes after emitting a single item, return that item, otherwise return a default item
      +* [**`singleOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) (`Observable`) — if the source Observable completes after emitting a single item, emit that item, otherwise emit a default item
      +* **`singleOrElse( )`** (scala) — _see [**`singleOrDefault( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators)_
      +* **`size( )`** (scala) — _see [**`count( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#count)_
      +* [**`skip( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#skip) — ignore the first _n_ items emitted by an Observable
      +* [**`skipLast( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#skiplast) — ignore the last _n_ items emitted by an Observable
      +* [**`skipUntil( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators) — discard items emitted by a source Observable until a second Observable emits an item, then emit the remainder of the source Observable's items
      +* [**`skipWhile( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators) — discard items emitted by an Observable until a specified condition is false, then emit the remainder
      +* **`sliding( )`** (scala) — _see [**`window( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#window)_
      +* **`slidingBuffer( )`** (scala) — _see [**`buffer( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#buffer)_
      +* [**`split( )`**](https://github.com/ReactiveX/RxJava/wiki/String-Observables) (`StringObservable`) — converts an Observable of Strings into an Observable of Strings that treats the source sequence as a stream and splits it on a specified regex boundary
      +* [**`start( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) — create an Observable that emits the return value of a function (`rxjava-async`)
      +* [**`startCancellableFuture( )`**](https://github.com/ReactiveX/RxJava/wiki/Phantom-Operators#fromcancellablefuture-startcancellablefuture-and-defercancellablefuture) — convert a function that returns Future into an Observable that emits that Future's return value in a way that monitors the subscription status of the Observable to determine whether to halt work on the Future (⁇)(`rxjava-async`)
      +* [**`startFuture( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) — convert a function that returns Future into an Observable that emits that Future's return value (`rxjava-async`)
      +* [**`startWith( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#startwith) — emit a specified sequence of items before beginning to emit the items from the Observable
      +* [**`stringConcat( )`**](https://github.com/ReactiveX/RxJava/wiki/String-Observables) (`StringObservable`) — converts an Observable that emits a sequence of strings into an Observable that emits a single string that concatenates them all
      +* [**`subscribeOn( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — specify which Scheduler an Observable should use when its subscription is invoked
      +* [**`sumDouble( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#sumdouble) — adds the Doubles emitted by an Observable and emits this sum (`rxjava-math`)
      +* [**`sumFloat( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#sumfloat) — adds the Floats emitted by an Observable and emits this sum (`rxjava-math`)
      +* [**`sumInt( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#sumint) — adds the Integers emitted by an Observable and emits this sum (`rxjava-math`)
      +* [**`sumLong( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#sumlong) — adds the Longs emitted by an Observable and emits this sum (`rxjava-math`)
      +* **`switch( )`** (scala) — _see [**`switchOnNext( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#switchonnext)_
      +* [**`switchCase( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators) — emit the sequence from a particular Observable based on the results of an evaluation (`contrib-computation-expressions`)
      +* [**`switchMap( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#switchmap) — transform the items emitted by an Observable into Observables, and mirror those items emitted by the most-recently transformed Observable
      +* [**`switchOnNext( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#switchonnext) — convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently emitted of those Observables
      +* **`synchronize( )`** — _see [**`serialize( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators)_
      +* [**`take( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#take) — emit only the first _n_ items emitted by an Observable
      +* [**`takeFirst( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) — emit only the first item emitted by an Observable, or the first item that meets some condition
      +* [**`takeLast( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#takelast) — only emit the last _n_ items emitted by an Observable
      +* [**`takeLastBuffer( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables) — emit the last _n_ items emitted by an Observable, as a single list item
      +* **`takeRight( )`** (scala) — _see [**`last( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#last) (`Observable`) or [**`takeLast( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#takelast)_
      +* [**`takeUntil( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators) — emits the items from the source Observable until a second Observable emits an item
      +* [**`takeWhile( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators) — emit items emitted by an Observable as long as a specified condition is true, then skip the remainder
      +* **`take-while( )`** (clojure) — _see [**`takeWhile( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators)_
      +* [**`then( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#rxjava-joins) — transform a series of `Pattern` objects via a `Plan` template (`rxjava-joins`)
      +* [**`throttleFirst( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#throttlefirst) — emit the first items emitted by an Observable within periodic time intervals
      +* [**`throttleLast( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#throttlelast) — emit the most recent items emitted by an Observable within periodic time intervals
      +* [**`throttleWithTimeout( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#throttlewithtimeout) — only emit an item from the source Observable after a particular timespan has passed without the Observable emitting any other items
      +* **`throw( )`** (clojure) — _see [**`error( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#error)_
      +* [**`timeInterval( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — emit the time lapsed between consecutive emissions of a source Observable
      +* [**`timeout( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#timeout) — emit items from a source Observable, but issue an exception if no item is emitted in a specified timespan
      +* [**`timer( )`**](https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#timer) — create an Observable that emits a single item after a given delay
      +* [**`timestamp( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — attach a timestamp to every item emitted by an Observable
      +* [**`toAsync( )`**](https://github.com/ReactiveX/RxJava/wiki/Async-Operators) — convert a function or Action into an Observable that executes the function and emits its return value (`rxjava-async`)
      +* [**`toBlocking( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) — transform an Observable into a BlockingObservable
      +* **`toBlockingObservable( )`** - _see [**`toBlocking( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators)_
      +* [**`toFuture( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) — convert the Observable into a Future
      +* [**`toIterable( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators) — convert the sequence emitted by the Observable into an Iterable
      +* **`toIterator( )`** — _see [**`getIterator( )`**](https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators)_
      +* [**`toList( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#tolist) — collect all items from an Observable and emit them as a single List
      +* [**`toMap( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#tomap) — convert the sequence of items emitted by an Observable into a map keyed by a specified key function
      +* [**`toMultimap( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#tomultimap) — convert the sequence of items emitted by an Observable into an ArrayList that is also a map keyed by a specified key function
      +* **`toSeq( )`** (scala) — _see [**`toList( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#tolist)_
      +* [**`toSortedList( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#tosortedlist) — collect all items from an Observable and emit them as a single, sorted List
      +* **`tumbling( )`** (scala) — _see [**`window( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#window)_
      +* **`tumblingBuffer( )`** (scala) — _see [**`buffer( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#buffer)_
      +* [**`using( )`**](https://github.com/ReactiveX/RxJava/wiki/Observable-Utility-Operators) — create a disposable resource that has the same lifespan as an Observable
      +* [**`when( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#rxjava-joins) — convert a series of `Plan` objects into an Observable (`rxjava-joins`)
      +* **`where( )`** — _see: [**`filter( )`**](https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#filter)_
      +* [**`whileDo( )`**](https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#conditional-operators) — if a condition is true, emit the source Observable's sequence and then repeat the sequence as long as the condition remains true (`contrib-computation-expressions`)
      +* [**`window( )`**](https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#window) — periodically subdivide items from an Observable into Observable windows and emit these windows rather than emitting the items one at a time
      +* [**`zip( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#zip) — combine sets of items emitted by two or more Observables together via a specified function and emit items based on the results of this function
      +* **`zipWith( )`** — _instance version of [**`zip( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#zip)_
      +* **`zipWithIndex( )`** (scala) — _see [**`zip( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#zip)_
      +* **`++`** (scala) — _see [**`concat( )`**](https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators)_
      +* **`+:`** (scala) — _see [**`startWith( )`**](https://github.com/ReactiveX/RxJava/wiki/Combining-Observables#startwith)_
       
      -(⁇) — this proposed operator is not part of RxJava 1.0
      \ No newline at end of file
      +(⁇) — this proposed operator is not part of RxJava 1.0
      
      From 15e52bbf7221498f37cf563fba1abf38ebbf5b90 Mon Sep 17 00:00:00 2001
      From: David Karnok 
      Date: Fri, 7 Jun 2019 11:51:05 +0200
      Subject: [PATCH 158/211] Create What's-different-in-3.0.md
      
      ---
       docs/What's-different-in-3.0.md | 33 +++++++++++++++++++++++++++++++++
       1 file changed, 33 insertions(+)
       create mode 100644 docs/What's-different-in-3.0.md
      
      diff --git a/docs/What's-different-in-3.0.md b/docs/What's-different-in-3.0.md
      new file mode 100644
      index 0000000000..e936692c06
      --- /dev/null
      +++ b/docs/What's-different-in-3.0.md
      @@ -0,0 +1,33 @@
      +Table of contents
      +
      +# Introduction
      +TBD.
      +
      +### API signature changes
      +
      +TBD.
      +
      +- as() merged into to()
      +- some operators returning a more appropriate Single or Maybe
      +- functional interfaces throws widening to Throwable
      +- standard methods removed
      +- standard methods signature changes
      +
      +### Standardized operators
      +
      +(former experimental and beta operators from 2.x)
      +
      +TBD.
      +
      +### Operator behavior changes
      +
      +TBD.
      +
      +- connectable sources lifecycle-fixes
      +
      +
      +### Test support changes
      +
      +TBD.
      +
      +- methods removed from the test consumers
      
      From 89d506d587a9fc0614a45a599f2e45f04e08eac5 Mon Sep 17 00:00:00 2001
      From: David Karnok 
      Date: Sat, 15 Jun 2019 21:30:30 +0200
      Subject: [PATCH 159/211] 2.x: Fix javadocs & imports (#6504)
      
      ---
       gradle/javadoc_cleanup.gradle                          |  2 ++
       .../java/io/reactivex/processors/package-info.java     |  4 ++--
       src/main/java/io/reactivex/schedulers/Schedulers.java  | 10 +++++-----
       .../operators/maybe/MaybeDoOnTerminateTest.java        |  2 --
       .../operators/single/SingleDoOnTerminateTest.java      |  1 -
       5 files changed, 9 insertions(+), 10 deletions(-)
      
      diff --git a/gradle/javadoc_cleanup.gradle b/gradle/javadoc_cleanup.gradle
      index 79f4d5411a..518d7a1d51 100644
      --- a/gradle/javadoc_cleanup.gradle
      +++ b/gradle/javadoc_cleanup.gradle
      @@ -12,6 +12,8 @@ task javadocCleanup(dependsOn: "javadoc") doLast {
           fixJavadocFile(rootProject.file('build/docs/javadoc/io/reactivex/subjects/ReplaySubject.html'));
           fixJavadocFile(rootProject.file('build/docs/javadoc/io/reactivex/processors/ReplayProcessor.html'));
           fixJavadocFile(rootProject.file('build/docs/javadoc/io/reactivex/plugins/RxJavaPlugins.html'));
      +
      +    fixJavadocFile(rootProject.file('build/docs/javadoc/io/reactivex/parallel/ParallelFlowable.html'));
       }
       
       def fixJavadocFile(file) {
      diff --git a/src/main/java/io/reactivex/processors/package-info.java b/src/main/java/io/reactivex/processors/package-info.java
      index 1266a74ee1..b6a619372f 100644
      --- a/src/main/java/io/reactivex/processors/package-info.java
      +++ b/src/main/java/io/reactivex/processors/package-info.java
      @@ -16,7 +16,7 @@
       
       /**
        * Classes representing so-called hot backpressure-aware sources, aka processors,
      - * that implement the {@link FlowableProcessor} class,
      + * that implement the {@link io.reactivex.processors.FlowableProcessor FlowableProcessor} class,
        * the Reactive Streams {@link org.reactivestreams.Processor Processor} interface
        * to allow forms of multicasting events to one or more subscribers as well as consuming another
        * Reactive Streams {@link org.reactivestreams.Publisher Publisher}.
      @@ -33,7 +33,7 @@
        * 
        * 

      * The non-backpressured variants of the {@code FlowableProcessor} class are called - * {@link io.reactivex.Subject}s and reside in the {@code io.reactivex.subjects} package. + * {@link io.reactivex.subjects.Subject}s and reside in the {@code io.reactivex.subjects} package. * @see io.reactivex.subjects */ package io.reactivex.processors; diff --git a/src/main/java/io/reactivex/schedulers/Schedulers.java b/src/main/java/io/reactivex/schedulers/Schedulers.java index 4edaf65b1a..9e070690b8 100644 --- a/src/main/java/io/reactivex/schedulers/Schedulers.java +++ b/src/main/java/io/reactivex/schedulers/Schedulers.java @@ -299,7 +299,7 @@ public static Scheduler single() { * a time delay or periodically will use the {@link #single()} scheduler for the timed waiting * before posting the actual task to the given executor. *

      - * Tasks submitted to the {@link Scheduler.Worker} of this {@code Scheduler} are also not interruptible. Use the + * Tasks submitted to the {@link io.reactivex.Scheduler.Worker Scheduler.Worker} of this {@code Scheduler} are also not interruptible. Use the * {@link #from(Executor, boolean)} overload to enable task interruption via this wrapper. *

      * If the provided executor supports the standard Java {@link ExecutorService} API, @@ -332,7 +332,7 @@ public static Scheduler single() { * } * *

      - * This type of scheduler is less sensitive to leaking {@link Scheduler.Worker} instances, although + * This type of scheduler is less sensitive to leaking {@link io.reactivex.Scheduler.Worker Scheduler.Worker} instances, although * not disposing a worker that has timed/delayed tasks not cancelled by other means may leak resources and/or * execute those tasks "unexpectedly". *

      @@ -350,7 +350,7 @@ public static Scheduler from(@NonNull Executor executor) { * Wraps an {@link Executor} into a new Scheduler instance and delegates {@code schedule()} * calls to it. *

      - * The tasks scheduled by the returned {@link Scheduler} and its {@link Scheduler.Worker} + * The tasks scheduled by the returned {@link Scheduler} and its {@link io.reactivex.Scheduler.Worker Scheduler.Worker} * can be optionally interrupted. *

      * If the provided executor doesn't support any of the more specific standard Java executor @@ -388,14 +388,14 @@ public static Scheduler from(@NonNull Executor executor) { * } * *

      - * This type of scheduler is less sensitive to leaking {@link Scheduler.Worker} instances, although + * This type of scheduler is less sensitive to leaking {@link io.reactivex.Scheduler.Worker Scheduler.Worker} instances, although * not disposing a worker that has timed/delayed tasks not cancelled by other means may leak resources and/or * execute those tasks "unexpectedly". *

      * Note that this method returns a new {@link Scheduler} instance, even for the same {@link Executor} instance. * @param executor * the executor to wrap - * @param interruptibleWorker if {@code true} the tasks submitted to the {@link Scheduler.Worker} will + * @param interruptibleWorker if {@code true} the tasks submitted to the {@link io.reactivex.Scheduler.Worker Scheduler.Worker} will * be interrupted when the task is disposed. * @return the new Scheduler wrapping the Executor * @since 2.2.6 - experimental diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java index d442fcc135..0e90e57731 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java @@ -19,8 +19,6 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Action; import io.reactivex.observers.TestObserver; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.PublishSubject; import org.junit.Test; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java index ba15f9f71b..425ee84205 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java @@ -19,7 +19,6 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Action; import io.reactivex.observers.TestObserver; -import org.junit.Assert; import org.junit.Test; import java.util.List; From c5e1b3a29b916341bfe5ab8ea58f94053e79b497 Mon Sep 17 00:00:00 2001 From: Jan Knotek Date: Mon, 17 Jun 2019 13:43:35 +0100 Subject: [PATCH 160/211] Null check for BufferExactBoundedObserver (#6499) * Null check for BufferExactBoundedObserver Other variants contain this Null check already, e.g. BufferExactUnboundedObserver It is causing 0.1% crashes in our production app. * ObservableBufferTimed.BufferExactBoundedObserver - failing supplier unit test FlowableBufferTimed.BufferExactBoundedSubscriber - failing supplier fix + unit test * Better Unit tests for FlowableBufferTimed and BufferExactBoundedSubscriber NPE issue Reverted --- .../operators/flowable/FlowableBufferTimed.java | 13 +++++++------ .../observable/ObservableBufferTimed.java | 10 ++++++---- .../operators/flowable/FlowableBufferTest.java | 15 +++++++++++++++ .../observable/ObservableBufferTest.java | 15 +++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java index 4e3be8a9e5..06736603f1 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java @@ -501,13 +501,14 @@ public void onComplete() { buffer = null; } - queue.offer(b); - done = true; - if (enter()) { - QueueDrainHelper.drainMaxLoop(queue, downstream, false, this, this); + if (b != null) { + queue.offer(b); + done = true; + if (enter()) { + QueueDrainHelper.drainMaxLoop(queue, downstream, false, this, this); + } + w.dispose(); } - - w.dispose(); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java index 8a6fafea6e..b9f692db9d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBufferTimed.java @@ -504,10 +504,12 @@ public void onComplete() { buffer = null; } - queue.offer(b); - done = true; - if (enter()) { - QueueDrainHelper.drainLoop(queue, downstream, false, this, this); + if (b != null) { + queue.offer(b); + done = true; + if (enter()) { + QueueDrainHelper.drainLoop(queue, downstream, false, this, this); + } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java index 5060c58253..e79130ff41 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java @@ -2769,4 +2769,19 @@ public void timedSizeBufferAlreadyCleared() { sub.run(); } + + @Test + public void bufferExactFailingSupplier() { + Flowable.empty() + .buffer(1, TimeUnit.SECONDS, Schedulers.computation(), 10, new Callable>() { + @Override + public List call() throws Exception { + throw new TestException(); + } + }, false) + .test() + .awaitDone(1, TimeUnit.SECONDS) + .assertFailure(TestException.class) + ; + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java index 43612b228d..66a4e24dc0 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java @@ -2136,4 +2136,19 @@ public ObservableSource> apply(Observable o) } }); } + + @Test + public void bufferExactFailingSupplier() { + Observable.empty() + .buffer(1, TimeUnit.SECONDS, Schedulers.computation(), 10, new Callable>() { + @Override + public List call() throws Exception { + throw new TestException(); + } + }, false) + .test() + .awaitDone(1, TimeUnit.SECONDS) + .assertFailure(TestException.class) + ; + } } From ed29fac873fb44d8ab3fab08c65f483fe52e05ab Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 17 Jun 2019 14:51:04 +0200 Subject: [PATCH 161/211] 2.x: Expand the Javadoc of Flowable (#6506) --- src/main/java/io/reactivex/Flowable.java | 108 +++++++++++++++++++-- src/main/java/io/reactivex/Observable.java | 2 +- 2 files changed, 101 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index fe27b9bfd3..7dc6d77716 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -36,12 +36,12 @@ import io.reactivex.subscribers.*; /** - * The Flowable class that implements the Reactive-Streams Pattern and offers factory methods, - * intermediate operators and the ability to consume reactive dataflows. + * The Flowable class that implements the Reactive Streams + * Pattern and offers factory methods, intermediate operators and the ability to consume reactive dataflows. *

      - * Reactive-Streams operates with {@code Publisher}s which {@code Flowable} extends. Many operators + * Reactive Streams operates with {@link Publisher}s which {@code Flowable} extends. Many operators * therefore accept general {@code Publisher}s directly and allow direct interoperation with other - * Reactive-Streams implementations. + * Reactive Streams implementations. *

      * The Flowable hosts the default buffer size of 128 elements for operators, accessible via {@link #bufferSize()}, * that can be overridden globally via the system parameter {@code rx2.buffer-size}. Most operators, however, have @@ -51,11 +51,103 @@ *

      * *

      + * The {@code Flowable} follows the protocol + *

      
      + *      onSubscribe onNext* (onError | onComplete)?
      + * 
      + * where the stream can be disposed through the {@link Subscription} instance provided to consumers through + * {@link Subscriber#onSubscribe(Subscription)}. + * Unlike the {@code Observable.subscribe()} of version 1.x, {@link #subscribe(Subscriber)} does not allow external cancellation + * of a subscription and the {@link Subscriber} instance is expected to expose such capability if needed. + *

      + * Flowables support backpressure and require {@link Subscriber}s to signal demand via {@link Subscription#request(long)}. + *

      + * Example: + *

      
      + * Disposable d = Flowable.just("Hello world!")
      + *     .delay(1, TimeUnit.SECONDS)
      + *     .subscribeWith(new DisposableSubscriber<String>() {
      + *         @Override public void onStart() {
      + *             System.out.println("Start!");
      + *             request(1);
      + *         }
      + *         @Override public void onNext(String t) {
      + *             System.out.println(t);
      + *             request(1);
      + *         }
      + *         @Override public void onError(Throwable t) {
      + *             t.printStackTrace();
      + *         }
      + *         @Override public void onComplete() {
      + *             System.out.println("Done!");
      + *         }
      + *     });
      + *
      + * Thread.sleep(500);
      + * // the sequence can now be cancelled via dispose()
      + * d.dispose();
      + * 
      + *

      + * The Reactive Streams specification is relatively strict when defining interactions between {@code Publisher}s and {@code Subscriber}s, so much so + * that there is a significant performance penalty due certain timing requirements and the need to prepare for invalid + * request amounts via {@link Subscription#request(long)}. + * Therefore, RxJava has introduced the {@link FlowableSubscriber} interface that indicates the consumer can be driven with relaxed rules. + * All RxJava operators are implemented with these relaxed rules in mind. + * If the subscribing {@code Subscriber} does not implement this interface, for example, due to it being from another Reactive Streams compliant + * library, the Flowable will automatically apply a compliance wrapper around it. + *

      + * {@code Flowable} is an abstract class, but it is not advised to implement sources and custom operators by extending the class directly due + * to the large amounts of Reactive Streams + * rules to be followed to the letter. See the wiki for + * some guidance if such custom implementations are necessary. + *

      + * The recommended way of creating custom {@code Flowable}s is by using the {@link #create(FlowableOnSubscribe, BackpressureStrategy)} factory method: + *

      
      + * Flowable<String> source = Flowable.create(new FlowableOnSubscribe<String>() {
      + *     @Override
      + *     public void subscribe(FlowableEmitter<String> emitter) throws Exception {
      + *
      + *         // signal an item
      + *         emitter.onNext("Hello");
      + *
      + *         // could be some blocking operation
      + *         Thread.sleep(1000);
      + *         
      + *         // the consumer might have cancelled the flow
      + *         if (emitter.isCancelled() {
      + *             return;
      + *         }
      + *
      + *         emitter.onNext("World");
      + *
      + *         Thread.sleep(1000);
      + *
      + *         // the end-of-sequence has to be signaled, otherwise the
      + *         // consumers may never finish
      + *         emitter.onComplete();
      + *     }
      + * }, BackpressureStrategy.BUFFER);
      + *
      + * System.out.println("Subscribe!");
      + * 
      + * source.subscribe(System.out::println);
      + * 
      + * System.out.println("Done!");
      + * 
      + *

      + * RxJava reactive sources, such as {@code Flowable}, are generally synchronous and sequential in nature. In the ReactiveX design, the location (thread) + * where operators run is orthogonal to when the operators can work with data. This means that asynchrony and parallelism + * has to be explicitly expressed via operators such as {@link #subscribeOn(Scheduler)}, {@link #observeOn(Scheduler)} and {@link #parallel()}. In general, + * operators featuring a {@link Scheduler} parameter are introducing this type of asynchrony into the flow. + *

      * For more information see the ReactiveX * documentation. * * @param * the type of the items emitted by the Flowable + * @see Observable + * @see ParallelFlowable + * @see io.reactivex.subscribers.DisposableSubscriber */ public abstract class Flowable implements Publisher { /** The default buffer size. */ @@ -2199,7 +2291,7 @@ public static Flowable fromIterable(Iterable source) { } /** - * Converts an arbitrary Reactive-Streams Publisher into a Flowable if not already a + * Converts an arbitrary Reactive Streams Publisher into a Flowable if not already a * Flowable. *

      * The {@link Publisher} must follow the @@ -4385,7 +4477,7 @@ public static Flowable timer(long delay, TimeUnit unit, Scheduler schedule /** * Create a Flowable by wrapping a Publisher which has to be implemented according - * to the Reactive-Streams specification by handling backpressure and + * to the Reactive Streams specification by handling backpressure and * cancellation correctly; no safeguards are provided by the Flowable itself. *

      *
      Backpressure:
      @@ -13569,7 +13661,7 @@ public final Flowable retryWhen( * Subscribes to the current Flowable and wraps the given Subscriber into a SafeSubscriber * (if not already a SafeSubscriber) that * deals with exceptions thrown by a misbehaving Subscriber (that doesn't follow the - * Reactive-Streams specification). + * Reactive Streams specification). *
      *
      Backpressure:
      *
      This operator leaves the reactive world and the backpressure behavior depends on the Subscriber's behavior.
      @@ -14792,7 +14884,7 @@ public final void subscribe(Subscriber s) { * If the {@link Flowable} rejects the subscription attempt or otherwise fails it will signal * the error via {@link FlowableSubscriber#onError(Throwable)}. *

      - * This subscribe method relaxes the following Reactive-Streams rules: + * This subscribe method relaxes the following Reactive Streams rules: *

        *
      • §1.3: onNext should not be called concurrently until onSubscribe returns. * FlowableSubscriber.onSubscribe should make sure a sync or async call triggered by request() is safe.
      • diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 5bdd940909..20b829ad2e 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -42,7 +42,7 @@ * Many operators in the class accept {@code ObservableSource}(s), the base reactive interface * for such non-backpressured flows, which {@code Observable} itself implements as well. *

        - * The Observable's operators, by default, run with a buffer size of 128 elements (see {@link Flowable#bufferSize()}, + * The Observable's operators, by default, run with a buffer size of 128 elements (see {@link Flowable#bufferSize()}), * that can be overridden globally via the system parameter {@code rx2.buffer-size}. Most operators, however, have * overloads that allow setting their internal buffer size explicitly. *

        From 31e8d48a53c42c46a01f1db3d09ab4cafe5133f6 Mon Sep 17 00:00:00 2001 From: Jonathan Sawyer Date: Mon, 17 Jun 2019 22:49:56 +0900 Subject: [PATCH 162/211] 2.x: Correct Reactive-Streams to Reactive Streams in Documentation (#6510) --- DESIGN.md | 4 +- README.md | 4 +- docs/What's-different-in-2.0.md | 38 +++++++++---------- docs/Writing-operators-for-2.0.md | 26 ++++++------- src/main/java/io/reactivex/Completable.java | 2 +- src/main/java/io/reactivex/Flowable.java | 2 +- .../java/io/reactivex/FlowableSubscriber.java | 2 +- src/main/java/io/reactivex/Observable.java | 10 ++--- src/main/java/io/reactivex/Single.java | 2 +- .../ProtocolViolationException.java | 2 +- .../subscribers/StrictSubscriber.java | 2 +- src/main/java/io/reactivex/package-info.java | 2 +- 12 files changed, 48 insertions(+), 48 deletions(-) diff --git a/DESIGN.md b/DESIGN.md index 53f828186a..5480b39948 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -528,13 +528,13 @@ interface ScalarCallable extends java.util.Callable { `ScalarCallable` is also `Callable` and thus its value can be extracted practically anytime. For convenience (and for sense), `ScalarCallable` overrides and hides the superclass' `throws Exception` clause - throwing during assembly time is likely unreasonable for scalars. -Since Reactive-Streams doesn't allow `null`s in the value flow, we have the opportunity to define `ScalarCallable`s and `Callable`s returning `null` should be considered as an empty source - allowing operators to dispatch on the type `Callable` first then branch on the nullness of `call()`. +Since Reactive Streams doesn't allow `null`s in the value flow, we have the opportunity to define `ScalarCallable`s and `Callable`s returning `null` should be considered as an empty source - allowing operators to dispatch on the type `Callable` first then branch on the nullness of `call()`. Interoperating with other libraries, at this level is possible. Reactor-Core uses the same pattern and the two libraries can work with each other's `Publisher+Callable` types. Unfortunately, this means subscription-time only fusion as `ScalarCallable`s live locally in each library. ##### Micro-fusion -Micro-fusion goes a step deeper and tries to reuse internal structures, mostly queues, in operator pairs, saving on allocation and sometimes on atomic operations. It's property is that, in a way, subverts the standard Reactive-Streams protocol between subsequent operators that both support fusion. However, from the outside world's view, they still work according to the RS protocol. +Micro-fusion goes a step deeper and tries to reuse internal structures, mostly queues, in operator pairs, saving on allocation and sometimes on atomic operations. It's property is that, in a way, subverts the standard Reactive Streams protocol between subsequent operators that both support fusion. However, from the outside world's view, they still work according to the RS protocol. Currently, two main kinds of micro-fusion opportunities are available. diff --git a/README.md b/README.md index 982f0c393d..fd53e02083 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ It extends the [observer pattern](http://en.wikipedia.org/wiki/Observer_pattern) #### Version 2.x ([Javadoc](http://reactivex.io/RxJava/2.x/javadoc/)) -- single dependency: [Reactive-Streams](https://github.com/reactive-streams/reactive-streams-jvm) +- single dependency: [Reactive Streams](https://github.com/reactive-streams/reactive-streams-jvm) - continued support for Java 6+ & [Android](https://github.com/ReactiveX/RxAndroid) 2.3+ - performance gains through design changes learned through the 1.x cycle and through [Reactive-Streams-Commons](https://github.com/reactor/reactive-streams-commons) research project. - Java 8 lambda-friendly API @@ -72,7 +72,7 @@ Flowable.just("Hello world") RxJava 2 features several base classes you can discover operators on: - - [`io.reactivex.Flowable`](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html): 0..N flows, supporting Reactive-Streams and backpressure + - [`io.reactivex.Flowable`](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html): 0..N flows, supporting Reactive Streams and backpressure - [`io.reactivex.Observable`](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html): 0..N flows, no backpressure, - [`io.reactivex.Single`](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html): a flow of exactly 1 item or an error, - [`io.reactivex.Completable`](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html): a flow without items but only a completion or error signal, diff --git a/docs/What's-different-in-2.0.md b/docs/What's-different-in-2.0.md index fac50df56d..30f9a4ccba 100644 --- a/docs/What's-different-in-2.0.md +++ b/docs/What's-different-in-2.0.md @@ -1,6 +1,6 @@ -RxJava 2.0 has been completely rewritten from scratch on top of the Reactive-Streams specification. The specification itself has evolved out of RxJava 1.x and provides a common baseline for reactive systems and libraries. +RxJava 2.0 has been completely rewritten from scratch on top of the Reactive Streams specification. The specification itself has evolved out of RxJava 1.x and provides a common baseline for reactive systems and libraries. -Because Reactive-Streams has a different architecture, it mandates changes to some well known RxJava types. This wiki page attempts to summarize what has changed and describes how to rewrite 1.x code into 2.x code. +Because Reactive Streams has a different architecture, it mandates changes to some well known RxJava types. This wiki page attempts to summarize what has changed and describes how to rewrite 1.x code into 2.x code. For technical details on how to write operators for 2.x, please visit the [Writing Operators](https://github.com/ReactiveX/RxJava/wiki/Writing-operators-for-2.0) wiki page. @@ -20,7 +20,7 @@ For technical details on how to write operators for 2.x, please visit the [Writi - [Subscriber](#subscriber) - [Subscription](#subscription) - [Backpressure](#backpressure) - - [Reactive-Streams compliance](#reactive-streams-compliance) + - [Reactive Streams compliance](#reactive-streams-compliance) - [Runtime hooks](#runtime-hooks) - [Error handling](#error-handling) - [Scheduler](#schedulers) @@ -105,7 +105,7 @@ When architecting dataflows (as an end-consumer of RxJava) or deciding upon what # Single -The 2.x `Single` reactive base type, which can emit a single `onSuccess` or `onError` has been redesigned from scratch. Its architecture now derives from the Reactive-Streams design. Its consumer type (`rx.Single.SingleSubscriber`) has been changed from being a class that accepts `rx.Subscription` resources to be an interface `io.reactivex.SingleObserver` that has only 3 methods: +The 2.x `Single` reactive base type, which can emit a single `onSuccess` or `onError` has been redesigned from scratch. Its architecture now derives from the Reactive Streams design. Its consumer type (`rx.Single.SingleSubscriber`) has been changed from being a class that accepts `rx.Subscription` resources to be an interface `io.reactivex.SingleObserver` that has only 3 methods: ```java interface SingleObserver { @@ -119,7 +119,7 @@ and follows the protocol `onSubscribe (onSuccess | onError)?`. # Completable -The `Completable` type remains largely the same. It was already designed along the Reactive-Streams style for 1.x so no user-level changes there. +The `Completable` type remains largely the same. It was already designed along the Reactive Streams style for 1.x so no user-level changes there. Similar to the naming changes, `rx.Completable.CompletableSubscriber` has become `io.reactivex.CompletableObserver` with `onSubscribe(Disposable)`: @@ -154,7 +154,7 @@ Maybe.just(1) # Base reactive interfaces -Following the style of extending the Reactive-Streams `Publisher` in `Flowable`, the other base reactive classes now extend similar base interfaces (in package `io.reactivex`): +Following the style of extending the Reactive Streams `Publisher` in `Flowable`, the other base reactive classes now extend similar base interfaces (in package `io.reactivex`): ```java interface ObservableSource { @@ -182,7 +182,7 @@ Flowable flatMap(Function> mapper Observable flatMap(Function> mapper); ``` -By having `Publisher` as input this way, you can compose with other Reactive-Streams compliant libraries without the need to wrap them or convert them into `Flowable` first. +By having `Publisher` as input this way, you can compose with other Reactive Streams compliant libraries without the need to wrap them or convert them into `Flowable` first. If an operator has to offer a reactive base type, however, the user will receive the full reactive class (as giving out an `XSource` is practically useless as it doesn't have operators on it): @@ -197,7 +197,7 @@ source.compose((Flowable flowable) -> # Subjects and Processors -In the Reactive-Streams specification, the `Subject`-like behavior, namely being a consumer and supplier of events at the same time, is done by the `org.reactivestreams.Processor` interface. As with the `Observable`/`Flowable` split, the backpressure-aware, Reactive-Streams compliant implementations are based on the `FlowableProcessor` class (which extends `Flowable` to give a rich set of instance operators). An important change regarding `Subject`s (and by extension, `FlowableProcessor`) that they no longer support `T -> R` like conversion (that is, input is of type `T` and the output is of type `R`). (We never had a use for it in 1.x and the original `Subject` came from .NET where there is a `Subject` overload because .NET allows the same class name with a different number of type arguments.) +In the Reactive Streams specification, the `Subject`-like behavior, namely being a consumer and supplier of events at the same time, is done by the `org.reactivestreams.Processor` interface. As with the `Observable`/`Flowable` split, the backpressure-aware, Reactive Streams compliant implementations are based on the `FlowableProcessor` class (which extends `Flowable` to give a rich set of instance operators). An important change regarding `Subject`s (and by extension, `FlowableProcessor`) that they no longer support `T -> R` like conversion (that is, input is of type `T` and the output is of type `R`). (We never had a use for it in 1.x and the original `Subject` came from .NET where there is a `Subject` overload because .NET allows the same class name with a different number of type arguments.) The `io.reactivex.subjects.AsyncSubject`, `io.reactivex.subjects.BehaviorSubject`, `io.reactivex.subjects.PublishSubject`, `io.reactivex.subjects.ReplaySubject` and `io.reactivex.subjects.UnicastSubject` in 2.x don't support backpressure (as part of the 2.x `Observable` family). @@ -296,7 +296,7 @@ In addition, operators requiring a predicate no longer use `Func1` b # Subscriber -The Reactive-Streams specification has its own Subscriber as an interface. This interface is lightweight and combines request management with cancellation into a single interface `org.reactivestreams.Subscription` instead of having `rx.Producer` and `rx.Subscription` separately. This allows creating stream consumers with less internal state than the quite heavy `rx.Subscriber` of 1.x. +The Reactive Streams specification has its own Subscriber as an interface. This interface is lightweight and combines request management with cancellation into a single interface `org.reactivestreams.Subscription` instead of having `rx.Producer` and `rx.Subscription` separately. This allows creating stream consumers with less internal state than the quite heavy `rx.Subscriber` of 1.x. ```java Flowable.range(1, 10).subscribe(new Subscriber() { @@ -354,7 +354,7 @@ Flowable.range(1, 10).delay(1, TimeUnit.SECONDS).subscribe(subscriber); subscriber.dispose(); ``` -Note also that due to Reactive-Streams compatibility, the method `onCompleted` has been renamed to `onComplete` without the trailing `d`. +Note also that due to Reactive Streams compatibility, the method `onCompleted` has been renamed to `onComplete` without the trailing `d`. Since 1.x `Observable.subscribe(Subscriber)` returned `Subscription`, users often added the `Subscription` to a `CompositeSubscription` for example: @@ -364,7 +364,7 @@ CompositeSubscription composite = new CompositeSubscription(); composite.add(Observable.range(1, 5).subscribe(new TestSubscriber())); ``` -Due to the Reactive-Streams specification, `Publisher.subscribe` returns void and the pattern by itself no longer works in 2.0. To remedy this, the method `E subscribeWith(E subscriber)` has been added to each base reactive class which returns its input subscriber/observer as is. With the two examples before, the 2.x code can now look like this since `ResourceSubscriber` implements `Disposable` directly: +Due to the Reactive Streams specification, `Publisher.subscribe` returns void and the pattern by itself no longer works in 2.0. To remedy this, the method `E subscribeWith(E subscriber)` has been added to each base reactive class which returns its input subscriber/observer as is. With the two examples before, the 2.x code can now look like this since `ResourceSubscriber` implements `Disposable` directly: ```java CompositeDisposable composite2 = new CompositeDisposable(); @@ -420,11 +420,11 @@ This behavior differs from 1.x where a `request` call went through a deferred lo # Subscription -In RxJava 1.x, the interface `rx.Subscription` was responsible for stream and resource lifecycle management, namely unsubscribing a sequence and releasing general resources such as scheduled tasks. The Reactive-Streams specification took this name for specifying an interaction point between a source and a consumer: `org.reactivestreams.Subscription` allows requesting a positive amount from the upstream and allows cancelling the sequence. +In RxJava 1.x, the interface `rx.Subscription` was responsible for stream and resource lifecycle management, namely unsubscribing a sequence and releasing general resources such as scheduled tasks. The Reactive Streams specification took this name for specifying an interaction point between a source and a consumer: `org.reactivestreams.Subscription` allows requesting a positive amount from the upstream and allows cancelling the sequence. To avoid the name clash, the 1.x `rx.Subscription` has been renamed into `io.reactivex.Disposable` (somewhat resembling .NET's own IDisposable). -Because Reactive-Streams base interface, `org.reactivestreams.Publisher` defines the `subscribe()` method as `void`, `Flowable.subscribe(Subscriber)` no longer returns any `Subscription` (or `Disposable`). The other base reactive types also follow this signature with their respective subscriber types. +Because Reactive Streams base interface, `org.reactivestreams.Publisher` defines the `subscribe()` method as `void`, `Flowable.subscribe(Subscriber)` no longer returns any `Subscription` (or `Disposable`). The other base reactive types also follow this signature with their respective subscriber types. The other overloads of `subscribe` now return `Disposable` in 2.x. @@ -436,19 +436,19 @@ The original `Subscription` container types have been renamed and updated # Backpressure -The Reactive-Streams specification mandates operators supporting backpressure, specifically via the guarantee that they don't overflow their consumers when those don't request. Operators of the new `Flowable` base reactive type now consider downstream request amounts properly, however, this doesn't mean `MissingBackpressureException` is gone. The exception is still there but this time, the operator that can't signal more `onNext` will signal this exception instead (allowing better identification of who is not properly backpressured). +The Reactive Streams specification mandates operators supporting backpressure, specifically via the guarantee that they don't overflow their consumers when those don't request. Operators of the new `Flowable` base reactive type now consider downstream request amounts properly, however, this doesn't mean `MissingBackpressureException` is gone. The exception is still there but this time, the operator that can't signal more `onNext` will signal this exception instead (allowing better identification of who is not properly backpressured). As an alternative, the 2.x `Observable` doesn't do backpressure at all and is available as a choice to switch over. -# Reactive-Streams compliance +# Reactive Streams compliance **updated in 2.0.7** -**The `Flowable`-based sources and operators are, as of 2.0.7, fully Reactive-Streams version 1.0.0 specification compliant.** +**The `Flowable`-based sources and operators are, as of 2.0.7, fully Reactive Streams version 1.0.0 specification compliant.** Before 2.0.7, the operator `strict()` had to be applied in order to achieve the same level of compliance. In 2.0.7, the operator `strict()` returns `this`, is deprecated and will be removed completely in 2.1.0. -As one of the primary goals of RxJava 2, the design focuses on performance and in order enable it, RxJava 2.0.7 adds a custom `io.reactivex.FlowableSubscriber` interface (extends `org.reactivestreams.Subscriber`) but adds no new methods to it. The new interface is **constrained to RxJava 2** and represents a consumer to `Flowable` that is able to work in a mode that relaxes the Reactive-Streams version 1.0.0 specification in rules §1.3, §2.3, §2.12 and §3.9: +As one of the primary goals of RxJava 2, the design focuses on performance and in order enable it, RxJava 2.0.7 adds a custom `io.reactivex.FlowableSubscriber` interface (extends `org.reactivestreams.Subscriber`) but adds no new methods to it. The new interface is **constrained to RxJava 2** and represents a consumer to `Flowable` that is able to work in a mode that relaxes the Reactive Streams version 1.0.0 specification in rules §1.3, §2.3, §2.12 and §3.9: - §1.3 relaxation: `onSubscribe` may run concurrently with `onNext` in case the `FlowableSubscriber` calls `request()` from inside `onSubscribe` and it is the resposibility of `FlowableSubscriber` to ensure thread-safety between the remaining instructions in `onSubscribe` and `onNext`. - §2.3 relaxation: calling `Subscription.cancel` and `Subscription.request` from `FlowableSubscriber.onComplete()` or `FlowableSubscriber.onError()` is considered a no-operation. @@ -603,7 +603,7 @@ Integer i = Flowable.range(100, 100).blockingLast(); (The reason for this is twofold: performance and ease of use of the library as a synchronous Java 8 Streams-like processor.) -Another significant difference between `rx.Subscriber` (and co) and `org.reactivestreams.Subscriber` (and co) is that in 2.x, your `Subscriber`s and `Observer`s are not allowed to throw anything but fatal exceptions (see `Exceptions.throwIfFatal()`). (The Reactive-Streams specification allows throwing `NullPointerException` if the `onSubscribe`, `onNext` or `onError` receives a `null` value, but RxJava doesn't let `null`s in any way.) This means the following code is no longer legal: +Another significant difference between `rx.Subscriber` (and co) and `org.reactivestreams.Subscriber` (and co) is that in 2.x, your `Subscriber`s and `Observer`s are not allowed to throw anything but fatal exceptions (see `Exceptions.throwIfFatal()`). (The Reactive Streams specification allows throwing `NullPointerException` if the `onSubscribe`, `onNext` or `onError` receives a `null` value, but RxJava doesn't let `null`s in any way.) This means the following code is no longer legal: ```java Subscriber subscriber = new Subscriber() { @@ -933,7 +933,7 @@ To make sure the final API of 2.0 is clean as possible, we remove methods and ot ## doOnCancel/doOnDispose/unsubscribeOn -In 1.x, the `doOnUnsubscribe` was always executed on a terminal event because 1.x' `SafeSubscriber` called `unsubscribe` on itself. This was practically unnecessary and the Reactive-Streams specification states that when a terminal event arrives at a `Subscriber`, the upstream `Subscription` should be considered cancelled and thus calling `cancel()` is a no-op. +In 1.x, the `doOnUnsubscribe` was always executed on a terminal event because 1.x' `SafeSubscriber` called `unsubscribe` on itself. This was practically unnecessary and the Reactive Streams specification states that when a terminal event arrives at a `Subscriber`, the upstream `Subscription` should be considered cancelled and thus calling `cancel()` is a no-op. For the same reason, `unsubscribeOn` is not called on the regular termination path but only when there is an actual `cancel` (or `dispose`) call on the chain. diff --git a/docs/Writing-operators-for-2.0.md b/docs/Writing-operators-for-2.0.md index 7b6e57666e..9649c02be7 100644 --- a/docs/Writing-operators-for-2.0.md +++ b/docs/Writing-operators-for-2.0.md @@ -40,7 +40,7 @@ Writing operators, source-like (`fromEmitter`) or intermediate-like (`flatMap`) *(If you have been following [my blog](http://akarnokd.blogspot.hu/) about RxJava internals, writing operators is maybe only 2 times harder than 1.x; some things have moved around, some tools popped up while others have been dropped but there is a relatively straight mapping from 1.x concepts and approaches to 2.x concepts and approaches.)* -In this article, I'll describe the how-to's from the perspective of a developer who skipped the 1.x knowledge base and basically wants to write operators that conforms the Reactive-Streams specification as well as RxJava 2.x's own extensions and additional expectations/requirements. +In this article, I'll describe the how-to's from the perspective of a developer who skipped the 1.x knowledge base and basically wants to write operators that conforms the Reactive Streams specification as well as RxJava 2.x's own extensions and additional expectations/requirements. Since **Reactor 3** has the same architecture as **RxJava 2** (no accident, I architected and contributed 80% of **Reactor 3** as well) the same principles outlined in this page applies to writing operators for **Reactor 3**. Note however that they chose different naming and locations for their utility and support classes so you may have to search for the equivalent components. @@ -66,7 +66,7 @@ When dealing with backpressure in `Flowable` operators, one needs a way to accou The naive approach for accounting would be to simply call `AtomicLong.getAndAdd()` with new requests and `AtomicLong.addAndGet()` for decrementing based on how many elements were emitted. -The problem with this is that the Reactive-Streams specification declares `Long.MAX_VALUE` as the upper bound for outstanding requests (interprets it as the unbounded mode) but adding two large longs may overflow the `long` into a negative value. In addition, if for some reason, there are more values emitted than were requested, the subtraction may yield a negative current request value, causing crashes or hangs. +The problem with this is that the Reactive Streams specification declares `Long.MAX_VALUE` as the upper bound for outstanding requests (interprets it as the unbounded mode) but adding two large longs may overflow the `long` into a negative value. In addition, if for some reason, there are more values emitted than were requested, the subtraction may yield a negative current request value, causing crashes or hangs. Therefore, both addition and subtraction have to be capped at `Long.MAX_VALUE` and `0` respectively. Since there is no dedicated `AtomicLong` method for it, we have to use a Compare-And-Set loop. (Usually, requesting happens relatively rarely compared to emission amounts thus the lack of dedicated machine code instruction is not a performance bottleneck.) @@ -225,7 +225,7 @@ This simplified queue API gets rid of the unused parts (iterator, collections AP ## Deferred actions -The Reactive-Streams has a strict requirement that calling `onSubscribe()` must happen before any calls to the rest of the `onXXX` methods and by nature, any calls to `Subscription.request()` and `Subscription.cancel()`. The same logic applies to the design of `Observable`, `Single`, `Completable` and `Maybe` with their connection type of `Disposable`. +The Reactive Streams has a strict requirement that calling `onSubscribe()` must happen before any calls to the rest of the `onXXX` methods and by nature, any calls to `Subscription.request()` and `Subscription.cancel()`. The same logic applies to the design of `Observable`, `Single`, `Completable` and `Maybe` with their connection type of `Disposable`. Often though, such call to `onSubscribe` may happen later than the respective `cancel()` needs to happen. For example, the user may want to call `cancel()` before the respective `Subscription` actually becomes available in `subscribeOn`. Other operators may need to call `onSubscribe` before they connect to other sources but at that time, there is no direct way for relaying a `cancel` call to an unavailable upstream `Subscription`. @@ -286,7 +286,7 @@ The same pattern applies to `Subscription` with its `cancel()` method and with h ### Deferred requesting -With `Flowable`s (and Reactive-Streams `Publisher`s) the `request()` calls need to be deferred as well. In one form (the simpler one), the respective late `Subscription` will eventually arrive and we need to relay all previous and all subsequent request amount to its `request()` method. +With `Flowable`s (and Reactive Streams `Publisher`s) the `request()` calls need to be deferred as well. In one form (the simpler one), the respective late `Subscription` will eventually arrive and we need to relay all previous and all subsequent request amount to its `request()` method. In 1.x, this behavior was implicitly provided by `rx.Subscriber` but at a high cost that had to be payed by all instances whether or not they needed this feature. @@ -561,7 +561,7 @@ On the fast path, when we try to leave it, it is possible a concurrent call to ` ## FlowableSubscriber -Version 2.0.7 introduced a new interface, `FlowableSubscriber` that extends `Subscriber` from Reactive-Streams. It has the same methods with the same parameter types but different textual rules attached to it, a set of relaxations to the Reactive-Streams specification to enable better performing RxJava internals while still honoring the specification to the letter for non-RxJava consumers of `Flowable`s. +Version 2.0.7 introduced a new interface, `FlowableSubscriber` that extends `Subscriber` from Reactive Streams. It has the same methods with the same parameter types but different textual rules attached to it, a set of relaxations to the Reactive Streams specification to enable better performing RxJava internals while still honoring the specification to the letter for non-RxJava consumers of `Flowable`s. The rule relaxations are as follows: @@ -588,7 +588,7 @@ The other base reactive consumers, `Observer`, `SingleObserver`, `MaybeObserver` # Backpressure and cancellation -Backpressure (or flow control) in Reactive-Streams is the means to tell the upstream how many elements to produce or to tell it to stop producing elements altogether. Unlike the name suggest, there is no physical pressure preventing the upstream from calling `onNext` but the protocol to honor the request amount. +Backpressure (or flow control) in Reactive Streams is the means to tell the upstream how many elements to produce or to tell it to stop producing elements altogether. Unlike the name suggest, there is no physical pressure preventing the upstream from calling `onNext` but the protocol to honor the request amount. ## Replenishing @@ -1425,7 +1425,7 @@ public final class FlowableMyOperator extends Flowable { } ``` -When taking other reactive types as inputs in these operators, it is recommended one defines the base reactive interfaces instead of the abstract classes, allowing better interoperability between libraries (especially with `Flowable` operators and other Reactive-Streams `Publisher`s). To recap, these are the class-interface pairs: +When taking other reactive types as inputs in these operators, it is recommended one defines the base reactive interfaces instead of the abstract classes, allowing better interoperability between libraries (especially with `Flowable` operators and other Reactive Streams `Publisher`s). To recap, these are the class-interface pairs: - `Flowable` - `Publisher` - `FlowableSubscriber`/`Subscriber` - `Observable` - `ObservableSource` - `Observer` @@ -1433,7 +1433,7 @@ When taking other reactive types as inputs in these operators, it is recommended - `Completable` - `CompletableSource` - `CompletableObserver` - `Maybe` - `MaybeSource` - `MaybeObserver` -RxJava 2.x locks down `Flowable.subscribe` (and the same methods in the other types) in order to provide runtime hooks into the various flows, therefore, implementors are given the `subscribeActual()` to be overridden. When it is invoked, all relevant hooks and wrappers have been applied. Implementors should avoid throwing unchecked exceptions as the library generally can't deliver it to the respective `Subscriber` due to lifecycle restrictions of the Reactive-Streams specification and sends it to the global error consumer via `RxJavaPlugins.onError`. +RxJava 2.x locks down `Flowable.subscribe` (and the same methods in the other types) in order to provide runtime hooks into the various flows, therefore, implementors are given the `subscribeActual()` to be overridden. When it is invoked, all relevant hooks and wrappers have been applied. Implementors should avoid throwing unchecked exceptions as the library generally can't deliver it to the respective `Subscriber` due to lifecycle restrictions of the Reactive Streams specification and sends it to the global error consumer via `RxJavaPlugins.onError`. Unlike in 1.x, In the example above, the incoming `Subscriber` is simply used directly for subscribing again (but still at most once) without any kind of wrapping. In 1.x, one needs to call `Subscribers.wrap` to avoid double calls to `onStart` and cause unexpected double initialization or double-requesting. @@ -1516,7 +1516,7 @@ public final class MyOperator implements FlowableOperator { You may recognize that implementing operators via extension or lifting looks quite similar. In both cases, one usually implements a `FlowableSubscriber` (`Observer`, etc) that takes a downstream `Subscriber`, implements the business logic in the `onXXX` methods and somehow (manually or as part of `lift()`'s lifecycle) gets subscribed to an upstream source. -The benefit of applying the Reactive-Streams design to all base reactive types is that each consumer type is now an interface and can be applied to operators that have to extend some class. This was a pain in 1.x because `Subscriber` and `SingleSubscriber` are classes themselves, plus `Subscriber.request()` is a protected-final method and an operator's `Subscriber` can't implement the `Producer` interface at the same time. In 2.x there is no such problem and one can have both `Subscriber`, `Subscription` or even `Observer` together in the same consumer type. +The benefit of applying the Reactive Streams design to all base reactive types is that each consumer type is now an interface and can be applied to operators that have to extend some class. This was a pain in 1.x because `Subscriber` and `SingleSubscriber` are classes themselves, plus `Subscriber.request()` is a protected-final method and an operator's `Subscriber` can't implement the `Producer` interface at the same time. In 2.x there is no such problem and one can have both `Subscriber`, `Subscription` or even `Observer` together in the same consumer type. # Operator fusion @@ -1569,12 +1569,12 @@ This is the level of the **Rx.NET** library (even up to 3.x) that supports compo This is what **RxJava 1.x** is categorized, it supports composition, backpressure and synchronous cancellation along with the ability to lift an operator into a sequence. #### Generation 3 -This is the level of the Reactive-Streams based libraries such as **Reactor 2** and **Akka-Stream**. They are based upon a specification that evolved out of RxJava but left behind its drawbacks (such as the need to return anything from `subscribe()`). This is incompatible with RxJava 1.x and thus 2.x had to be rewritten from scratch. +This is the level of the Reactive Streams based libraries such as **Reactor 2** and **Akka-Stream**. They are based upon a specification that evolved out of RxJava but left behind its drawbacks (such as the need to return anything from `subscribe()`). This is incompatible with RxJava 1.x and thus 2.x had to be rewritten from scratch. #### Generation 4 -This level expands upon the Reactive-Streams interfaces with operator-fusion (in a compatible fashion, that is, op-fusion is optional between two stages and works without them). **Reactor 3** and **RxJava 2** are at this level. The material around **Akka-Stream** mentions operator-fusion as well, however, **Akka-Stream** is not a native Reactive-Streams implementation (requires a materializer to get a `Publisher` out) and as such it is only Gen 3. +This level expands upon the Reactive Streams interfaces with operator-fusion (in a compatible fashion, that is, op-fusion is optional between two stages and works without them). **Reactor 3** and **RxJava 2** are at this level. The material around **Akka-Stream** mentions operator-fusion as well, however, **Akka-Stream** is not a native Reactive Streams implementation (requires a materializer to get a `Publisher` out) and as such it is only Gen 3. -There are discussions among the 4th generation library providers to have the elements of operator-fusion standardized in Reactive-Streams 2.0 specification (or in a neighboring extension) and have **RxJava 3** and **Reactor 4** work together on that aspect as well. +There are discussions among the 4th generation library providers to have the elements of operator-fusion standardized in Reactive Streams 2.0 specification (or in a neighboring extension) and have **RxJava 3** and **Reactor 4** work together on that aspect as well. ## Components @@ -1629,7 +1629,7 @@ The reason for the two separate interfaces is that if a source is constant, like `Callable` denotes sources, such as `fromCallable` that indicates the single value has to be calculated at runtime of the flow. By this logic, you can see that `ScalarCallable` is a `Callable` on its own right because the constant can be "calculated" as late as the runtime phase of the flow. -Since Reactive-Streams forbids using `null`s as emission values, we can use `null` in `(Scalar)Callable` marked sources to indicate there is no value to be emitted, thus one can't mistake an user's `null` with the empty indicator `null`. For example, this is how `empty()` is implemented: +Since Reactive Streams forbids using `null`s as emission values, we can use `null` in `(Scalar)Callable` marked sources to indicate there is no value to be emitted, thus one can't mistake an user's `null` with the empty indicator `null`. For example, this is how `empty()` is implemented: ```java final class FlowableEmpty extends Flowable implements ScalarCallable { diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index 79fcc9b432..1994632307 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -557,7 +557,7 @@ public static Completable fromObservable(final ObservableSource observabl * *

        * The {@link Publisher} must follow the - * Reactive-Streams specification. + * Reactive Streams specification. * Violating the specification may result in undefined behavior. *

        * If possible, use {@link #create(CompletableOnSubscribe)} to create a diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 7dc6d77716..4fe78199fe 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -2295,7 +2295,7 @@ public static Flowable fromIterable(Iterable source) { * Flowable. *

        * The {@link Publisher} must follow the - * Reactive-Streams specification. + * Reactive Streams specification. * Violating the specification may result in undefined behavior. *

        * If possible, use {@link #create(FlowableOnSubscribe, BackpressureStrategy)} to create a diff --git a/src/main/java/io/reactivex/FlowableSubscriber.java b/src/main/java/io/reactivex/FlowableSubscriber.java index 2ef1019acf..e2636406e1 100644 --- a/src/main/java/io/reactivex/FlowableSubscriber.java +++ b/src/main/java/io/reactivex/FlowableSubscriber.java @@ -17,7 +17,7 @@ import org.reactivestreams.*; /** - * Represents a Reactive-Streams inspired Subscriber that is RxJava 2 only + * Represents a Reactive Streams inspired Subscriber that is RxJava 2 only * and weakens rules §1.3 and §3.9 of the specification for gaining performance. * *

        History: 2.0.7 - experimental; 2.1 - beta diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 20b829ad2e..d2f11d2b5b 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -51,7 +51,7 @@ * *

        * The design of this class was derived from the - * Reactive-Streams design and specification + * Reactive Streams design and specification * by removing any backpressure-related infrastructure and implementation detail, replacing the * {@code org.reactivestreams.Subscription} with {@link Disposable} as the primary means to dispose of * a flow. @@ -1985,12 +1985,12 @@ public static Observable fromIterable(Iterable source) { } /** - * Converts an arbitrary Reactive-Streams Publisher into an Observable. + * Converts an arbitrary Reactive Streams Publisher into an Observable. *

        * *

        * The {@link Publisher} must follow the - * Reactive-Streams specification. + * Reactive Streams specification. * Violating the specification may result in undefined behavior. *

        * If possible, use {@link #create(ObservableOnSubscribe)} to create a @@ -3982,7 +3982,7 @@ public static Observable timer(long delay, TimeUnit unit, Scheduler schedu /** * Create an Observable by wrapping an ObservableSource which has to be implemented according - * to the Reactive-Streams-based Observable specification by handling + * to the Reactive Streams based Observable specification by handling * disposal correctly; no safeguards are provided by the Observable itself. *

        *
        Scheduler:
        @@ -11229,7 +11229,7 @@ public final Observable retryWhen( * Subscribes to the current Observable and wraps the given Observer into a SafeObserver * (if not already a SafeObserver) that * deals with exceptions thrown by a misbehaving Observer (that doesn't follow the - * Reactive-Streams specification). + * Reactive Streams specification). *
        *
        Scheduler:
        *
        {@code safeSubscribe} does not operate by default on a particular {@link Scheduler}.
        diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index f97f4d22b7..3dd0776e11 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -755,7 +755,7 @@ public static Single fromFuture(Future future, Scheduler sch * the source has more than one element, an IndexOutOfBoundsException is signalled. *

        * The {@link Publisher} must follow the - * Reactive-Streams specification. + * Reactive Streams specification. * Violating the specification may result in undefined behavior. *

        * If possible, use {@link #create(SingleOnSubscribe)} to create a diff --git a/src/main/java/io/reactivex/exceptions/ProtocolViolationException.java b/src/main/java/io/reactivex/exceptions/ProtocolViolationException.java index 09c0361108..ff36ce1cf3 100644 --- a/src/main/java/io/reactivex/exceptions/ProtocolViolationException.java +++ b/src/main/java/io/reactivex/exceptions/ProtocolViolationException.java @@ -14,7 +14,7 @@ package io.reactivex.exceptions; /** - * Explicitly named exception to indicate a Reactive-Streams + * Explicitly named exception to indicate a Reactive Streams * protocol violation. *

        History: 2.0.6 - experimental; 2.1 - beta * @since 2.2 diff --git a/src/main/java/io/reactivex/internal/subscribers/StrictSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/StrictSubscriber.java index 0fb9d5666c..c7770bf163 100644 --- a/src/main/java/io/reactivex/internal/subscribers/StrictSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/StrictSubscriber.java @@ -23,7 +23,7 @@ /** * Ensures that the event flow between the upstream and downstream follow - * the Reactive-Streams 1.0 specification by honoring the 3 additional rules + * the Reactive Streams 1.0 specification by honoring the 3 additional rules * (which are omitted in standard operators due to performance reasons). *

          *
        • §1.3: onNext should not be called concurrently until onSubscribe returns
        • diff --git a/src/main/java/io/reactivex/package-info.java b/src/main/java/io/reactivex/package-info.java index 7d78294b6d..75ceb6cd7b 100644 --- a/src/main/java/io/reactivex/package-info.java +++ b/src/main/java/io/reactivex/package-info.java @@ -25,7 +25,7 @@ * Completable/CompletableObserver interfaces and associated operators (in * the {@code io.reactivex.internal.operators} package) are inspired by the * Reactive Rx library in Microsoft .NET but designed and implemented on - * the more advanced Reactive-Streams ( http://www.reactivestreams.org ) principles.

          + * the more advanced Reactive Streams ( http://www.reactivestreams.org ) principles.

          *

          * More information can be found at http://msdn.microsoft.com/en-us/data/gg577609. From b763ffadb4c9aefb0b168d8684ac0b3a7f8d42d0 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 20 Jun 2019 14:34:47 +0200 Subject: [PATCH 163/211] 2.x: Fix concatMapDelayError not continuing on fused inner source crash (#6522) --- .../operators/flowable/FlowableConcatMap.java | 9 ++-- .../flowable/FlowableConcatMapTest.java | 42 ++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java index 2dc316d1e9..f3dc0c58b8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java @@ -520,10 +520,13 @@ void drain() { vr = supplier.call(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - upstream.cancel(); errors.addThrowable(e); - downstream.onError(errors.terminate()); - return; + if (!veryEnd) { + upstream.cancel(); + downstream.onError(errors.terminate()); + return; + } + vr = null; } if (vr == null) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java index eba09e564f..d9fe79977f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java @@ -15,14 +15,14 @@ import static org.junit.Assert.assertEquals; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; import org.reactivestreams.Publisher; import io.reactivex.*; -import io.reactivex.exceptions.TestException; +import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.operators.flowable.FlowableConcatMap.WeakScalarSubscription; import io.reactivex.schedulers.Schedulers; @@ -168,4 +168,42 @@ public void run() throws Exception { assertEquals(0, counter.get()); } + + @Test + public void delayErrorCallableTillTheEnd() { + Flowable.just(1, 2, 3, 101, 102, 23, 890, 120, 32) + .concatMapDelayError(new Function>() { + @Override public Flowable apply(final Integer integer) throws Exception { + return Flowable.fromCallable(new Callable() { + @Override public Integer call() throws Exception { + if (integer >= 100) { + throw new NullPointerException("test null exp"); + } + return integer; + } + }); + } + }) + .test() + .assertFailure(CompositeException.class, 1, 2, 3, 23, 32); + } + + @Test + public void delayErrorCallableEager() { + Flowable.just(1, 2, 3, 101, 102, 23, 890, 120, 32) + .concatMapDelayError(new Function>() { + @Override public Flowable apply(final Integer integer) throws Exception { + return Flowable.fromCallable(new Callable() { + @Override public Integer call() throws Exception { + if (integer >= 100) { + throw new NullPointerException("test null exp"); + } + return integer; + } + }); + } + }, 2, false) + .test() + .assertFailure(NullPointerException.class, 1, 2, 3); + } } From 19c09592801e8ae84bc11c23837f824292b7da86 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 20 Jun 2019 21:30:04 +0200 Subject: [PATCH 164/211] 2.x: Fix publish().refCount() hang due to race (#6505) * 2.x: Fix publish().refCount() hang due to race * Add more time to GC when detecting leaks. * Fix subscriber swap mistake in the Alt implementation --- .../flowables/ConnectableFlowable.java | 22 +- .../operators/flowable/FlowablePublish.java | 16 +- .../flowable/FlowablePublishAlt.java | 483 +++++ .../flowable/FlowablePublishClassic.java | 41 + .../observable/ObservablePublish.java | 8 +- .../observable/ObservablePublishAlt.java | 282 +++ .../observable/ObservablePublishClassic.java | 36 + .../observables/ConnectableObservable.java | 21 +- .../flowable/FlowablePublishAltTest.java | 1629 +++++++++++++++++ .../flowable/FlowablePublishTest.java | 22 + .../flowable/FlowableRefCountAltTest.java | 1447 +++++++++++++++ .../flowable/FlowableRefCountTest.java | 30 +- .../observable/ObservablePublishAltTest.java | 794 ++++++++ .../observable/ObservablePublishTest.java | 23 +- .../observable/ObservableRefCountAltTest.java | 1394 ++++++++++++++ .../observable/ObservableRefCountTest.java | 23 +- 16 files changed, 6262 insertions(+), 9 deletions(-) create mode 100644 src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishAlt.java create mode 100644 src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishClassic.java create mode 100644 src/main/java/io/reactivex/internal/operators/observable/ObservablePublishAlt.java create mode 100644 src/main/java/io/reactivex/internal/operators/observable/ObservablePublishClassic.java create mode 100644 src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishAltTest.java create mode 100644 src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java create mode 100644 src/test/java/io/reactivex/internal/operators/observable/ObservablePublishAltTest.java create mode 100644 src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java diff --git a/src/main/java/io/reactivex/flowables/ConnectableFlowable.java b/src/main/java/io/reactivex/flowables/ConnectableFlowable.java index 21636e67da..ef5b667bac 100644 --- a/src/main/java/io/reactivex/flowables/ConnectableFlowable.java +++ b/src/main/java/io/reactivex/flowables/ConnectableFlowable.java @@ -68,6 +68,24 @@ public final Disposable connect() { return cc.disposable; } + /** + * Apply a workaround for a race condition with the regular publish().refCount() + * so that racing subscribers and refCount won't hang. + * + * @return the ConnectableFlowable to work with + * @since 2.2.10 + */ + private ConnectableFlowable onRefCount() { + if (this instanceof FlowablePublishClassic) { + @SuppressWarnings("unchecked") + FlowablePublishClassic fp = (FlowablePublishClassic) this; + return RxJavaPlugins.onAssembly( + new FlowablePublishAlt(fp.publishSource(), fp.publishBufferSize()) + ); + } + return this; + } + /** * Returns a {@code Flowable} that stays connected to this {@code ConnectableFlowable} as long as there * is at least one subscription to this {@code ConnectableFlowable}. @@ -89,7 +107,7 @@ public final Disposable connect() { @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.PASS_THROUGH) public Flowable refCount() { - return RxJavaPlugins.onAssembly(new FlowableRefCount(this)); + return RxJavaPlugins.onAssembly(new FlowableRefCount(onRefCount())); } /** @@ -216,7 +234,7 @@ public final Flowable refCount(int subscriberCount, long timeout, TimeUnit un ObjectHelper.verifyPositive(subscriberCount, "subscriberCount"); ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return RxJavaPlugins.onAssembly(new FlowableRefCount(this, subscriberCount, timeout, unit, scheduler)); + return RxJavaPlugins.onAssembly(new FlowableRefCount(onRefCount(), subscriberCount, timeout, unit, scheduler)); } /** diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java index 7ab84a568b..e573f3daf3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java @@ -33,7 +33,8 @@ * manner. * @param the value type */ -public final class FlowablePublish extends ConnectableFlowable implements HasUpstreamPublisher { +public final class FlowablePublish extends ConnectableFlowable +implements HasUpstreamPublisher, FlowablePublishClassic { /** * Indicates this child has been cancelled: the state is swapped in atomically and * will prevent the dispatch() to emit (too many) values to a terminated child subscriber. @@ -77,6 +78,19 @@ public Publisher source() { return source; } + /** + * @return The internal buffer size of this FloawblePublish operator. + */ + @Override + public int publishBufferSize() { + return bufferSize; + } + + @Override + public Publisher publishSource() { + return source; + } + @Override protected void subscribeActual(Subscriber s) { onSubscribe.subscribe(s); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishAlt.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishAlt.java new file mode 100644 index 0000000000..d58ba84503 --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishAlt.java @@ -0,0 +1,483 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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 java.util.concurrent.atomic.*; + +import org.reactivestreams.*; + +import io.reactivex.FlowableSubscriber; +import io.reactivex.disposables.Disposable; +import io.reactivex.exceptions.*; +import io.reactivex.flowables.ConnectableFlowable; +import io.reactivex.functions.Consumer; +import io.reactivex.internal.disposables.ResettableConnectable; +import io.reactivex.internal.fuseable.*; +import io.reactivex.internal.queue.SpscArrayQueue; +import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.internal.util.*; +import io.reactivex.plugins.RxJavaPlugins; + +/** + * Shares a single underlying connection to the upstream Publisher + * and multicasts events to all subscribed subscribers until the upstream + * completes or the connection is disposed. + *

          + * The difference to FlowablePublish is that when the upstream terminates, + * late subscriberss will receive that terminal event until the connection is + * disposed and the ConnectableFlowable is reset to its fresh state. + * + * @param the element type + * @since 2.2.10 + */ +public final class FlowablePublishAlt extends ConnectableFlowable +implements HasUpstreamPublisher, ResettableConnectable { + + final Publisher source; + + final int bufferSize; + + final AtomicReference> current; + + public FlowablePublishAlt(Publisher source, int bufferSize) { + this.source = source; + this.bufferSize = bufferSize; + this.current = new AtomicReference>(); + } + + @Override + public Publisher source() { + return source; + } + + /** + * @return The internal buffer size of this FloawblePublishAlt operator. + */ + public int publishBufferSize() { + return bufferSize; + } + + @Override + public void connect(Consumer connection) { + PublishConnection conn; + boolean doConnect = false; + + for (;;) { + conn = current.get(); + + if (conn == null || conn.isDisposed()) { + PublishConnection fresh = new PublishConnection(current, bufferSize); + if (!current.compareAndSet(conn, fresh)) { + continue; + } + conn = fresh; + } + + doConnect = !conn.connect.get() && conn.connect.compareAndSet(false, true); + break; + } + + try { + connection.accept(conn); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + throw ExceptionHelper.wrapOrThrow(ex); + } + + if (doConnect) { + source.subscribe(conn); + } + } + + @Override + protected void subscribeActual(Subscriber s) { + PublishConnection conn; + + for (;;) { + conn = current.get(); + + // don't create a fresh connection if the current is disposed + if (conn == null) { + PublishConnection fresh = new PublishConnection(current, bufferSize); + if (!current.compareAndSet(conn, fresh)) { + continue; + } + conn = fresh; + } + + break; + } + + InnerSubscription inner = new InnerSubscription(s, conn); + s.onSubscribe(inner); + + if (conn.add(inner)) { + if (inner.isCancelled()) { + conn.remove(inner); + } else { + conn.drain(); + } + return; + } + + Throwable ex = conn.error; + if (ex != null) { + s.onError(ex); + } else { + s.onComplete(); + } + } + + @SuppressWarnings("unchecked") + @Override + public void resetIf(Disposable connection) { + current.compareAndSet((PublishConnection)connection, null); + } + + static final class PublishConnection + extends AtomicInteger + implements FlowableSubscriber, Disposable { + + private static final long serialVersionUID = -1672047311619175801L; + + final AtomicReference> current; + + final AtomicReference upstream; + + final AtomicBoolean connect; + + final AtomicReference[]> subscribers; + + final int bufferSize; + + volatile SimpleQueue queue; + + int sourceMode; + + volatile boolean done; + Throwable error; + + int consumed; + + @SuppressWarnings("rawtypes") + static final InnerSubscription[] EMPTY = new InnerSubscription[0]; + @SuppressWarnings("rawtypes") + static final InnerSubscription[] TERMINATED = new InnerSubscription[0]; + + @SuppressWarnings("unchecked") + PublishConnection(AtomicReference> current, int bufferSize) { + this.current = current; + this.upstream = new AtomicReference(); + this.connect = new AtomicBoolean(); + this.bufferSize = bufferSize; + this.subscribers = new AtomicReference[]>(EMPTY); + } + + @SuppressWarnings("unchecked") + @Override + public void dispose() { + subscribers.getAndSet(TERMINATED); + current.compareAndSet(this, null); + SubscriptionHelper.cancel(upstream); + } + + @Override + public boolean isDisposed() { + return subscribers.get() == TERMINATED; + } + + @Override + public void onSubscribe(Subscription s) { + if (SubscriptionHelper.setOnce(this.upstream, s)) { + if (s instanceof QueueSubscription) { + @SuppressWarnings("unchecked") + QueueSubscription qs = (QueueSubscription) s; + + int m = qs.requestFusion(QueueSubscription.ANY | QueueSubscription.BOUNDARY); + if (m == QueueSubscription.SYNC) { + sourceMode = m; + queue = qs; + done = true; + drain(); + return; + } + if (m == QueueSubscription.ASYNC) { + sourceMode = m; + queue = qs; + s.request(bufferSize); + return; + } + } + + queue = new SpscArrayQueue(bufferSize); + + s.request(bufferSize); + } + } + + @Override + public void onNext(T t) { + // we expect upstream to honor backpressure requests + if (sourceMode == QueueSubscription.NONE && !queue.offer(t)) { + onError(new MissingBackpressureException("Prefetch queue is full?!")); + return; + } + // since many things can happen concurrently, we have a common dispatch + // loop to act on the current state serially + drain(); + } + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + } else { + error = t; + done = true; + drain(); + } + } + + @Override + public void onComplete() { + done = true; + drain(); + } + + void drain() { + if (getAndIncrement() != 0) { + return; + } + + int missed = 1; + SimpleQueue queue = this.queue; + int consumed = this.consumed; + int limit = this.bufferSize - (this.bufferSize >> 2); + boolean async = this.sourceMode != QueueSubscription.SYNC; + + outer: + for (;;) { + if (queue != null) { + long minDemand = Long.MAX_VALUE; + boolean hasDemand = false; + + InnerSubscription[] innerSubscriptions = subscribers.get(); + + for (InnerSubscription inner : innerSubscriptions) { + long request = inner.get(); + if (request != Long.MIN_VALUE) { + hasDemand = true; + minDemand = Math.min(request - inner.emitted, minDemand); + } + } + + if (!hasDemand) { + minDemand = 0L; + } + + while (minDemand != 0L) { + boolean d = done; + T v; + + try { + v = queue.poll(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + upstream.get().cancel(); + queue.clear(); + done = true; + signalError(ex); + return; + } + + boolean empty = v == null; + + if (checkTerminated(d, empty)) { + return; + } + + if (empty) { + break; + } + + for (InnerSubscription inner : innerSubscriptions) { + if (!inner.isCancelled()) { + inner.downstream.onNext(v); + inner.emitted++; + } + } + + if (async && ++consumed == limit) { + consumed = 0; + upstream.get().request(limit); + } + minDemand--; + + if (innerSubscriptions != subscribers.get()) { + continue outer; + } + } + + if (checkTerminated(done, queue.isEmpty())) { + return; + } + } + + this.consumed = consumed; + missed = addAndGet(-missed); + if (missed == 0) { + break; + } + if (queue == null) { + queue = this.queue; + } + } + } + + @SuppressWarnings("unchecked") + boolean checkTerminated(boolean isDone, boolean isEmpty) { + if (isDone && isEmpty) { + Throwable ex = error; + + if (ex != null) { + signalError(ex); + } else { + for (InnerSubscription inner : subscribers.getAndSet(TERMINATED)) { + if (!inner.isCancelled()) { + inner.downstream.onComplete(); + } + } + } + return true; + } + return false; + } + + @SuppressWarnings("unchecked") + void signalError(Throwable ex) { + for (InnerSubscription inner : subscribers.getAndSet(TERMINATED)) { + if (!inner.isCancelled()) { + inner.downstream.onError(ex); + } + } + } + + boolean add(InnerSubscription inner) { + // the state can change so we do a CAS loop to achieve atomicity + for (;;) { + // get the current producer array + InnerSubscription[] c = subscribers.get(); + // if this subscriber-to-source reached a terminal state by receiving + // an onError or onComplete, just refuse to add the new producer + if (c == TERMINATED) { + return false; + } + // we perform a copy-on-write logic + int len = c.length; + @SuppressWarnings("unchecked") + InnerSubscription[] u = new InnerSubscription[len + 1]; + System.arraycopy(c, 0, u, 0, len); + u[len] = inner; + // try setting the subscribers array + if (subscribers.compareAndSet(c, u)) { + return true; + } + // if failed, some other operation succeeded (another add, remove or termination) + // so retry + } + } + + @SuppressWarnings("unchecked") + void remove(InnerSubscription inner) { + // the state can change so we do a CAS loop to achieve atomicity + for (;;) { + // let's read the current subscribers array + InnerSubscription[] c = subscribers.get(); + int len = c.length; + // if it is either empty or terminated, there is nothing to remove so we quit + if (len == 0) { + break; + } + // let's find the supplied producer in the array + // although this is O(n), we don't expect too many child subscribers in general + int j = -1; + for (int i = 0; i < len; i++) { + if (c[i] == inner) { + j = i; + break; + } + } + // we didn't find it so just quit + if (j < 0) { + return; + } + // we do copy-on-write logic here + InnerSubscription[] u; + // we don't create a new empty array if producer was the single inhabitant + // but rather reuse an empty array + if (len == 1) { + u = EMPTY; + } else { + // otherwise, create a new array one less in size + u = new InnerSubscription[len - 1]; + // copy elements being before the given producer + System.arraycopy(c, 0, u, 0, j); + // copy elements being after the given producer + System.arraycopy(c, j + 1, u, j, len - j - 1); + } + // try setting this new array as + if (subscribers.compareAndSet(c, u)) { + break; + } + // if we failed, it means something else happened + // (a concurrent add/remove or termination), we need to retry + } + } + } + + static final class InnerSubscription extends AtomicLong + implements Subscription { + + private static final long serialVersionUID = 2845000326761540265L; + + final Subscriber downstream; + + final PublishConnection parent; + + long emitted; + + InnerSubscription(Subscriber downstream, PublishConnection parent) { + this.downstream = downstream; + this.parent = parent; + } + + @Override + public void request(long n) { + BackpressureHelper.addCancel(this, n); + parent.drain(); + } + + @Override + public void cancel() { + if (getAndSet(Long.MIN_VALUE) != Long.MIN_VALUE) { + parent.remove(this); + parent.drain(); + } + } + + public boolean isCancelled() { + return get() == Long.MIN_VALUE; + } + } +} diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishClassic.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishClassic.java new file mode 100644 index 0000000000..0cbf70efad --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishClassic.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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 org.reactivestreams.Publisher; + +/** + * Interface to mark classic publish() operators to + * indicate refCount() should replace them with the Alt + * implementation. + *

          + * Without this, hooking the connectables with an intercept + * implementation would result in the unintended lack + * or presense of the replacement by refCount(). + * + * @param the element type of the sequence + * @since 2.2.10 + */ +public interface FlowablePublishClassic { + + /** + * @return the upstream source of this publish operator + */ + Publisher publishSource(); + + /** + * @return the internal buffer size of this publish operator + */ + int publishBufferSize(); +} diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java index debc37875b..04b90506c3 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java @@ -30,7 +30,8 @@ * manner. * @param the value type */ -public final class ObservablePublish extends ConnectableObservable implements HasUpstreamObservableSource { +public final class ObservablePublish extends ConnectableObservable +implements HasUpstreamObservableSource, ObservablePublishClassic { /** The source observable. */ final ObservableSource source; /** Holds the current subscriber that is, will be or just was subscribed to the source observable. */ @@ -63,6 +64,11 @@ public ObservableSource source() { return source; } + @Override + public ObservableSource publishSource() { + return source; + } + @Override protected void subscribeActual(Observer observer) { onSubscribe.subscribe(observer); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishAlt.java b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishAlt.java new file mode 100644 index 0000000000..771e58dda8 --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishAlt.java @@ -0,0 +1,282 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.observable; + +import java.util.concurrent.atomic.*; + +import io.reactivex.*; +import io.reactivex.disposables.Disposable; +import io.reactivex.exceptions.Exceptions; +import io.reactivex.functions.Consumer; +import io.reactivex.internal.disposables.*; +import io.reactivex.internal.fuseable.HasUpstreamObservableSource; +import io.reactivex.internal.util.ExceptionHelper; +import io.reactivex.observables.ConnectableObservable; + +/** + * Shares a single underlying connection to the upstream ObservableSource + * and multicasts events to all subscribed observers until the upstream + * completes or the connection is disposed. + *

          + * The difference to ObservablePublish is that when the upstream terminates, + * late observers will receive that terminal event until the connection is + * disposed and the ConnectableObservable is reset to its fresh state. + * + * @param the element type + * @since 2.2.10 + */ +public final class ObservablePublishAlt extends ConnectableObservable +implements HasUpstreamObservableSource, ResettableConnectable { + + final ObservableSource source; + + final AtomicReference> current; + + public ObservablePublishAlt(ObservableSource source) { + this.source = source; + this.current = new AtomicReference>(); + } + + @Override + public void connect(Consumer connection) { + boolean doConnect = false; + PublishConnection conn; + + for (;;) { + conn = current.get(); + + if (conn == null || conn.isDisposed()) { + PublishConnection fresh = new PublishConnection(current); + if (!current.compareAndSet(conn, fresh)) { + continue; + } + conn = fresh; + } + + doConnect = !conn.connect.get() && conn.connect.compareAndSet(false, true); + break; + } + + try { + connection.accept(conn); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + throw ExceptionHelper.wrapOrThrow(ex); + } + + if (doConnect) { + source.subscribe(conn); + } + } + + @Override + protected void subscribeActual(Observer observer) { + PublishConnection conn; + + for (;;) { + conn = current.get(); + // we don't create a fresh connection if the current is terminated + if (conn == null) { + PublishConnection fresh = new PublishConnection(current); + if (!current.compareAndSet(conn, fresh)) { + continue; + } + conn = fresh; + } + break; + } + + InnerDisposable inner = new InnerDisposable(observer, conn); + observer.onSubscribe(inner); + if (conn.add(inner)) { + if (inner.isDisposed()) { + conn.remove(inner); + } + return; + } + // Late observers will be simply terminated + Throwable error = conn.error; + if (error != null) { + observer.onError(error); + } else { + observer.onComplete(); + } + } + + @Override + @SuppressWarnings("unchecked") + public void resetIf(Disposable connection) { + current.compareAndSet((PublishConnection)connection, null); + } + + @Override + public ObservableSource source() { + return source; + } + + static final class PublishConnection + extends AtomicReference[]> + implements Observer, Disposable { + + private static final long serialVersionUID = -3251430252873581268L; + + final AtomicBoolean connect; + + final AtomicReference> current; + + final AtomicReference upstream; + + @SuppressWarnings("rawtypes") + static final InnerDisposable[] EMPTY = new InnerDisposable[0]; + + @SuppressWarnings("rawtypes") + static final InnerDisposable[] TERMINATED = new InnerDisposable[0]; + + Throwable error; + + @SuppressWarnings("unchecked") + public PublishConnection(AtomicReference> current) { + this.connect = new AtomicBoolean(); + this.current = current; + this.upstream = new AtomicReference(); + lazySet(EMPTY); + } + + @SuppressWarnings("unchecked") + @Override + public void dispose() { + getAndSet(TERMINATED); + current.compareAndSet(this, null); + DisposableHelper.dispose(upstream); + } + + @Override + public boolean isDisposed() { + return get() == TERMINATED; + } + + @Override + public void onSubscribe(Disposable d) { + DisposableHelper.setOnce(upstream, d); + } + + @Override + public void onNext(T t) { + for (InnerDisposable inner : get()) { + inner.downstream.onNext(t); + } + } + + @Override + @SuppressWarnings("unchecked") + public void onError(Throwable e) { + error = e; + upstream.lazySet(DisposableHelper.DISPOSED); + for (InnerDisposable inner : getAndSet(TERMINATED)) { + inner.downstream.onError(e); + } + } + + @Override + @SuppressWarnings("unchecked") + public void onComplete() { + upstream.lazySet(DisposableHelper.DISPOSED); + for (InnerDisposable inner : getAndSet(TERMINATED)) { + inner.downstream.onComplete(); + } + } + + public boolean add(InnerDisposable inner) { + for (;;) { + InnerDisposable[] a = get(); + if (a == TERMINATED) { + return false; + } + int n = a.length; + @SuppressWarnings("unchecked") + InnerDisposable[] b = new InnerDisposable[n + 1]; + System.arraycopy(a, 0, b, 0, n); + b[n] = inner; + if (compareAndSet(a, b)) { + return true; + } + } + } + + @SuppressWarnings("unchecked") + public void remove(InnerDisposable inner) { + for (;;) { + InnerDisposable[] a = get(); + int n = a.length; + if (n == 0) { + return; + } + + int j = -1; + for (int i = 0; i < n; i++) { + if (a[i] == inner) { + j = i; + break; + } + } + + if (j < 0) { + return; + } + InnerDisposable[] b = EMPTY; + if (n != 1) { + b = new InnerDisposable[n - 1]; + System.arraycopy(a, 0, b, 0, j); + System.arraycopy(a, j + 1, b, j, n - j - 1); + } + if (compareAndSet(a, b)) { + return; + } + } + } + } + + /** + * Intercepts the dispose signal from the downstream and + * removes itself from the connection's observers array + * at most once. + * @param the element type + */ + static final class InnerDisposable + extends AtomicReference> + implements Disposable { + + private static final long serialVersionUID = 7463222674719692880L; + + final Observer downstream; + + public InnerDisposable(Observer downstream, PublishConnection parent) { + this.downstream = downstream; + lazySet(parent); + } + + @Override + public void dispose() { + PublishConnection p = getAndSet(null); + if (p != null) { + p.remove(this); + } + } + + @Override + public boolean isDisposed() { + return get() == null; + } + } +} diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishClassic.java b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishClassic.java new file mode 100644 index 0000000000..f072779930 --- /dev/null +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishClassic.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.observable; + +import io.reactivex.ObservableSource; + +/** + * Interface to mark classic publish() operators to + * indicate refCount() should replace them with the Alt + * implementation. + *

          + * Without this, hooking the connectables with an intercept + * implementation would result in the unintended lack + * or presense of the replacement by refCount(). + * + * @param the element type of the sequence + * @since 2.2.10 + */ +public interface ObservablePublishClassic { + + /** + * @return the upstream source of this publish operator + */ + ObservableSource publishSource(); +} diff --git a/src/main/java/io/reactivex/observables/ConnectableObservable.java b/src/main/java/io/reactivex/observables/ConnectableObservable.java index b5e54054b1..09fa70899e 100644 --- a/src/main/java/io/reactivex/observables/ConnectableObservable.java +++ b/src/main/java/io/reactivex/observables/ConnectableObservable.java @@ -66,6 +66,23 @@ public final Disposable connect() { return cc.disposable; } + /** + * Apply a workaround for a race condition with the regular publish().refCount() + * so that racing observers and refCount won't hang. + * + * @return the ConnectableObservable to work with + * @since 2.2.10 + */ + @SuppressWarnings("unchecked") + private ConnectableObservable onRefCount() { + if (this instanceof ObservablePublishClassic) { + return RxJavaPlugins.onAssembly( + new ObservablePublishAlt(((ObservablePublishClassic)this).publishSource()) + ); + } + return this; + } + /** * Returns an {@code Observable} that stays connected to this {@code ConnectableObservable} as long as there * is at least one subscription to this {@code ConnectableObservable}. @@ -83,7 +100,7 @@ public final Disposable connect() { @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public Observable refCount() { - return RxJavaPlugins.onAssembly(new ObservableRefCount(this)); + return RxJavaPlugins.onAssembly(new ObservableRefCount(onRefCount())); } /** @@ -190,7 +207,7 @@ public final Observable refCount(int subscriberCount, long timeout, TimeUnit ObjectHelper.verifyPositive(subscriberCount, "subscriberCount"); ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return RxJavaPlugins.onAssembly(new ObservableRefCount(this, subscriberCount, timeout, unit, scheduler)); + return RxJavaPlugins.onAssembly(new ObservableRefCount(onRefCount(), subscriberCount, timeout, unit, scheduler)); } /** diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishAltTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishAltTest.java new file mode 100644 index 0000000000..414aa79c07 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishAltTest.java @@ -0,0 +1,1629 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.junit.Assert.*; + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import org.junit.*; +import org.reactivestreams.*; + +import io.reactivex.*; +import io.reactivex.disposables.Disposable; +import io.reactivex.exceptions.*; +import io.reactivex.flowables.ConnectableFlowable; +import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.fuseable.HasUpstreamPublisher; +import io.reactivex.internal.operators.flowable.FlowablePublish.*; +import io.reactivex.internal.schedulers.ImmediateThinScheduler; +import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.processors.PublishProcessor; +import io.reactivex.schedulers.*; +import io.reactivex.subscribers.TestSubscriber; + +public class FlowablePublishAltTest { + + @Test + public void testPublish() throws InterruptedException { + final AtomicInteger counter = new AtomicInteger(); + ConnectableFlowable f = Flowable.unsafeCreate(new Publisher() { + + @Override + public void subscribe(final Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + new Thread(new Runnable() { + + @Override + public void run() { + counter.incrementAndGet(); + subscriber.onNext("one"); + subscriber.onComplete(); + } + }).start(); + } + }).publish(); + + final CountDownLatch latch = new CountDownLatch(2); + + // subscribe once + f.subscribe(new Consumer() { + + @Override + public void accept(String v) { + assertEquals("one", v); + latch.countDown(); + } + }); + + // subscribe again + f.subscribe(new Consumer() { + + @Override + public void accept(String v) { + assertEquals("one", v); + latch.countDown(); + } + }); + + Disposable connection = f.connect(); + try { + if (!latch.await(1000, TimeUnit.MILLISECONDS)) { + fail("subscriptions did not receive values"); + } + assertEquals(1, counter.get()); + } finally { + connection.dispose(); + } + } + + @Test + public void testBackpressureFastSlow() { + ConnectableFlowable is = Flowable.range(1, Flowable.bufferSize() * 2).publish(); + Flowable fast = is.observeOn(Schedulers.computation()) + .doOnComplete(new Action() { + @Override + public void run() { + System.out.println("^^^^^^^^^^^^^ completed FAST"); + } + }); + + Flowable slow = is.observeOn(Schedulers.computation()).map(new Function() { + int c; + + @Override + public Integer apply(Integer i) { + if (c == 0) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + } + c++; + return i; + } + + }).doOnComplete(new Action() { + + @Override + public void run() { + System.out.println("^^^^^^^^^^^^^ completed SLOW"); + } + + }); + + TestSubscriber ts = new TestSubscriber(); + Flowable.merge(fast, slow).subscribe(ts); + is.connect(); + ts.awaitTerminalEvent(); + ts.assertNoErrors(); + 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(); + Flowable xs = Flowable.range(0, Flowable.bufferSize() * 2).doOnNext(new Consumer() { + + @Override + public void accept(Integer t1) { + emitted.incrementAndGet(); + } + + }); + TestSubscriber ts = new TestSubscriber(); + xs.publish(new Function, Flowable>() { + + @Override + public Flowable apply(Flowable xs) { + return xs.takeUntil(xs.skipWhile(new Predicate() { + + @Override + public boolean test(Integer i) { + return i <= 3; + } + + })); + } + + }).subscribe(ts); + ts.awaitTerminalEvent(); + ts.assertNoErrors(); + ts.assertValues(0, 1, 2, 3); + assertEquals(5, emitted.get()); + System.out.println(ts.values()); + } + + // use case from https://github.com/ReactiveX/RxJava/issues/1732 + @Test + public void testTakeUntilWithPublishedStream() { + Flowable xs = Flowable.range(0, Flowable.bufferSize() * 2); + TestSubscriber ts = new TestSubscriber(); + ConnectableFlowable xsp = xs.publish(); + xsp.takeUntil(xsp.skipWhile(new Predicate() { + + @Override + public boolean test(Integer i) { + return i <= 3; + } + + })).subscribe(ts); + xsp.connect(); + System.out.println(ts.values()); + } + + @Test(timeout = 10000) + public void testBackpressureTwoConsumers() { + final AtomicInteger sourceEmission = new AtomicInteger(); + final AtomicBoolean sourceUnsubscribed = new AtomicBoolean(); + final Flowable source = Flowable.range(1, 100) + .doOnNext(new Consumer() { + @Override + public void accept(Integer t1) { + sourceEmission.incrementAndGet(); + } + }) + .doOnCancel(new Action() { + @Override + public void run() { + sourceUnsubscribed.set(true); + } + }).share(); + ; + + final AtomicBoolean child1Unsubscribed = new AtomicBoolean(); + final AtomicBoolean child2Unsubscribed = new AtomicBoolean(); + + final TestSubscriber ts2 = new TestSubscriber(); + + final TestSubscriber ts1 = new TestSubscriber() { + @Override + public void onNext(Integer t) { + if (valueCount() == 2) { + source.doOnCancel(new Action() { + @Override + public void run() { + child2Unsubscribed.set(true); + } + }).take(5).subscribe(ts2); + } + super.onNext(t); + } + }; + + source.doOnCancel(new Action() { + @Override + public void run() { + child1Unsubscribed.set(true); + } + }).take(5) + .subscribe(ts1); + + ts1.awaitTerminalEvent(); + ts2.awaitTerminalEvent(); + + ts1.assertNoErrors(); + ts2.assertNoErrors(); + + assertTrue(sourceUnsubscribed.get()); + assertTrue(child1Unsubscribed.get()); + assertTrue(child2Unsubscribed.get()); + + ts1.assertValues(1, 2, 3, 4, 5); + ts2.assertValues(4, 5, 6, 7, 8); + + assertEquals(8, sourceEmission.get()); + } + + @Test + public void testConnectWithNoSubscriber() { + TestScheduler scheduler = new TestScheduler(); + ConnectableFlowable cf = Flowable.interval(10, 10, TimeUnit.MILLISECONDS, scheduler).take(3).publish(); + cf.connect(); + // Emit 0 + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + TestSubscriber subscriber = new TestSubscriber(); + cf.subscribe(subscriber); + // Emit 1 and 2 + scheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS); + subscriber.assertValues(1L, 2L); + subscriber.assertNoErrors(); + subscriber.assertTerminated(); + } + + @Test + public void testSubscribeAfterDisconnectThenConnect() { + ConnectableFlowable source = Flowable.just(1).publish(); + + TestSubscriber ts1 = new TestSubscriber(); + + source.subscribe(ts1); + + Disposable connection = source.connect(); + + ts1.assertValue(1); + ts1.assertNoErrors(); + ts1.assertTerminated(); + + TestSubscriber ts2 = new TestSubscriber(); + + source.subscribe(ts2); + + Disposable connection2 = source.connect(); + + ts2.assertValue(1); + ts2.assertNoErrors(); + ts2.assertTerminated(); + + System.out.println(connection); + System.out.println(connection2); + } + + @Test + public void testNoSubscriberRetentionOnCompleted() { + FlowablePublish source = (FlowablePublish)Flowable.just(1).publish(); + + TestSubscriber ts1 = new TestSubscriber(); + + source.subscribe(ts1); + + ts1.assertNoValues(); + ts1.assertNoErrors(); + ts1.assertNotComplete(); + + source.connect(); + + ts1.assertValue(1); + ts1.assertNoErrors(); + ts1.assertTerminated(); + + assertNull(source.current.get()); + } + + @Test + public void testNonNullConnection() { + ConnectableFlowable source = Flowable.never().publish(); + + assertNotNull(source.connect()); + assertNotNull(source.connect()); + } + + @Test + public void testNoDisconnectSomeoneElse() { + ConnectableFlowable source = Flowable.never().publish(); + + Disposable connection1 = source.connect(); + Disposable connection2 = source.connect(); + + connection1.dispose(); + + Disposable connection3 = source.connect(); + + connection2.dispose(); + + assertTrue(checkPublishDisposed(connection1)); + assertTrue(checkPublishDisposed(connection2)); + assertFalse(checkPublishDisposed(connection3)); + } + + @SuppressWarnings("unchecked") + static boolean checkPublishDisposed(Disposable d) { + return ((FlowablePublish.PublishSubscriber)d).isDisposed(); + } + + @Test + public void testZeroRequested() { + ConnectableFlowable source = Flowable.just(1).publish(); + + TestSubscriber ts = new TestSubscriber(0L); + + source.subscribe(ts); + + ts.assertNoValues(); + ts.assertNoErrors(); + ts.assertNotComplete(); + + source.connect(); + + ts.assertNoValues(); + ts.assertNoErrors(); + ts.assertNotComplete(); + + ts.request(5); + + ts.assertValue(1); + ts.assertNoErrors(); + ts.assertTerminated(); + } + + @Test + public void testConnectIsIdempotent() { + final AtomicInteger calls = new AtomicInteger(); + Flowable source = Flowable.unsafeCreate(new Publisher() { + @Override + public void subscribe(Subscriber t) { + t.onSubscribe(new BooleanSubscription()); + calls.getAndIncrement(); + } + }); + + ConnectableFlowable conn = source.publish(); + + assertEquals(0, calls.get()); + + conn.connect(); + conn.connect(); + + assertEquals(1, calls.get()); + + conn.connect().dispose(); + + conn.connect(); + conn.connect(); + + assertEquals(2, calls.get()); + } + + @Test + public void syncFusedObserveOn() { + ConnectableFlowable cf = Flowable.range(0, 1000).publish(); + Flowable obs = cf.observeOn(Schedulers.computation()); + for (int i = 0; i < 1000; i++) { + for (int j = 1; j < 6; j++) { + List> tss = new ArrayList>(); + for (int k = 1; k < j; k++) { + TestSubscriber ts = new TestSubscriber(); + tss.add(ts); + obs.subscribe(ts); + } + + Disposable connection = cf.connect(); + + for (TestSubscriber ts : tss) { + ts.awaitDone(5, TimeUnit.SECONDS) + .assertSubscribed() + .assertValueCount(1000) + .assertNoErrors() + .assertComplete(); + } + connection.dispose(); + } + } + } + + @Test + public void syncFusedObserveOn2() { + ConnectableFlowable cf = Flowable.range(0, 1000).publish(); + Flowable obs = cf.observeOn(ImmediateThinScheduler.INSTANCE); + for (int i = 0; i < 1000; i++) { + for (int j = 1; j < 6; j++) { + List> tss = new ArrayList>(); + for (int k = 1; k < j; k++) { + TestSubscriber ts = new TestSubscriber(); + tss.add(ts); + obs.subscribe(ts); + } + + Disposable connection = cf.connect(); + + for (TestSubscriber ts : tss) { + ts.awaitDone(5, TimeUnit.SECONDS) + .assertSubscribed() + .assertValueCount(1000) + .assertNoErrors() + .assertComplete(); + } + connection.dispose(); + } + } + } + + @Test + public void asyncFusedObserveOn() { + ConnectableFlowable cf = Flowable.range(0, 1000).observeOn(ImmediateThinScheduler.INSTANCE).publish(); + for (int i = 0; i < 1000; i++) { + for (int j = 1; j < 6; j++) { + List> tss = new ArrayList>(); + for (int k = 1; k < j; k++) { + TestSubscriber ts = new TestSubscriber(); + tss.add(ts); + cf.subscribe(ts); + } + + Disposable connection = cf.connect(); + + for (TestSubscriber ts : tss) { + ts.awaitDone(5, TimeUnit.SECONDS) + .assertSubscribed() + .assertValueCount(1000) + .assertNoErrors() + .assertComplete(); + } + connection.dispose(); + } + } + } + + @Test + public void testObserveOn() { + ConnectableFlowable cf = Flowable.range(0, 1000).hide().publish(); + Flowable obs = cf.observeOn(Schedulers.computation()); + for (int i = 0; i < 1000; i++) { + for (int j = 1; j < 6; j++) { + List> tss = new ArrayList>(); + for (int k = 1; k < j; k++) { + TestSubscriber ts = new TestSubscriber(); + tss.add(ts); + obs.subscribe(ts); + } + + Disposable connection = cf.connect(); + + for (TestSubscriber ts : tss) { + ts.awaitDone(5, TimeUnit.SECONDS) + .assertSubscribed() + .assertValueCount(1000) + .assertNoErrors() + .assertComplete(); + } + connection.dispose(); + } + } + } + + @Test + public void source() { + Flowable f = Flowable.never(); + + assertSame(f, (((HasUpstreamPublisher)f.publish()).source())); + } + + @Test + public void connectThrows() { + ConnectableFlowable cf = Flowable.empty().publish(); + try { + cf.connect(new Consumer() { + @Override + public void accept(Disposable d) throws Exception { + throw new TestException(); + } + }); + } catch (TestException ex) { + // expected + } + } + + @Test + public void addRemoveRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final ConnectableFlowable cf = Flowable.empty().publish(); + + final TestSubscriber ts = cf.test(); + + final TestSubscriber ts2 = new TestSubscriber(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + cf.subscribe(ts2); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + ts.cancel(); + } + }; + + TestHelper.race(r1, r2); + } + } + + @Test + public void disposeOnArrival() { + ConnectableFlowable cf = Flowable.empty().publish(); + + cf.test(Long.MAX_VALUE, true).assertEmpty(); + } + + @Test + public void disposeOnArrival2() { + Flowable co = Flowable.never().publish().autoConnect(); + + co.test(Long.MAX_VALUE, true).assertEmpty(); + } + + @Test + public void dispose() { + TestHelper.checkDisposed(Flowable.never().publish()); + + TestHelper.checkDisposed(Flowable.never().publish(Functions.>identity())); + } + + @Test + public void empty() { + ConnectableFlowable cf = Flowable.empty().publish(); + + cf.connect(); + } + + @Test + public void take() { + ConnectableFlowable cf = Flowable.range(1, 2).publish(); + + TestSubscriber ts = cf.take(1).test(); + + cf.connect(); + + ts.assertResult(1); + } + + @Test + public void just() { + final PublishProcessor pp = PublishProcessor.create(); + + ConnectableFlowable cf = pp.publish(); + + TestSubscriber ts = new TestSubscriber() { + @Override + public void onNext(Integer t) { + super.onNext(t); + pp.onComplete(); + } + }; + + cf.subscribe(ts); + cf.connect(); + + pp.onNext(1); + + ts.assertResult(1); + } + + @Test + public void nextCancelRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final PublishProcessor pp = PublishProcessor.create(); + + final ConnectableFlowable cf = pp.publish(); + + final TestSubscriber ts = cf.test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + pp.onNext(1); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + ts.cancel(); + } + }; + + TestHelper.race(r1, r2); + } + } + + @Test + public void badSource() { + List errors = TestHelper.trackPluginErrors(); + try { + new Flowable() { + @Override + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext(1); + subscriber.onComplete(); + subscriber.onNext(2); + subscriber.onError(new TestException()); + subscriber.onComplete(); + } + } + .publish() + .autoConnect() + .test() + .assertResult(1); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void noErrorLoss() { + List errors = TestHelper.trackPluginErrors(); + try { + ConnectableFlowable cf = Flowable.error(new TestException()).publish(); + + cf.connect(); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void subscribeDisconnectRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final PublishProcessor pp = PublishProcessor.create(); + + final ConnectableFlowable cf = pp.publish(); + + final Disposable d = cf.connect(); + final TestSubscriber ts = new TestSubscriber(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + d.dispose(); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + cf.subscribe(ts); + } + }; + + TestHelper.race(r1, r2); + } + } + + @Test + public void selectorDisconnectsIndependentSource() { + PublishProcessor pp = PublishProcessor.create(); + + pp.publish(new Function, Flowable>() { + @Override + public Flowable apply(Flowable v) throws Exception { + return Flowable.range(1, 2); + } + }) + .test() + .assertResult(1, 2); + + assertFalse(pp.hasSubscribers()); + } + + @Test(timeout = 5000) + public void selectorLatecommer() { + Flowable.range(1, 5) + .publish(new Function, Flowable>() { + @Override + public Flowable apply(Flowable v) throws Exception { + return v.concatWith(v); + } + }) + .test() + .assertResult(1, 2, 3, 4, 5); + } + + @Test + public void mainError() { + Flowable.error(new TestException()) + .publish(Functions.>identity()) + .test() + .assertFailure(TestException.class); + } + + @Test + public void selectorInnerError() { + PublishProcessor pp = PublishProcessor.create(); + + pp.publish(new Function, Flowable>() { + @Override + public Flowable apply(Flowable v) throws Exception { + return Flowable.error(new TestException()); + } + }) + .test() + .assertFailure(TestException.class); + + assertFalse(pp.hasSubscribers()); + } + + @Test + public void preNextConnect() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final ConnectableFlowable cf = Flowable.empty().publish(); + + cf.connect(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + cf.test(); + } + }; + + TestHelper.race(r1, r1); + } + } + + @Test + public void connectRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final ConnectableFlowable cf = Flowable.empty().publish(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + cf.connect(); + } + }; + + TestHelper.race(r1, r1); + } + } + + @Test + public void selectorCrash() { + Flowable.just(1).publish(new Function, Flowable>() { + @Override + public Flowable apply(Flowable v) throws Exception { + throw new TestException(); + } + }) + .test() + .assertFailure(TestException.class); + } + + @Test + public void pollThrows() { + Flowable.just(1) + .map(new Function() { + @Override + public Object apply(Integer v) throws Exception { + throw new TestException(); + } + }) + .compose(TestHelper.flowableStripBoundary()) + .publish() + .autoConnect() + .test() + .assertFailure(TestException.class); + } + + @Test + public void pollThrowsNoSubscribers() { + ConnectableFlowable cf = Flowable.just(1, 2) + .map(new Function() { + @Override + public Integer apply(Integer v) throws Exception { + if (v == 2) { + throw new TestException(); + } + return v; + } + }) + .compose(TestHelper.flowableStripBoundary()) + .publish(); + + TestSubscriber ts = cf.take(1) + .test(); + + cf.connect(); + + ts.assertResult(1); + } + + @Test + public void dryRunCrash() { + List errors = TestHelper.trackPluginErrors(); + try { + final TestSubscriber ts = new TestSubscriber(1L) { + @Override + public void onNext(Object t) { + super.onNext(t); + onComplete(); + cancel(); + } + }; + + Flowable.range(1, 10) + .map(new Function() { + @Override + public Object apply(Integer v) throws Exception { + if (v == 2) { + throw new TestException(); + } + return v; + } + }) + .publish() + .autoConnect() + .subscribe(ts); + + ts + .assertResult(1); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void overflowQueue() { + List errors = TestHelper.trackPluginErrors(); + try { + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter s) throws Exception { + for (int i = 0; i < 10; i++) { + s.onNext(i); + } + } + }, BackpressureStrategy.MISSING) + .publish(8) + .autoConnect() + .test(0L) + .assertFailure(MissingBackpressureException.class); + + TestHelper.assertError(errors, 0, MissingBackpressureException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void delayedUpstreamOnSubscribe() { + final Subscriber[] sub = { null }; + + new Flowable() { + @Override + protected void subscribeActual(Subscriber s) { + sub[0] = s; + } + } + .publish() + .connect() + .dispose(); + + BooleanSubscription bs = new BooleanSubscription(); + + sub[0].onSubscribe(bs); + + assertTrue(bs.isCancelled()); + } + + @Test + public void disposeRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final AtomicReference ref = new AtomicReference(); + + final ConnectableFlowable cf = new Flowable() { + @Override + protected void subscribeActual(Subscriber s) { + s.onSubscribe(new BooleanSubscription()); + ref.set((Disposable)s); + } + }.publish(); + + cf.connect(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + ref.get().dispose(); + } + }; + + TestHelper.race(r1, r1); + } + } + + @Test + public void removeNotPresent() { + final AtomicReference> ref = new AtomicReference>(); + + final ConnectableFlowable cf = new Flowable() { + @Override + @SuppressWarnings("unchecked") + protected void subscribeActual(Subscriber s) { + s.onSubscribe(new BooleanSubscription()); + ref.set((PublishSubscriber)s); + } + }.publish(); + + cf.connect(); + + ref.get().add(new InnerSubscriber(new TestSubscriber())); + ref.get().remove(null); + } + + @Test + @Ignore("publish() keeps consuming the upstream if there are no subscribers, 3.x should change this") + public void subscriberSwap() { + final ConnectableFlowable cf = Flowable.range(1, 5).publish(); + + cf.connect(); + + TestSubscriber ts1 = new TestSubscriber() { + @Override + public void onNext(Integer t) { + super.onNext(t); + cancel(); + onComplete(); + } + }; + + cf.subscribe(ts1); + + ts1.assertResult(1); + + TestSubscriber ts2 = new TestSubscriber(0); + cf.subscribe(ts2); + + ts2 + .assertEmpty() + .requestMore(4) + .assertResult(2, 3, 4, 5); + } + + @Test + public void subscriberLiveSwap() { + final ConnectableFlowable cf = new FlowablePublishAlt(Flowable.range(1, 5), 128); + + final TestSubscriber ts2 = new TestSubscriber(0); + + TestSubscriber ts1 = new TestSubscriber() { + @Override + public void onNext(Integer t) { + super.onNext(t); + cancel(); + onComplete(); + cf.subscribe(ts2); + } + }; + + cf.subscribe(ts1); + + cf.connect(); + + ts1.assertResult(1); + + ts2 + .assertEmpty() + .requestMore(4) + .assertResult(2, 3, 4, 5); + } + + @Test + public void selectorSubscriberSwap() { + final AtomicReference> ref = new AtomicReference>(); + + Flowable.range(1, 5).publish(new Function, Publisher>() { + @Override + public Publisher apply(Flowable f) throws Exception { + ref.set(f); + return Flowable.never(); + } + }).test(); + + ref.get().take(2).test().assertResult(1, 2); + + ref.get() + .test(0) + .assertEmpty() + .requestMore(2) + .assertValuesOnly(3, 4) + .requestMore(1) + .assertResult(3, 4, 5); + } + + @Test + public void leavingSubscriberOverrequests() { + final AtomicReference> ref = new AtomicReference>(); + + PublishProcessor pp = PublishProcessor.create(); + + pp.publish(new Function, Publisher>() { + @Override + public Publisher apply(Flowable f) throws Exception { + ref.set(f); + return Flowable.never(); + } + }).test(); + + TestSubscriber ts1 = ref.get().take(2).test(); + + pp.onNext(1); + pp.onNext(2); + + ts1.assertResult(1, 2); + + pp.onNext(3); + pp.onNext(4); + + TestSubscriber ts2 = ref.get().test(0L); + + ts2.assertEmpty(); + + ts2.requestMore(2); + + ts2.assertValuesOnly(3, 4); + } + + // call a transformer only if the input is non-empty + @Test + public void composeIfNotEmpty() { + final FlowableTransformer transformer = new FlowableTransformer() { + @Override + public Publisher apply(Flowable g) { + return g.map(new Function() { + @Override + public Integer apply(Integer v) throws Exception { + return v + 1; + } + }); + } + }; + + final AtomicInteger calls = new AtomicInteger(); + Flowable.range(1, 5) + .publish(new Function, Publisher>() { + @Override + public Publisher apply(final Flowable shared) + throws Exception { + return shared.take(1).concatMap(new Function>() { + @Override + public Publisher apply(Integer first) + throws Exception { + calls.incrementAndGet(); + return transformer.apply(Flowable.just(first).concatWith(shared)); + } + }); + } + }) + .test() + .assertResult(2, 3, 4, 5, 6); + + assertEquals(1, calls.get()); + } + + // call a transformer only if the input is non-empty + @Test + public void composeIfNotEmptyNotFused() { + final FlowableTransformer transformer = new FlowableTransformer() { + @Override + public Publisher apply(Flowable g) { + return g.map(new Function() { + @Override + public Integer apply(Integer v) throws Exception { + return v + 1; + } + }); + } + }; + + final AtomicInteger calls = new AtomicInteger(); + Flowable.range(1, 5).hide() + .publish(new Function, Publisher>() { + @Override + public Publisher apply(final Flowable shared) + throws Exception { + return shared.take(1).concatMap(new Function>() { + @Override + public Publisher apply(Integer first) + throws Exception { + calls.incrementAndGet(); + return transformer.apply(Flowable.just(first).concatWith(shared)); + } + }); + } + }) + .test() + .assertResult(2, 3, 4, 5, 6); + + assertEquals(1, calls.get()); + } + + // call a transformer only if the input is non-empty + @Test + public void composeIfNotEmptyIsEmpty() { + final FlowableTransformer transformer = new FlowableTransformer() { + @Override + public Publisher apply(Flowable g) { + return g.map(new Function() { + @Override + public Integer apply(Integer v) throws Exception { + return v + 1; + } + }); + } + }; + + final AtomicInteger calls = new AtomicInteger(); + Flowable.empty().hide() + .publish(new Function, Publisher>() { + @Override + public Publisher apply(final Flowable shared) + throws Exception { + return shared.take(1).concatMap(new Function>() { + @Override + public Publisher apply(Integer first) + throws Exception { + calls.incrementAndGet(); + return transformer.apply(Flowable.just(first).concatWith(shared)); + } + }); + } + }) + .test() + .assertResult(); + + assertEquals(0, calls.get()); + } + + @Test + public void publishFunctionCancelOuterAfterOneInner() { + final AtomicReference> ref = new AtomicReference>(); + + PublishProcessor pp = PublishProcessor.create(); + + final TestSubscriber ts = pp.publish(new Function, Publisher>() { + @Override + public Publisher apply(Flowable f) throws Exception { + ref.set(f); + return Flowable.never(); + } + }).test(); + + ref.get().subscribe(new TestSubscriber() { + @Override + public void onNext(Integer t) { + super.onNext(t); + onComplete(); + ts.cancel(); + } + }); + + pp.onNext(1); + } + + @Test + public void publishFunctionCancelOuterAfterOneInnerBackpressured() { + final AtomicReference> ref = new AtomicReference>(); + + PublishProcessor pp = PublishProcessor.create(); + + final TestSubscriber ts = pp.publish(new Function, Publisher>() { + @Override + public Publisher apply(Flowable f) throws Exception { + ref.set(f); + return Flowable.never(); + } + }).test(); + + ref.get().subscribe(new TestSubscriber(1L) { + @Override + public void onNext(Integer t) { + super.onNext(t); + onComplete(); + ts.cancel(); + } + }); + + pp.onNext(1); + } + + @Test + public void publishCancelOneAsync() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + + final PublishProcessor pp = PublishProcessor.create(); + + final AtomicReference> ref = new AtomicReference>(); + + pp.publish(new Function, Publisher>() { + @Override + public Publisher apply(Flowable f) throws Exception { + ref.set(f); + return Flowable.never(); + } + }).test(); + + final TestSubscriber ts1 = ref.get().test(); + TestSubscriber ts2 = ref.get().test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + pp.onNext(1); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + ts1.cancel(); + } + }; + + TestHelper.race(r1, r2); + + ts2.assertValuesOnly(1); + } + } + + @Test + public void publishCancelOneAsync2() { + final PublishProcessor pp = PublishProcessor.create(); + + ConnectableFlowable cf = pp.publish(); + + final TestSubscriber ts1 = new TestSubscriber(); + + final AtomicReference> ref = new AtomicReference>(); + + cf.subscribe(new FlowableSubscriber() { + @SuppressWarnings("unchecked") + @Override + public void onSubscribe(Subscription s) { + ts1.onSubscribe(new BooleanSubscription()); + // pretend to be cancelled without removing it from the subscriber list + ref.set((InnerSubscriber)s); + } + + @Override + public void onNext(Integer t) { + ts1.onNext(t); + } + + @Override + public void onError(Throwable t) { + ts1.onError(t); + } + + @Override + public void onComplete() { + ts1.onComplete(); + } + }); + TestSubscriber ts2 = cf.test(); + + cf.connect(); + + ref.get().set(Long.MIN_VALUE); + + pp.onNext(1); + + ts1.assertEmpty(); + ts2.assertValuesOnly(1); + } + + @Test + public void boundaryFusion() { + Flowable.range(1, 10000) + .observeOn(Schedulers.single()) + .map(new Function() { + @Override + public String apply(Integer t) throws Exception { + String name = Thread.currentThread().getName(); + if (name.contains("RxSingleScheduler")) { + return "RxSingleScheduler"; + } + return name; + } + }) + .share() + .observeOn(Schedulers.computation()) + .distinct() + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult("RxSingleScheduler"); + } + + @Test + public void badRequest() { + TestHelper.assertBadRequestReported(Flowable.range(1, 5).publish()); + } + + @Test + @SuppressWarnings("unchecked") + public void splitCombineSubscriberChangeAfterOnNext() { + Flowable source = Flowable.range(0, 20) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription v) throws Exception { + System.out.println("Subscribed"); + } + }) + .publish(10) + .refCount() + ; + + Flowable evenNumbers = source.filter(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return v % 2 == 0; + } + }); + + Flowable oddNumbers = source.filter(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return v % 2 != 0; + } + }); + + final Single getNextOdd = oddNumbers.first(0); + + TestSubscriber> ts = evenNumbers.concatMap(new Function>>() { + @Override + public Publisher> apply(Integer v) throws Exception { + return Single.zip( + Single.just(v), getNextOdd, + new BiFunction>() { + @Override + public List apply(Integer a, Integer b) throws Exception { + return Arrays.asList( a, b ); + } + } + ) + .toFlowable(); + } + }) + .takeWhile(new Predicate>() { + @Override + public boolean test(List v) throws Exception { + return v.get(0) < 20; + } + }) + .test(); + + ts + .assertResult( + Arrays.asList(0, 1), + Arrays.asList(2, 3), + Arrays.asList(4, 5), + Arrays.asList(6, 7), + Arrays.asList(8, 9), + Arrays.asList(10, 11), + Arrays.asList(12, 13), + Arrays.asList(14, 15), + Arrays.asList(16, 17), + Arrays.asList(18, 19) + ); + } + + @Test + @SuppressWarnings("unchecked") + public void splitCombineSubscriberChangeAfterOnNextFused() { + Flowable source = Flowable.range(0, 20) + .publish(10) + .refCount() + ; + + Flowable evenNumbers = source.filter(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return v % 2 == 0; + } + }); + + Flowable oddNumbers = source.filter(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return v % 2 != 0; + } + }); + + final Single getNextOdd = oddNumbers.first(0); + + TestSubscriber> ts = evenNumbers.concatMap(new Function>>() { + @Override + public Publisher> apply(Integer v) throws Exception { + return Single.zip( + Single.just(v), getNextOdd, + new BiFunction>() { + @Override + public List apply(Integer a, Integer b) throws Exception { + return Arrays.asList( a, b ); + } + } + ) + .toFlowable(); + } + }) + .takeWhile(new Predicate>() { + @Override + public boolean test(List v) throws Exception { + return v.get(0) < 20; + } + }) + .test(); + + ts + .assertResult( + Arrays.asList(0, 1), + Arrays.asList(2, 3), + Arrays.asList(4, 5), + Arrays.asList(6, 7), + Arrays.asList(8, 9), + Arrays.asList(10, 11), + Arrays.asList(12, 13), + Arrays.asList(14, 15), + Arrays.asList(16, 17), + Arrays.asList(18, 19) + ); + } + + @Test + public void altConnectCrash() { + try { + new FlowablePublishAlt(Flowable.empty(), 128) + .connect(new Consumer() { + @Override + public void accept(Disposable t) throws Exception { + throw new TestException(); + } + }); + fail("Should have thrown"); + } catch (TestException expected) { + // expected + } + } + + @Test + public void altConnectRace() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final ConnectableFlowable cf = + new FlowablePublishAlt(Flowable.never(), 128); + + Runnable r = new Runnable() { + @Override + public void run() { + cf.connect(); + } + }; + + TestHelper.race(r, r); + } + } + + @Test + public void fusedPollCrash() { + Flowable.range(1, 5) + .map(new Function() { + @Override + public Object apply(Integer v) throws Exception { + throw new TestException(); + } + }) + .compose(TestHelper.flowableStripBoundary()) + .publish() + .refCount() + .test() + .assertFailure(TestException.class); + } + + @Test + public void syncFusedNoRequest() { + Flowable.range(1, 5) + .publish(1) + .refCount() + .test() + .assertResult(1, 2, 3, 4, 5); + } + + @Test + public void normalBackpressuredPolls() { + Flowable.range(1, 5) + .hide() + .publish(1) + .refCount() + .test() + .assertResult(1, 2, 3, 4, 5); + } + + @Test + public void emptyHidden() { + Flowable.empty() + .hide() + .publish(1) + .refCount() + .test() + .assertResult(); + } + + @Test + public void emptyFused() { + Flowable.empty() + .publish(1) + .refCount() + .test() + .assertResult(); + } + + @Test + public void overflowQueueRefCount() { + new Flowable() { + @Override + protected void subscribeActual(Subscriber s) { + s.onSubscribe(new BooleanSubscription()); + s.onNext(1); + s.onNext(2); + } + } + .publish(1) + .refCount() + .test(0) + .requestMore(1) + .assertFailure(MissingBackpressureException.class, 1); + } + + @Test + public void doubleErrorRefCount() { + List errors = TestHelper.trackPluginErrors(); + try { + new Flowable() { + @Override + protected void subscribeActual(Subscriber s) { + s.onSubscribe(new BooleanSubscription()); + s.onError(new TestException("one")); + s.onError(new TestException("two")); + } + } + .publish(1) + .refCount() + .test(0) + .assertFailureAndMessage(TestException.class, "one"); + + TestHelper.assertUndeliverable(errors, 0, TestException.class, "two"); + assertEquals(1, errors.size()); + } finally { + RxJavaPlugins.reset(); + } + } +} diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java index eac12749f5..80af00c66f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java @@ -39,6 +39,28 @@ public class FlowablePublishTest { + // This will undo the workaround so that the plain ObservablePublish is still + // tested. + @Before + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void before() { + RxJavaPlugins.setOnConnectableFlowableAssembly(new Function() { + @Override + public ConnectableFlowable apply(ConnectableFlowable co) throws Exception { + if (co instanceof FlowablePublishAlt) { + FlowablePublishAlt fpa = (FlowablePublishAlt) co; + return FlowablePublish.create(Flowable.fromPublisher(fpa.source()), fpa.publishBufferSize()); + } + return co; + } + }); + } + + @After + public void after() { + RxJavaPlugins.setOnConnectableFlowableAssembly(null); + } + @Test public void testPublish() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java new file mode 100644 index 0000000000..e048d47650 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java @@ -0,0 +1,1447 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import org.junit.Test; +import org.mockito.InOrder; +import org.reactivestreams.*; + +import io.reactivex.*; +import io.reactivex.disposables.*; +import io.reactivex.exceptions.*; +import io.reactivex.flowables.ConnectableFlowable; +import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.operators.flowable.FlowableRefCount.RefConnection; +import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.internal.util.ExceptionHelper; +import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.processors.*; +import io.reactivex.schedulers.*; +import io.reactivex.subscribers.TestSubscriber; + +public class FlowableRefCountAltTest { + + @Test + public void testRefCountAsync() { + final AtomicInteger subscribeCount = new AtomicInteger(); + final AtomicInteger nextCount = new AtomicInteger(); + Flowable r = Flowable.interval(0, 20, TimeUnit.MILLISECONDS) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) { + subscribeCount.incrementAndGet(); + } + }) + .doOnNext(new Consumer() { + @Override + public void accept(Long l) { + nextCount.incrementAndGet(); + } + }) + .publish().refCount(); + + final AtomicInteger receivedCount = new AtomicInteger(); + Disposable d1 = r.subscribe(new Consumer() { + @Override + public void accept(Long l) { + receivedCount.incrementAndGet(); + } + }); + + Disposable d2 = r.subscribe(); + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + + for (;;) { + int a = nextCount.get(); + int b = receivedCount.get(); + if (a > 10 && a < 20 && a == b) { + break; + } + if (a >= 20) { + break; + } + try { + Thread.sleep(20); + } catch (InterruptedException e) { + } + } + // give time to emit + + // now unsubscribe + d2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one subscriber getting a value but not the other + d1.dispose(); + + System.out.println("onNext: " + nextCount.get()); + + // should emit once for both subscribers + assertEquals(nextCount.get(), receivedCount.get()); + // only 1 subscribe + assertEquals(1, subscribeCount.get()); + } + + @Test + public void testRefCountSynchronous() { + final AtomicInteger subscribeCount = new AtomicInteger(); + final AtomicInteger nextCount = new AtomicInteger(); + Flowable r = Flowable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) { + subscribeCount.incrementAndGet(); + } + }) + .doOnNext(new Consumer() { + @Override + public void accept(Integer l) { + nextCount.incrementAndGet(); + } + }) + .publish().refCount(); + + final AtomicInteger receivedCount = new AtomicInteger(); + Disposable d1 = r.subscribe(new Consumer() { + @Override + public void accept(Integer l) { + receivedCount.incrementAndGet(); + } + }); + + Disposable d2 = r.subscribe(); + + // give time to emit + try { + Thread.sleep(50); + } catch (InterruptedException e) { + } + + // now unsubscribe + d2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one subscriber getting a value but not the other + d1.dispose(); + + System.out.println("onNext Count: " + nextCount.get()); + + // it will emit twice because it is synchronous + assertEquals(nextCount.get(), receivedCount.get() * 2); + // it will subscribe twice because it is synchronous + assertEquals(2, subscribeCount.get()); + } + + @Test + public void testRefCountSynchronousTake() { + final AtomicInteger nextCount = new AtomicInteger(); + Flowable r = Flowable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) + .doOnNext(new Consumer() { + @Override + public void accept(Integer l) { + System.out.println("onNext --------> " + l); + nextCount.incrementAndGet(); + } + }) + .take(4) + .publish().refCount(); + + final AtomicInteger receivedCount = new AtomicInteger(); + r.subscribe(new Consumer() { + @Override + public void accept(Integer l) { + receivedCount.incrementAndGet(); + } + }); + + System.out.println("onNext: " + nextCount.get()); + + assertEquals(4, receivedCount.get()); + assertEquals(4, receivedCount.get()); + } + + @Test + public void testRepeat() { + final AtomicInteger subscribeCount = new AtomicInteger(); + final AtomicInteger unsubscribeCount = new AtomicInteger(); + Flowable r = Flowable.interval(0, 1, TimeUnit.MILLISECONDS) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) { + System.out.println("******************************* Subscribe received"); + // when we are subscribed + subscribeCount.incrementAndGet(); + } + }) + .doOnCancel(new Action() { + @Override + public void run() { + System.out.println("******************************* Unsubscribe received"); + // when we are unsubscribed + unsubscribeCount.incrementAndGet(); + } + }) + .publish().refCount(); + + for (int i = 0; i < 10; i++) { + TestSubscriber ts1 = new TestSubscriber(); + TestSubscriber ts2 = new TestSubscriber(); + r.subscribe(ts1); + r.subscribe(ts2); + try { + Thread.sleep(50); + } catch (InterruptedException e) { + } + ts1.dispose(); + ts2.dispose(); + ts1.assertNoErrors(); + ts2.assertNoErrors(); + assertTrue(ts1.valueCount() > 0); + assertTrue(ts2.valueCount() > 0); + } + + assertEquals(10, subscribeCount.get()); + assertEquals(10, unsubscribeCount.get()); + } + + @Test + public void testConnectUnsubscribe() throws InterruptedException { + final CountDownLatch unsubscribeLatch = new CountDownLatch(1); + final CountDownLatch subscribeLatch = new CountDownLatch(1); + + Flowable f = synchronousInterval() + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) { + System.out.println("******************************* Subscribe received"); + // when we are subscribed + subscribeLatch.countDown(); + } + }) + .doOnCancel(new Action() { + @Override + public void run() { + System.out.println("******************************* Unsubscribe received"); + // when we are unsubscribed + unsubscribeLatch.countDown(); + } + }); + + TestSubscriber s = new TestSubscriber(); + f.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(s); + System.out.println("send unsubscribe"); + // wait until connected + subscribeLatch.await(); + // now unsubscribe + s.dispose(); + System.out.println("DONE sending unsubscribe ... now waiting"); + if (!unsubscribeLatch.await(3000, TimeUnit.MILLISECONDS)) { + System.out.println("Errors: " + s.errors()); + if (s.errors().size() > 0) { + s.errors().get(0).printStackTrace(); + } + fail("timed out waiting for unsubscribe"); + } + s.assertNoErrors(); + } + + @Test + public void testConnectUnsubscribeRaceConditionLoop() throws InterruptedException { + for (int i = 0; i < 100; i++) { + testConnectUnsubscribeRaceCondition(); + } + } + + @Test + public void testConnectUnsubscribeRaceCondition() throws InterruptedException { + final AtomicInteger subUnsubCount = new AtomicInteger(); + Flowable f = synchronousInterval() + .doOnCancel(new Action() { + @Override + public void run() { + System.out.println("******************************* Unsubscribe received"); + // when we are unsubscribed + subUnsubCount.decrementAndGet(); + } + }) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) { + System.out.println("******************************* SUBSCRIBE received"); + subUnsubCount.incrementAndGet(); + } + }); + + TestSubscriber s = new TestSubscriber(); + + f.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(s); + System.out.println("send unsubscribe"); + // now immediately unsubscribe while subscribeOn is racing to subscribe + s.dispose(); + // this generally will mean it won't even subscribe as it is already unsubscribed by the time connect() gets scheduled + // give time to the counter to update + Thread.sleep(10); + // either we subscribed and then unsubscribed, or we didn't ever even subscribe + assertEquals(0, subUnsubCount.get()); + + System.out.println("DONE sending unsubscribe ... now waiting"); + System.out.println("Errors: " + s.errors()); + if (s.errors().size() > 0) { + s.errors().get(0).printStackTrace(); + } + s.assertNoErrors(); + } + + private Flowable synchronousInterval() { + return Flowable.unsafeCreate(new Publisher() { + @Override + public void subscribe(Subscriber subscriber) { + final AtomicBoolean cancel = new AtomicBoolean(); + subscriber.onSubscribe(new Subscription() { + @Override + public void request(long n) { + + } + + @Override + public void cancel() { + cancel.set(true); + } + + }); + for (;;) { + if (cancel.get()) { + break; + } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + subscriber.onNext(1L); + } + } + }); + } + + @Test + public void onlyFirstShouldSubscribeAndLastUnsubscribe() { + final AtomicInteger subscriptionCount = new AtomicInteger(); + final AtomicInteger unsubscriptionCount = new AtomicInteger(); + Flowable flowable = Flowable.unsafeCreate(new Publisher() { + @Override + public void subscribe(Subscriber subscriber) { + subscriptionCount.incrementAndGet(); + subscriber.onSubscribe(new Subscription() { + @Override + public void request(long n) { + + } + + @Override + public void cancel() { + unsubscriptionCount.incrementAndGet(); + } + }); + } + }); + Flowable refCounted = flowable.publish().refCount(); + + Disposable first = refCounted.subscribe(); + assertEquals(1, subscriptionCount.get()); + + Disposable second = refCounted.subscribe(); + assertEquals(1, subscriptionCount.get()); + + first.dispose(); + assertEquals(0, unsubscriptionCount.get()); + + second.dispose(); + assertEquals(1, unsubscriptionCount.get()); + } + + @Test + public void testRefCount() { + TestScheduler s = new TestScheduler(); + Flowable interval = Flowable.interval(100, TimeUnit.MILLISECONDS, s).publish().refCount(); + + // subscribe list1 + final List list1 = new ArrayList(); + Disposable d1 = interval.subscribe(new Consumer() { + @Override + public void accept(Long t1) { + list1.add(t1); + } + }); + + s.advanceTimeBy(200, TimeUnit.MILLISECONDS); + + assertEquals(2, list1.size()); + assertEquals(0L, list1.get(0).longValue()); + assertEquals(1L, list1.get(1).longValue()); + + // subscribe list2 + final List list2 = new ArrayList(); + Disposable d2 = interval.subscribe(new Consumer() { + @Override + public void accept(Long t1) { + list2.add(t1); + } + }); + + s.advanceTimeBy(300, TimeUnit.MILLISECONDS); + + // list 1 should have 5 items + assertEquals(5, list1.size()); + assertEquals(2L, list1.get(2).longValue()); + assertEquals(3L, list1.get(3).longValue()); + assertEquals(4L, list1.get(4).longValue()); + + // list 2 should only have 3 items + assertEquals(3, list2.size()); + assertEquals(2L, list2.get(0).longValue()); + assertEquals(3L, list2.get(1).longValue()); + assertEquals(4L, list2.get(2).longValue()); + + // unsubscribe list1 + d1.dispose(); + + // advance further + s.advanceTimeBy(300, TimeUnit.MILLISECONDS); + + // list 1 should still have 5 items + assertEquals(5, list1.size()); + + // list 2 should have 6 items + assertEquals(6, list2.size()); + assertEquals(5L, list2.get(3).longValue()); + assertEquals(6L, list2.get(4).longValue()); + assertEquals(7L, list2.get(5).longValue()); + + // unsubscribe list2 + d2.dispose(); + + // advance further + s.advanceTimeBy(1000, TimeUnit.MILLISECONDS); + + // subscribing a new one should start over because the source should have been unsubscribed + // subscribe list3 + final List list3 = new ArrayList(); + interval.subscribe(new Consumer() { + @Override + public void accept(Long t1) { + list3.add(t1); + } + }); + + s.advanceTimeBy(200, TimeUnit.MILLISECONDS); + + assertEquals(2, list3.size()); + assertEquals(0L, list3.get(0).longValue()); + assertEquals(1L, list3.get(1).longValue()); + + } + + @Test + public void testAlreadyUnsubscribedClient() { + Subscriber done = CancelledSubscriber.INSTANCE; + + Subscriber subscriber = TestHelper.mockSubscriber(); + + Flowable result = Flowable.just(1).publish().refCount(); + + result.subscribe(done); + + result.subscribe(subscriber); + + verify(subscriber).onNext(1); + verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + } + + @Test + public void testAlreadyUnsubscribedInterleavesWithClient() { + ReplayProcessor source = ReplayProcessor.create(); + + Subscriber done = CancelledSubscriber.INSTANCE; + + Subscriber subscriber = TestHelper.mockSubscriber(); + InOrder inOrder = inOrder(subscriber); + + Flowable result = source.publish().refCount(); + + result.subscribe(subscriber); + + source.onNext(1); + + result.subscribe(done); + + source.onNext(2); + source.onComplete(); + + inOrder.verify(subscriber).onNext(1); + inOrder.verify(subscriber).onNext(2); + inOrder.verify(subscriber).onComplete(); + verify(subscriber, never()).onError(any(Throwable.class)); + } + + @Test + public void testConnectDisconnectConnectAndSubjectState() { + Flowable f1 = Flowable.just(10); + Flowable f2 = Flowable.just(20); + Flowable combined = Flowable.combineLatest(f1, f2, new BiFunction() { + @Override + public Integer apply(Integer t1, Integer t2) { + return t1 + t2; + } + }) + .publish().refCount(); + + TestSubscriber ts1 = new TestSubscriber(); + TestSubscriber ts2 = new TestSubscriber(); + + combined.subscribe(ts1); + combined.subscribe(ts2); + + ts1.assertTerminated(); + ts1.assertNoErrors(); + ts1.assertValue(30); + + ts2.assertTerminated(); + ts2.assertNoErrors(); + ts2.assertValue(30); + } + + @Test(timeout = 10000) + public void testUpstreamErrorAllowsRetry() throws InterruptedException { + List errors = TestHelper.trackPluginErrors(); + try { + final AtomicInteger intervalSubscribed = new AtomicInteger(); + Flowable interval = + Flowable.interval(200, TimeUnit.MILLISECONDS) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) { + System.out.println("Subscribing to interval " + intervalSubscribed.incrementAndGet()); + } + } + ) + .flatMap(new Function>() { + @Override + public Publisher apply(Long t1) { + return Flowable.defer(new Callable>() { + @Override + public Publisher call() { + return Flowable.error(new TestException("Some exception")); + } + }); + } + }) + .onErrorResumeNext(new Function>() { + @Override + public Publisher apply(Throwable t1) { + return Flowable.error(t1); + } + }) + .publish() + .refCount(); + + interval + .doOnError(new Consumer() { + @Override + public void accept(Throwable t1) { + System.out.println("Subscriber 1 onError: " + t1); + } + }) + .retry(5) + .subscribe(new Consumer() { + @Override + public void accept(String t1) { + System.out.println("Subscriber 1: " + t1); + } + }); + Thread.sleep(100); + interval + .doOnError(new Consumer() { + @Override + public void accept(Throwable t1) { + System.out.println("Subscriber 2 onError: " + t1); + } + }) + .retry(5) + .subscribe(new Consumer() { + @Override + public void accept(String t1) { + System.out.println("Subscriber 2: " + t1); + } + }); + + Thread.sleep(1300); + + System.out.println(intervalSubscribed.get()); + assertEquals(6, intervalSubscribed.get()); + + TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + private enum CancelledSubscriber implements FlowableSubscriber { + INSTANCE; + + @Override public void onSubscribe(Subscription s) { + s.cancel(); + } + + @Override public void onNext(Integer o) { + } + + @Override public void onError(Throwable t) { + } + + @Override public void onComplete() { + } + } + + @Test + public void disposed() { + TestHelper.checkDisposed(Flowable.just(1).publish().refCount()); + } + + @Test + public void noOpConnect() { + final int[] calls = { 0 }; + Flowable f = new ConnectableFlowable() { + @Override + public void connect(Consumer connection) { + calls[0]++; + } + + @Override + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + } + }.refCount(); + + f.test(); + f.test(); + + assertEquals(1, calls[0]); + } + + Flowable source; + + @Test + public void replayNoLeak() throws Exception { + Thread.sleep(100); + System.gc(); + Thread.sleep(100); + + long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = Flowable.fromCallable(new Callable() { + @Override + public Object call() throws Exception { + return new byte[100 * 1000 * 1000]; + } + }) + .replay(1) + .refCount(); + + source.subscribe(); + + Thread.sleep(100); + System.gc(); + Thread.sleep(100); + + long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = null; + assertTrue(String.format("%,3d -> %,3d%n", start, after), start + 20 * 1000 * 1000 > after); + } + + @Test + public void replayNoLeak2() throws Exception { + Thread.sleep(100); + System.gc(); + Thread.sleep(100); + + long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = Flowable.fromCallable(new Callable() { + @Override + public Object call() throws Exception { + return new byte[100 * 1000 * 1000]; + } + }).concatWith(Flowable.never()) + .replay(1) + .refCount(); + + Disposable d1 = source.subscribe(); + Disposable d2 = source.subscribe(); + + d1.dispose(); + d2.dispose(); + + d1 = null; + d2 = null; + + Thread.sleep(100); + System.gc(); + Thread.sleep(100); + + long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = null; + assertTrue(String.format("%,3d -> %,3d%n", start, after), start + 20 * 1000 * 1000 > after); + } + + static final class ExceptionData extends Exception { + private static final long serialVersionUID = -6763898015338136119L; + + public final Object data; + + ExceptionData(Object data) { + this.data = data; + } + } + + @Test + public void publishNoLeak() throws Exception { + Thread.sleep(100); + System.gc(); + Thread.sleep(100); + + long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = Flowable.fromCallable(new Callable() { + @Override + public Object call() throws Exception { + throw new ExceptionData(new byte[100 * 1000 * 1000]); + } + }) + .publish() + .refCount(); + + source.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); + + Thread.sleep(100); + System.gc(); + Thread.sleep(200); + + long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = null; + + assertTrue(String.format("%,3d -> %,3d%n", start, after), start + 20 * 1000 * 1000 > after); + } + + @Test + public void publishNoLeak2() throws Exception { + System.gc(); + Thread.sleep(100); + + long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = Flowable.fromCallable(new Callable() { + @Override + public Object call() throws Exception { + return new byte[100 * 1000 * 1000]; + } + }).concatWith(Flowable.never()) + .publish() + .refCount(); + + Disposable d1 = source.test(); + Disposable d2 = source.test(); + + d1.dispose(); + d2.dispose(); + + d1 = null; + d2 = null; + + System.gc(); + Thread.sleep(100); + + long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = null; + assertTrue(String.format("%,3d -> %,3d%n", start, after), start + 20 * 1000 * 1000 > after); + } + + @Test + public void replayIsUnsubscribed() { + ConnectableFlowable cf = Flowable.just(1) + .replay(); + + if (cf instanceof Disposable) { + assertTrue(((Disposable)cf).isDisposed()); + + Disposable connection = cf.connect(); + + assertFalse(((Disposable)cf).isDisposed()); + + connection.dispose(); + + assertTrue(((Disposable)cf).isDisposed()); + } + } + + static final class BadFlowableSubscribe extends ConnectableFlowable { + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Subscriber subscriber) { + throw new TestException("subscribeActual"); + } + } + + static final class BadFlowableDispose extends ConnectableFlowable implements Disposable { + + @Override + public void dispose() { + throw new TestException("dispose"); + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + } + } + + static final class BadFlowableConnect extends ConnectableFlowable { + + @Override + public void connect(Consumer connection) { + throw new TestException("connect"); + } + + @Override + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + } + } + + @Test + public void badSourceSubscribe() { + List errors = TestHelper.trackPluginErrors(); + try { + BadFlowableSubscribe bo = new BadFlowableSubscribe(); + + try { + bo.refCount() + .test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void badSourceDispose() { + BadFlowableDispose bf = new BadFlowableDispose(); + + try { + bf.refCount() + .test() + .cancel(); + fail("Should have thrown"); + } catch (TestException expected) { + } + } + + @Test + public void badSourceConnect() { + List errors = TestHelper.trackPluginErrors(); + try { + BadFlowableConnect bf = new BadFlowableConnect(); + + try { + bf.refCount() + .test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + static final class BadFlowableSubscribe2 extends ConnectableFlowable { + + int count; + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Subscriber subscriber) { + if (++count == 1) { + subscriber.onSubscribe(new BooleanSubscription()); + } else { + throw new TestException("subscribeActual"); + } + } + } + + @Test + public void badSourceSubscribe2() { + List errors = TestHelper.trackPluginErrors(); + try { + BadFlowableSubscribe2 bf = new BadFlowableSubscribe2(); + + Flowable f = bf.refCount(); + f.test(); + try { + f.test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + static final class BadFlowableConnect2 extends ConnectableFlowable + implements Disposable { + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); + } + + @Override + public void dispose() { + throw new TestException("dispose"); + } + + @Override + public boolean isDisposed() { + return false; + } + } + + @Test + public void badSourceCompleteDisconnect() { + List errors = TestHelper.trackPluginErrors(); + try { + BadFlowableConnect2 bf = new BadFlowableConnect2(); + + try { + bf.refCount() + .test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test(timeout = 7500) + public void blockingSourceAsnycCancel() throws Exception { + BehaviorProcessor bp = BehaviorProcessor.createDefault(1); + + Flowable f = bp + .replay(1) + .refCount(); + + f.subscribe(); + + final AtomicBoolean interrupted = new AtomicBoolean(); + + f.switchMap(new Function>() { + @Override + public Publisher apply(Integer v) throws Exception { + return Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter emitter) throws Exception { + while (!emitter.isCancelled()) { + Thread.sleep(100); + } + interrupted.set(true); + } + }, BackpressureStrategy.MISSING); + } + }) + .takeUntil(Flowable.timer(500, TimeUnit.MILLISECONDS)) + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(); + + assertTrue(interrupted.get()); + } + + @Test + public void byCount() { + final int[] subscriptions = { 0 }; + + Flowable source = Flowable.range(1, 5) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) throws Exception { + subscriptions[0]++; + } + }) + .publish() + .refCount(2); + + for (int i = 0; i < 3; i++) { + TestSubscriber ts1 = source.test(); + + ts1.assertEmpty(); + + TestSubscriber ts2 = source.test(); + + ts1.assertResult(1, 2, 3, 4, 5); + ts2.assertResult(1, 2, 3, 4, 5); + } + + assertEquals(3, subscriptions[0]); + } + + @Test + public void resubscribeBeforeTimeout() throws Exception { + final int[] subscriptions = { 0 }; + + PublishProcessor pp = PublishProcessor.create(); + + Flowable source = pp + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) throws Exception { + subscriptions[0]++; + } + }) + .publish() + .refCount(500, TimeUnit.MILLISECONDS); + + TestSubscriber ts1 = source.test(0); + + assertEquals(1, subscriptions[0]); + + ts1.cancel(); + + Thread.sleep(100); + + ts1 = source.test(0); + + assertEquals(1, subscriptions[0]); + + Thread.sleep(500); + + assertEquals(1, subscriptions[0]); + + pp.onNext(1); + pp.onNext(2); + pp.onNext(3); + pp.onNext(4); + pp.onNext(5); + pp.onComplete(); + + ts1.requestMore(5) + .assertResult(1, 2, 3, 4, 5); + } + + @Test + public void letitTimeout() throws Exception { + final int[] subscriptions = { 0 }; + + PublishProcessor pp = PublishProcessor.create(); + + Flowable source = pp + .doOnSubscribe(new Consumer() { + @Override + public void accept(Subscription s) throws Exception { + subscriptions[0]++; + } + }) + .publish() + .refCount(1, 100, TimeUnit.MILLISECONDS); + + TestSubscriber ts1 = source.test(0); + + assertEquals(1, subscriptions[0]); + + ts1.cancel(); + + assertTrue(pp.hasSubscribers()); + + Thread.sleep(200); + + assertFalse(pp.hasSubscribers()); + } + + @Test + public void error() { + Flowable.error(new IOException()) + .publish() + .refCount(500, TimeUnit.MILLISECONDS) + .test() + .assertFailure(IOException.class); + } + + @Test + public void comeAndGo() { + PublishProcessor pp = PublishProcessor.create(); + + Flowable source = pp + .publish() + .refCount(1); + + TestSubscriber ts1 = source.test(0); + + assertTrue(pp.hasSubscribers()); + + for (int i = 0; i < 3; i++) { + TestSubscriber ts2 = source.test(); + ts1.cancel(); + ts1 = ts2; + } + + ts1.cancel(); + + assertFalse(pp.hasSubscribers()); + } + + @Test + public void unsubscribeSubscribeRace() { + for (int i = 0; i < 1000; i++) { + + final Flowable source = Flowable.range(1, 5) + .replay() + .refCount(1) + ; + + final TestSubscriber ts1 = source.test(0); + + final TestSubscriber ts2 = new TestSubscriber(0); + + Runnable r1 = new Runnable() { + @Override + public void run() { + ts1.cancel(); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + source.subscribe(ts2); + } + }; + + TestHelper.race(r1, r2, Schedulers.single()); + + ts2.requestMore(6) // FIXME RxJava replay() doesn't issue onComplete without request + .withTag("Round: " + i) + .assertResult(1, 2, 3, 4, 5); + } + } + + static final class BadFlowableDoubleOnX extends ConnectableFlowable + implements Disposable { + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Subscriber subscriber) { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onComplete(); + subscriber.onComplete(); + subscriber.onError(new TestException()); + } + + @Override + public void dispose() { + } + + @Override + public boolean isDisposed() { + return false; + } + } + + @Test + public void doubleOnX() { + List errors = TestHelper.trackPluginErrors(); + try { + new BadFlowableDoubleOnX() + .refCount() + .test() + .assertResult(); + + TestHelper.assertError(errors, 0, ProtocolViolationException.class); + TestHelper.assertUndeliverable(errors, 1, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void doubleOnXCount() { + List errors = TestHelper.trackPluginErrors(); + try { + new BadFlowableDoubleOnX() + .refCount(1) + .test() + .assertResult(); + + TestHelper.assertError(errors, 0, ProtocolViolationException.class); + TestHelper.assertUndeliverable(errors, 1, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void doubleOnXTime() { + List errors = TestHelper.trackPluginErrors(); + try { + new BadFlowableDoubleOnX() + .refCount(5, TimeUnit.SECONDS, Schedulers.single()) + .test() + .assertResult(); + + TestHelper.assertError(errors, 0, ProtocolViolationException.class); + TestHelper.assertUndeliverable(errors, 1, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void cancelTerminateStateExclusion() { + FlowableRefCount o = (FlowableRefCount)PublishProcessor.create() + .publish() + .refCount(); + + o.cancel(null); + + RefConnection rc = new RefConnection(o); + o.connection = null; + rc.subscriberCount = 0; + o.timeout(rc); + + rc.subscriberCount = 1; + o.timeout(rc); + + o.connection = rc; + o.timeout(rc); + + rc.subscriberCount = 0; + o.timeout(rc); + + // ------------------- + + rc.subscriberCount = 2; + rc.connected = false; + o.connection = rc; + o.cancel(rc); + + rc.subscriberCount = 1; + rc.connected = false; + o.connection = rc; + o.cancel(rc); + + rc.subscriberCount = 2; + rc.connected = true; + o.connection = rc; + o.cancel(rc); + + rc.subscriberCount = 1; + rc.connected = true; + o.connection = rc; + rc.set(null); + o.cancel(rc); + + o.connection = rc; + o.cancel(new RefConnection(o)); + } + + @Test + public void replayRefCountShallBeThreadSafe() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + Flowable flowable = Flowable.just(1).replay(1).refCount(); + + TestSubscriber ts1 = flowable + .subscribeOn(Schedulers.io()) + .test(); + + TestSubscriber ts2 = flowable + .subscribeOn(Schedulers.io()) + .test(); + + ts1 + .withTag("" + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(1); + + ts2 + .withTag("" + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(1); + } + } + + static final class TestConnectableFlowable extends ConnectableFlowable + implements Disposable { + + volatile boolean disposed; + + @Override + public void dispose() { + disposed = true; + } + + @Override + public boolean isDisposed() { + return disposed; + } + + @Override + public void connect(Consumer connection) { + // not relevant + } + + @Override + protected void subscribeActual(Subscriber subscriber) { + // not relevant + } + } + + @Test + public void timeoutDisposesSource() { + FlowableRefCount o = (FlowableRefCount)new TestConnectableFlowable().refCount(); + + RefConnection rc = new RefConnection(o); + o.connection = rc; + + o.timeout(rc); + + assertTrue(((Disposable)o.source).isDisposed()); + } + + @Test + public void disconnectBeforeConnect() { + BehaviorProcessor processor = BehaviorProcessor.create(); + + Flowable flowable = processor + .replay(1) + .refCount(); + + flowable.takeUntil(Flowable.just(1)).test(); + + processor.onNext(2); + + flowable.take(1).test().assertResult(2); + } + + @Test + public void publishRefCountShallBeThreadSafe() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + Flowable flowable = Flowable.just(1).publish().refCount(); + + TestSubscriber subscriber1 = flowable + .subscribeOn(Schedulers.io()) + .test(); + + TestSubscriber subscriber2 = flowable + .subscribeOn(Schedulers.io()) + .test(); + + subscriber1 + .withTag("subscriber1 " + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertNoErrors() + .assertComplete(); + + subscriber2 + .withTag("subscriber2 " + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertNoErrors() + .assertComplete(); + } + } +} diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java index 673a0f4add..88aa2b17c1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java @@ -23,7 +23,7 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import org.junit.Test; +import org.junit.*; import org.mockito.InOrder; import org.reactivestreams.*; @@ -43,6 +43,28 @@ public class FlowableRefCountTest { + // This will undo the workaround so that the plain ObservablePublish is still + // tested. + @Before + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void before() { + RxJavaPlugins.setOnConnectableFlowableAssembly(new Function() { + @Override + public ConnectableFlowable apply(ConnectableFlowable co) throws Exception { + if (co instanceof FlowablePublishAlt) { + FlowablePublishAlt fpa = (FlowablePublishAlt) co; + return FlowablePublish.create(Flowable.fromPublisher(fpa.source()), fpa.publishBufferSize()); + } + return co; + } + }); + } + + @After + public void after() { + RxJavaPlugins.setOnConnectableFlowableAssembly(null); + } + @Test public void testRefCountAsync() { final AtomicInteger subscribeCount = new AtomicInteger(); @@ -653,6 +675,7 @@ protected void subscribeActual(Subscriber subscriber) { @Test public void replayNoLeak() throws Exception { + Thread.sleep(100); System.gc(); Thread.sleep(100); @@ -669,6 +692,7 @@ public Object call() throws Exception { source.subscribe(); + Thread.sleep(100); System.gc(); Thread.sleep(100); @@ -680,6 +704,7 @@ public Object call() throws Exception { @Test public void replayNoLeak2() throws Exception { + Thread.sleep(100); System.gc(); Thread.sleep(100); @@ -703,6 +728,7 @@ public Object call() throws Exception { d1 = null; d2 = null; + Thread.sleep(100); System.gc(); Thread.sleep(100); @@ -724,6 +750,7 @@ static final class ExceptionData extends Exception { @Test public void publishNoLeak() throws Exception { + Thread.sleep(100); System.gc(); Thread.sleep(100); @@ -740,6 +767,7 @@ public Object call() throws Exception { source.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); + Thread.sleep(100); System.gc(); Thread.sleep(100); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishAltTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishAltTest.java new file mode 100644 index 0000000000..b268e5b2ed --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishAltTest.java @@ -0,0 +1,794 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.observable; + +import static org.junit.Assert.*; + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import org.junit.Test; + +import io.reactivex.*; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.disposables.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.fuseable.HasUpstreamObservableSource; +import io.reactivex.observables.ConnectableObservable; +import io.reactivex.observers.TestObserver; +import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.schedulers.*; +import io.reactivex.subjects.PublishSubject; + +public class ObservablePublishAltTest { + + @Test + public void testPublish() throws InterruptedException { + final AtomicInteger counter = new AtomicInteger(); + ConnectableObservable o = Observable.unsafeCreate(new ObservableSource() { + + @Override + public void subscribe(final Observer observer) { + observer.onSubscribe(Disposables.empty()); + new Thread(new Runnable() { + + @Override + public void run() { + counter.incrementAndGet(); + observer.onNext("one"); + observer.onComplete(); + } + }).start(); + } + }).publish(); + + final CountDownLatch latch = new CountDownLatch(2); + + // subscribe once + o.subscribe(new Consumer() { + + @Override + public void accept(String v) { + assertEquals("one", v); + latch.countDown(); + } + }); + + // subscribe again + o.subscribe(new Consumer() { + + @Override + public void accept(String v) { + assertEquals("one", v); + latch.countDown(); + } + }); + + Disposable connection = o.connect(); + try { + if (!latch.await(1000, TimeUnit.MILLISECONDS)) { + fail("subscriptions did not receive values"); + } + assertEquals(1, counter.get()); + } finally { + connection.dispose(); + } + } + + @Test + public void testBackpressureFastSlow() { + ConnectableObservable is = Observable.range(1, Flowable.bufferSize() * 2).publish(); + Observable fast = is.observeOn(Schedulers.computation()) + .doOnComplete(new Action() { + @Override + public void run() { + System.out.println("^^^^^^^^^^^^^ completed FAST"); + } + }); + + Observable slow = is.observeOn(Schedulers.computation()).map(new Function() { + int c; + + @Override + public Integer apply(Integer i) { + if (c == 0) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + } + c++; + return i; + } + + }).doOnComplete(new Action() { + + @Override + public void run() { + System.out.println("^^^^^^^^^^^^^ completed SLOW"); + } + + }); + + TestObserver to = new TestObserver(); + Observable.merge(fast, slow).subscribe(to); + is.connect(); + to.awaitTerminalEvent(); + to.assertNoErrors(); + assertEquals(Flowable.bufferSize() * 4, to.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, Flowable.bufferSize() * 2).doOnNext(new Consumer() { + + @Override + public void accept(Integer t1) { + emitted.incrementAndGet(); + } + + }); + TestObserver to = new TestObserver(); + xs.publish(new Function, Observable>() { + + @Override + public Observable apply(Observable xs) { + return xs.takeUntil(xs.skipWhile(new Predicate() { + + @Override + public boolean test(Integer i) { + return i <= 3; + } + + })); + } + + }).subscribe(to); + to.awaitTerminalEvent(); + to.assertNoErrors(); + to.assertValues(0, 1, 2, 3); + assertEquals(5, emitted.get()); + System.out.println(to.values()); + } + + // use case from https://github.com/ReactiveX/RxJava/issues/1732 + @Test + public void testTakeUntilWithPublishedStream() { + Observable xs = Observable.range(0, Flowable.bufferSize() * 2); + TestObserver to = new TestObserver(); + ConnectableObservable xsp = xs.publish(); + xsp.takeUntil(xsp.skipWhile(new Predicate() { + + @Override + public boolean test(Integer i) { + return i <= 3; + } + + })).subscribe(to); + xsp.connect(); + System.out.println(to.values()); + } + + @Test(timeout = 10000) + public void testBackpressureTwoConsumers() { + final AtomicInteger sourceEmission = new AtomicInteger(); + final AtomicBoolean sourceUnsubscribed = new AtomicBoolean(); + final Observable source = Observable.range(1, 100) + .doOnNext(new Consumer() { + @Override + public void accept(Integer t1) { + sourceEmission.incrementAndGet(); + } + }) + .doOnDispose(new Action() { + @Override + public void run() { + sourceUnsubscribed.set(true); + } + }).share(); + ; + + final AtomicBoolean child1Unsubscribed = new AtomicBoolean(); + final AtomicBoolean child2Unsubscribed = new AtomicBoolean(); + + final TestObserver to2 = new TestObserver(); + + final TestObserver to1 = new TestObserver() { + @Override + public void onNext(Integer t) { + if (valueCount() == 2) { + source.doOnDispose(new Action() { + @Override + public void run() { + child2Unsubscribed.set(true); + } + }).take(5).subscribe(to2); + } + super.onNext(t); + } + }; + + source.doOnDispose(new Action() { + @Override + public void run() { + child1Unsubscribed.set(true); + } + }).take(5) + .subscribe(to1); + + to1.awaitTerminalEvent(); + to2.awaitTerminalEvent(); + + to1.assertNoErrors(); + to2.assertNoErrors(); + + assertTrue(sourceUnsubscribed.get()); + assertTrue(child1Unsubscribed.get()); + assertTrue(child2Unsubscribed.get()); + + to1.assertValues(1, 2, 3, 4, 5); + to2.assertValues(4, 5, 6, 7, 8); + + assertEquals(8, sourceEmission.get()); + } + + @Test + public void testConnectWithNoSubscriber() { + TestScheduler scheduler = new TestScheduler(); + ConnectableObservable co = Observable.interval(10, 10, TimeUnit.MILLISECONDS, scheduler).take(3).publish(); + co.connect(); + // Emit 0 + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + TestObserver to = new TestObserver(); + co.subscribe(to); + // Emit 1 and 2 + scheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS); + to.assertValues(1L, 2L); + to.assertNoErrors(); + to.assertTerminated(); + } + + @Test + public void testSubscribeAfterDisconnectThenConnect() { + ConnectableObservable source = Observable.just(1).publish(); + + TestObserver to1 = new TestObserver(); + + source.subscribe(to1); + + Disposable connection = source.connect(); + + to1.assertValue(1); + to1.assertNoErrors(); + to1.assertTerminated(); + + TestObserver to2 = new TestObserver(); + + source.subscribe(to2); + + Disposable connection2 = source.connect(); + + to2.assertValue(1); + to2.assertNoErrors(); + to2.assertTerminated(); + + System.out.println(connection); + System.out.println(connection2); + } + + @Test + public void testNoSubscriberRetentionOnCompleted() { + ObservablePublish source = (ObservablePublish)Observable.just(1).publish(); + + TestObserver to1 = new TestObserver(); + + source.subscribe(to1); + + to1.assertNoValues(); + to1.assertNoErrors(); + to1.assertNotComplete(); + + source.connect(); + + to1.assertValue(1); + to1.assertNoErrors(); + to1.assertTerminated(); + + assertNull(source.current.get()); + } + + @Test + public void testNonNullConnection() { + ConnectableObservable source = Observable.never().publish(); + + assertNotNull(source.connect()); + assertNotNull(source.connect()); + } + + @Test + public void testNoDisconnectSomeoneElse() { + ConnectableObservable source = Observable.never().publish(); + + Disposable connection1 = source.connect(); + Disposable connection2 = source.connect(); + + connection1.dispose(); + + Disposable connection3 = source.connect(); + + connection2.dispose(); + + assertTrue(checkPublishDisposed(connection1)); + assertTrue(checkPublishDisposed(connection2)); + assertFalse(checkPublishDisposed(connection3)); + } + + @SuppressWarnings("unchecked") + static boolean checkPublishDisposed(Disposable d) { + return ((ObservablePublish.PublishObserver)d).isDisposed(); + } + + @Test + public void testConnectIsIdempotent() { + final AtomicInteger calls = new AtomicInteger(); + Observable source = Observable.unsafeCreate(new ObservableSource() { + @Override + public void subscribe(Observer t) { + t.onSubscribe(Disposables.empty()); + calls.getAndIncrement(); + } + }); + + ConnectableObservable conn = source.publish(); + + assertEquals(0, calls.get()); + + conn.connect(); + conn.connect(); + + assertEquals(1, calls.get()); + + conn.connect().dispose(); + + conn.connect(); + conn.connect(); + + assertEquals(2, calls.get()); + } + + @Test + public void testObserveOn() { + 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> tos = new ArrayList>(); + for (int k = 1; k < j; k++) { + TestObserver to = new TestObserver(); + tos.add(to); + obs.subscribe(to); + } + + Disposable connection = co.connect(); + + for (TestObserver to : tos) { + to.awaitTerminalEvent(2, TimeUnit.SECONDS); + to.assertTerminated(); + to.assertNoErrors(); + assertEquals(1000, to.valueCount()); + } + connection.dispose(); + } + } + } + + @Test + public void preNextConnect() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final ConnectableObservable co = Observable.empty().publish(); + + co.connect(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + co.test(); + } + }; + + TestHelper.race(r1, r1); + } + } + + @Test + public void connectRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final ConnectableObservable co = Observable.empty().publish(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + co.connect(); + } + }; + + TestHelper.race(r1, r1); + } + } + + @Test + public void selectorCrash() { + Observable.just(1).publish(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable v) throws Exception { + throw new TestException(); + } + }) + .test() + .assertFailure(TestException.class); + } + + @Test + public void source() { + Observable o = Observable.never(); + + assertSame(o, (((HasUpstreamObservableSource)o.publish()).source())); + } + + @Test + public void connectThrows() { + ConnectableObservable co = Observable.empty().publish(); + try { + co.connect(new Consumer() { + @Override + public void accept(Disposable d) throws Exception { + throw new TestException(); + } + }); + } catch (TestException ex) { + // expected + } + } + + @Test + public void addRemoveRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final ConnectableObservable co = Observable.empty().publish(); + + final TestObserver to = co.test(); + + final TestObserver to2 = new TestObserver(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + co.subscribe(to2); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + to.cancel(); + } + }; + + TestHelper.race(r1, r2); + } + } + + @Test + public void disposeOnArrival() { + ConnectableObservable co = Observable.empty().publish(); + + co.test(true).assertEmpty(); + } + + @Test + public void dispose() { + TestHelper.checkDisposed(Observable.never().publish()); + + TestHelper.checkDisposed(Observable.never().publish(Functions.>identity())); + } + + @Test + public void empty() { + ConnectableObservable co = Observable.empty().publish(); + + co.connect(); + } + + @Test + public void take() { + ConnectableObservable co = Observable.range(1, 2).publish(); + + TestObserver to = co.take(1).test(); + + co.connect(); + + to.assertResult(1); + } + + @Test + public void just() { + final PublishSubject ps = PublishSubject.create(); + + ConnectableObservable co = ps.publish(); + + TestObserver to = new TestObserver() { + @Override + public void onNext(Integer t) { + super.onNext(t); + ps.onComplete(); + } + }; + + co.subscribe(to); + co.connect(); + + ps.onNext(1); + + to.assertResult(1); + } + + @Test + public void nextCancelRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final PublishSubject ps = PublishSubject.create(); + + final ConnectableObservable co = ps.publish(); + + final TestObserver to = co.test(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + ps.onNext(1); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + to.cancel(); + } + }; + + TestHelper.race(r1, r2); + } + } + + @Test + public void badSource() { + List errors = TestHelper.trackPluginErrors(); + try { + new Observable() { + @Override + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onNext(1); + observer.onComplete(); + observer.onNext(2); + observer.onError(new TestException()); + observer.onComplete(); + } + } + .publish() + .autoConnect() + .test() + .assertResult(1); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void noErrorLoss() { + List errors = TestHelper.trackPluginErrors(); + try { + ConnectableObservable co = Observable.error(new TestException()).publish(); + + co.connect(); + + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void subscribeDisconnectRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final PublishSubject ps = PublishSubject.create(); + + final ConnectableObservable co = ps.publish(); + + final Disposable d = co.connect(); + final TestObserver to = new TestObserver(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + d.dispose(); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + co.subscribe(to); + } + }; + + TestHelper.race(r1, r2); + } + } + + @Test + public void selectorDisconnectsIndependentSource() { + PublishSubject ps = PublishSubject.create(); + + ps.publish(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable v) throws Exception { + return Observable.range(1, 2); + } + }) + .test() + .assertResult(1, 2); + + assertFalse(ps.hasObservers()); + } + + @Test(timeout = 5000) + public void selectorLatecommer() { + Observable.range(1, 5) + .publish(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable v) throws Exception { + return v.concatWith(v); + } + }) + .test() + .assertResult(1, 2, 3, 4, 5); + } + + @Test + public void mainError() { + Observable.error(new TestException()) + .publish(Functions.>identity()) + .test() + .assertFailure(TestException.class); + } + + @Test + public void selectorInnerError() { + PublishSubject ps = PublishSubject.create(); + + ps.publish(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable v) throws Exception { + return Observable.error(new TestException()); + } + }) + .test() + .assertFailure(TestException.class); + + assertFalse(ps.hasObservers()); + } + + @Test + public void delayedUpstreamOnSubscribe() { + final Observer[] sub = { null }; + + new Observable() { + @Override + protected void subscribeActual(Observer observer) { + sub[0] = observer; + } + } + .publish() + .connect() + .dispose(); + + Disposable bs = Disposables.empty(); + + sub[0].onSubscribe(bs); + + assertTrue(bs.isDisposed()); + } + + @Test + public void doubleOnSubscribe() { + TestHelper.checkDoubleOnSubscribeObservable(new Function, ObservableSource>() { + @Override + public ObservableSource apply(final Observable o) + throws Exception { + return Observable.never().publish(new Function, ObservableSource>() { + @Override + public ObservableSource apply(Observable v) + throws Exception { + return o; + } + }); + } + } + ); + } + + @Test + public void disposedUpfront() { + ConnectableObservable co = Observable.just(1) + .concatWith(Observable.never()) + .publish(); + + TestObserver to1 = co.test(); + + TestObserver to2 = co.test(true); + + co.connect(); + + to1.assertValuesOnly(1); + + to2.assertEmpty(); + + ((ObservablePublish)co).current.get().remove(null); + } + + @Test + public void altConnectCrash() { + try { + new ObservablePublishAlt(Observable.empty()) + .connect(new Consumer() { + @Override + public void accept(Disposable t) throws Exception { + throw new TestException(); + } + }); + fail("Should have thrown"); + } catch (TestException expected) { + // expected + } + } + + @Test + public void altConnectRace() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + final ConnectableObservable co = + new ObservablePublishAlt(Observable.never()); + + Runnable r = new Runnable() { + @Override + public void run() { + co.connect(); + } + }; + + TestHelper.race(r, r); + } + } +} diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java index 2f2a0e677e..7534f07346 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java @@ -19,7 +19,7 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import org.junit.Test; +import org.junit.*; import io.reactivex.*; import io.reactivex.Observable; @@ -37,6 +37,27 @@ public class ObservablePublishTest { + // This will undo the workaround so that the plain ObservablePublish is still + // tested. + @Before + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void before() { + RxJavaPlugins.setOnConnectableObservableAssembly(new Function() { + @Override + public ConnectableObservable apply(ConnectableObservable co) throws Exception { + if (co instanceof ObservablePublishAlt) { + return ObservablePublish.create(((ObservablePublishAlt)co).source()); + } + return co; + } + }); + } + + @After + public void after() { + RxJavaPlugins.setOnConnectableObservableAssembly(null); + } + @Test public void testPublish() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java new file mode 100644 index 0000000000..effe8ef206 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java @@ -0,0 +1,1394 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.observable; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import org.junit.Test; +import org.mockito.InOrder; + +import io.reactivex.*; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.disposables.*; +import io.reactivex.exceptions.*; +import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.operators.observable.ObservableRefCount.RefConnection; +import io.reactivex.internal.util.ExceptionHelper; +import io.reactivex.observables.ConnectableObservable; +import io.reactivex.observers.TestObserver; +import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.schedulers.*; +import io.reactivex.subjects.*; + +public class ObservableRefCountAltTest { + + @Test + public void testRefCountAsync() { + final AtomicInteger subscribeCount = new AtomicInteger(); + final AtomicInteger nextCount = new AtomicInteger(); + Observable r = Observable.interval(0, 25, TimeUnit.MILLISECONDS) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Disposable d) { + subscribeCount.incrementAndGet(); + } + }) + .doOnNext(new Consumer() { + @Override + public void accept(Long l) { + nextCount.incrementAndGet(); + } + }) + .publish().refCount(); + + final AtomicInteger receivedCount = new AtomicInteger(); + Disposable d1 = r.subscribe(new Consumer() { + @Override + public void accept(Long l) { + receivedCount.incrementAndGet(); + } + }); + + Disposable d2 = r.subscribe(); + + // give time to emit + try { + Thread.sleep(260); + } catch (InterruptedException e) { + } + + // now unsubscribe + d2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one Observer getting a value but not the other + d1.dispose(); + + System.out.println("onNext: " + nextCount.get()); + + // should emit once for both subscribers + assertEquals(nextCount.get(), receivedCount.get()); + // only 1 subscribe + assertEquals(1, subscribeCount.get()); + } + + @Test + 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) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Disposable d) { + subscribeCount.incrementAndGet(); + } + }) + .doOnNext(new Consumer() { + @Override + public void accept(Integer l) { + nextCount.incrementAndGet(); + } + }) + .publish().refCount(); + + final AtomicInteger receivedCount = new AtomicInteger(); + Disposable d1 = r.subscribe(new Consumer() { + @Override + public void accept(Integer l) { + receivedCount.incrementAndGet(); + } + }); + + Disposable d2 = r.subscribe(); + + // give time to emit + try { + Thread.sleep(50); + } catch (InterruptedException e) { + } + + // now unsubscribe + d2.dispose(); // unsubscribe s2 first as we're counting in 1 and there can be a race between unsubscribe and one Observer getting a value but not the other + d1.dispose(); + + System.out.println("onNext Count: " + nextCount.get()); + + // it will emit twice because it is synchronous + assertEquals(nextCount.get(), receivedCount.get() * 2); + // it will subscribe twice because it is synchronous + assertEquals(2, subscribeCount.get()); + } + + @Test + public void testRefCountSynchronousTake() { + final AtomicInteger nextCount = new AtomicInteger(); + Observable r = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) + .doOnNext(new Consumer() { + @Override + public void accept(Integer l) { + System.out.println("onNext --------> " + l); + nextCount.incrementAndGet(); + } + }) + .take(4) + .publish().refCount(); + + final AtomicInteger receivedCount = new AtomicInteger(); + r.subscribe(new Consumer() { + @Override + public void accept(Integer l) { + receivedCount.incrementAndGet(); + } + }); + + System.out.println("onNext: " + nextCount.get()); + + assertEquals(4, receivedCount.get()); + assertEquals(4, receivedCount.get()); + } + + @Test + public void testRepeat() { + final AtomicInteger subscribeCount = new AtomicInteger(); + final AtomicInteger unsubscribeCount = new AtomicInteger(); + Observable r = Observable.interval(0, 1, TimeUnit.MILLISECONDS) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Disposable d) { + System.out.println("******************************* Subscribe received"); + // when we are subscribed + subscribeCount.incrementAndGet(); + } + }) + .doOnDispose(new Action() { + @Override + public void run() { + System.out.println("******************************* Unsubscribe received"); + // when we are unsubscribed + unsubscribeCount.incrementAndGet(); + } + }) + .publish().refCount(); + + for (int i = 0; i < 10; i++) { + TestObserver to1 = new TestObserver(); + TestObserver to2 = new TestObserver(); + r.subscribe(to1); + r.subscribe(to2); + try { + Thread.sleep(50); + } catch (InterruptedException e) { + } + to1.dispose(); + to2.dispose(); + to1.assertNoErrors(); + to2.assertNoErrors(); + assertTrue(to1.valueCount() > 0); + assertTrue(to2.valueCount() > 0); + } + + assertEquals(10, subscribeCount.get()); + assertEquals(10, unsubscribeCount.get()); + } + + @Test + public void testConnectUnsubscribe() throws InterruptedException { + final CountDownLatch unsubscribeLatch = new CountDownLatch(1); + final CountDownLatch subscribeLatch = new CountDownLatch(1); + + Observable o = synchronousInterval() + .doOnSubscribe(new Consumer() { + @Override + public void accept(Disposable d) { + System.out.println("******************************* Subscribe received"); + // when we are subscribed + subscribeLatch.countDown(); + } + }) + .doOnDispose(new Action() { + @Override + public void run() { + System.out.println("******************************* Unsubscribe received"); + // when we are unsubscribed + unsubscribeLatch.countDown(); + } + }); + + TestObserver observer = new TestObserver(); + o.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(observer); + System.out.println("send unsubscribe"); + // wait until connected + subscribeLatch.await(); + // now unsubscribe + observer.dispose(); + System.out.println("DONE sending unsubscribe ... now waiting"); + if (!unsubscribeLatch.await(3000, TimeUnit.MILLISECONDS)) { + System.out.println("Errors: " + observer.errors()); + if (observer.errors().size() > 0) { + observer.errors().get(0).printStackTrace(); + } + fail("timed out waiting for unsubscribe"); + } + observer.assertNoErrors(); + } + + @Test + public void testConnectUnsubscribeRaceConditionLoop() throws InterruptedException { + for (int i = 0; i < 100; i++) { + testConnectUnsubscribeRaceCondition(); + } + } + + @Test + public void testConnectUnsubscribeRaceCondition() throws InterruptedException { + final AtomicInteger subUnsubCount = new AtomicInteger(); + Observable o = synchronousInterval() + .doOnDispose(new Action() { + @Override + public void run() { + System.out.println("******************************* Unsubscribe received"); + // when we are unsubscribed + subUnsubCount.decrementAndGet(); + } + }) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Disposable d) { + System.out.println("******************************* SUBSCRIBE received"); + subUnsubCount.incrementAndGet(); + } + }); + + TestObserver observer = new TestObserver(); + + o.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(observer); + System.out.println("send unsubscribe"); + // now immediately unsubscribe while subscribeOn is racing to subscribe + observer.dispose(); + + // this generally will mean it won't even subscribe as it is already unsubscribed by the time connect() gets scheduled + // give time to the counter to update + Thread.sleep(10); + + // make sure we wait a bit in case the counter is still nonzero + int counter = 200; + while (subUnsubCount.get() != 0 && counter-- != 0) { + Thread.sleep(10); + } + // either we subscribed and then unsubscribed, or we didn't ever even subscribe + assertEquals(0, subUnsubCount.get()); + + System.out.println("DONE sending unsubscribe ... now waiting"); + System.out.println("Errors: " + observer.errors()); + if (observer.errors().size() > 0) { + observer.errors().get(0).printStackTrace(); + } + observer.assertNoErrors(); + } + + private Observable synchronousInterval() { + return Observable.unsafeCreate(new ObservableSource() { + @Override + public void subscribe(Observer observer) { + final AtomicBoolean cancel = new AtomicBoolean(); + observer.onSubscribe(Disposables.fromRunnable(new Runnable() { + @Override + public void run() { + cancel.set(true); + } + })); + for (;;) { + if (cancel.get()) { + break; + } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + observer.onNext(1L); + } + } + }); + } + + @Test + public void onlyFirstShouldSubscribeAndLastUnsubscribe() { + final AtomicInteger subscriptionCount = new AtomicInteger(); + final AtomicInteger unsubscriptionCount = new AtomicInteger(); + Observable o = Observable.unsafeCreate(new ObservableSource() { + @Override + public void subscribe(Observer observer) { + subscriptionCount.incrementAndGet(); + observer.onSubscribe(Disposables.fromRunnable(new Runnable() { + @Override + public void run() { + unsubscriptionCount.incrementAndGet(); + } + })); + } + }); + Observable refCounted = o.publish().refCount(); + + Disposable first = refCounted.subscribe(); + assertEquals(1, subscriptionCount.get()); + + Disposable second = refCounted.subscribe(); + assertEquals(1, subscriptionCount.get()); + + first.dispose(); + assertEquals(0, unsubscriptionCount.get()); + + second.dispose(); + assertEquals(1, unsubscriptionCount.get()); + } + + @Test + public void testRefCount() { + TestScheduler s = new TestScheduler(); + Observable interval = Observable.interval(100, TimeUnit.MILLISECONDS, s).publish().refCount(); + + // subscribe list1 + final List list1 = new ArrayList(); + Disposable d1 = interval.subscribe(new Consumer() { + @Override + public void accept(Long t1) { + list1.add(t1); + } + }); + + s.advanceTimeBy(200, TimeUnit.MILLISECONDS); + + assertEquals(2, list1.size()); + assertEquals(0L, list1.get(0).longValue()); + assertEquals(1L, list1.get(1).longValue()); + + // subscribe list2 + final List list2 = new ArrayList(); + Disposable d2 = interval.subscribe(new Consumer() { + @Override + public void accept(Long t1) { + list2.add(t1); + } + }); + + s.advanceTimeBy(300, TimeUnit.MILLISECONDS); + + // list 1 should have 5 items + assertEquals(5, list1.size()); + assertEquals(2L, list1.get(2).longValue()); + assertEquals(3L, list1.get(3).longValue()); + assertEquals(4L, list1.get(4).longValue()); + + // list 2 should only have 3 items + assertEquals(3, list2.size()); + assertEquals(2L, list2.get(0).longValue()); + assertEquals(3L, list2.get(1).longValue()); + assertEquals(4L, list2.get(2).longValue()); + + // unsubscribe list1 + d1.dispose(); + + // advance further + s.advanceTimeBy(300, TimeUnit.MILLISECONDS); + + // list 1 should still have 5 items + assertEquals(5, list1.size()); + + // list 2 should have 6 items + assertEquals(6, list2.size()); + assertEquals(5L, list2.get(3).longValue()); + assertEquals(6L, list2.get(4).longValue()); + assertEquals(7L, list2.get(5).longValue()); + + // unsubscribe list2 + d2.dispose(); + + // advance further + s.advanceTimeBy(1000, TimeUnit.MILLISECONDS); + + // subscribing a new one should start over because the source should have been unsubscribed + // subscribe list3 + final List list3 = new ArrayList(); + interval.subscribe(new Consumer() { + @Override + public void accept(Long t1) { + list3.add(t1); + } + }); + + s.advanceTimeBy(200, TimeUnit.MILLISECONDS); + + assertEquals(2, list3.size()); + assertEquals(0L, list3.get(0).longValue()); + assertEquals(1L, list3.get(1).longValue()); + + } + + @Test + public void testAlreadyUnsubscribedClient() { + Observer done = DisposingObserver.INSTANCE; + + Observer o = TestHelper.mockObserver(); + + Observable result = Observable.just(1).publish().refCount(); + + result.subscribe(done); + + result.subscribe(o); + + verify(o).onNext(1); + verify(o).onComplete(); + verify(o, never()).onError(any(Throwable.class)); + } + + @Test + public void testAlreadyUnsubscribedInterleavesWithClient() { + ReplaySubject source = ReplaySubject.create(); + + Observer done = DisposingObserver.INSTANCE; + + Observer o = TestHelper.mockObserver(); + InOrder inOrder = inOrder(o); + + Observable result = source.publish().refCount(); + + result.subscribe(o); + + source.onNext(1); + + result.subscribe(done); + + source.onNext(2); + source.onComplete(); + + inOrder.verify(o).onNext(1); + inOrder.verify(o).onNext(2); + inOrder.verify(o).onComplete(); + verify(o, never()).onError(any(Throwable.class)); + } + + @Test + public void testConnectDisconnectConnectAndSubjectState() { + 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; + } + }) + .publish().refCount(); + + TestObserver to1 = new TestObserver(); + TestObserver to2 = new TestObserver(); + + combined.subscribe(to1); + combined.subscribe(to2); + + to1.assertTerminated(); + to1.assertNoErrors(); + to1.assertValue(30); + + to2.assertTerminated(); + to2.assertNoErrors(); + to2.assertValue(30); + } + + @Test(timeout = 10000) + public void testUpstreamErrorAllowsRetry() throws InterruptedException { + final AtomicInteger intervalSubscribed = new AtomicInteger(); + Observable interval = + Observable.interval(200, TimeUnit.MILLISECONDS) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Disposable d) { + System.out.println("Subscribing to interval " + intervalSubscribed.incrementAndGet()); + } + } + ) + .flatMap(new Function>() { + @Override + public Observable apply(Long t1) { + return Observable.defer(new Callable>() { + @Override + public Observable call() { + return Observable.error(new Exception("Some exception")); + } + }); + } + }) + .onErrorResumeNext(new Function>() { + @Override + public Observable apply(Throwable t1) { + return Observable.error(t1); + } + }) + .publish() + .refCount(); + + interval + .doOnError(new Consumer() { + @Override + public void accept(Throwable t1) { + System.out.println("Observer 1 onError: " + t1); + } + }) + .retry(5) + .subscribe(new Consumer() { + @Override + public void accept(String t1) { + System.out.println("Observer 1: " + t1); + } + }); + Thread.sleep(100); + interval + .doOnError(new Consumer() { + @Override + public void accept(Throwable t1) { + System.out.println("Observer 2 onError: " + t1); + } + }) + .retry(5) + .subscribe(new Consumer() { + @Override + public void accept(String t1) { + System.out.println("Observer 2: " + t1); + } + }); + + Thread.sleep(1300); + + System.out.println(intervalSubscribed.get()); + assertEquals(6, intervalSubscribed.get()); + } + + private enum DisposingObserver implements Observer { + INSTANCE; + + @Override + public void onSubscribe(Disposable d) { + d.dispose(); + } + + @Override + public void onNext(Integer t) { + } + + @Override + public void onError(Throwable t) { + } + + @Override + public void onComplete() { + } + } + + @Test + public void disposed() { + TestHelper.checkDisposed(Observable.just(1).publish().refCount()); + } + + @Test + public void noOpConnect() { + final int[] calls = { 0 }; + Observable o = new ConnectableObservable() { + @Override + public void connect(Consumer connection) { + calls[0]++; + } + + @Override + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.disposed()); + } + }.refCount(); + + o.test(); + o.test(); + + assertEquals(1, calls[0]); + } + Observable source; + + @Test + public void replayNoLeak() throws Exception { + System.gc(); + Thread.sleep(100); + + long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = Observable.fromCallable(new Callable() { + @Override + public Object call() throws Exception { + return new byte[100 * 1000 * 1000]; + } + }) + .replay(1) + .refCount(); + + source.subscribe(); + + System.gc(); + Thread.sleep(100); + + long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = null; + assertTrue(String.format("%,3d -> %,3d%n", start, after), start + 20 * 1000 * 1000 > after); + } + + @Test + public void replayNoLeak2() throws Exception { + System.gc(); + Thread.sleep(100); + + long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = Observable.fromCallable(new Callable() { + @Override + public Object call() throws Exception { + return new byte[100 * 1000 * 1000]; + } + }).concatWith(Observable.never()) + .replay(1) + .refCount(); + + Disposable d1 = source.subscribe(); + Disposable d2 = source.subscribe(); + + d1.dispose(); + d2.dispose(); + + d1 = null; + d2 = null; + + System.gc(); + Thread.sleep(100); + + long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = null; + assertTrue(String.format("%,3d -> %,3d%n", start, after), start + 20 * 1000 * 1000 > after); + } + + static final class ExceptionData extends Exception { + private static final long serialVersionUID = -6763898015338136119L; + + public final Object data; + + ExceptionData(Object data) { + this.data = data; + } + } + + @Test + public void publishNoLeak() throws Exception { + System.gc(); + Thread.sleep(100); + + long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = Observable.fromCallable(new Callable() { + @Override + public Object call() throws Exception { + throw new ExceptionData(new byte[100 * 1000 * 1000]); + } + }) + .publish() + .refCount(); + + source.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); + + System.gc(); + Thread.sleep(100); + + long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = null; + assertTrue(String.format("%,3d -> %,3d%n", start, after), start + 20 * 1000 * 1000 > after); + } + + @Test + public void publishNoLeak2() throws Exception { + System.gc(); + Thread.sleep(100); + + long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = Observable.fromCallable(new Callable() { + @Override + public Object call() throws Exception { + return new byte[100 * 1000 * 1000]; + } + }).concatWith(Observable.never()) + .publish() + .refCount(); + + Disposable d1 = source.test(); + Disposable d2 = source.test(); + + d1.dispose(); + d2.dispose(); + + d1 = null; + d2 = null; + + System.gc(); + Thread.sleep(100); + + long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + source = null; + assertTrue(String.format("%,3d -> %,3d%n", start, after), start + 20 * 1000 * 1000 > after); + } + + @Test + public void replayIsUnsubscribed() { + ConnectableObservable co = Observable.just(1).concatWith(Observable.never()) + .replay(); + + if (co instanceof Disposable) { + assertTrue(((Disposable)co).isDisposed()); + + Disposable connection = co.connect(); + + assertFalse(((Disposable)co).isDisposed()); + + connection.dispose(); + + assertTrue(((Disposable)co).isDisposed()); + } + } + + static final class BadObservableSubscribe extends ConnectableObservable { + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Observer observer) { + throw new TestException("subscribeActual"); + } + } + + static final class BadObservableDispose extends ConnectableObservable implements Disposable { + + @Override + public void dispose() { + throw new TestException("dispose"); + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + } + } + + static final class BadObservableConnect extends ConnectableObservable { + + @Override + public void connect(Consumer connection) { + throw new TestException("connect"); + } + + @Override + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + } + } + + @Test + public void badSourceSubscribe() { + BadObservableSubscribe bo = new BadObservableSubscribe(); + + try { + bo.refCount() + .test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + } + + @Test + public void badSourceDispose() { + BadObservableDispose bo = new BadObservableDispose(); + + try { + bo.refCount() + .test() + .cancel(); + fail("Should have thrown"); + } catch (TestException expected) { + } + } + + @Test + public void badSourceConnect() { + BadObservableConnect bo = new BadObservableConnect(); + + try { + bo.refCount() + .test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + } + + static final class BadObservableSubscribe2 extends ConnectableObservable { + + int count; + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Observer observer) { + if (++count == 1) { + observer.onSubscribe(Disposables.empty()); + } else { + throw new TestException("subscribeActual"); + } + } + } + + @Test + public void badSourceSubscribe2() { + BadObservableSubscribe2 bo = new BadObservableSubscribe2(); + + Observable o = bo.refCount(); + o.test(); + try { + o.test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + } + + static final class BadObservableConnect2 extends ConnectableObservable + implements Disposable { + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); + } + + @Override + public void dispose() { + throw new TestException("dispose"); + } + + @Override + public boolean isDisposed() { + return false; + } + } + + @Test + public void badSourceCompleteDisconnect() { + BadObservableConnect2 bo = new BadObservableConnect2(); + + try { + bo.refCount() + .test(); + fail("Should have thrown"); + } catch (NullPointerException ex) { + assertTrue(ex.getCause() instanceof TestException); + } + } + + @Test(timeout = 7500) + public void blockingSourceAsnycCancel() throws Exception { + BehaviorSubject bs = BehaviorSubject.createDefault(1); + + Observable o = bs + .replay(1) + .refCount(); + + o.subscribe(); + + final AtomicBoolean interrupted = new AtomicBoolean(); + + o.switchMap(new Function>() { + @Override + public ObservableSource apply(Integer v) throws Exception { + return Observable.create(new ObservableOnSubscribe() { + @Override + public void subscribe(ObservableEmitter emitter) throws Exception { + while (!emitter.isDisposed()) { + Thread.sleep(100); + } + interrupted.set(true); + } + }); + } + }) + .take(500, TimeUnit.MILLISECONDS) + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(); + + assertTrue(interrupted.get()); + } + + @Test + public void byCount() { + final int[] subscriptions = { 0 }; + + Observable source = Observable.range(1, 5) + .doOnSubscribe(new Consumer() { + @Override + public void accept(Disposable d) throws Exception { + subscriptions[0]++; + } + }) + .publish() + .refCount(2); + + for (int i = 0; i < 3; i++) { + TestObserver to1 = source.test(); + + to1.withTag("to1 " + i); + to1.assertEmpty(); + + TestObserver to2 = source.test(); + + to2.withTag("to2 " + i); + + to1.assertResult(1, 2, 3, 4, 5); + to2.assertResult(1, 2, 3, 4, 5); + } + + assertEquals(3, subscriptions[0]); + } + + @Test + public void resubscribeBeforeTimeout() throws Exception { + final int[] subscriptions = { 0 }; + + PublishSubject ps = PublishSubject.create(); + + Observable source = ps + .doOnSubscribe(new Consumer() { + @Override + public void accept(Disposable d) throws Exception { + subscriptions[0]++; + } + }) + .publish() + .refCount(500, TimeUnit.MILLISECONDS); + + TestObserver to1 = source.test(); + + assertEquals(1, subscriptions[0]); + + to1.cancel(); + + Thread.sleep(100); + + to1 = source.test(); + + assertEquals(1, subscriptions[0]); + + Thread.sleep(500); + + assertEquals(1, subscriptions[0]); + + ps.onNext(1); + ps.onNext(2); + ps.onNext(3); + ps.onNext(4); + ps.onNext(5); + ps.onComplete(); + + to1 + .assertResult(1, 2, 3, 4, 5); + } + + @Test + public void letitTimeout() throws Exception { + final int[] subscriptions = { 0 }; + + PublishSubject ps = PublishSubject.create(); + + Observable source = ps + .doOnSubscribe(new Consumer() { + @Override + public void accept(Disposable d) throws Exception { + subscriptions[0]++; + } + }) + .publish() + .refCount(1, 100, TimeUnit.MILLISECONDS); + + TestObserver to1 = source.test(); + + assertEquals(1, subscriptions[0]); + + to1.cancel(); + + assertTrue(ps.hasObservers()); + + Thread.sleep(200); + + assertFalse(ps.hasObservers()); + } + + @Test + public void error() { + Observable.error(new IOException()) + .publish() + .refCount(500, TimeUnit.MILLISECONDS) + .test() + .assertFailure(IOException.class); + } + + @Test + public void comeAndGo() { + PublishSubject ps = PublishSubject.create(); + + Observable source = ps + .publish() + .refCount(1); + + TestObserver to1 = source.test(); + + assertTrue(ps.hasObservers()); + + for (int i = 0; i < 3; i++) { + TestObserver to2 = source.test(); + to1.cancel(); + to1 = to2; + } + + to1.cancel(); + + assertFalse(ps.hasObservers()); + } + + @Test + public void unsubscribeSubscribeRace() { + for (int i = 0; i < 1000; i++) { + + final Observable source = Observable.range(1, 5) + .replay() + .refCount(1) + ; + + final TestObserver to1 = source.test(); + + final TestObserver to2 = new TestObserver(); + + Runnable r1 = new Runnable() { + @Override + public void run() { + to1.cancel(); + } + }; + + Runnable r2 = new Runnable() { + @Override + public void run() { + source.subscribe(to2); + } + }; + + TestHelper.race(r1, r2, Schedulers.single()); + + to2 + .withTag("Round: " + i) + .assertResult(1, 2, 3, 4, 5); + } + } + + static final class BadObservableDoubleOnX extends ConnectableObservable + implements Disposable { + + @Override + public void connect(Consumer connection) { + try { + connection.accept(Disposables.empty()); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + @Override + protected void subscribeActual(Observer observer) { + observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposables.empty()); + observer.onComplete(); + observer.onComplete(); + observer.onError(new TestException()); + } + + @Override + public void dispose() { + } + + @Override + public boolean isDisposed() { + return false; + } + } + + @Test + public void doubleOnX() { + List errors = TestHelper.trackPluginErrors(); + try { + new BadObservableDoubleOnX() + .refCount() + .test() + .assertResult(); + + TestHelper.assertError(errors, 0, ProtocolViolationException.class); + TestHelper.assertUndeliverable(errors, 1, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void doubleOnXCount() { + List errors = TestHelper.trackPluginErrors(); + try { + new BadObservableDoubleOnX() + .refCount(1) + .test() + .assertResult(); + + TestHelper.assertError(errors, 0, ProtocolViolationException.class); + TestHelper.assertUndeliverable(errors, 1, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void doubleOnXTime() { + List errors = TestHelper.trackPluginErrors(); + try { + new BadObservableDoubleOnX() + .refCount(5, TimeUnit.SECONDS, Schedulers.single()) + .test() + .assertResult(); + + TestHelper.assertError(errors, 0, ProtocolViolationException.class); + TestHelper.assertUndeliverable(errors, 1, TestException.class); + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void cancelTerminateStateExclusion() { + ObservableRefCount o = (ObservableRefCount)PublishSubject.create() + .publish() + .refCount(); + + o.cancel(null); + + o.cancel(new RefConnection(o)); + + RefConnection rc = new RefConnection(o); + o.connection = null; + rc.subscriberCount = 0; + o.timeout(rc); + + rc.subscriberCount = 1; + o.timeout(rc); + + o.connection = rc; + o.timeout(rc); + + rc.subscriberCount = 0; + o.timeout(rc); + + // ------------------- + + rc.subscriberCount = 2; + rc.connected = false; + o.connection = rc; + o.cancel(rc); + + rc.subscriberCount = 1; + rc.connected = false; + o.connection = rc; + o.cancel(rc); + + rc.subscriberCount = 2; + rc.connected = true; + o.connection = rc; + o.cancel(rc); + + rc.subscriberCount = 1; + rc.connected = true; + o.connection = rc; + rc.lazySet(null); + o.cancel(rc); + + o.connection = rc; + o.cancel(new RefConnection(o)); + } + + @Test + public void replayRefCountShallBeThreadSafe() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + Observable observable = Observable.just(1).replay(1).refCount(); + + TestObserver observer1 = observable + .subscribeOn(Schedulers.io()) + .test(); + + TestObserver observer2 = observable + .subscribeOn(Schedulers.io()) + .test(); + + observer1 + .withTag("" + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(1); + + observer2 + .withTag("" + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(1); + } + } + + static final class TestConnectableObservable extends ConnectableObservable + implements Disposable { + + volatile boolean disposed; + + @Override + public void dispose() { + disposed = true; + } + + @Override + public boolean isDisposed() { + return disposed; + } + + @Override + public void connect(Consumer connection) { + // not relevant + } + + @Override + protected void subscribeActual(Observer observer) { + // not relevant + } + } + + @Test + public void timeoutDisposesSource() { + ObservableRefCount o = (ObservableRefCount)new TestConnectableObservable().refCount(); + + RefConnection rc = new RefConnection(o); + o.connection = rc; + + o.timeout(rc); + + assertTrue(((Disposable)o.source).isDisposed()); + } + + @Test + public void disconnectBeforeConnect() { + BehaviorSubject subject = BehaviorSubject.create(); + + Observable observable = subject + .replay(1) + .refCount(); + + observable.takeUntil(Observable.just(1)).test(); + + subject.onNext(2); + + observable.take(1).test().assertResult(2); + } + + @Test + public void publishRefCountShallBeThreadSafe() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + Observable observable = Observable.just(1).publish().refCount(); + + TestObserver observer1 = observable + .subscribeOn(Schedulers.io()) + .test(); + + TestObserver observer2 = observable + .subscribeOn(Schedulers.io()) + .test(); + + observer1 + .withTag("observer1 " + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertNoErrors() + .assertComplete(); + + observer2 + .withTag("observer2 " + i) + .awaitDone(5, TimeUnit.SECONDS) + .assertNoErrors() + .assertComplete(); + } + } +} diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index 0f0d930d8d..48a9ff2d5a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -23,7 +23,7 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import org.junit.Test; +import org.junit.*; import org.mockito.InOrder; import io.reactivex.*; @@ -43,6 +43,27 @@ public class ObservableRefCountTest { + // This will undo the workaround so that the plain ObservablePublish is still + // tested. + @Before + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void before() { + RxJavaPlugins.setOnConnectableObservableAssembly(new Function() { + @Override + public ConnectableObservable apply(ConnectableObservable co) throws Exception { + if (co instanceof ObservablePublishAlt) { + return ObservablePublish.create(((ObservablePublishAlt)co).source()); + } + return co; + } + }); + } + + @After + public void after() { + RxJavaPlugins.setOnConnectableObservableAssembly(null); + } + @Test public void testRefCountAsync() { final AtomicInteger subscribeCount = new AtomicInteger(); From 0df3285af53be02dedeabbcded56fc789b554b58 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 21 Jun 2019 07:33:56 +0200 Subject: [PATCH 165/211] Release 2.2.10 --- CHANGES.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7a5a441cea..df4bd2c840 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,22 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.10 - June 21, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.10%7C)) + +#### Bugfixes + + - [Pull 6499](https://github.com/ReactiveX/RxJava/pull/6499): Add missing null check to `BufferExactBoundedObserver`. + - [Pull 6505](https://github.com/ReactiveX/RxJava/pull/6505): Fix `publish().refCount()` hang due to race. + - [Pull 6522](https://github.com/ReactiveX/RxJava/pull/6522): Fix `concatMapDelayError` not continuing on fused inner source crash. + +#### Documentation changes + + - [Pull 6496](https://github.com/ReactiveX/RxJava/pull/6496): Fix outdated links in `Additional-Reading.md`. + - [Pull 6497](https://github.com/ReactiveX/RxJava/pull/6497): Fix links in `Alphabetical-List-of-Observable-Operators.md`. + - [Pull 6504](https://github.com/ReactiveX/RxJava/pull/6504): Fix various Javadocs & imports. + - [Pull 6506](https://github.com/ReactiveX/RxJava/pull/6506): Expand the Javadoc of `Flowable`. + - [Pull 6510](https://github.com/ReactiveX/RxJava/pull/6510): Correct "Reactive-Streams" to "Reactive Streams" in documentation. + ### Version 2.2.9 - May 30, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.9%7C)) #### Bugfixes From 0f4a3b981ac3efc4d4e7b03093202ade810132b9 Mon Sep 17 00:00:00 2001 From: jimin Date: Thu, 27 Jun 2019 23:00:04 +0800 Subject: [PATCH 166/211] simplify junit (#6546) --- src/test/java/io/reactivex/NotificationTest.java | 6 +++--- .../reactivex/completable/CompletableTest.java | 2 +- .../io/reactivex/exceptions/OnNextValueTest.java | 2 +- .../reactivex/flowable/FlowableMergeTests.java | 4 ++-- .../flowable/FlowableNotificationTest.java | 16 ++++++++-------- .../flowable/BlockingFlowableLatestTest.java | 12 ++++++------ .../flowable/BlockingFlowableMostRecentTest.java | 6 +++--- .../flowable/BlockingFlowableNextTest.java | 2 +- .../flowable/BlockingFlowableToFutureTest.java | 2 +- .../flowable/BlockingFlowableToIteratorTest.java | 12 ++++++------ .../FlowableOnBackpressureBufferTest.java | 2 +- .../flowable/FlowableUnsubscribeOnTest.java | 2 +- .../observable/BlockingObservableLatestTest.java | 12 ++++++------ .../BlockingObservableMostRecentTest.java | 6 +++--- .../observable/BlockingObservableNextTest.java | 2 +- .../BlockingObservableToFutureTest.java | 2 +- .../BlockingObservableToIteratorTest.java | 12 ++++++------ .../observable/ObservableGroupByTest.java | 2 +- .../observable/ObservableUnsubscribeOnTest.java | 2 +- .../internal/util/NotificationLiteTest.java | 2 +- .../internal/util/VolatileSizeArrayListTest.java | 16 ++++++++-------- .../observable/ObservableMergeTests.java | 4 ++-- .../io/reactivex/plugins/RxJavaPluginsTest.java | 2 +- .../processors/ReplayProcessorTest.java | 2 +- .../processors/UnicastProcessorTest.java | 12 ++++++------ .../AbstractSchedulerConcurrencyTests.java | 2 +- .../schedulers/ComputationSchedulerTests.java | 2 +- .../java/io/reactivex/schedulers/TimedTest.java | 2 +- .../schedulers/TrampolineSchedulerTest.java | 2 +- .../io/reactivex/subjects/ReplaySubjectTest.java | 2 +- .../reactivex/subjects/UnicastSubjectTest.java | 12 ++++++------ 31 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/test/java/io/reactivex/NotificationTest.java b/src/test/java/io/reactivex/NotificationTest.java index c3283edd3c..504c0425bc 100644 --- a/src/test/java/io/reactivex/NotificationTest.java +++ b/src/test/java/io/reactivex/NotificationTest.java @@ -41,11 +41,11 @@ public void valueOfOnCompleteIsNull() { @Test public void notEqualsToObject() { Notification n1 = Notification.createOnNext(0); - assertFalse(n1.equals(0)); + assertNotEquals(0, n1); Notification n2 = Notification.createOnError(new TestException()); - assertFalse(n2.equals(0)); + assertNotEquals(0, n2); Notification n3 = Notification.createOnComplete(); - assertFalse(n3.equals(0)); + assertNotEquals(0, n3); } @Test diff --git a/src/test/java/io/reactivex/completable/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java index 80f4b49d5a..3fda12b46e 100644 --- a/src/test/java/io/reactivex/completable/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -4326,7 +4326,7 @@ public boolean test(Throwable t) { Assert.assertEquals(2, errors.size()); Assert.assertTrue(errors.get(0).toString(), errors.get(0) instanceof TestException); - Assert.assertEquals(errors.get(0).toString(), null, errors.get(0).getMessage()); + Assert.assertNull(errors.get(0).toString(), errors.get(0).getMessage()); Assert.assertTrue(errors.get(1).toString(), errors.get(1) instanceof TestException); Assert.assertEquals(errors.get(1).toString(), "Forced inner failure", errors.get(1).getMessage()); } diff --git a/src/test/java/io/reactivex/exceptions/OnNextValueTest.java b/src/test/java/io/reactivex/exceptions/OnNextValueTest.java index 6e0541436b..c0d9df5981 100644 --- a/src/test/java/io/reactivex/exceptions/OnNextValueTest.java +++ b/src/test/java/io/reactivex/exceptions/OnNextValueTest.java @@ -71,7 +71,7 @@ public void onError(Throwable e) { assertTrue(trace, trace.contains("OnNextValue")); - assertTrue("No Cause on throwable" + e, e.getCause() != null); + assertNotNull("No Cause on throwable" + e, e.getCause()); // assertTrue(e.getCause().getClass().getSimpleName() + " no OnNextValue", // e.getCause() instanceof OnErrorThrowable.OnNextValue); } diff --git a/src/test/java/io/reactivex/flowable/FlowableMergeTests.java b/src/test/java/io/reactivex/flowable/FlowableMergeTests.java index 5c96bcf096..5facc6665f 100644 --- a/src/test/java/io/reactivex/flowable/FlowableMergeTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableMergeTests.java @@ -69,7 +69,7 @@ public void testMergeCovariance3() { assertTrue(values.get(0) instanceof HorrorMovie); assertTrue(values.get(1) instanceof Movie); - assertTrue(values.get(2) != null); + assertNotNull(values.get(2)); assertTrue(values.get(3) instanceof HorrorMovie); } @@ -92,7 +92,7 @@ public Publisher call() { assertTrue(values.get(0) instanceof HorrorMovie); assertTrue(values.get(1) instanceof Movie); - assertTrue(values.get(2) != null); + assertNotNull(values.get(2)); assertTrue(values.get(3) instanceof HorrorMovie); } diff --git a/src/test/java/io/reactivex/flowable/FlowableNotificationTest.java b/src/test/java/io/reactivex/flowable/FlowableNotificationTest.java index e068cb7399..37b79676d3 100644 --- a/src/test/java/io/reactivex/flowable/FlowableNotificationTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableNotificationTest.java @@ -23,28 +23,28 @@ public class FlowableNotificationTest { public void testOnNextIntegerNotificationDoesNotEqualNullNotification() { final Notification integerNotification = Notification.createOnNext(1); final Notification nullNotification = Notification.createOnNext(null); - Assert.assertFalse(integerNotification.equals(nullNotification)); + Assert.assertNotEquals(integerNotification, nullNotification); } @Test(expected = NullPointerException.class) public void testOnNextNullNotificationDoesNotEqualIntegerNotification() { final Notification integerNotification = Notification.createOnNext(1); final Notification nullNotification = Notification.createOnNext(null); - Assert.assertFalse(nullNotification.equals(integerNotification)); + Assert.assertNotEquals(nullNotification, integerNotification); } @Test public void testOnNextIntegerNotificationsWhenEqual() { final Notification integerNotification = Notification.createOnNext(1); final Notification integerNotification2 = Notification.createOnNext(1); - Assert.assertTrue(integerNotification.equals(integerNotification2)); + Assert.assertEquals(integerNotification, integerNotification2); } @Test public void testOnNextIntegerNotificationsWhenNotEqual() { final Notification integerNotification = Notification.createOnNext(1); final Notification integerNotification2 = Notification.createOnNext(2); - Assert.assertFalse(integerNotification.equals(integerNotification2)); + Assert.assertNotEquals(integerNotification, integerNotification2); } @Test @@ -52,7 +52,7 @@ public void testOnNextIntegerNotificationsWhenNotEqual() { public void testOnErrorIntegerNotificationDoesNotEqualNullNotification() { final Notification integerNotification = Notification.createOnError(new Exception()); final Notification nullNotification = Notification.createOnError(null); - Assert.assertFalse(integerNotification.equals(nullNotification)); + Assert.assertNotEquals(integerNotification, nullNotification); } @Test @@ -60,7 +60,7 @@ public void testOnErrorIntegerNotificationDoesNotEqualNullNotification() { public void testOnErrorNullNotificationDoesNotEqualIntegerNotification() { final Notification integerNotification = Notification.createOnError(new Exception()); final Notification nullNotification = Notification.createOnError(null); - Assert.assertFalse(nullNotification.equals(integerNotification)); + Assert.assertNotEquals(nullNotification, integerNotification); } @Test @@ -68,13 +68,13 @@ public void testOnErrorIntegerNotificationsWhenEqual() { final Exception exception = new Exception(); final Notification onErrorNotification = Notification.createOnError(exception); final Notification onErrorNotification2 = Notification.createOnError(exception); - Assert.assertTrue(onErrorNotification.equals(onErrorNotification2)); + Assert.assertEquals(onErrorNotification, onErrorNotification2); } @Test public void testOnErrorIntegerNotificationWhenNotEqual() { final Notification onErrorNotification = Notification.createOnError(new Exception()); final Notification onErrorNotification2 = Notification.createOnError(new Exception()); - Assert.assertFalse(onErrorNotification.equals(onErrorNotification2)); + Assert.assertNotEquals(onErrorNotification, onErrorNotification2); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableLatestTest.java index 92dcd3dd02..a0249db01e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableLatestTest.java @@ -43,13 +43,13 @@ public void testSimple() { for (int i = 0; i < 9; i++) { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(true, it.hasNext()); + Assert.assertTrue(it.hasNext()); Assert.assertEquals(Long.valueOf(i), it.next()); } scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); } @Test(timeout = 1000) @@ -68,13 +68,13 @@ public void testSameSourceMultipleIterators() { for (int i = 0; i < 9; i++) { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(true, it.hasNext()); + Assert.assertTrue(it.hasNext()); Assert.assertEquals(Long.valueOf(i), it.next()); } scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); } } @@ -86,7 +86,7 @@ public void testEmpty() { Iterator it = iter.iterator(); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); it.next(); } @@ -165,7 +165,7 @@ public void testFasterSource() { source.onNext(7); source.onComplete(); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); } @Ignore("THe target is an enum") diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java index 26e6eb5716..70a43694d4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java @@ -28,7 +28,7 @@ public class BlockingFlowableMostRecentTest { @Test public void testMostRecentNull() { - assertEquals(null, Flowable.never().blockingMostRecent(null).iterator().next()); + assertNull(Flowable.never().blockingMostRecent(null).iterator().next()); } @Test @@ -87,12 +87,12 @@ public void testSingleSourceManyIterators() { for (int i = 0; i < 9; i++) { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(true, it.hasNext()); + Assert.assertTrue(it.hasNext()); Assert.assertEquals(Long.valueOf(i), it.next()); } scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java index 32ee150cf3..e2e2cc4337 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java @@ -318,7 +318,7 @@ public void testSingleSourceManyIterators() throws InterruptedException { BlockingFlowableNext.NextIterator it = (BlockingFlowableNext.NextIterator)iter.iterator(); for (long i = 0; i < 10; i++) { - Assert.assertEquals(true, it.hasNext()); + Assert.assertTrue(it.hasNext()); Assert.assertEquals(j + "th iteration next", Long.valueOf(i), it.next()); } terminal.onNext(1); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToFutureTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToFutureTest.java index d90b0b2f43..c1363a452b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToFutureTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToFutureTest.java @@ -120,6 +120,6 @@ public void testGetWithEmptyFlowable() throws Throwable { public void testGetWithASingleNullItem() throws Exception { Flowable obs = Flowable.just((String)null); Future f = obs.toFuture(); - assertEquals(null, f.get()); + assertNull(f.get()); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java index 412d59ac5f..df3fe6d62c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java @@ -33,16 +33,16 @@ public void testToIterator() { Iterator it = obs.blockingIterable().iterator(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals("one", it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals("two", it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals("three", it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); } @@ -60,10 +60,10 @@ public void subscribe(Subscriber subscriber) { Iterator it = obs.blockingIterable().iterator(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals("one", it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); it.next(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java index 84793d3136..f44fbc8353 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java @@ -143,7 +143,7 @@ public void run() { int size = ts.values().size(); assertTrue(size <= 150); // will get up to 50 more - assertTrue(ts.values().get(size - 1) == size - 1); + assertEquals((long)ts.values().get(size - 1), size - 1); } static final Flowable infinite = Flowable.unsafeCreate(new Publisher() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java index cd6f22ea56..36112023bb 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java @@ -73,7 +73,7 @@ public void subscribe(Subscriber t1) { System.out.println("unsubscribeThread: " + unsubscribeThread); System.out.println("subscribeThread.get(): " + subscribeThread.get()); - assertTrue(unsubscribeThread == uiEventLoop.getThread()); + assertSame(unsubscribeThread, uiEventLoop.getThread()); ts.assertValues(1, 2); ts.assertTerminated(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableLatestTest.java index cdd95c58f2..27aa27ec2d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableLatestTest.java @@ -44,13 +44,13 @@ public void testSimple() { for (int i = 0; i < 9; i++) { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(true, it.hasNext()); + Assert.assertTrue(it.hasNext()); Assert.assertEquals(Long.valueOf(i), it.next()); } scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); } @Test(timeout = 1000) @@ -69,13 +69,13 @@ public void testSameSourceMultipleIterators() { for (int i = 0; i < 9; i++) { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(true, it.hasNext()); + Assert.assertTrue(it.hasNext()); Assert.assertEquals(Long.valueOf(i), it.next()); } scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); } } @@ -87,7 +87,7 @@ public void testEmpty() { Iterator it = iter.iterator(); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); it.next(); } @@ -166,7 +166,7 @@ public void testFasterSource() { source.onNext(7); source.onComplete(); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); } @Test(expected = UnsupportedOperationException.class) diff --git a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecentTest.java b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecentTest.java index 5a277d6ddd..a109beb2d7 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecentTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecentTest.java @@ -28,7 +28,7 @@ public class BlockingObservableMostRecentTest { @Test public void testMostRecentNull() { - assertEquals(null, Observable.never().blockingMostRecent(null).iterator().next()); + assertNull(Observable.never().blockingMostRecent(null).iterator().next()); } static Iterable mostRecent(Observable source, T initialValue) { @@ -91,12 +91,12 @@ public void testSingleSourceManyIterators() { for (int i = 0; i < 9; i++) { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(true, it.hasNext()); + Assert.assertTrue(it.hasNext()); Assert.assertEquals(Long.valueOf(i), it.next()); } scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - Assert.assertEquals(false, it.hasNext()); + Assert.assertFalse(it.hasNext()); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java index 2b8e670c16..947a2a027d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java @@ -323,7 +323,7 @@ public void testSingleSourceManyIterators() throws InterruptedException { BlockingObservableNext.NextIterator it = (BlockingObservableNext.NextIterator)iter.iterator(); for (long i = 0; i < 10; i++) { - Assert.assertEquals(true, it.hasNext()); + Assert.assertTrue(it.hasNext()); Assert.assertEquals(j + "th iteration next", Long.valueOf(i), it.next()); } terminal.onNext(1); diff --git a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToFutureTest.java b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToFutureTest.java index f4fa707ee4..632d3dad72 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToFutureTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToFutureTest.java @@ -121,6 +121,6 @@ public void testGetWithEmptyFlowable() throws Throwable { public void testGetWithASingleNullItem() throws Exception { Observable obs = Observable.just((String)null); Future f = obs.toFuture(); - assertEquals(null, f.get()); + assertNull(f.get()); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToIteratorTest.java b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToIteratorTest.java index af22e83993..f79b2a294d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToIteratorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToIteratorTest.java @@ -34,16 +34,16 @@ public void testToIterator() { Iterator it = obs.blockingIterable().iterator(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals("one", it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals("two", it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals("three", it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); } @@ -61,10 +61,10 @@ public void subscribe(Observer observer) { Iterator it = obs.blockingIterable().iterator(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals("one", it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); it.next(); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java index 42f441bd10..31bb5cf6a0 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java @@ -1364,7 +1364,7 @@ public void accept(String s) { }); } }); - assertEquals(null, key[0]); + assertNull(key[0]); assertEquals(Arrays.asList("a", "b", "c"), values); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java index 2b7d7f4141..1067ff37c9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java @@ -72,7 +72,7 @@ public void subscribe(Observer t1) { System.out.println("unsubscribeThread: " + unsubscribeThread); System.out.println("subscribeThread.get(): " + subscribeThread.get()); - assertTrue(unsubscribeThread.toString(), unsubscribeThread == uiEventLoop.getThread()); + assertSame(unsubscribeThread.toString(), unsubscribeThread, uiEventLoop.getThread()); observer.assertValues(1, 2); observer.assertTerminated(); diff --git a/src/test/java/io/reactivex/internal/util/NotificationLiteTest.java b/src/test/java/io/reactivex/internal/util/NotificationLiteTest.java index 36bfe52566..f6e463c7da 100644 --- a/src/test/java/io/reactivex/internal/util/NotificationLiteTest.java +++ b/src/test/java/io/reactivex/internal/util/NotificationLiteTest.java @@ -45,6 +45,6 @@ public void errorNotificationCompare() { assertEquals(ex.hashCode(), n1.hashCode()); - assertFalse(n1.equals(NotificationLite.complete())); + assertNotEquals(n1, NotificationLite.complete()); } } diff --git a/src/test/java/io/reactivex/internal/util/VolatileSizeArrayListTest.java b/src/test/java/io/reactivex/internal/util/VolatileSizeArrayListTest.java index 6086fff7e3..00d3119b32 100644 --- a/src/test/java/io/reactivex/internal/util/VolatileSizeArrayListTest.java +++ b/src/test/java/io/reactivex/internal/util/VolatileSizeArrayListTest.java @@ -82,22 +82,22 @@ public void normal() { VolatileSizeArrayList list2 = new VolatileSizeArrayList(); list2.addAll(Arrays.asList(1, 2, 3, 4, 5, 6)); - assertFalse(list2.equals(list)); - assertFalse(list.equals(list2)); + assertNotEquals(list2, list); + assertNotEquals(list, list2); list2.add(7); - assertTrue(list2.equals(list)); - assertTrue(list.equals(list2)); + assertEquals(list2, list); + assertEquals(list, list2); List list3 = new ArrayList(); list3.addAll(Arrays.asList(1, 2, 3, 4, 5, 6)); - assertFalse(list3.equals(list)); - assertFalse(list.equals(list3)); + assertNotEquals(list3, list); + assertNotEquals(list, list3); list3.add(7); - assertTrue(list3.equals(list)); - assertTrue(list.equals(list3)); + assertEquals(list3, list); + assertEquals(list, list3); assertEquals(list.hashCode(), list3.hashCode()); assertEquals(list.toString(), list3.toString()); diff --git a/src/test/java/io/reactivex/observable/ObservableMergeTests.java b/src/test/java/io/reactivex/observable/ObservableMergeTests.java index c7ee01c591..1d68a5d28e 100644 --- a/src/test/java/io/reactivex/observable/ObservableMergeTests.java +++ b/src/test/java/io/reactivex/observable/ObservableMergeTests.java @@ -68,7 +68,7 @@ public void testMergeCovariance3() { assertTrue(values.get(0) instanceof HorrorMovie); assertTrue(values.get(1) instanceof Movie); - assertTrue(values.get(2) != null); + assertNotNull(values.get(2)); assertTrue(values.get(3) instanceof HorrorMovie); } @@ -91,7 +91,7 @@ public Observable call() { assertTrue(values.get(0) instanceof HorrorMovie); assertTrue(values.get(1) instanceof Movie); - assertTrue(values.get(2) != null); + assertNotNull(values.get(2)); assertTrue(values.get(3) instanceof HorrorMovie); } diff --git a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java index efd4642d7e..229dc7c873 100644 --- a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java +++ b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java @@ -2070,7 +2070,7 @@ public void run() { Thread t = value.get(); assertNotNull(t); - assertTrue(expectedThreadName.equals(t.getName())); + assertEquals(expectedThreadName, t.getName()); } catch (Exception e) { fail(); } finally { diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java index cf930b062a..7ecc2bea31 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java @@ -1051,7 +1051,7 @@ public void peekStateTimeAndSizeValueExpired() { scheduler.advanceTimeBy(2, TimeUnit.DAYS); - assertEquals(null, rp.getValue()); + assertNull(rp.getValue()); assertEquals(0, rp.getValues().length); assertNull(rp.getValues(new Integer[2])[0]); } diff --git a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java index 5bbe6dca75..84335845a9 100644 --- a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java +++ b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java @@ -132,9 +132,9 @@ public void onTerminateCalledWhenOnError() { } }); - assertEquals(false, didRunOnTerminate.get()); + assertFalse(didRunOnTerminate.get()); us.onError(new RuntimeException("some error")); - assertEquals(true, didRunOnTerminate.get()); + assertTrue(didRunOnTerminate.get()); } @Test @@ -147,9 +147,9 @@ public void onTerminateCalledWhenOnComplete() { } }); - assertEquals(false, didRunOnTerminate.get()); + assertFalse(didRunOnTerminate.get()); us.onComplete(); - assertEquals(true, didRunOnTerminate.get()); + assertTrue(didRunOnTerminate.get()); } @Test @@ -164,9 +164,9 @@ public void onTerminateCalledWhenCanceled() { final Disposable subscribe = us.subscribe(); - assertEquals(false, didRunOnTerminate.get()); + assertFalse(didRunOnTerminate.get()); subscribe.dispose(); - assertEquals(true, didRunOnTerminate.get()); + assertTrue(didRunOnTerminate.get()); } @Test(expected = NullPointerException.class) diff --git a/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java b/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java index 3605c74679..af489f5650 100644 --- a/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java +++ b/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java @@ -405,7 +405,7 @@ public void accept(Integer t) { throw new RuntimeException("The latch should have released if we are async.", e); } - assertFalse(Thread.currentThread().getName().equals(currentThreadName)); + assertNotEquals(Thread.currentThread().getName(), currentThreadName); System.out.println("Thread: " + Thread.currentThread().getName()); System.out.println("t: " + t); count.incrementAndGet(); diff --git a/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java b/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java index b33efed40b..86ae8ac54e 100644 --- a/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java +++ b/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java @@ -122,7 +122,7 @@ public final void testMergeWithExecutorScheduler() { @Override public String apply(Integer t) { - assertFalse(Thread.currentThread().getName().equals(currentThreadName)); + assertNotEquals(Thread.currentThread().getName(), currentThreadName); assertTrue(Thread.currentThread().getName().startsWith("RxComputationThreadPool")); return "Value_" + t + "_Thread_" + Thread.currentThread().getName(); } diff --git a/src/test/java/io/reactivex/schedulers/TimedTest.java b/src/test/java/io/reactivex/schedulers/TimedTest.java index 7e8cb41e1a..c380188665 100644 --- a/src/test/java/io/reactivex/schedulers/TimedTest.java +++ b/src/test/java/io/reactivex/schedulers/TimedTest.java @@ -75,7 +75,7 @@ public void equalsWith() { assertNotEquals(new Object(), t1); - assertFalse(t1.equals(new Object())); + assertNotEquals(t1, new Object()); } @Test diff --git a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java index 2768a12b1a..b125d43252 100644 --- a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java @@ -51,7 +51,7 @@ public final void testMergeWithCurrentThreadScheduler1() { @Override public String apply(Integer t) { - assertTrue(Thread.currentThread().getName().equals(currentThreadName)); + assertEquals(Thread.currentThread().getName(), currentThreadName); return "Value_" + t + "_Thread_" + Thread.currentThread().getName(); } }); diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java index aa91270226..c836e179b5 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java @@ -965,7 +965,7 @@ public void peekStateTimeAndSizeValueExpired() { scheduler.advanceTimeBy(2, TimeUnit.DAYS); - assertEquals(null, rp.getValue()); + assertNull(rp.getValue()); assertEquals(0, rp.getValues().length); assertNull(rp.getValues(new Integer[2])[0]); } diff --git a/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java b/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java index ca13ba0495..9b0a16879d 100644 --- a/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java @@ -168,9 +168,9 @@ public void onTerminateCalledWhenOnError() { } }); - assertEquals(false, didRunOnTerminate.get()); + assertFalse(didRunOnTerminate.get()); us.onError(new RuntimeException("some error")); - assertEquals(true, didRunOnTerminate.get()); + assertTrue(didRunOnTerminate.get()); } @Test @@ -183,9 +183,9 @@ public void onTerminateCalledWhenOnComplete() { } }); - assertEquals(false, didRunOnTerminate.get()); + assertFalse(didRunOnTerminate.get()); us.onComplete(); - assertEquals(true, didRunOnTerminate.get()); + assertTrue(didRunOnTerminate.get()); } @Test @@ -200,9 +200,9 @@ public void onTerminateCalledWhenCanceled() { final Disposable subscribe = us.subscribe(); - assertEquals(false, didRunOnTerminate.get()); + assertFalse(didRunOnTerminate.get()); subscribe.dispose(); - assertEquals(true, didRunOnTerminate.get()); + assertTrue(didRunOnTerminate.get()); } @Test(expected = NullPointerException.class) From 67b9cf6ac86907e83044e516b82f6594409b091c Mon Sep 17 00:00:00 2001 From: jimin Date: Fri, 28 Jun 2019 13:22:00 +0800 Subject: [PATCH 167/211] remove unnecessary import (#6545) --- src/test/java/io/reactivex/completable/CompletableTest.java | 1 - src/test/java/io/reactivex/disposables/DisposablesTest.java | 1 - src/test/java/io/reactivex/flowable/FlowableTests.java | 1 - .../operators/completable/CompletableFromCallableTest.java | 1 - .../reactivex/internal/operators/flowable/FlowableAllTest.java | 1 - .../reactivex/internal/operators/flowable/FlowableAnyTest.java | 1 - .../internal/operators/flowable/FlowableAsObservableTest.java | 1 - .../internal/operators/flowable/FlowableBufferTest.java | 1 - .../internal/operators/flowable/FlowableCombineLatestTest.java | 1 - .../internal/operators/flowable/FlowableConcatTest.java | 1 - .../internal/operators/flowable/FlowableDebounceTest.java | 1 - .../internal/operators/flowable/FlowableDelayTest.java | 1 - .../internal/operators/flowable/FlowableDematerializeTest.java | 1 - .../internal/operators/flowable/FlowableDistinctTest.java | 1 - .../operators/flowable/FlowableDistinctUntilChangedTest.java | 1 - .../internal/operators/flowable/FlowableDoOnEachTest.java | 1 - .../internal/operators/flowable/FlowableFilterTest.java | 1 - .../internal/operators/flowable/FlowableFlatMapTest.java | 1 - .../internal/operators/flowable/FlowableFromCallableTest.java | 1 - .../internal/operators/flowable/FlowableFromIterableTest.java | 1 - .../internal/operators/flowable/FlowableGroupByTest.java | 1 - .../internal/operators/flowable/FlowableGroupJoinTest.java | 1 - .../reactivex/internal/operators/flowable/FlowableHideTest.java | 1 - .../reactivex/internal/operators/flowable/FlowableJoinTest.java | 1 - .../reactivex/internal/operators/flowable/FlowableMapTest.java | 2 -- .../operators/flowable/FlowableMergeDelayErrorTest.java | 1 - .../internal/operators/flowable/FlowableMergeTest.java | 1 - .../internal/operators/flowable/FlowableObserveOnTest.java | 1 - .../flowable/FlowableOnErrorResumeNextViaFunctionTest.java | 1 - .../internal/operators/flowable/FlowableRangeLongTest.java | 1 - .../internal/operators/flowable/FlowableRangeTest.java | 1 - .../internal/operators/flowable/FlowableReduceTest.java | 1 - .../internal/operators/flowable/FlowableRefCountAltTest.java | 1 - .../internal/operators/flowable/FlowableRefCountTest.java | 1 - .../internal/operators/flowable/FlowableRepeatTest.java | 1 - .../internal/operators/flowable/FlowableReplayTest.java | 1 - .../internal/operators/flowable/FlowableRetryTest.java | 1 - .../operators/flowable/FlowableRetryWithPredicateTest.java | 1 - .../internal/operators/flowable/FlowableSampleTest.java | 1 - .../reactivex/internal/operators/flowable/FlowableScanTest.java | 1 - .../internal/operators/flowable/FlowableSequenceEqualTest.java | 1 - .../internal/operators/flowable/FlowableSingleTest.java | 1 - .../internal/operators/flowable/FlowableSkipLastTimedTest.java | 1 - .../internal/operators/flowable/FlowableSkipWhileTest.java | 1 - .../internal/operators/flowable/FlowableSwitchTest.java | 1 - .../internal/operators/flowable/FlowableTakeLastTest.java | 1 - .../reactivex/internal/operators/flowable/FlowableTakeTest.java | 1 - .../operators/flowable/FlowableTakeUntilPredicateTest.java | 1 - .../internal/operators/flowable/FlowableTakeWhileTest.java | 1 - .../internal/operators/flowable/FlowableThrottleFirstTest.java | 1 - .../internal/operators/flowable/FlowableTimeoutTests.java | 1 - .../operators/flowable/FlowableTimeoutWithSelectorTest.java | 1 - .../internal/operators/flowable/FlowableTimerTest.java | 1 - .../internal/operators/flowable/FlowableToListTest.java | 1 - .../operators/flowable/FlowableWindowWithFlowableTest.java | 1 - .../internal/operators/flowable/FlowableWindowWithSizeTest.java | 1 - .../internal/operators/flowable/FlowableWithLatestFromTest.java | 1 - .../internal/operators/flowable/FlowableZipIterableTest.java | 1 - .../reactivex/internal/operators/flowable/FlowableZipTest.java | 1 - .../internal/operators/maybe/MaybeFromCallableTest.java | 1 - .../internal/operators/observable/ObservableAllTest.java | 1 - .../internal/operators/observable/ObservableAnyTest.java | 1 - .../internal/operators/observable/ObservableBufferTest.java | 1 - .../operators/observable/ObservableCombineLatestTest.java | 1 - .../internal/operators/observable/ObservableDebounceTest.java | 1 - .../internal/operators/observable/ObservableDelayTest.java | 1 - .../operators/observable/ObservableDematerializeTest.java | 1 - .../internal/operators/observable/ObservableDistinctTest.java | 1 - .../observable/ObservableDistinctUntilChangedTest.java | 1 - .../internal/operators/observable/ObservableDoOnEachTest.java | 1 - .../internal/operators/observable/ObservableFilterTest.java | 1 - .../internal/operators/observable/ObservableFlatMapTest.java | 1 - .../operators/observable/ObservableFromCallableTest.java | 1 - .../operators/observable/ObservableFromIterableTest.java | 1 - .../internal/operators/observable/ObservableGroupJoinTest.java | 1 - .../internal/operators/observable/ObservableJoinTest.java | 1 - .../internal/operators/observable/ObservableLastTest.java | 1 - .../internal/operators/observable/ObservableMapTest.java | 1 - .../internal/operators/observable/ObservableObserveOnTest.java | 1 - .../observable/ObservableOnErrorResumeNextViaFunctionTest.java | 1 - .../internal/operators/observable/ObservableRangeLongTest.java | 1 - .../internal/operators/observable/ObservableRangeTest.java | 1 - .../internal/operators/observable/ObservableReduceTest.java | 1 - .../operators/observable/ObservableRefCountAltTest.java | 1 - .../internal/operators/observable/ObservableRefCountTest.java | 1 - .../internal/operators/observable/ObservableRepeatTest.java | 1 - .../internal/operators/observable/ObservableReplayTest.java | 1 - .../internal/operators/observable/ObservableRetryTest.java | 1 - .../operators/observable/ObservableRetryWithPredicateTest.java | 1 - .../internal/operators/observable/ObservableSampleTest.java | 1 - .../internal/operators/observable/ObservableScanTest.java | 1 - .../operators/observable/ObservableSequenceEqualTest.java | 1 - .../internal/operators/observable/ObservableSkipLastTest.java | 1 - .../operators/observable/ObservableSkipLastTimedTest.java | 1 - .../internal/operators/observable/ObservableSkipWhileTest.java | 1 - .../internal/operators/observable/ObservableSwitchTest.java | 1 - .../internal/operators/observable/ObservableTakeLastTest.java | 1 - .../operators/observable/ObservableTakeLastTimedTest.java | 1 - .../internal/operators/observable/ObservableTakeTest.java | 1 - .../operators/observable/ObservableTakeUntilPredicateTest.java | 1 - .../internal/operators/observable/ObservableTimeoutTests.java | 1 - .../operators/observable/ObservableTimeoutWithSelectorTest.java | 1 - .../internal/operators/observable/ObservableTimerTest.java | 1 - .../internal/operators/observable/ObservableToListTest.java | 1 - .../observable/ObservableWindowWithObservableTest.java | 1 - .../operators/observable/ObservableZipIterableTest.java | 1 - .../internal/operators/observable/ObservableZipTest.java | 1 - .../internal/operators/single/SingleFromCallableTest.java | 1 - src/test/java/io/reactivex/observable/ObservableTest.java | 1 - src/test/java/io/reactivex/processors/AsyncProcessorTest.java | 1 - .../java/io/reactivex/processors/BehaviorProcessorTest.java | 1 - src/test/java/io/reactivex/processors/PublishProcessorTest.java | 1 - src/test/java/io/reactivex/processors/ReplayProcessorTest.java | 1 - src/test/java/io/reactivex/single/SingleNullTests.java | 1 - src/test/java/io/reactivex/subjects/AsyncSubjectTest.java | 1 - src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java | 1 - src/test/java/io/reactivex/subjects/PublishSubjectTest.java | 1 - src/test/java/io/reactivex/subjects/ReplaySubjectTest.java | 1 - .../java/io/reactivex/subscribers/SerializedSubscriberTest.java | 1 - 119 files changed, 120 deletions(-) diff --git a/src/test/java/io/reactivex/completable/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java index 3fda12b46e..40e52c8e24 100644 --- a/src/test/java/io/reactivex/completable/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -14,7 +14,6 @@ package io.reactivex.completable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/disposables/DisposablesTest.java b/src/test/java/io/reactivex/disposables/DisposablesTest.java index 779b85fead..531838acc1 100644 --- a/src/test/java/io/reactivex/disposables/DisposablesTest.java +++ b/src/test/java/io/reactivex/disposables/DisposablesTest.java @@ -14,7 +14,6 @@ package io.reactivex.disposables; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/flowable/FlowableTests.java b/src/test/java/io/reactivex/flowable/FlowableTests.java index fa8026da6c..c9e226da9e 100644 --- a/src/test/java/io/reactivex/flowable/FlowableTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableTests.java @@ -14,7 +14,6 @@ package io.reactivex.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableFromCallableTest.java index b0d551a64e..412e3a2d1f 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableFromCallableTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.completable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.concurrent.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java index e859766ca8..409510b23f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java index 76d4b034b7..5c8a9d6f84 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java index a297911040..7dd78955ee 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertFalse; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import org.junit.Test; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java index e79130ff41..8edd8e7cd2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java index 4443a71759..a96b8c8193 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.lang.reflect.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java index 772f559733..c1faba86d4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.lang.reflect.Method; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java index 8df7c9c193..459d63e5c1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java index 401b9c62b4..cf1817e0e4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java index 66fd932dcc..723d3b1e59 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java index 448e963d49..86b6200440 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java index 7c5eb993e1..0ea9353505 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java index 4a9ac3eca2..e61fdc4b38 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java index 85093c4576..a6928a1157 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java index 4c1441775b..953a5f44dc 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java index f3239001ee..254274b1cf 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java @@ -17,7 +17,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java index e33556cb4e..d2e15fa60d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java index 97a0a5ca23..63d6152a3e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java index b9e1b4f995..0704878805 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java @@ -16,7 +16,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java index af85b261c6..fbc4708710 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertFalse; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import org.junit.Test; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java index 14a5ec3d59..e8f71d7aae 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java @@ -15,7 +15,6 @@ */ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java index 9ebc328d56..0ff960c4cc 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; @@ -24,7 +23,6 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java index 67129c956b..671abc314e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java @@ -25,7 +25,6 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.LongConsumer; import io.reactivex.internal.subscriptions.BooleanSubscription; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java index 010da8bd69..34a732be7c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java @@ -15,7 +15,6 @@ import static java.util.Arrays.asList; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.lang.reflect.Method; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java index ca4bd28986..ba640c3e5a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java index 06f10e835d..8d3cef82d0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java index 470e0e8cc0..e3d67bb8a2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java index b0af47585b..3772aefd85 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java index 37d7012065..af88de841f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java index e048d47650..2ee23b2dc1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java index 88aa2b17c1..3cb5f57fb0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java index fd5061d9ed..46d240b620 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java index b3bea718bd..56daf0c5e5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.lang.management.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java index a47a5d6eca..d0c73867e6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java index de31e283a4..c24e4f5f7d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java index 74cbcc24c2..1ea39f76ce 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertFalse; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java index 7e761ca53f..1b2b9ac4ca 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java @@ -24,7 +24,6 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.flowable.*; import io.reactivex.flowable.FlowableEventStream.Event; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java index fb65114e42..b40a40bb56 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java index 62f662804f..71085466cb 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java index d24a84b4b6..31c8294a64 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java index b9574cd8ef..0ac4a1369e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import org.junit.Test; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java index dc5f2a8313..c1d8c4134c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java index b0d1af43c7..3320650881 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java @@ -24,7 +24,6 @@ import org.reactivestreams.Subscriber; import io.reactivex.*; -import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.schedulers.Schedulers; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java index 91d4d4ea8b..59d049a7c0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java index acba2b1294..72e08bd1b3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java index 97eac27982..f99b7d1d86 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java index 2e5fd020e7..12fc35760e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java index 7e4b97c899..5f6aa08fa6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java @@ -15,7 +15,6 @@ import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java index 178e015413..d1ba19d32b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java index e5b9c61de4..b02fea95b3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java index ffa4d0eba3..08dc9c244d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.flowable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java index 919ca0e468..ce321df789 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java index b6fb51f6d2..af412d9a02 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java index 070176bdb0..c534ddd990 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java index a86de18f52..2ca5481fc3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java index 12f81c33e0..ee691d93c2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.lang.reflect.*; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCallableTest.java index 7a56347a32..44f50947ee 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCallableTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.maybe; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java index dc8445068c..e53fd7161c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java index 7c66cba3f6..fcdc13fee9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java index 66a4e24dc0..92299a5754 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java index 55256bccd8..418a19678e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java index 01bf61ac6e..e1c96cd135 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDelayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDelayTest.java index 1088f2abc1..40e396b314 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDelayTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java index d815a70ea5..d2c5a4ca57 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctTest.java index 8114d64f9a..67f73d3ede 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java index b0ba634354..6bd333e814 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java index 161ae3db9e..a22c969c9b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFilterTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFilterTest.java index e855c07820..7ac6418db7 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFilterTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFilterTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import org.junit.Test; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index 960722060a..b4da14e9a1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java index 542165907f..c10d53db36 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java @@ -17,7 +17,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromIterableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromIterableTest.java index 3b0a9d4970..5ed25eb269 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromIterableTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java index 3f902cb4a4..59c5a96332 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java @@ -16,7 +16,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableJoinTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableJoinTest.java index 8ced523827..00a733959d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableJoinTest.java @@ -15,7 +15,6 @@ */ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableLastTest.java index 6f3ecd39c8..77f02bfe71 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableLastTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.NoSuchElementException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMapTest.java index 3d824be862..4d271a4197 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMapTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java index 8d948b2592..a60328a899 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java index b8b3f67f1e..fa48b217f8 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeLongTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeLongTest.java index d09ec0d6ce..dfe1713902 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeLongTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeLongTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.ArrayList; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeTest.java index cbdc0130ec..d54847c0b2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.ArrayList; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java index cb6e61e8f6..c1c7ffbeb6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java index effe8ef206..5fc3aea8c6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index 48a9ff2d5a..96be759db2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java index dbb72e21ef..538b4a0c69 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java index 40d09f4f33..7c768f36cc 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.lang.management.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java index 0055449ef5..ab7998c8a1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java index 7b0322ab87..debeb8eec4 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java index 01f04653f2..7e3098216c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java index 35df1a462e..e078f92505 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java index 4a7a33ddd6..da996cfc22 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.*; import org.junit.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTest.java index b89d70b8df..c97f851700 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.Arrays; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimedTest.java index 50df641a26..3cf4d2e155 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimedTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipWhileTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipWhileTest.java index d4772b1a6a..9e809b88cc 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipWhileTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import org.junit.Test; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java index 610f49eac4..7e3d4dc505 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java index 34ab87312b..1eb89adc6a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java index bc933f9b02..9269bd0b5a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java index a9b9ae35d9..341409f958 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java index 0e6f040972..9fa6c21bca 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java index 935922b67c..9d517ec1be 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java @@ -15,7 +15,6 @@ import static io.reactivex.internal.util.ExceptionHelper.timeoutMessage; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java index 3dad40f34a..a0d8a93ebe 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java index c8af9d88b8..124283dc1f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java index 18447143aa..1f28cfc5d2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java @@ -13,7 +13,6 @@ package io.reactivex.internal.operators.observable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java index a82e876464..9f8969222b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipIterableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipIterableTest.java index 971359d8ad..f05c41cfd3 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipIterableTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java index ba86f16175..14fda0058d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java index 2c4ebcc321..23fb50c01d 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java @@ -33,7 +33,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; public class SingleFromCallableTest { diff --git a/src/test/java/io/reactivex/observable/ObservableTest.java b/src/test/java/io/reactivex/observable/ObservableTest.java index ab915ffa53..f59a41857e 100644 --- a/src/test/java/io/reactivex/observable/ObservableTest.java +++ b/src/test/java/io/reactivex/observable/ObservableTest.java @@ -14,7 +14,6 @@ package io.reactivex.observable; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; diff --git a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java index 963171d30e..3d85d97eee 100644 --- a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java +++ b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java @@ -14,7 +14,6 @@ package io.reactivex.processors; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java index a0e3996f41..d465aa7a56 100644 --- a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java +++ b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java @@ -14,7 +14,6 @@ package io.reactivex.processors; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/processors/PublishProcessorTest.java b/src/test/java/io/reactivex/processors/PublishProcessorTest.java index f91e61551f..980ed84187 100644 --- a/src/test/java/io/reactivex/processors/PublishProcessorTest.java +++ b/src/test/java/io/reactivex/processors/PublishProcessorTest.java @@ -14,7 +14,6 @@ package io.reactivex.processors; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.ArrayList; diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java index 7ecc2bea31..2279f500c8 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java @@ -14,7 +14,6 @@ package io.reactivex.processors; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.lang.management.*; diff --git a/src/test/java/io/reactivex/single/SingleNullTests.java b/src/test/java/io/reactivex/single/SingleNullTests.java index ff7ddf19d0..059f106ffe 100644 --- a/src/test/java/io/reactivex/single/SingleNullTests.java +++ b/src/test/java/io/reactivex/single/SingleNullTests.java @@ -22,7 +22,6 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.SingleOperator; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; diff --git a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java b/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java index efd643e8d9..c1be4ab34c 100644 --- a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java @@ -14,7 +14,6 @@ package io.reactivex.subjects; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java b/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java index 9a2b52f8f7..1a6f48a0e7 100644 --- a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java @@ -14,7 +14,6 @@ package io.reactivex.subjects; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; diff --git a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java index 7731d508f8..fc20c7b195 100644 --- a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java @@ -14,7 +14,6 @@ package io.reactivex.subjects; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.ArrayList; diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java index c836e179b5..3d02387c92 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java @@ -14,7 +14,6 @@ package io.reactivex.subjects; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.lang.management.*; diff --git a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java index c38105eb68..e0524350c9 100644 --- a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java @@ -14,7 +14,6 @@ package io.reactivex.subscribers; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; From 5c83b50893143a265cfeab299d087affc9d7c566 Mon Sep 17 00:00:00 2001 From: Artem Hluhovskyi Date: Fri, 5 Jul 2019 00:03:42 +0300 Subject: [PATCH 168/211] Fix NPE when debouncing empty source (#6560) --- .../internal/operators/flowable/FlowableDebounce.java | 4 +++- .../operators/observable/ObservableDebounce.java | 4 +++- .../operators/flowable/FlowableDebounceTest.java | 10 ++++++++++ .../operators/observable/ObservableDebounceTest.java | 10 ++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounce.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounce.java index 92b1c48254..143e61ec55 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounce.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounce.java @@ -119,7 +119,9 @@ public void onComplete() { if (!DisposableHelper.isDisposed(d)) { @SuppressWarnings("unchecked") DebounceInnerSubscriber dis = (DebounceInnerSubscriber)d; - dis.emit(); + if (dis != null) { + dis.emit(); + } DisposableHelper.dispose(debouncer); downstream.onComplete(); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounce.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounce.java index 2c056eb70e..db8b9d4794 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounce.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableDebounce.java @@ -112,7 +112,9 @@ public void onComplete() { if (d != DisposableHelper.DISPOSED) { @SuppressWarnings("unchecked") DebounceInnerObserver dis = (DebounceInnerObserver)d; - dis.emit(); + if (dis != null) { + dis.emit(); + } DisposableHelper.dispose(debouncer); downstream.onComplete(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java index 459d63e5c1..aacff6e5af 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java @@ -546,4 +546,14 @@ public void timedError() { .test() .assertFailure(TestException.class); } + + @Test + public void debounceOnEmpty() { + Flowable.empty().debounce(new Function>() { + @Override + public Publisher apply(Object o) { + return Flowable.just(new Object()); + } + }).subscribe(); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java index e1c96cd135..aa24f68cd9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java @@ -504,4 +504,14 @@ public void timedError() { .test() .assertFailure(TestException.class); } + + @Test + public void debounceOnEmpty() { + Observable.empty().debounce(new Function>() { + @Override + public ObservableSource apply(Object o) { + return Observable.just(new Object()); + } + }).subscribe(); + } } From 5550b6303db96763640dd3490101dcbd4f37d87f Mon Sep 17 00:00:00 2001 From: Supasin Tatiyanupanwong Date: Mon, 15 Jul 2019 15:53:21 +0700 Subject: [PATCH 169/211] Fix JavaDocs of Single.doOnTerminate refer to onComplete notification (#6565) --- src/main/java/io/reactivex/Single.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 3dd0776e11..299e6da76f 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -2501,13 +2501,13 @@ public final Single doOnSubscribe(final Consumer onSubscr *

          * *

          - * This differs from {@code doAfterTerminate} in that this happens before the {@code onComplete} or + * This differs from {@code doAfterTerminate} in that this happens before the {@code onSuccess} or * {@code onError} notification. *

          *
          Scheduler:
          *
          {@code doOnTerminate} does not operate by default on a particular {@link Scheduler}.
          *
          - * @param onTerminate the action to invoke when the consumer calls {@code onComplete} or {@code onError} + * @param onTerminate the action to invoke when the consumer calls {@code onSuccess} or {@code onError} * @return the new Single instance * @see ReactiveX operators documentation: Do * @see #doOnTerminate(Action) From e7842014e9b80304723c488fa1fcffe2b32a228b Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 30 Jul 2019 10:54:54 +0200 Subject: [PATCH 170/211] 2.x: Fix mergeWith not canceling other when the main fails (#6599) * 2.x: Fix mergeWith not canceling other when the main fails * Switch to OpenJDK compilation as OracleJDK is not available * Add more time to refCount testing * More time again * Looks like 250ms is still not enough, let's loop --- .travis.yml | 2 +- .../FlowableMergeWithCompletable.java | 2 +- .../flowable/FlowableMergeWithMaybe.java | 2 +- .../flowable/FlowableMergeWithSingle.java | 2 +- .../ObservableMergeWithCompletable.java | 2 +- .../observable/ObservableMergeWithMaybe.java | 2 +- .../observable/ObservableMergeWithSingle.java | 2 +- .../FlowableMergeWithCompletableTest.java | 36 +++++++++++++++++++ .../flowable/FlowableMergeWithMaybeTest.java | 36 +++++++++++++++++++ .../flowable/FlowableMergeWithSingleTest.java | 36 +++++++++++++++++++ .../ObservableMergeWithCompletableTest.java | 36 +++++++++++++++++++ .../ObservableMergeWithMaybeTest.java | 35 ++++++++++++++++++ .../ObservableMergeWithSingleTest.java | 36 +++++++++++++++++++ .../observable/ObservableRefCountAltTest.java | 29 +++++++++------ .../observable/ObservableRefCountTest.java | 16 ++++----- 15 files changed, 249 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 83835caeba..9c5c0f6909 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: java jdk: -- oraclejdk8 +- openjdk8 # force upgrade Java8 as per https://github.com/travis-ci/travis-ci/issues/4042 (fixes compilation issue) #addons: diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java index 271bd9c50d..c65386bbb1 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletable.java @@ -86,7 +86,7 @@ public void onNext(T t) { @Override public void onError(Throwable ex) { - SubscriptionHelper.cancel(mainSubscription); + DisposableHelper.dispose(otherObserver); HalfSerializer.onError(downstream, ex, this, error); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java index a32a0c92fc..1787d5fce3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybe.java @@ -143,7 +143,7 @@ public void onNext(T t) { @Override public void onError(Throwable ex) { if (error.addThrowable(ex)) { - SubscriptionHelper.cancel(mainSubscription); + DisposableHelper.dispose(otherObserver); drain(); } else { RxJavaPlugins.onError(ex); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java index 586bc07c07..486cb73f8c 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingle.java @@ -143,7 +143,7 @@ public void onNext(T t) { @Override public void onError(Throwable ex) { if (error.addThrowable(ex)) { - SubscriptionHelper.cancel(mainSubscription); + DisposableHelper.dispose(otherObserver); drain(); } else { RxJavaPlugins.onError(ex); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java index fa020b6ae4..3b9e649062 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletable.java @@ -80,7 +80,7 @@ public void onNext(T t) { @Override public void onError(Throwable ex) { - DisposableHelper.dispose(mainDisposable); + DisposableHelper.dispose(otherObserver); HalfSerializer.onError(downstream, ex, this, error); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java index 23b2532d9b..e7caad3b21 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybe.java @@ -106,7 +106,7 @@ public void onNext(T t) { @Override public void onError(Throwable ex) { if (error.addThrowable(ex)) { - DisposableHelper.dispose(mainDisposable); + DisposableHelper.dispose(otherObserver); drain(); } else { RxJavaPlugins.onError(ex); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java index 20c4d21b5c..7332a29a25 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingle.java @@ -106,7 +106,7 @@ public void onNext(T t) { @Override public void onError(Throwable ex) { if (error.addThrowable(ex)) { - DisposableHelper.dispose(mainDisposable); + DisposableHelper.dispose(otherObserver); drain(); } else { RxJavaPlugins.onError(ex); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletableTest.java index cf5b7917a6..18f5551e4a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletableTest.java @@ -136,4 +136,40 @@ public void run() { ts.assertResult(1); } } + + @Test + public void cancelOtherOnMainError() { + PublishProcessor pp = PublishProcessor.create(); + CompletableSubject cs = CompletableSubject.create(); + + TestSubscriber ts = pp.mergeWith(cs).test(); + + assertTrue(pp.hasSubscribers()); + assertTrue(cs.hasObservers()); + + pp.onError(new TestException()); + + ts.assertFailure(TestException.class); + + assertFalse("main has observers!", pp.hasSubscribers()); + assertFalse("other has observers", cs.hasObservers()); + } + + @Test + public void cancelMainOnOtherError() { + PublishProcessor pp = PublishProcessor.create(); + CompletableSubject cs = CompletableSubject.create(); + + TestSubscriber ts = pp.mergeWith(cs).test(); + + assertTrue(pp.hasSubscribers()); + assertTrue(cs.hasObservers()); + + cs.onError(new TestException()); + + ts.assertFailure(TestException.class); + + assertFalse("main has observers!", pp.hasSubscribers()); + assertFalse("other has observers", cs.hasObservers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybeTest.java index c38bf6ae7b..676c9074c3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybeTest.java @@ -401,4 +401,40 @@ public void onNext(Integer t) { ts.assertValueCount(Flowable.bufferSize()); ts.assertComplete(); } + + @Test + public void cancelOtherOnMainError() { + PublishProcessor pp = PublishProcessor.create(); + MaybeSubject ms = MaybeSubject.create(); + + TestSubscriber ts = pp.mergeWith(ms).test(); + + assertTrue(pp.hasSubscribers()); + assertTrue(ms.hasObservers()); + + pp.onError(new TestException()); + + ts.assertFailure(TestException.class); + + assertFalse("main has observers!", pp.hasSubscribers()); + assertFalse("other has observers", ms.hasObservers()); + } + + @Test + public void cancelMainOnOtherError() { + PublishProcessor pp = PublishProcessor.create(); + MaybeSubject ms = MaybeSubject.create(); + + TestSubscriber ts = pp.mergeWith(ms).test(); + + assertTrue(pp.hasSubscribers()); + assertTrue(ms.hasObservers()); + + ms.onError(new TestException()); + + ts.assertFailure(TestException.class); + + assertFalse("main has observers!", pp.hasSubscribers()); + assertFalse("other has observers", ms.hasObservers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingleTest.java index 2ab0568a7e..6a182785da 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingleTest.java @@ -397,4 +397,40 @@ public void onNext(Integer t) { ts.assertValueCount(Flowable.bufferSize()); ts.assertComplete(); } + + @Test + public void cancelOtherOnMainError() { + PublishProcessor pp = PublishProcessor.create(); + SingleSubject ss = SingleSubject.create(); + + TestSubscriber ts = pp.mergeWith(ss).test(); + + assertTrue(pp.hasSubscribers()); + assertTrue(ss.hasObservers()); + + pp.onError(new TestException()); + + ts.assertFailure(TestException.class); + + assertFalse("main has observers!", pp.hasSubscribers()); + assertFalse("other has observers", ss.hasObservers()); + } + + @Test + public void cancelMainOnOtherError() { + PublishProcessor pp = PublishProcessor.create(); + SingleSubject ss = SingleSubject.create(); + + TestSubscriber ts = pp.mergeWith(ss).test(); + + assertTrue(pp.hasSubscribers()); + assertTrue(ss.hasObservers()); + + ss.onError(new TestException()); + + ts.assertFailure(TestException.class); + + assertFalse("main has observers!", pp.hasSubscribers()); + assertFalse("other has observers", ss.hasObservers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletableTest.java index 872509e164..d9a54c916a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletableTest.java @@ -135,4 +135,40 @@ protected void subscribeActual(Observer observer) { .test() .assertResult(1); } + + @Test + public void cancelOtherOnMainError() { + PublishSubject ps = PublishSubject.create(); + CompletableSubject cs = CompletableSubject.create(); + + TestObserver to = ps.mergeWith(cs).test(); + + assertTrue(ps.hasObservers()); + assertTrue(cs.hasObservers()); + + ps.onError(new TestException()); + + to.assertFailure(TestException.class); + + assertFalse("main has observers!", ps.hasObservers()); + assertFalse("other has observers", cs.hasObservers()); + } + + @Test + public void cancelMainOnOtherError() { + PublishSubject ps = PublishSubject.create(); + CompletableSubject cs = CompletableSubject.create(); + + TestObserver to = ps.mergeWith(cs).test(); + + assertTrue(ps.hasObservers()); + assertTrue(cs.hasObservers()); + + cs.onError(new TestException()); + + to.assertFailure(TestException.class); + + assertFalse("main has observers!", ps.hasObservers()); + assertFalse("other has observers", cs.hasObservers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java index a70e4c2fa8..ee9eb9b576 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java @@ -272,4 +272,39 @@ public void onNext(Integer t) { to.assertResult(0, 1, 2, 3, 4); } + @Test + public void cancelOtherOnMainError() { + PublishSubject ps = PublishSubject.create(); + MaybeSubject ms = MaybeSubject.create(); + + TestObserver to = ps.mergeWith(ms).test(); + + assertTrue(ps.hasObservers()); + assertTrue(ms.hasObservers()); + + ps.onError(new TestException()); + + to.assertFailure(TestException.class); + + assertFalse("main has observers!", ps.hasObservers()); + assertFalse("other has observers", ms.hasObservers()); + } + + @Test + public void cancelMainOnOtherError() { + PublishSubject ps = PublishSubject.create(); + MaybeSubject ms = MaybeSubject.create(); + + TestObserver to = ps.mergeWith(ms).test(); + + assertTrue(ps.hasObservers()); + assertTrue(ms.hasObservers()); + + ms.onError(new TestException()); + + to.assertFailure(TestException.class); + + assertFalse("main has observers!", ps.hasObservers()); + assertFalse("other has observers", ms.hasObservers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java index 25ce78d486..0d8fb3432b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java @@ -263,4 +263,40 @@ public void onNext(Integer t) { to.assertResult(0, 1, 2, 3, 4); } + + @Test + public void cancelOtherOnMainError() { + PublishSubject ps = PublishSubject.create(); + SingleSubject ss = SingleSubject.create(); + + TestObserver to = ps.mergeWith(ss).test(); + + assertTrue(ps.hasObservers()); + assertTrue(ss.hasObservers()); + + ps.onError(new TestException()); + + to.assertFailure(TestException.class); + + assertFalse("main has observers!", ps.hasObservers()); + assertFalse("other has observers", ss.hasObservers()); + } + + @Test + public void cancelMainOnOtherError() { + PublishSubject ps = PublishSubject.create(); + SingleSubject ss = SingleSubject.create(); + + TestObserver to = ps.mergeWith(ss).test(); + + assertTrue(ps.hasObservers()); + assertTrue(ss.hasObservers()); + + ss.onError(new TestException()); + + to.assertFailure(TestException.class); + + assertFalse("main has observers!", ps.hasObservers()); + assertFalse("other has observers", ss.hasObservers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java index 5fc3aea8c6..05aada6b84 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java @@ -630,7 +630,7 @@ protected void subscribeActual(Observer observer) { @Test public void replayNoLeak() throws Exception { System.gc(); - Thread.sleep(100); + Thread.sleep(250); long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -646,7 +646,7 @@ public Object call() throws Exception { source.subscribe(); System.gc(); - Thread.sleep(100); + Thread.sleep(250); long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -657,7 +657,7 @@ public Object call() throws Exception { @Test public void replayNoLeak2() throws Exception { System.gc(); - Thread.sleep(100); + Thread.sleep(250); long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -680,7 +680,7 @@ public Object call() throws Exception { d2 = null; System.gc(); - Thread.sleep(100); + Thread.sleep(250); long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -701,7 +701,7 @@ static final class ExceptionData extends Exception { @Test public void publishNoLeak() throws Exception { System.gc(); - Thread.sleep(100); + Thread.sleep(250); long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -716,10 +716,19 @@ public Object call() throws Exception { source.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); - System.gc(); - Thread.sleep(100); + long after = 0L; - long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + for (int i = 0; i < 10; i++) { + System.gc(); + + after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + + if (start + 20 * 1000 * 1000 > after) { + break; + } + + Thread.sleep(100); + } source = null; assertTrue(String.format("%,3d -> %,3d%n", start, after), start + 20 * 1000 * 1000 > after); @@ -728,7 +737,7 @@ public Object call() throws Exception { @Test public void publishNoLeak2() throws Exception { System.gc(); - Thread.sleep(100); + Thread.sleep(250); long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -751,7 +760,7 @@ public Object call() throws Exception { d2 = null; System.gc(); - Thread.sleep(100); + Thread.sleep(250); long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index 96be759db2..99a2a79f79 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -651,7 +651,7 @@ protected void subscribeActual(Observer observer) { @Test public void replayNoLeak() throws Exception { System.gc(); - Thread.sleep(100); + Thread.sleep(250); long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -667,7 +667,7 @@ public Object call() throws Exception { source.subscribe(); System.gc(); - Thread.sleep(100); + Thread.sleep(250); long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -678,7 +678,7 @@ public Object call() throws Exception { @Test public void replayNoLeak2() throws Exception { System.gc(); - Thread.sleep(100); + Thread.sleep(250); long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -701,7 +701,7 @@ public Object call() throws Exception { d2 = null; System.gc(); - Thread.sleep(100); + Thread.sleep(250); long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -722,7 +722,7 @@ static final class ExceptionData extends Exception { @Test public void publishNoLeak() throws Exception { System.gc(); - Thread.sleep(100); + Thread.sleep(250); long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -738,7 +738,7 @@ public Object call() throws Exception { source.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); System.gc(); - Thread.sleep(100); + Thread.sleep(250); long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -749,7 +749,7 @@ public Object call() throws Exception { @Test public void publishNoLeak2() throws Exception { System.gc(); - Thread.sleep(100); + Thread.sleep(250); long start = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); @@ -772,7 +772,7 @@ public Object call() throws Exception { d2 = null; System.gc(); - Thread.sleep(100); + Thread.sleep(250); long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); From 70f25df30ba5a1e3dfbff474dd0e70f44de2a519 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 30 Jul 2019 11:20:17 +0200 Subject: [PATCH 171/211] 2.x: ObservableBlockingSubscribe compares with wrong object (#6601) --- .../operators/observable/ObservableBlockingSubscribe.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBlockingSubscribe.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBlockingSubscribe.java index 4373a321aa..589b71c5f9 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBlockingSubscribe.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBlockingSubscribe.java @@ -61,7 +61,7 @@ public static void subscribe(ObservableSource o, Observer Date: Tue, 30 Jul 2019 12:47:50 +0200 Subject: [PATCH 172/211] 2.x: Fix truncation bugs in replay() and ReplaySubject/Processor (#6602) --- .../operators/flowable/FlowableReplay.java | 7 +- .../observable/ObservableReplay.java | 7 +- .../reactivex/processors/ReplayProcessor.java | 5 ++ .../io/reactivex/subjects/ReplaySubject.java | 5 ++ .../io/reactivex/TimesteppingScheduler.java | 60 +++++++++++++++ .../processors/ReplayProcessorTest.java | 75 +++++++++++++++++++ .../reactivex/subjects/ReplaySubjectTest.java | 75 +++++++++++++++++++ 7 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 src/test/java/io/reactivex/TimesteppingScheduler.java diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java index 7a02482b4b..196596f1b2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableReplay.java @@ -773,6 +773,11 @@ final void removeFirst() { } setFirst(head); + // correct the tail if all items have been removed + head = get(); + if (head.get() == null) { + tail = head; + } } /** * Arranges the given node is the new head from now on. @@ -1015,7 +1020,7 @@ void truncate() { int e = 0; for (;;) { if (next != null) { - if (size > limit) { + if (size > limit && size > 1) { // never truncate the very last item just added e++; size--; prev = next; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java index 197ada9706..2818d975f1 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableReplay.java @@ -638,6 +638,11 @@ final void trimHead() { } setFirst(head); + // correct the tail if all items have been removed + head = get(); + if (head.get() == null) { + tail = head; + } } /** * Arranges the given node is the new head from now on. @@ -839,7 +844,7 @@ void truncate() { int e = 0; for (;;) { if (next != null) { - if (size > limit) { + if (size > limit && size > 1) { // never truncate the very last item just added e++; size--; prev = next; diff --git a/src/main/java/io/reactivex/processors/ReplayProcessor.java b/src/main/java/io/reactivex/processors/ReplayProcessor.java index ff98ff25d9..b04a17d07e 100644 --- a/src/main/java/io/reactivex/processors/ReplayProcessor.java +++ b/src/main/java/io/reactivex/processors/ReplayProcessor.java @@ -1070,6 +1070,10 @@ void trim() { TimedNode h = head; for (;;) { + if (size <= 1) { + head = h; + break; + } TimedNode next = h.get(); if (next == null) { head = h; @@ -1082,6 +1086,7 @@ void trim() { } h = next; + size--; } } diff --git a/src/main/java/io/reactivex/subjects/ReplaySubject.java b/src/main/java/io/reactivex/subjects/ReplaySubject.java index 703692bd57..622854b5ec 100644 --- a/src/main/java/io/reactivex/subjects/ReplaySubject.java +++ b/src/main/java/io/reactivex/subjects/ReplaySubject.java @@ -1071,6 +1071,10 @@ void trim() { TimedNode h = head; for (;;) { + if (size <= 1) { + head = h; + break; + } TimedNode next = h.get(); if (next == null) { head = h; @@ -1083,6 +1087,7 @@ void trim() { } h = next; + size--; } } diff --git a/src/test/java/io/reactivex/TimesteppingScheduler.java b/src/test/java/io/reactivex/TimesteppingScheduler.java new file mode 100644 index 0000000000..73996cc56f --- /dev/null +++ b/src/test/java/io/reactivex/TimesteppingScheduler.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.concurrent.TimeUnit; + +import io.reactivex.Scheduler; +import io.reactivex.disposables.*; + +/** + * Basic scheduler that produces an ever increasing {@link #now(TimeUnit)} value. + * Use this scheduler only as a time source! + */ +public class TimesteppingScheduler extends Scheduler { + + final class TimesteppingWorker extends Worker { + @Override + public void dispose() { + } + + @Override + public boolean isDisposed() { + return false; + } + + @Override + public Disposable schedule(Runnable run, long delay, TimeUnit unit) { + run.run(); + return Disposables.disposed(); + } + + @Override + public long now(TimeUnit unit) { + return time++; + } + } + + long time; + + @Override + public Worker createWorker() { + return new TimesteppingWorker(); + } + + @Override + public long now(TimeUnit unit) { + return time++; + } +} \ No newline at end of file diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java index 2279f500c8..b59d20fb94 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java @@ -1750,4 +1750,79 @@ public void accept(byte[] v) throws Exception { + " -> " + after.get() / 1024.0 / 1024.0); } } + + @Test + public void timeAndSizeNoTerminalTruncationOnTimechange() { + ReplayProcessor rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 1); + + TestSubscriber ts = rp.test(); + + rp.onNext(1); + rp.cleanupBuffer(); + rp.onComplete(); + + ts.assertNoErrors() + .assertComplete(); + } + + @Test + public void timeAndSizeNoTerminalTruncationOnTimechange2() { + ReplayProcessor rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 1); + + TestSubscriber ts = rp.test(); + + rp.onNext(1); + rp.cleanupBuffer(); + rp.onNext(2); + rp.cleanupBuffer(); + rp.onComplete(); + + ts.assertNoErrors() + .assertComplete(); + } + + @Test + public void timeAndSizeNoTerminalTruncationOnTimechange3() { + ReplayProcessor rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 1); + + TestSubscriber ts = rp.test(); + + rp.onNext(1); + rp.onNext(2); + rp.onComplete(); + + ts.assertNoErrors() + .assertComplete(); + } + + @Test + public void timeAndSizeNoTerminalTruncationOnTimechange4() { + ReplayProcessor rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 10); + + TestSubscriber ts = rp.test(); + + rp.onNext(1); + rp.onNext(2); + rp.onComplete(); + + ts.assertNoErrors() + .assertComplete(); + } + + @Test + public void timeAndSizeRemoveCorrectNumberOfOld() { + TestScheduler scheduler = new TestScheduler(); + ReplayProcessor rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2); + + rp.onNext(1); + rp.onNext(2); + rp.onNext(3); + + scheduler.advanceTimeBy(2, TimeUnit.SECONDS); + + rp.onNext(4); + rp.onNext(5); + + rp.test().assertValuesOnly(4, 5); + } } diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java index 3d02387c92..ce098ca16d 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java @@ -1342,4 +1342,79 @@ public void accept(byte[] v) throws Exception { + " -> " + after.get() / 1024.0 / 1024.0); } } + + @Test + public void timeAndSizeNoTerminalTruncationOnTimechange() { + ReplaySubject rs = ReplaySubject.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 1); + + TestObserver to = rs.test(); + + rs.onNext(1); + rs.cleanupBuffer(); + rs.onComplete(); + + to.assertNoErrors() + .assertComplete(); + } + + @Test + public void timeAndSizeNoTerminalTruncationOnTimechange2() { + ReplaySubject rs = ReplaySubject.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 1); + + TestObserver to = rs.test(); + + rs.onNext(1); + rs.cleanupBuffer(); + rs.onNext(2); + rs.cleanupBuffer(); + rs.onComplete(); + + to.assertNoErrors() + .assertComplete(); + } + + @Test + public void timeAndSizeNoTerminalTruncationOnTimechange3() { + ReplaySubject rs = ReplaySubject.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 1); + + TestObserver to = rs.test(); + + rs.onNext(1); + rs.onNext(2); + rs.onComplete(); + + to.assertNoErrors() + .assertComplete(); + } + + @Test + public void timeAndSizeNoTerminalTruncationOnTimechange4() { + ReplaySubject rs = ReplaySubject.createWithTimeAndSize(1, TimeUnit.SECONDS, new TimesteppingScheduler(), 10); + + TestObserver to = rs.test(); + + rs.onNext(1); + rs.onNext(2); + rs.onComplete(); + + to.assertNoErrors() + .assertComplete(); + } + + @Test + public void timeAndSizeRemoveCorrectNumberOfOld() { + TestScheduler scheduler = new TestScheduler(); + ReplaySubject rs = ReplaySubject.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2); + + rs.onNext(1); + rs.onNext(2); + rs.onNext(3); // remove 1 due to maxSize, size == 2 + + scheduler.advanceTimeBy(2, TimeUnit.SECONDS); + + rs.onNext(4); // remove 2 due to maxSize, remove 3 due to age, size == 1 + rs.onNext(5); // size == 2 + + rs.test().assertValuesOnly(4, 5); + } } From 17a8eef0f660f58deed7f7ee399915a61ce404d6 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 2 Aug 2019 08:23:52 +0200 Subject: [PATCH 173/211] Release 2.2.11 --- CHANGES.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index df4bd2c840..5e373bc389 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,19 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.11 - August 2, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.11%7C)) + +#### Bugfixes + + - [Pull 6560](https://github.com/ReactiveX/RxJava/pull/6560): Fix NPE when debouncing an empty source. + - [Pull 6599](https://github.com/ReactiveX/RxJava/pull/6599): Fix `mergeWith` not canceling other when the main fails. + - [Pull 6601](https://github.com/ReactiveX/RxJava/pull/6601): `ObservableBlockingSubscribe` compares with wrong object. + - [Pull 6602](https://github.com/ReactiveX/RxJava/pull/): Fix truncation bugs in `replay()` and `ReplaySubject`/`Processor`. + +#### Documentation changes + + - [Pull 6565](https://github.com/ReactiveX/RxJava/pull/6565): Fix JavaDocs of `Single.doOnTerminate` refer to `onComplete` notification. + ### Version 2.2.10 - June 21, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.10%7C)) #### Bugfixes From 8db356994aa1ffb7553261e0404527125279c391 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 14 Aug 2019 12:12:41 +0200 Subject: [PATCH 174/211] 2.x: Fix switchMap incorrect sync-fusion & error management (#6618) --- .../operators/flowable/FlowableSwitchMap.java | 9 ++++- .../observable/ObservableSwitchMap.java | 1 + .../flowable/FlowableSwitchTest.java | 28 +++++++++++++++ .../observable/ObservableSwitchTest.java | 35 +++++++++++++++++-- 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java index 9730bd38b2..d3832d4edc 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java @@ -314,7 +314,7 @@ void drain() { if (r != Long.MAX_VALUE) { requested.addAndGet(-e); } - inner.get().request(e); + inner.request(e); } } @@ -398,6 +398,7 @@ public void onError(Throwable t) { if (index == p.unique && p.error.addThrowable(t)) { if (!p.delayErrors) { p.upstream.cancel(); + p.done = true; } done = true; p.drain(); @@ -418,5 +419,11 @@ public void onComplete() { public void cancel() { SubscriptionHelper.cancel(this); } + + public void request(long n) { + if (fusionMode != QueueSubscription.SYNC) { + get().request(n); + } + } } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchMap.java index 8c5aa371dc..4e97ea405d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableSwitchMap.java @@ -314,6 +314,7 @@ void innerError(SwitchMapInnerObserver inner, Throwable ex) { if (inner.index == unique && errors.addThrowable(ex)) { if (!delayErrors) { upstream.dispose(); + done = true; } inner.done = true; drain(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java index c1d8c4134c..b4880d4ff6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java @@ -1201,4 +1201,32 @@ public Object apply(Integer w) throws Exception { .assertNoErrors() .assertComplete(); } + + @Test + public void switchMapFusedIterable() { + Flowable.range(1, 2) + .switchMap(new Function>() { + @Override + public Publisher apply(Integer v) + throws Exception { + return Flowable.fromIterable(Arrays.asList(v * 10)); + } + }) + .test() + .assertResult(10, 20); + } + + @Test + public void switchMapHiddenIterable() { + Flowable.range(1, 2) + .switchMap(new Function>() { + @Override + public Publisher apply(Integer v) + throws Exception { + return Flowable.fromIterable(Arrays.asList(v * 10)).hide(); + } + }) + .test() + .assertResult(10, 20); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java index 7e3d4dc505..100052f028 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java @@ -14,9 +14,10 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import java.util.List; +import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; @@ -24,6 +25,8 @@ import org.mockito.InOrder; import io.reactivex.*; +import io.reactivex.Observable; +import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; @@ -33,7 +36,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; -import io.reactivex.subjects.*; +import io.reactivex.subjects.PublishSubject; public class ObservableSwitchTest { @@ -1191,4 +1194,32 @@ public Object apply(Integer w) throws Exception { .assertNoErrors() .assertComplete(); } + + @Test + public void switchMapFusedIterable() { + Observable.range(1, 2) + .switchMap(new Function>() { + @Override + public Observable apply(Integer v) + throws Exception { + return Observable.fromIterable(Arrays.asList(v * 10)); + } + }) + .test() + .assertResult(10, 20); + } + + @Test + public void switchMapHiddenIterable() { + Observable.range(1, 2) + .switchMap(new Function>() { + @Override + public Observable apply(Integer v) + throws Exception { + return Observable.fromIterable(Arrays.asList(v * 10)).hide(); + } + }) + .test() + .assertResult(10, 20); + } } From a9df239eefacd5761febca24c6076cd95702bee9 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 21 Aug 2019 16:25:39 +0200 Subject: [PATCH 175/211] 2.x: Fix blockingIterable hang when force-disposed (#6627) --- src/main/java/io/reactivex/Flowable.java | 6 ++-- .../flowable/BlockingFlowableIterable.java | 12 ++++++-- .../operators/flowable/FlowableSwitchMap.java | 2 +- .../BlockingObservableIterable.java | 12 ++++++-- .../BlockingFlowableToIteratorTest.java | 28 ++++++++++++++++++ .../flowable/FlowableBufferTest.java | 1 + .../BlockingObservableNextTest.java | 7 ++--- .../BlockingObservableToIteratorTest.java | 29 ++++++++++++++++++- .../observable/ObservableBufferTest.java | 1 + .../schedulers/TrampolineSchedulerTest.java | 1 - 10 files changed, 85 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 4fe78199fe..91333947e9 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -89,7 +89,7 @@ * *

          * The Reactive Streams specification is relatively strict when defining interactions between {@code Publisher}s and {@code Subscriber}s, so much so - * that there is a significant performance penalty due certain timing requirements and the need to prepare for invalid + * that there is a significant performance penalty due certain timing requirements and the need to prepare for invalid * request amounts via {@link Subscription#request(long)}. * Therefore, RxJava has introduced the {@link FlowableSubscriber} interface that indicates the consumer can be driven with relaxed rules. * All RxJava operators are implemented with these relaxed rules in mind. @@ -112,7 +112,7 @@ * * // could be some blocking operation * Thread.sleep(1000); - * + * * // the consumer might have cancelled the flow * if (emitter.isCancelled() { * return; @@ -138,7 +138,7 @@ * RxJava reactive sources, such as {@code Flowable}, are generally synchronous and sequential in nature. In the ReactiveX design, the location (thread) * where operators run is orthogonal to when the operators can work with data. This means that asynchrony and parallelism * has to be explicitly expressed via operators such as {@link #subscribeOn(Scheduler)}, {@link #observeOn(Scheduler)} and {@link #parallel()}. In general, - * operators featuring a {@link Scheduler} parameter are introducing this type of asynchrony into the flow. + * operators featuring a {@link Scheduler} parameter are introducing this type of asynchrony into the flow. *

          * For more information see the ReactiveX * documentation. diff --git a/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableIterable.java b/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableIterable.java index af6613b224..d09af33ee0 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableIterable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableIterable.java @@ -62,7 +62,7 @@ static final class BlockingFlowableIterator long produced; volatile boolean done; - Throwable error; + volatile Throwable error; BlockingFlowableIterator(int batchSize) { this.queue = new SpscArrayQueue(batchSize); @@ -75,6 +75,13 @@ static final class BlockingFlowableIterator @Override public boolean hasNext() { for (;;) { + if (isDisposed()) { + Throwable e = error; + if (e != null) { + throw ExceptionHelper.wrapOrThrow(e); + } + return false; + } boolean d = done; boolean empty = queue.isEmpty(); if (d) { @@ -90,7 +97,7 @@ public boolean hasNext() { BlockingHelper.verifyNonBlocking(); lock.lock(); try { - while (!done && queue.isEmpty()) { + while (!done && queue.isEmpty() && !isDisposed()) { condition.await(); } } catch (InterruptedException ex) { @@ -175,6 +182,7 @@ public void remove() { @Override public void dispose() { SubscriptionHelper.cancel(this); + signalConsumer(); } @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java index d3832d4edc..4d0bc47158 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java @@ -419,7 +419,7 @@ public void onComplete() { public void cancel() { SubscriptionHelper.cancel(this); } - + public void request(long n) { if (fusionMode != QueueSubscription.SYNC) { get().request(n); diff --git a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java index 3fdd26f9b6..24a7cb7701 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableIterable.java @@ -53,7 +53,7 @@ static final class BlockingObservableIterator final Condition condition; volatile boolean done; - Throwable error; + volatile Throwable error; BlockingObservableIterator(int batchSize) { this.queue = new SpscLinkedArrayQueue(batchSize); @@ -64,6 +64,13 @@ static final class BlockingObservableIterator @Override public boolean hasNext() { for (;;) { + if (isDisposed()) { + Throwable e = error; + if (e != null) { + throw ExceptionHelper.wrapOrThrow(e); + } + return false; + } boolean d = done; boolean empty = queue.isEmpty(); if (d) { @@ -80,7 +87,7 @@ public boolean hasNext() { BlockingHelper.verifyNonBlocking(); lock.lock(); try { - while (!done && queue.isEmpty()) { + while (!done && queue.isEmpty() && !isDisposed()) { condition.await(); } } finally { @@ -146,6 +153,7 @@ public void remove() { @Override public void dispose() { DisposableHelper.dispose(this); + signalConsumer(); } @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java index df3fe6d62c..68490f9257 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java @@ -16,14 +16,18 @@ import static org.junit.Assert.*; import java.util.*; +import java.util.concurrent.TimeUnit; import org.junit.*; import org.reactivestreams.*; import io.reactivex.Flowable; +import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.internal.operators.flowable.BlockingFlowableIterable.BlockingFlowableIterator; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.processors.PublishProcessor; +import io.reactivex.schedulers.Schedulers; public class BlockingFlowableToIteratorTest { @@ -185,4 +189,28 @@ protected void subscribeActual(Subscriber s) { it.next(); } + + @Test(expected = NoSuchElementException.class) + public void disposedIteratorHasNextReturns() { + Iterator it = PublishProcessor.create() + .blockingIterable().iterator(); + ((Disposable)it).dispose(); + assertFalse(it.hasNext()); + it.next(); + } + + @Test + public void asyncDisposeUnblocks() { + final Iterator it = PublishProcessor.create() + .blockingIterable().iterator(); + + Schedulers.single().scheduleDirect(new Runnable() { + @Override + public void run() { + ((Disposable)it).dispose(); + } + }, 1, TimeUnit.SECONDS); + + assertFalse(it.hasNext()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java index 8edd8e7cd2..d0023d3e38 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java @@ -2770,6 +2770,7 @@ public void timedSizeBufferAlreadyCleared() { } @Test + @SuppressWarnings("unchecked") public void bufferExactFailingSupplier() { Flowable.empty() .buffer(1, TimeUnit.SECONDS, Schedulers.computation(), 10, new Callable>() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java index 947a2a027d..b854c317b2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java @@ -28,7 +28,6 @@ import io.reactivex.exceptions.TestException; import io.reactivex.internal.operators.observable.BlockingObservableNext.NextObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.BehaviorProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; @@ -332,9 +331,9 @@ public void testSingleSourceManyIterators() throws InterruptedException { @Test public void testSynchronousNext() { - assertEquals(1, BehaviorProcessor.createDefault(1).take(1).blockingSingle().intValue()); - assertEquals(2, BehaviorProcessor.createDefault(2).blockingIterable().iterator().next().intValue()); - assertEquals(3, BehaviorProcessor.createDefault(3).blockingNext().iterator().next().intValue()); + assertEquals(1, BehaviorSubject.createDefault(1).take(1).blockingSingle().intValue()); + assertEquals(2, BehaviorSubject.createDefault(2).blockingIterable().iterator().next().intValue()); + assertEquals(3, BehaviorSubject.createDefault(3).blockingNext().iterator().next().intValue()); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToIteratorTest.java b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToIteratorTest.java index f79b2a294d..324b7c2172 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToIteratorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableToIteratorTest.java @@ -16,15 +16,18 @@ import static org.junit.Assert.*; import java.util.*; +import java.util.concurrent.TimeUnit; import org.junit.*; import io.reactivex.Observable; import io.reactivex.ObservableSource; import io.reactivex.Observer; -import io.reactivex.disposables.Disposables; +import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.internal.operators.observable.BlockingObservableIterable.BlockingObservableIterator; +import io.reactivex.schedulers.Schedulers; +import io.reactivex.subjects.PublishSubject; public class BlockingObservableToIteratorTest { @@ -119,4 +122,28 @@ public void remove() { BlockingObservableIterator it = new BlockingObservableIterator(128); it.remove(); } + + @Test(expected = NoSuchElementException.class) + public void disposedIteratorHasNextReturns() { + Iterator it = PublishSubject.create() + .blockingIterable().iterator(); + ((Disposable)it).dispose(); + assertFalse(it.hasNext()); + it.next(); + } + + @Test + public void asyncDisposeUnblocks() { + final Iterator it = PublishSubject.create() + .blockingIterable().iterator(); + + Schedulers.single().scheduleDirect(new Runnable() { + @Override + public void run() { + ((Disposable)it).dispose(); + } + }, 1, TimeUnit.SECONDS); + + assertFalse(it.hasNext()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java index 92299a5754..16ba2fab6d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java @@ -2137,6 +2137,7 @@ public ObservableSource> apply(Observable o) } @Test + @SuppressWarnings("unchecked") public void bufferExactFailingSupplier() { Observable.empty() .buffer(1, TimeUnit.SECONDS, Schedulers.computation(), 10, new Callable>() { diff --git a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java index b125d43252..9f651bb50e 100644 --- a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java @@ -31,7 +31,6 @@ import org.reactivestreams.Subscriber; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; public class TrampolineSchedulerTest extends AbstractSchedulerTests { From fa406d12f016ed96c62459f774e78da7c8877450 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 22 Aug 2019 22:08:49 +0200 Subject: [PATCH 176/211] 2.x: Fix refCount() not resetting when cross-canceled (#6629) * 2.x: Fix refCount() not resetting when cross-canceled * Undo test timeout comment --- .../operators/flowable/FlowableRefCount.java | 40 ++++++++++++++----- .../observable/ObservableRefCount.java | 40 ++++++++++++++----- .../flowable/FlowableRefCountAltTest.java | 19 +++++++++ .../flowable/FlowableRefCountTest.java | 20 ++++++++++ .../observable/ObservableRefCountAltTest.java | 19 +++++++++ .../observable/ObservableRefCountTest.java | 19 +++++++++ 6 files changed, 137 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java index 02ed97b462..2da1306632 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java @@ -115,22 +115,42 @@ void cancel(RefConnection rc) { void terminated(RefConnection rc) { synchronized (this) { - if (connection != null && connection == rc) { - connection = null; - if (rc.timer != null) { - rc.timer.dispose(); + if (source instanceof FlowablePublishClassic) { + if (connection != null && connection == rc) { + connection = null; + clearTimer(rc); } - } - if (--rc.subscriberCount == 0) { - if (source instanceof Disposable) { - ((Disposable)source).dispose(); - } else if (source instanceof ResettableConnectable) { - ((ResettableConnectable)source).resetIf(rc.get()); + + if (--rc.subscriberCount == 0) { + reset(rc); + } + } else { + if (connection != null && connection == rc) { + clearTimer(rc); + if (--rc.subscriberCount == 0) { + connection = null; + reset(rc); + } } } } } + void clearTimer(RefConnection rc) { + if (rc.timer != null) { + rc.timer.dispose(); + rc.timer = null; + } + } + + void reset(RefConnection rc) { + if (source instanceof Disposable) { + ((Disposable)source).dispose(); + } else if (source instanceof ResettableConnectable) { + ((ResettableConnectable)source).resetIf(rc.get()); + } + } + void timeout(RefConnection rc) { synchronized (this) { if (rc.subscriberCount == 0 && rc == connection) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java index 5306f4481d..27e633c664 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java @@ -112,22 +112,42 @@ void cancel(RefConnection rc) { void terminated(RefConnection rc) { synchronized (this) { - if (connection != null && connection == rc) { - connection = null; - if (rc.timer != null) { - rc.timer.dispose(); + if (source instanceof ObservablePublishClassic) { + if (connection != null && connection == rc) { + connection = null; + clearTimer(rc); } - } - if (--rc.subscriberCount == 0) { - if (source instanceof Disposable) { - ((Disposable)source).dispose(); - } else if (source instanceof ResettableConnectable) { - ((ResettableConnectable)source).resetIf(rc.get()); + + if (--rc.subscriberCount == 0) { + reset(rc); + } + } else { + if (connection != null && connection == rc) { + clearTimer(rc); + if (--rc.subscriberCount == 0) { + connection = null; + reset(rc); + } } } } } + void clearTimer(RefConnection rc) { + if (rc.timer != null) { + rc.timer.dispose(); + rc.timer = null; + } + } + + void reset(RefConnection rc) { + if (source instanceof Disposable) { + ((Disposable)source).dispose(); + } else if (source instanceof ResettableConnectable) { + ((ResettableConnectable)source).resetIf(rc.get()); + } + } + void timeout(RefConnection rc) { synchronized (this) { if (rc.subscriberCount == 0 && rc == connection) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java index 2ee23b2dc1..c8eca05dca 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountAltTest.java @@ -1443,4 +1443,23 @@ public void publishRefCountShallBeThreadSafe() { .assertComplete(); } } + + @Test + public void upstreamTerminationTriggersAnotherCancel() throws Exception { + ReplayProcessor rp = ReplayProcessor.create(); + rp.onNext(1); + rp.onComplete(); + + Flowable shared = rp.share(); + + shared + .buffer(shared.debounce(5, TimeUnit.SECONDS)) + .test() + .assertValueCount(2); + + shared + .buffer(shared.debounce(5, TimeUnit.SECONDS)) + .test() + .assertValueCount(2); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java index 3cb5f57fb0..c032e61da5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.IOException; @@ -1436,4 +1437,23 @@ public void disconnectBeforeConnect() { flowable.take(1).test().assertResult(2); } + + @Test + public void upstreamTerminationTriggersAnotherCancel() throws Exception { + ReplayProcessor rp = ReplayProcessor.create(); + rp.onNext(1); + rp.onComplete(); + + Flowable shared = rp.share(); + + shared + .buffer(shared.debounce(5, TimeUnit.SECONDS)) + .test() + .assertValueCount(2); + + shared + .buffer(shared.debounce(5, TimeUnit.SECONDS)) + .test() + .assertValueCount(2); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java index 05aada6b84..0f675bd15d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountAltTest.java @@ -1399,4 +1399,23 @@ public void publishRefCountShallBeThreadSafe() { .assertComplete(); } } + + @Test + public void upstreamTerminationTriggersAnotherCancel() throws Exception { + ReplaySubject rs = ReplaySubject.create(); + rs.onNext(1); + rs.onComplete(); + + Observable shared = rs.share(); + + shared + .buffer(shared.debounce(5, TimeUnit.SECONDS)) + .test() + .assertValueCount(2); + + shared + .buffer(shared.debounce(5, TimeUnit.SECONDS)) + .test() + .assertValueCount(2); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index 99a2a79f79..485afc54e1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -1380,4 +1380,23 @@ public void disconnectBeforeConnect() { observable.take(1).test().assertResult(2); } + + @Test + public void upstreamTerminationTriggersAnotherCancel() throws Exception { + ReplaySubject rs = ReplaySubject.create(); + rs.onNext(1); + rs.onComplete(); + + Observable shared = rs.share(); + + shared + .buffer(shared.debounce(5, TimeUnit.SECONDS)) + .test() + .assertValueCount(2); + + shared + .buffer(shared.debounce(5, TimeUnit.SECONDS)) + .test() + .assertValueCount(2); + } } From 13772a173cb6a59643dfd5eaf023a1412f804096 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sun, 25 Aug 2019 20:30:24 +0200 Subject: [PATCH 177/211] Release 2.2.12 --- CHANGES.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5e373bc389..fb4c345d29 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,14 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.12 - August 25, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.12%7C)) + +#### Bugfixes + + - [Pull 6618](https://github.com/ReactiveX/RxJava/pull/6618): Fix `switchMap` incorrect sync-fusion & error management. + - [Pull 6627](https://github.com/ReactiveX/RxJava/pull/6627): Fix `blockingIterable` hang when force-disposed. + - [Pull 6629](https://github.com/ReactiveX/RxJava/pull/6629): Fix `refCount` not resetting when cross-canceled. + ### Version 2.2.11 - August 2, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.11%7C)) #### Bugfixes From cc690ff2f757873b11cd075ebc22262f76f28459 Mon Sep 17 00:00:00 2001 From: akarnokd Date: Wed, 28 Aug 2019 13:08:50 +0200 Subject: [PATCH 178/211] 2.x: Avoid using System.getProperties(), some cleanup, up RS 1.0.3 --- build.gradle | 2 +- .../CompletableAndThenCompletable.java | 2 +- .../operators/flowable/FlowablePublish.java | 1 + .../flowable/FlowablePublishAlt.java | 1 + .../flowable/FlowablePublishClassic.java | 2 + .../observable/ObservablePublishAlt.java | 4 +- .../observable/ObservablePublishClassic.java | 1 + .../schedulers/SchedulerPoolFactory.java | 60 ++++++++------ .../reactivex/observers/BaseTestConsumer.java | 1 - .../schedulers/SchedulerPoolFactoryTest.java | 82 +++++++++++-------- 10 files changed, 91 insertions(+), 65 deletions(-) diff --git a/build.gradle b/build.gradle index 2f33e66093..48565d07d0 100644 --- a/build.gradle +++ b/build.gradle @@ -52,7 +52,7 @@ targetCompatibility = JavaVersion.VERSION_1_6 // --------------------------------------- def junitVersion = "4.12" -def reactiveStreamsVersion = "1.0.2" +def reactiveStreamsVersion = "1.0.3" def mockitoVersion = "2.1.0" def jmhLibVersion = "1.20" def testNgVersion = "6.11" diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java index 20d2332214..ff7b6cced5 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java @@ -84,7 +84,7 @@ static final class NextObserver implements CompletableObserver { final CompletableObserver downstream; - public NextObserver(AtomicReference parent, CompletableObserver downstream) { + NextObserver(AtomicReference parent, CompletableObserver downstream) { this.parent = parent; this.downstream = downstream; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java index e573f3daf3..b325d2b78d 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java @@ -79,6 +79,7 @@ public Publisher source() { } /** + * The internal buffer size of this FloawblePublish operator. * @return The internal buffer size of this FloawblePublish operator. */ @Override diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishAlt.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishAlt.java index d58ba84503..932e0bf003 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishAlt.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishAlt.java @@ -62,6 +62,7 @@ public Publisher source() { } /** + * The internal buffer size of this FloawblePublishAlt operator. * @return The internal buffer size of this FloawblePublishAlt operator. */ public int publishBufferSize() { diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishClassic.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishClassic.java index 0cbf70efad..27ded26592 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishClassic.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublishClassic.java @@ -30,11 +30,13 @@ public interface FlowablePublishClassic { /** + * The upstream source of this publish operator. * @return the upstream source of this publish operator */ Publisher publishSource(); /** + * The internal buffer size of this publish operator. * @return the internal buffer size of this publish operator */ int publishBufferSize(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishAlt.java b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishAlt.java index 771e58dda8..a9e62babde 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishAlt.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishAlt.java @@ -146,7 +146,7 @@ static final class PublishConnection Throwable error; @SuppressWarnings("unchecked") - public PublishConnection(AtomicReference> current) { + PublishConnection(AtomicReference> current) { this.connect = new AtomicBoolean(); this.current = current; this.upstream = new AtomicReference(); @@ -261,7 +261,7 @@ static final class InnerDisposable final Observer downstream; - public InnerDisposable(Observer downstream, PublishConnection parent) { + InnerDisposable(Observer downstream, PublishConnection parent) { this.downstream = downstream; lazySet(parent); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishClassic.java b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishClassic.java index f072779930..b2bfe87f71 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishClassic.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublishClassic.java @@ -30,6 +30,7 @@ public interface ObservablePublishClassic { /** + * The upstream source of this publish operator. * @return the upstream source of this publish operator */ ObservableSource publishSource(); diff --git a/src/main/java/io/reactivex/internal/schedulers/SchedulerPoolFactory.java b/src/main/java/io/reactivex/internal/schedulers/SchedulerPoolFactory.java index b0b1339d29..ab465046aa 100644 --- a/src/main/java/io/reactivex/internal/schedulers/SchedulerPoolFactory.java +++ b/src/main/java/io/reactivex/internal/schedulers/SchedulerPoolFactory.java @@ -20,6 +20,8 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; +import io.reactivex.functions.Function; + /** * Manages the creating of ScheduledExecutorServices and sets up purging. */ @@ -90,40 +92,48 @@ public static void shutdown() { } static { - Properties properties = System.getProperties(); - - PurgeProperties pp = new PurgeProperties(); - pp.load(properties); - - PURGE_ENABLED = pp.purgeEnable; - PURGE_PERIOD_SECONDS = pp.purgePeriod; + SystemPropertyAccessor propertyAccessor = new SystemPropertyAccessor(); + PURGE_ENABLED = getBooleanProperty(true, PURGE_ENABLED_KEY, true, true, propertyAccessor); + PURGE_PERIOD_SECONDS = getIntProperty(PURGE_ENABLED, PURGE_PERIOD_SECONDS_KEY, 1, 1, propertyAccessor); start(); } - static final class PurgeProperties { - - boolean purgeEnable; - - int purgePeriod; - - void load(Properties properties) { - if (properties.containsKey(PURGE_ENABLED_KEY)) { - purgeEnable = Boolean.parseBoolean(properties.getProperty(PURGE_ENABLED_KEY)); - } else { - purgeEnable = true; + static int getIntProperty(boolean enabled, String key, int defaultNotFound, int defaultNotEnabled, Function propertyAccessor) { + if (enabled) { + try { + String value = propertyAccessor.apply(key); + if (value == null) { + return defaultNotFound; + } + return Integer.parseInt(value); + } catch (Throwable ex) { + return defaultNotFound; } + } + return defaultNotEnabled; + } - if (purgeEnable && properties.containsKey(PURGE_PERIOD_SECONDS_KEY)) { - try { - purgePeriod = Integer.parseInt(properties.getProperty(PURGE_PERIOD_SECONDS_KEY)); - } catch (NumberFormatException ex) { - purgePeriod = 1; + static boolean getBooleanProperty(boolean enabled, String key, boolean defaultNotFound, boolean defaultNotEnabled, Function propertyAccessor) { + if (enabled) { + try { + String value = propertyAccessor.apply(key); + if (value == null) { + return defaultNotFound; } - } else { - purgePeriod = 1; + return "true".equals(value); + } catch (Throwable ex) { + return defaultNotFound; } } + return defaultNotEnabled; + } + + static final class SystemPropertyAccessor implements Function { + @Override + public String apply(String t) throws Exception { + return System.getProperty(t); + } } /** diff --git a/src/main/java/io/reactivex/observers/BaseTestConsumer.java b/src/main/java/io/reactivex/observers/BaseTestConsumer.java index 61db5a2356..4c92c27468 100644 --- a/src/main/java/io/reactivex/observers/BaseTestConsumer.java +++ b/src/main/java/io/reactivex/observers/BaseTestConsumer.java @@ -555,7 +555,6 @@ public final U assertValues(T... values) { * @return this * @since 2.2 */ - @SuppressWarnings("unchecked") public final U assertValuesOnly(T... values) { return assertSubscribed() .assertValues(values) diff --git a/src/test/java/io/reactivex/internal/schedulers/SchedulerPoolFactoryTest.java b/src/test/java/io/reactivex/internal/schedulers/SchedulerPoolFactoryTest.java index 603929ddb4..24b3daa801 100644 --- a/src/test/java/io/reactivex/internal/schedulers/SchedulerPoolFactoryTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/SchedulerPoolFactoryTest.java @@ -18,12 +18,11 @@ import static org.junit.Assert.*; -import java.util.Properties; - import org.junit.Test; import io.reactivex.TestHelper; -import io.reactivex.internal.schedulers.SchedulerPoolFactory.PurgeProperties; +import io.reactivex.functions.Function; +import io.reactivex.internal.functions.Functions; import io.reactivex.schedulers.Schedulers; public class SchedulerPoolFactoryTest { @@ -78,53 +77,66 @@ public void run() { } @Test - public void loadPurgeProperties() { - Properties props1 = new Properties(); - - PurgeProperties pp = new PurgeProperties(); - pp.load(props1); - - assertTrue(pp.purgeEnable); - assertEquals(pp.purgePeriod, 1); + public void boolPropertiesDisabledReturnsDefaultDisabled() throws Throwable { + assertTrue(SchedulerPoolFactory.getBooleanProperty(false, "key", false, true, failingPropertiesAccessor)); + assertFalse(SchedulerPoolFactory.getBooleanProperty(false, "key", true, false, failingPropertiesAccessor)); } @Test - public void loadPurgePropertiesDisabled() { - Properties props1 = new Properties(); - props1.setProperty(SchedulerPoolFactory.PURGE_ENABLED_KEY, "false"); + public void boolPropertiesEnabledMissingReturnsDefaultMissing() throws Throwable { + assertTrue(SchedulerPoolFactory.getBooleanProperty(true, "key", true, false, missingPropertiesAccessor)); + assertFalse(SchedulerPoolFactory.getBooleanProperty(true, "key", false, true, missingPropertiesAccessor)); + } - PurgeProperties pp = new PurgeProperties(); - pp.load(props1); + @Test + public void boolPropertiesFailureReturnsDefaultMissing() throws Throwable { + assertTrue(SchedulerPoolFactory.getBooleanProperty(true, "key", true, false, failingPropertiesAccessor)); + assertFalse(SchedulerPoolFactory.getBooleanProperty(true, "key", false, true, failingPropertiesAccessor)); + } - assertFalse(pp.purgeEnable); - assertEquals(pp.purgePeriod, 1); + @Test + public void boolPropertiesReturnsValue() throws Throwable { + assertTrue(SchedulerPoolFactory.getBooleanProperty(true, "true", true, false, Functions.identity())); + assertFalse(SchedulerPoolFactory.getBooleanProperty(true, "false", false, true, Functions.identity())); } @Test - public void loadPurgePropertiesEnabledCustomPeriod() { - Properties props1 = new Properties(); - props1.setProperty(SchedulerPoolFactory.PURGE_ENABLED_KEY, "true"); - props1.setProperty(SchedulerPoolFactory.PURGE_PERIOD_SECONDS_KEY, "2"); + public void intPropertiesDisabledReturnsDefaultDisabled() throws Throwable { + assertEquals(-1, SchedulerPoolFactory.getIntProperty(false, "key", 0, -1, failingPropertiesAccessor)); + assertEquals(-1, SchedulerPoolFactory.getIntProperty(false, "key", 1, -1, failingPropertiesAccessor)); + } - PurgeProperties pp = new PurgeProperties(); - pp.load(props1); + @Test + public void intPropertiesEnabledMissingReturnsDefaultMissing() throws Throwable { + assertEquals(-1, SchedulerPoolFactory.getIntProperty(true, "key", -1, 0, missingPropertiesAccessor)); + assertEquals(-1, SchedulerPoolFactory.getIntProperty(true, "key", -1, 1, missingPropertiesAccessor)); + } - assertTrue(pp.purgeEnable); - assertEquals(pp.purgePeriod, 2); + @Test + public void intPropertiesFailureReturnsDefaultMissing() throws Throwable { + assertEquals(-1, SchedulerPoolFactory.getIntProperty(true, "key", -1, 0, failingPropertiesAccessor)); + assertEquals(-1, SchedulerPoolFactory.getIntProperty(true, "key", -1, 1, failingPropertiesAccessor)); } @Test - public void loadPurgePropertiesEnabledCustomPeriodNaN() { - Properties props1 = new Properties(); - props1.setProperty(SchedulerPoolFactory.PURGE_ENABLED_KEY, "true"); - props1.setProperty(SchedulerPoolFactory.PURGE_PERIOD_SECONDS_KEY, "abc"); + public void intPropertiesReturnsValue() throws Throwable { + assertEquals(1, SchedulerPoolFactory.getIntProperty(true, "1", 0, 4, Functions.identity())); + assertEquals(2, SchedulerPoolFactory.getIntProperty(true, "2", 3, 5, Functions.identity())); + } - PurgeProperties pp = new PurgeProperties(); - pp.load(props1); + static final Function failingPropertiesAccessor = new Function() { + @Override + public String apply(String v) throws Exception { + throw new SecurityException(); + } + }; - assertTrue(pp.purgeEnable); - assertEquals(pp.purgePeriod, 1); - } + static final Function missingPropertiesAccessor = new Function() { + @Override + public String apply(String v) throws Exception { + return null; + } + }; @Test public void putIntoPoolNoPurge() { From 71bfcae35b8052c21e8564c417ae0a870eb5ddb8 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 13 Sep 2019 17:50:08 +0200 Subject: [PATCH 179/211] 3.x: Fix takeLast(time) last events time window calculation. (#6653) --- .../observable/ObservableTakeLastTimed.java | 3 ++- .../io/reactivex/TimesteppingScheduler.java | 11 ++++++--- .../flowable/FlowableTakeLastTimedTest.java | 23 +++++++++++++++++++ .../ObservableTakeLastTimedTest.java | 23 +++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimed.java index 7bd29092b4..213588032b 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimed.java @@ -139,6 +139,7 @@ void drain() { final Observer a = downstream; final SpscLinkedArrayQueue q = queue; final boolean delayError = this.delayError; + final long timestampLimit = scheduler.now(unit) - time; for (;;) { if (cancelled) { @@ -171,7 +172,7 @@ void drain() { @SuppressWarnings("unchecked") T o = (T)q.poll(); - if ((Long)ts < scheduler.now(unit) - time) { + if ((Long)ts < timestampLimit) { continue; } diff --git a/src/test/java/io/reactivex/TimesteppingScheduler.java b/src/test/java/io/reactivex/TimesteppingScheduler.java index 73996cc56f..1bf0df2b8e 100644 --- a/src/test/java/io/reactivex/TimesteppingScheduler.java +++ b/src/test/java/io/reactivex/TimesteppingScheduler.java @@ -42,11 +42,13 @@ public Disposable schedule(Runnable run, long delay, TimeUnit unit) { @Override public long now(TimeUnit unit) { - return time++; + return TimesteppingScheduler.this.now(unit); } } - long time; + public long time; + + public boolean stepEnabled; @Override public Worker createWorker() { @@ -55,6 +57,9 @@ public Worker createWorker() { @Override public long now(TimeUnit unit) { - return time++; + if (stepEnabled) { + return time++; + } + return time; } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java index 4864cac7f6..5f2cda82ea 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java @@ -336,4 +336,27 @@ public Publisher apply(Flowable f) throws Exception { public void badRequest() { TestHelper.assertBadRequestReported(PublishProcessor.create().takeLast(1, TimeUnit.SECONDS)); } + + @Test + public void lastWindowIsFixedInTime() { + TimesteppingScheduler scheduler = new TimesteppingScheduler(); + scheduler.stepEnabled = false; + + PublishProcessor pp = PublishProcessor.create(); + + TestSubscriber ts = pp + .takeLast(2, TimeUnit.SECONDS, scheduler) + .test(); + + pp.onNext(1); + pp.onNext(2); + pp.onNext(3); + pp.onNext(4); + + scheduler.stepEnabled = true; + + pp.onComplete(); + + ts.assertResult(1, 2, 3, 4); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java index 9269bd0b5a..2aa3f38c7e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java @@ -275,4 +275,27 @@ public void run() { TestHelper.race(r1, r2); } } + + @Test + public void lastWindowIsFixedInTime() { + TimesteppingScheduler scheduler = new TimesteppingScheduler(); + scheduler.stepEnabled = false; + + PublishSubject ps = PublishSubject.create(); + + TestObserver to = ps + .takeLast(2, TimeUnit.SECONDS, scheduler) + .test(); + + ps.onNext(1); + ps.onNext(2); + ps.onNext(3); + ps.onNext(4); + + scheduler.stepEnabled = true; + + ps.onComplete(); + + to.assertResult(1, 2, 3, 4); + } } From 1cf6e3e73a1ac48abca17d8e76b18b946cf86a8a Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 30 Sep 2019 12:43:09 +0200 Subject: [PATCH 180/211] 2.x: Fix size+time bound window not creating windows properly (#6657) --- .../flowable/FlowableWindowTimed.java | 2 +- .../observable/ObservableWindowTimed.java | 2 +- .../flowable/FlowableWindowTests.java | 45 ++++++++++++++++++- .../flowable/FlowableWindowWithTimeTest.java | 14 +++--- .../ObservableWindowWithTimeTest.java | 14 +++--- .../observable/ObservableWindowTests.java | 44 ++++++++++++++++++ 6 files changed, 106 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java index ae284ef27a..00f783a39e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java @@ -498,7 +498,7 @@ void drainLoop() { if (isHolder) { ConsumerIndexHolder consumerIndexHolder = (ConsumerIndexHolder) o; - if (restartTimerOnMaxSize || producerIndex == consumerIndexHolder.index) { + if (!restartTimerOnMaxSize || producerIndex == consumerIndexHolder.index) { w.onComplete(); count = 0; w = UnicastProcessor.create(bufferSize); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java index 1ffc0f475e..406d8f03ff 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java @@ -444,7 +444,7 @@ void drainLoop() { if (isHolder) { ConsumerIndexHolder consumerIndexHolder = (ConsumerIndexHolder) o; - if (restartTimerOnMaxSize || producerIndex == consumerIndexHolder.index) { + if (!restartTimerOnMaxSize || producerIndex == consumerIndexHolder.index) { w.onComplete(); count = 0; w = UnicastSubject.create(bufferSize); diff --git a/src/test/java/io/reactivex/flowable/FlowableWindowTests.java b/src/test/java/io/reactivex/flowable/FlowableWindowTests.java index 9ef4211aa4..08151bcb8b 100644 --- a/src/test/java/io/reactivex/flowable/FlowableWindowTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableWindowTests.java @@ -16,11 +16,15 @@ import static org.junit.Assert.*; import java.util.*; +import java.util.concurrent.TimeUnit; import org.junit.Test; -import io.reactivex.Flowable; +import io.reactivex.*; import io.reactivex.functions.*; +import io.reactivex.processors.PublishProcessor; +import io.reactivex.schedulers.TestScheduler; +import io.reactivex.subscribers.TestSubscriber; public class FlowableWindowTests { @@ -50,4 +54,43 @@ public void accept(List xs) { assertEquals(2, lists.size()); } + + @Test + public void timeSizeWindowAlternatingBounds() { + TestScheduler scheduler = new TestScheduler(); + PublishProcessor pp = PublishProcessor.create(); + + TestSubscriber> ts = pp.window(5, TimeUnit.SECONDS, scheduler, 2) + .flatMapSingle(new Function, SingleSource>>() { + @Override + public SingleSource> apply(Flowable v) { + return v.toList(); + } + }) + .test(); + + pp.onNext(1); + pp.onNext(2); + ts.assertValueCount(1); // size bound hit + + scheduler.advanceTimeBy(1, TimeUnit.SECONDS); + pp.onNext(3); + scheduler.advanceTimeBy(6, TimeUnit.SECONDS); + ts.assertValueCount(2); // time bound hit + + pp.onNext(4); + pp.onNext(5); + + ts.assertValueCount(3); // size bound hit again + + pp.onNext(4); + + scheduler.advanceTimeBy(6, TimeUnit.SECONDS); + + ts.assertValueCount(4) + .assertNoErrors() + .assertNotComplete(); + + ts.cancel(); + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java index 157faae1a5..37d8928571 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java @@ -64,17 +64,19 @@ public void subscribe(Subscriber subscriber) { Flowable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler, 2); windowed.subscribe(observeWindow(list, lists)); - scheduler.advanceTimeTo(100, TimeUnit.MILLISECONDS); + scheduler.advanceTimeTo(95, TimeUnit.MILLISECONDS); assertEquals(1, lists.size()); assertEquals(lists.get(0), list("one", "two")); - scheduler.advanceTimeTo(200, TimeUnit.MILLISECONDS); - assertEquals(2, lists.size()); - assertEquals(lists.get(1), list("three", "four")); + scheduler.advanceTimeTo(195, TimeUnit.MILLISECONDS); + assertEquals(3, lists.size()); + assertTrue(lists.get(1).isEmpty()); + assertEquals(lists.get(2), list("three", "four")); scheduler.advanceTimeTo(300, TimeUnit.MILLISECONDS); - assertEquals(3, lists.size()); - assertEquals(lists.get(2), list("five")); + assertEquals(5, lists.size()); + assertTrue(lists.get(3).isEmpty()); + assertEquals(lists.get(4), list("five")); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java index 4eb90f4e50..fbd90088ed 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java @@ -64,17 +64,19 @@ public void subscribe(Observer observer) { Observable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler, 2); windowed.subscribe(observeWindow(list, lists)); - scheduler.advanceTimeTo(100, TimeUnit.MILLISECONDS); + scheduler.advanceTimeTo(95, TimeUnit.MILLISECONDS); assertEquals(1, lists.size()); assertEquals(lists.get(0), list("one", "two")); - scheduler.advanceTimeTo(200, TimeUnit.MILLISECONDS); - assertEquals(2, lists.size()); - assertEquals(lists.get(1), list("three", "four")); + scheduler.advanceTimeTo(195, TimeUnit.MILLISECONDS); + assertEquals(3, lists.size()); + assertTrue(lists.get(1).isEmpty()); + assertEquals(lists.get(2), list("three", "four")); scheduler.advanceTimeTo(300, TimeUnit.MILLISECONDS); - assertEquals(3, lists.size()); - assertEquals(lists.get(2), list("five")); + assertEquals(5, lists.size()); + assertTrue(lists.get(3).isEmpty()); + assertEquals(lists.get(4), list("five")); } @Test diff --git a/src/test/java/io/reactivex/observable/ObservableWindowTests.java b/src/test/java/io/reactivex/observable/ObservableWindowTests.java index d4c68fd63b..701b07e0b7 100644 --- a/src/test/java/io/reactivex/observable/ObservableWindowTests.java +++ b/src/test/java/io/reactivex/observable/ObservableWindowTests.java @@ -16,11 +16,16 @@ import static org.junit.Assert.*; import java.util.*; +import java.util.concurrent.TimeUnit; import org.junit.Test; import io.reactivex.Observable; +import io.reactivex.SingleSource; import io.reactivex.functions.*; +import io.reactivex.observers.TestObserver; +import io.reactivex.schedulers.TestScheduler; +import io.reactivex.subjects.PublishSubject; public class ObservableWindowTests { @@ -50,4 +55,43 @@ public void accept(List xs) { assertEquals(2, lists.size()); } + + @Test + public void timeSizeWindowAlternatingBounds() { + TestScheduler scheduler = new TestScheduler(); + PublishSubject ps = PublishSubject.create(); + + TestObserver> to = ps.window(5, TimeUnit.SECONDS, scheduler, 2) + .flatMapSingle(new Function, SingleSource>>() { + @Override + public SingleSource> apply(Observable v) { + return v.toList(); + } + }) + .test(); + + ps.onNext(1); + ps.onNext(2); + to.assertValueCount(1); // size bound hit + + scheduler.advanceTimeBy(1, TimeUnit.SECONDS); + ps.onNext(3); + scheduler.advanceTimeBy(6, TimeUnit.SECONDS); + to.assertValueCount(2); // time bound hit + + ps.onNext(4); + ps.onNext(5); + + to.assertValueCount(3); // size bound hit again + + ps.onNext(4); + + scheduler.advanceTimeBy(6, TimeUnit.SECONDS); + + to.assertValueCount(4) + .assertNoErrors() + .assertNotComplete(); + + to.dispose(); + } } From d4eae73fb2c8f09f9ab05de22444009cb0ea4c45 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 3 Oct 2019 09:46:59 +0200 Subject: [PATCH 181/211] Release 2.2.13 --- CHANGES.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index fb4c345d29..af5f1d3074 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,18 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.13 - October 3, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.13%7C)) + +#### Dependencies + + - [Commit cc690ff2](https://github.com/ReactiveX/RxJava/commit/cc690ff2f757873b11cd075ebc22262f76f28459): Upgrade to **Reactive Streams 1.0.3**. + +#### Bugfixes + + - [Commit cc690ff2](https://github.com/ReactiveX/RxJava/commit/cc690ff2f757873b11cd075ebc22262f76f28459): Avoid using `System.getProperties()`. + - [Pull 6653](https://github.com/ReactiveX/RxJava/pull/6653): Fix `takeLast(time)` last events time window calculation. + - [Pull 6657](https://github.com/ReactiveX/RxJava/pull/6657): Fix size+time bound `window` not creating windows properly. + ### Version 2.2.12 - August 25, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.12%7C)) #### Bugfixes From 70fe91c7f7074cc36df93e3e2b22b077d9786ffe Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 17 Oct 2019 16:38:46 +0200 Subject: [PATCH 182/211] 2.x: Fix concurrent clear() calls when fused chains are canceled (#6677) --- .../operators/flowable/FlowableGroupBy.java | 3 +- .../FlowableOnBackpressureBuffer.java | 2 +- .../processors/UnicastProcessor.java | 8 +- .../io/reactivex/subjects/UnicastSubject.java | 5 +- .../flowable/FlowableGroupByTest.java | 85 ++++++++++++++++++- .../FlowableOnBackpressureBufferTest.java | 40 ++++++++- .../processors/UnicastProcessorTest.java | 41 ++++++++- .../subjects/UnicastSubjectTest.java | 40 ++++++++- 8 files changed, 208 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java index 719645afe9..11ec41a0f2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java @@ -262,7 +262,7 @@ public void cancel(K key) { if (groupCount.decrementAndGet() == 0) { upstream.cancel(); - if (getAndIncrement() == 0) { + if (!outputFused && getAndIncrement() == 0) { queue.clear(); } } @@ -288,7 +288,6 @@ void drainFused() { for (;;) { if (cancelled.get()) { - q.clear(); return; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBuffer.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBuffer.java index 20caa2c7e3..8cbb73ebf2 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBuffer.java @@ -150,7 +150,7 @@ public void cancel() { cancelled = true; upstream.cancel(); - if (getAndIncrement() == 0) { + if (!outputFused && getAndIncrement() == 0) { queue.clear(); } } diff --git a/src/main/java/io/reactivex/processors/UnicastProcessor.java b/src/main/java/io/reactivex/processors/UnicastProcessor.java index 94547b88fb..ec4d6c1a77 100644 --- a/src/main/java/io/reactivex/processors/UnicastProcessor.java +++ b/src/main/java/io/reactivex/processors/UnicastProcessor.java @@ -347,7 +347,6 @@ void drainFused(Subscriber a) { for (;;) { if (cancelled) { - q.clear(); downstream.lazySet(null); return; } @@ -550,10 +549,11 @@ public void cancel() { doTerminate(); - if (!enableOperatorFusion) { - if (wip.getAndIncrement() == 0) { + downstream.lazySet(null); + if (wip.getAndIncrement() == 0) { + downstream.lazySet(null); + if (!enableOperatorFusion) { queue.clear(); - downstream.lazySet(null); } } } diff --git a/src/main/java/io/reactivex/subjects/UnicastSubject.java b/src/main/java/io/reactivex/subjects/UnicastSubject.java index 8c3eae8af0..20aadbd460 100644 --- a/src/main/java/io/reactivex/subjects/UnicastSubject.java +++ b/src/main/java/io/reactivex/subjects/UnicastSubject.java @@ -420,7 +420,6 @@ void drainFused(Observer a) { if (disposed) { downstream.lazySet(null); - q.clear(); return; } boolean d = done; @@ -558,7 +557,9 @@ public void dispose() { downstream.lazySet(null); if (wip.getAndIncrement() == 0) { downstream.lazySet(null); - queue.clear(); + if (!enableOperatorFusion) { + queue.clear(); + } } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java index 63d6152a3e..85501e2578 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.IOException; @@ -29,12 +30,13 @@ import com.google.common.cache.*; import io.reactivex.*; -import io.reactivex.exceptions.TestException; +import io.reactivex.exceptions.*; import io.reactivex.flowables.GroupedFlowable; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.QueueFuseable; +import io.reactivex.internal.fuseable.*; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; @@ -2205,4 +2207,83 @@ public void accept(Object object) { }}; return evictingMapFactory; } + + @Test + public void fusedNoConcurrentCleanDueToCancel() { + for (int j = 0; j < TestHelper.RACE_LONG_LOOPS; j++) { + List errors = TestHelper.trackPluginErrors(); + try { + final PublishProcessor pp = PublishProcessor.create(); + + final AtomicReference>> qs = new AtomicReference>>(); + + final TestSubscriber ts2 = new TestSubscriber(); + + pp.groupBy(Functions.identity(), Functions.identity(), false, 4) + .subscribe(new FlowableSubscriber>() { + + boolean once; + + @Override + public void onNext(GroupedFlowable g) { + if (!once) { + try { + GroupedFlowable t = qs.get().poll(); + if (t != null) { + once = true; + t.subscribe(ts2); + } + } catch (Throwable ignored) { + // not relevant here + } + } + } + + @Override + public void onError(Throwable t) { + } + + @Override + public void onComplete() { + } + + @Override + public void onSubscribe(Subscription s) { + @SuppressWarnings("unchecked") + QueueSubscription> q = (QueueSubscription>)s; + qs.set(q); + q.requestFusion(QueueFuseable.ANY); + q.request(1); + } + }) + ; + + Runnable r1 = new Runnable() { + @Override + public void run() { + qs.get().cancel(); + qs.get().clear(); + } + }; + Runnable r2 = new Runnable() { + @Override + public void run() { + ts2.cancel(); + } + }; + + for (int i = 0; i < 100; i++) { + pp.onNext(i); + } + + TestHelper.race(r1, r2); + + if (!errors.isEmpty()) { + throw new CompositeException(errors); + } + } finally { + RxJavaPlugins.reset(); + } + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java index f44fbc8353..be7fe522da 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java @@ -15,17 +15,22 @@ import static org.junit.Assert.*; +import java.util.List; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.Flowable; +import io.reactivex.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.observers.TestObserver; +import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; @@ -307,4 +312,37 @@ public void fusionRejected() { SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) .assertEmpty(); } + + @Test + public void fusedNoConcurrentCleanDueToCancel() { + for (int j = 0; j < TestHelper.RACE_LONG_LOOPS; j++) { + List errors = TestHelper.trackPluginErrors(); + try { + final PublishProcessor pp = PublishProcessor.create(); + + TestObserver to = pp.onBackpressureBuffer(4, false, true) + .observeOn(Schedulers.io()) + .map(Functions.identity()) + .observeOn(Schedulers.single()) + .firstOrError() + .test(); + + for (int i = 0; pp.hasSubscribers(); i++) { + pp.onNext(i); + } + + to + .awaitDone(5, TimeUnit.SECONDS) + ; + + if (!errors.isEmpty()) { + throw new CompositeException(errors); + } + + to.assertResult(0); + } finally { + RxJavaPlugins.reset(); + } + } + } } diff --git a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java index 84335845a9..7b96e03b53 100644 --- a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java +++ b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java @@ -16,16 +16,20 @@ import static org.junit.Assert.*; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; import io.reactivex.*; import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.TestException; -import io.reactivex.internal.fuseable.*; +import io.reactivex.exceptions.*; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; public class UnicastProcessorTest extends FlowableProcessorTest { @@ -438,4 +442,37 @@ public void unicastSubscriptionBadRequest() { RxJavaPlugins.reset(); } } + + @Test + public void fusedNoConcurrentCleanDueToCancel() { + for (int j = 0; j < TestHelper.RACE_LONG_LOOPS; j++) { + List errors = TestHelper.trackPluginErrors(); + try { + final UnicastProcessor us = UnicastProcessor.create(); + + TestObserver to = us + .observeOn(Schedulers.io()) + .map(Functions.identity()) + .observeOn(Schedulers.single()) + .firstOrError() + .test(); + + for (int i = 0; us.hasSubscribers(); i++) { + us.onNext(i); + } + + to + .awaitDone(5, TimeUnit.SECONDS) + ; + + if (!errors.isEmpty()) { + throw new CompositeException(errors); + } + + to.assertResult(0); + } finally { + RxJavaPlugins.reset(); + } + } + } } diff --git a/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java b/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java index 9b0a16879d..ea68601722 100644 --- a/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java @@ -17,16 +17,19 @@ import static org.mockito.Mockito.mock; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; import io.reactivex.*; import io.reactivex.disposables.*; -import io.reactivex.exceptions.TestException; -import io.reactivex.internal.fuseable.*; +import io.reactivex.exceptions.*; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.schedulers.Schedulers; public class UnicastSubjectTest extends SubjectTest { @@ -456,4 +459,37 @@ public void drainFusedFailFastEmpty() { to.assertEmpty(); } + + @Test + public void fusedNoConcurrentCleanDueToCancel() { + for (int j = 0; j < TestHelper.RACE_LONG_LOOPS; j++) { + List errors = TestHelper.trackPluginErrors(); + try { + final UnicastSubject us = UnicastSubject.create(); + + TestObserver to = us + .observeOn(Schedulers.io()) + .map(Functions.identity()) + .observeOn(Schedulers.single()) + .firstOrError() + .test(); + + for (int i = 0; us.hasObservers(); i++) { + us.onNext(i); + } + + to + .awaitDone(5, TimeUnit.SECONDS) + ; + + if (!errors.isEmpty()) { + throw new CompositeException(errors); + } + + to.assertResult(0); + } finally { + RxJavaPlugins.reset(); + } + } + } } From 90ae2a39a7cf527c353253d2374474fede58aef4 Mon Sep 17 00:00:00 2001 From: Thiyagarajan <38608518+thiyagu-7@users.noreply.github.com> Date: Fri, 18 Oct 2019 11:47:18 +0530 Subject: [PATCH 183/211] Backport marble diagrams for Single from 3.x (#6681) --- src/main/java/io/reactivex/Single.java | 91 ++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 299e6da76f..15ef6b6c14 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -400,6 +400,8 @@ public static Flowable concatArray(SingleSource... sources) /** * Concatenates a sequence of SingleSource eagerly into a single stream of values. *

          + * + *

          * Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source SingleSources. The operator buffers the value emitted by these SingleSources and then drains them * in order, each one after the previous one completes. @@ -1108,6 +1110,8 @@ public static Flowable merge( /** * Merges an Iterable sequence of SingleSource instances into a single Flowable sequence, * running all SingleSources at once and delaying any error(s) until all sources succeed or fail. + *

          + * *

          *
          Backpressure:
          *
          The returned {@code Flowable} honors the backpressure of the downstream consumer.
          @@ -1132,6 +1136,8 @@ public static Flowable mergeDelayError(Iterable + * *
          *
          Backpressure:
          *
          The returned {@code Flowable} honors the backpressure of the downstream consumer.
          @@ -1159,7 +1165,7 @@ public static Flowable mergeDelayError(Publisher - * + * *

          * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by * using the {@code mergeDelayError} method. @@ -1197,7 +1203,7 @@ public static Flowable mergeDelayError( * Flattens three Singles into a single Flowable, without any transformation, delaying * any error(s) until all sources succeed or fail. *

          - * + * *

          * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using * the {@code mergeDelayError} method. @@ -1239,7 +1245,7 @@ public static Flowable mergeDelayError( * Flattens four Singles into a single Flowable, without any transformation, delaying * any error(s) until all sources succeed or fail. *

          - * + * *

          * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using * the {@code mergeDelayError} method. @@ -1370,6 +1376,8 @@ public static Single equals(final SingleSource first, /** * Advanced use only: creates a Single instance without * any safeguards by using a callback that is called with a SingleObserver. + *

          + * *

          *
          Scheduler:
          *
          {@code unsafeCreate} does not operate by default on a particular {@link Scheduler}.
          @@ -1396,6 +1404,8 @@ public static Single unsafeCreate(SingleSource onSubscribe) { /** * Allows using and disposing a resource while running a SingleSource instance generated from * that resource (similar to a try-with-resources). + *

          + * *

          *
          Scheduler:
          *
          {@code using} does not operate by default on a particular {@link Scheduler}.
          @@ -1423,6 +1433,8 @@ public static Single using(Callable resourceSupplier, /** * Allows using and disposing a resource while running a SingleSource instance generated from * that resource (similar to a try-with-resources). + *

          + * *

          *
          Scheduler:
          *
          {@code using} does not operate by default on a particular {@link Scheduler}.
          @@ -1460,6 +1472,8 @@ public static Single using( /** * Wraps a SingleSource instance into a new Single instance if not already a Single * instance. + *

          + * *

          *
          Scheduler:
          *
          {@code wrap} does not operate by default on a particular {@link Scheduler}.
          @@ -2067,6 +2081,7 @@ public final Single compose(SingleTransformer tra /** * Stores the success value or exception from the current Single and replays it to late SingleObservers. *

          + * * The returned Single subscribes to the current Single when the first SingleObserver subscribes. *

          *
          Scheduler:
          @@ -2085,6 +2100,8 @@ public final Single cache() { /** * Casts the success value of the current Single into the target type or signals a * ClassCastException if not compatible. + *

          + * *

          *
          Scheduler:
          *
          {@code cast} does not operate by default on a particular {@link Scheduler}.
          @@ -2225,6 +2242,8 @@ public final Single delay(final long time, final TimeUnit unit, final Schedul /** * Delays the actual subscription to the current Single until the given other CompletableSource * completes. + *

          + * *

          If the delaying source signals an error, that error is re-emitted and no subscription * to the current Single happens. *

          @@ -2247,6 +2266,8 @@ public final Single delaySubscription(CompletableSource other) { /** * Delays the actual subscription to the current Single until the given other SingleSource * signals success. + *

          + * *

          If the delaying source signals an error, that error is re-emitted and no subscription * to the current Single happens. *

          @@ -2270,6 +2291,8 @@ public final Single delaySubscription(SingleSource other) { /** * Delays the actual subscription to the current Single until the given other ObservableSource * signals its first value or completes. + *

          + * *

          If the delaying source signals an error, that error is re-emitted and no subscription * to the current Single happens. *

          @@ -2293,6 +2316,8 @@ public final Single delaySubscription(ObservableSource other) { /** * Delays the actual subscription to the current Single until the given other Publisher * signals its first value or completes. + *

          + * *

          If the delaying source signals an error, that error is re-emitted and no subscription * to the current Single happens. *

          The other source is consumed in an unbounded manner (requesting Long.MAX_VALUE from it). @@ -2320,6 +2345,8 @@ public final Single delaySubscription(Publisher other) { /** * Delays the actual subscription to the current Single until the given time delay elapsed. + *

          + * *

          *
          Scheduler:
          *
          {@code delaySubscription} does by default subscribe to the current Single @@ -2338,6 +2365,8 @@ public final Single delaySubscription(long time, TimeUnit unit) { /** * Delays the actual subscription to the current Single until the given time delay elapsed. + *

          + * *

          *
          Scheduler:
          *
          {@code delaySubscription} does by default subscribe to the current Single @@ -2360,6 +2389,8 @@ public final Single delaySubscription(long time, TimeUnit unit, Scheduler sch * {@code onSuccess}, {@code onError} or {@code onComplete} signals as a * {@link Maybe} source. *

          + * + *

          * The intended use of the {@code selector} function is to perform a * type-safe identity mapping (see example) on a source that is already of type * {@code Notification}. The Java language doesn't allow @@ -2547,6 +2578,8 @@ public final Single doOnSuccess(final Consumer onSuccess) { /** * Calls the shared consumer with the error sent via onError or the value * via onSuccess for each SingleObserver that subscribes to the current Single. + *

          + * *

          *
          Scheduler:
          *
          {@code doOnEvent} does not operate by default on a particular {@link Scheduler}.
          @@ -2817,6 +2850,8 @@ public final Completable flatMapCompletable(final Function + * *
          *
          Scheduler:
          *
          {@code blockingGet} does not operate by default on a particular {@link Scheduler}.
          @@ -2844,6 +2879,8 @@ public final T blockingGet() { * and providing a new {@code SingleObserver}, containing the custom operator's intended business logic, that will be * used in the subscription process going further upstream. *

          + * + *

          * Generally, such a new {@code SingleObserver} will wrap the downstream's {@code SingleObserver} and forwards the * {@code onSuccess} and {@code onError} events from the upstream directly or according to the * emission pattern the custom operator's business logic requires. In addition, such operator can intercept the @@ -3031,6 +3068,8 @@ public final Single> materialize() { /** * Signals true if the current Single signals a success value that is Object-equals with the value * provided. + *

          + * *

          *
          Scheduler:
          *
          {@code contains} does not operate by default on a particular {@link Scheduler}.
          @@ -3048,6 +3087,8 @@ public final Single contains(Object value) { /** * Signals true if the current Single signals a success value that is equal with * the value provided by calling a bi-predicate. + *

          + * *

          *
          Scheduler:
          *
          {@code contains} does not operate by default on a particular {@link Scheduler}.
          @@ -3249,6 +3290,8 @@ public final Single onErrorResumeNext( /** * Nulls out references to the upstream producer and downstream SingleObserver if * the sequence is terminated or downstream calls dispose(). + *

          + * *

          *
          Scheduler:
          *
          {@code onTerminateDetach} does not operate by default on a particular {@link Scheduler}.
          @@ -3356,6 +3399,8 @@ public final Flowable repeatUntil(BooleanSupplier stop) { /** * Repeatedly re-subscribes to the current Single indefinitely if it fails with an onError. + *

          + * *

          *
          Scheduler:
          *
          {@code retry} does not operate by default on a particular {@link Scheduler}.
          @@ -3372,6 +3417,8 @@ public final Single retry() { /** * Repeatedly re-subscribe at most the specified times to the current Single * if it fails with an onError. + *

          + * *

          *
          Scheduler:
          *
          {@code retry} does not operate by default on a particular {@link Scheduler}.
          @@ -3389,6 +3436,8 @@ public final Single retry(long times) { /** * Re-subscribe to the current Single if the given predicate returns true when the Single fails * with an onError. + *

          + * *

          *
          Scheduler:
          *
          {@code retry} does not operate by default on a particular {@link Scheduler}.
          @@ -3407,6 +3456,8 @@ public final Single retry(BiPredicate pre /** * Repeatedly re-subscribe at most times or until the predicate returns false, whichever happens first * if it fails with an onError. + *

          + * *

          *
          Scheduler:
          *
          {@code retry} does not operate by default on a particular {@link Scheduler}.
          @@ -3427,6 +3478,8 @@ public final Single retry(long times, Predicate predicate) /** * Re-subscribe to the current Single if the given predicate returns true when the Single fails * with an onError. + *

          + * *

          *
          Scheduler:
          *
          {@code retry} does not operate by default on a particular {@link Scheduler}.
          @@ -3446,6 +3499,8 @@ public final Single retry(Predicate predicate) { * Re-subscribes to the current Single if and when the Publisher returned by the handler * function signals a value. *

          + * + *

          * If the Publisher signals an onComplete, the resulting Single will signal a NoSuchElementException. *

          * Note that the inner {@code Publisher} returned by the handler function should signal @@ -3492,6 +3547,8 @@ public final Single retryWhen(Function, ? extends /** * Subscribes to a Single but ignore its emission or notification. *

          + * + *

          * If the Single emits an error, it is wrapped into an * {@link io.reactivex.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException} * and routed to the RxJavaPlugins.onError handler. @@ -3511,6 +3568,8 @@ public final Disposable subscribe() { /** * Subscribes to a Single and provides a composite callback to handle the item it emits * or any error notification it issues. + *

          + * *

          *
          Scheduler:
          *
          {@code subscribe} does not operate by default on a particular {@link Scheduler}.
          @@ -3538,6 +3597,8 @@ public final Disposable subscribe(final BiConsumer /** * Subscribes to a Single and provides a callback to handle the item it emits. *

          + * + *

          * If the Single emits an error, it is wrapped into an * {@link io.reactivex.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException} * and routed to the RxJavaPlugins.onError handler. @@ -3562,6 +3623,8 @@ public final Disposable subscribe(Consumer onSuccess) { /** * Subscribes to a Single and provides callbacks to handle the item it emits or any error notification it * issues. + *

          + * *

          *
          Scheduler:
          *
          {@code subscribe} does not operate by default on a particular {@link Scheduler}.
          @@ -3623,6 +3686,8 @@ public final void subscribe(SingleObserver observer) { /** * Subscribes a given SingleObserver (subclass) to this Single and returns the given * SingleObserver as is. + *

          + * *

          Usage example: *

          
                * Single<Integer> source = Single.just(1);
          @@ -3680,7 +3745,7 @@ public final Single subscribeOn(final Scheduler scheduler) {
                * termination of {@code other}, this will emit a {@link CancellationException} rather than go to
                * {@link SingleObserver#onSuccess(Object)}.
                * 

          - * + * *

          *
          Scheduler:
          *
          {@code takeUntil} does not operate by default on a particular {@link Scheduler}.
          @@ -3705,7 +3770,7 @@ public final Single takeUntil(final CompletableSource other) { * emission of an item from {@code other}, this will emit a {@link CancellationException} rather than go to * {@link SingleObserver#onSuccess(Object)}. *

          - * + * *

          *
          Backpressure:
          *
          The {@code other} publisher is consumed in an unbounded fashion but will be @@ -3737,7 +3802,7 @@ public final Single takeUntil(final Publisher other) { * emission of an item from {@code other}, this will emit a {@link CancellationException} rather than go to * {@link SingleObserver#onSuccess(Object)}. *

          - * + * *

          *
          Scheduler:
          *
          {@code takeUntil} does not operate by default on a particular {@link Scheduler}.
          @@ -3761,6 +3826,8 @@ public final Single takeUntil(final SingleSource other) { /** * Signals a TimeoutException if the current Single doesn't signal a success value within the * specified timeout window. + *

          + * *

          *
          Scheduler:
          *
          {@code timeout} signals the TimeoutException on the {@code computation} {@link Scheduler}.
          @@ -3779,6 +3846,8 @@ public final Single timeout(long timeout, TimeUnit unit) { /** * Signals a TimeoutException if the current Single doesn't signal a success value within the * specified timeout window. + *

          + * *

          *
          Scheduler:
          *
          {@code timeout} signals the TimeoutException on the {@link Scheduler} you specify.
          @@ -3799,6 +3868,8 @@ public final Single timeout(long timeout, TimeUnit unit, Scheduler scheduler) /** * Runs the current Single and if it doesn't signal within the specified timeout window, it is * disposed and the other SingleSource subscribed to. + *

          + * *

          *
          Scheduler:
          *
          {@code timeout} subscribes to the other SingleSource on the {@link Scheduler} you specify.
          @@ -3821,6 +3892,8 @@ public final Single timeout(long timeout, TimeUnit unit, Scheduler scheduler, /** * Runs the current Single and if it doesn't signal within the specified timeout window, it is * disposed and the other SingleSource subscribed to. + *

          + * *

          *
          Scheduler:
          *
          {@code timeout} subscribes to the other SingleSource on @@ -4005,6 +4078,8 @@ public final Observable toObservable() { /** * Returns a Single which makes sure when a SingleObserver disposes the Disposable, * that call is propagated up on the specified scheduler. + *

          + * *

          *
          Scheduler:
          *
          {@code unsubscribeOn} calls dispose() of the upstream on the {@link Scheduler} you specify.
          @@ -4058,6 +4133,8 @@ public final Single zipWith(SingleSource other, BiFunction + * *
          *
          Scheduler:
          *
          {@code test} does not operate by default on a particular {@link Scheduler}.
          @@ -4075,6 +4152,8 @@ public final TestObserver test() { /** * Creates a TestObserver optionally in cancelled state, then subscribes it to this Single. + *

          + * *

          *
          Scheduler:
          *
          {@code test} does not operate by default on a particular {@link Scheduler}.
          From bbaea423449872ae388b338fc9c3111b78087345 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 29 Oct 2019 09:38:44 +0100 Subject: [PATCH 184/211] 2.x: Fix window(time) possible interrupts while terminating (#6684) --- .../flowable/FlowableWindowTimed.java | 40 +-- .../observable/ObservableWindowTimed.java | 35 +-- .../flowable/FlowableWindowWithTimeTest.java | 243 ++++++++++++++++- .../ObservableWindowWithTimeTest.java | 244 +++++++++++++++++- 4 files changed, 503 insertions(+), 59 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java index 00f783a39e..2db0eba8cc 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableWindowTimed.java @@ -160,7 +160,6 @@ public void onError(Throwable t) { } downstream.onError(t); - dispose(); } @Override @@ -171,7 +170,6 @@ public void onComplete() { } downstream.onComplete(); - dispose(); } @Override @@ -184,22 +182,15 @@ public void cancel() { cancelled = true; } - public void dispose() { - DisposableHelper.dispose(timer); - } - @Override public void run() { - if (cancelled) { terminated = true; - dispose(); } queue.offer(NEXT); if (enter()) { drainLoop(); } - } void drainLoop() { @@ -221,13 +212,13 @@ void drainLoop() { if (d && (o == null || o == NEXT)) { window = null; q.clear(); - dispose(); Throwable err = error; if (err != null) { w.onError(err); } else { w.onComplete(); } + timer.dispose(); return; } @@ -251,8 +242,8 @@ void drainLoop() { window = null; queue.clear(); upstream.cancel(); - dispose(); a.onError(new MissingBackpressureException("Could not deliver first window due to lack of requests.")); + timer.dispose(); return; } } else { @@ -396,7 +387,7 @@ public void onNext(T t) { window = null; upstream.cancel(); downstream.onError(new MissingBackpressureException("Could not deliver window due to lack of requests")); - dispose(); + disposeTimer(); return; } } else { @@ -424,7 +415,6 @@ public void onError(Throwable t) { } downstream.onError(t); - dispose(); } @Override @@ -435,7 +425,6 @@ public void onComplete() { } downstream.onComplete(); - dispose(); } @Override @@ -448,8 +437,8 @@ public void cancel() { cancelled = true; } - public void dispose() { - DisposableHelper.dispose(timer); + public void disposeTimer() { + timer.dispose(); Worker w = worker; if (w != null) { w.dispose(); @@ -468,7 +457,7 @@ void drainLoop() { if (terminated) { upstream.cancel(); q.clear(); - dispose(); + disposeTimer(); return; } @@ -488,7 +477,7 @@ void drainLoop() { } else { w.onComplete(); } - dispose(); + disposeTimer(); return; } @@ -515,7 +504,7 @@ void drainLoop() { queue.clear(); upstream.cancel(); a.onError(new MissingBackpressureException("Could not deliver first window due to lack of requests.")); - dispose(); + disposeTimer(); return; } } @@ -554,7 +543,7 @@ void drainLoop() { window = null; upstream.cancel(); downstream.onError(new MissingBackpressureException("Could not deliver window due to lack of requests")); - dispose(); + disposeTimer(); return; } } else { @@ -585,7 +574,6 @@ public void run() { p.queue.offer(this); } else { p.terminated = true; - p.dispose(); } if (p.enter()) { p.drainLoop(); @@ -682,7 +670,6 @@ public void onError(Throwable t) { } downstream.onError(t); - dispose(); } @Override @@ -693,7 +680,6 @@ public void onComplete() { } downstream.onComplete(); - dispose(); } @Override @@ -706,10 +692,6 @@ public void cancel() { cancelled = true; } - public void dispose() { - worker.dispose(); - } - void complete(UnicastProcessor w) { queue.offer(new SubjectWork(w, false)); if (enter()) { @@ -730,9 +712,9 @@ void drainLoop() { for (;;) { if (terminated) { upstream.cancel(); - dispose(); q.clear(); ws.clear(); + worker.dispose(); return; } @@ -756,7 +738,7 @@ void drainLoop() { } } ws.clear(); - dispose(); + worker.dispose(); return; } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java index 406d8f03ff..5214d2b225 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableWindowTimed.java @@ -15,14 +15,13 @@ import java.util.*; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; import io.reactivex.*; import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import io.reactivex.internal.disposables.*; import io.reactivex.internal.observers.QueueDrainObserver; import io.reactivex.internal.queue.MpscLinkedQueue; import io.reactivex.internal.util.NotificationLite; @@ -85,7 +84,7 @@ static final class WindowExactUnboundedObserver UnicastSubject window; - final AtomicReference timer = new AtomicReference(); + final SequentialDisposable timer = new SequentialDisposable(); static final Object NEXT = new Object(); @@ -114,7 +113,7 @@ public void onSubscribe(Disposable d) { if (!cancelled) { Disposable task = scheduler.schedulePeriodicallyDirect(this, timespan, timespan, unit); - DisposableHelper.replace(timer, task); + timer.replace(task); } } } @@ -146,7 +145,6 @@ public void onError(Throwable t) { drainLoop(); } - disposeTimer(); downstream.onError(t); } @@ -157,7 +155,6 @@ public void onComplete() { drainLoop(); } - disposeTimer(); downstream.onComplete(); } @@ -171,15 +168,10 @@ public boolean isDisposed() { return cancelled; } - void disposeTimer() { - DisposableHelper.dispose(timer); - } - @Override public void run() { if (cancelled) { terminated = true; - disposeTimer(); } queue.offer(NEXT); if (enter()) { @@ -206,13 +198,13 @@ void drainLoop() { if (d && (o == null || o == NEXT)) { window = null; q.clear(); - disposeTimer(); Throwable err = error; if (err != null) { w.onError(err); } else { w.onComplete(); } + timer.dispose(); return; } @@ -266,7 +258,7 @@ static final class WindowExactBoundedObserver volatile boolean terminated; - final AtomicReference timer = new AtomicReference(); + final SequentialDisposable timer = new SequentialDisposable(); WindowExactBoundedObserver( Observer> actual, @@ -312,7 +304,7 @@ public void onSubscribe(Disposable d) { task = scheduler.schedulePeriodicallyDirect(consumerIndexHolder, timespan, timespan, unit); } - DisposableHelper.replace(timer, task); + timer.replace(task); } } @@ -370,7 +362,6 @@ public void onError(Throwable t) { } downstream.onError(t); - disposeTimer(); } @Override @@ -381,7 +372,6 @@ public void onComplete() { } downstream.onComplete(); - disposeTimer(); } @Override @@ -428,13 +418,13 @@ void drainLoop() { if (d && (empty || isHolder)) { window = null; q.clear(); - disposeTimer(); Throwable err = error; if (err != null) { w.onError(err); } else { w.onComplete(); } + disposeTimer(); return; } @@ -507,7 +497,6 @@ public void run() { p.queue.offer(this); } else { p.terminated = true; - p.disposeTimer(); } if (p.enter()) { p.drainLoop(); @@ -592,7 +581,6 @@ public void onError(Throwable t) { } downstream.onError(t); - disposeWorker(); } @Override @@ -603,7 +591,6 @@ public void onComplete() { } downstream.onComplete(); - disposeWorker(); } @Override @@ -616,10 +603,6 @@ public boolean isDisposed() { return cancelled; } - void disposeWorker() { - worker.dispose(); - } - void complete(UnicastSubject w) { queue.offer(new SubjectWork(w, false)); if (enter()) { @@ -640,9 +623,9 @@ void drainLoop() { for (;;) { if (terminated) { upstream.dispose(); - disposeWorker(); q.clear(); ws.clear(); + worker.dispose(); return; } @@ -665,8 +648,8 @@ void drainLoop() { w.onComplete(); } } - disposeWorker(); ws.clear(); + worker.dispose(); return; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java index 37d8928571..56e1a736e6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java @@ -16,7 +16,7 @@ import static org.junit.Assert.*; import java.util.*; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.*; import org.junit.*; @@ -918,5 +918,244 @@ public void nextWindowMissingBackpressureDrainOnTime() { .assertError(MissingBackpressureException.class) .assertNotComplete(); } -} + @Test + public void exactTimeBoundNoInterruptWindowOutputOnComplete() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishProcessor pp = PublishProcessor.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + pp.window(100, TimeUnit.MILLISECONDS) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Flowable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + pp.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + pp.onComplete(); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void exactTimeBoundNoInterruptWindowOutputOnError() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishProcessor pp = PublishProcessor.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + pp.window(100, TimeUnit.MILLISECONDS) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Flowable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + pp.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + pp.onError(new TestException()); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void exactTimeAndSizeBoundNoInterruptWindowOutputOnComplete() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishProcessor pp = PublishProcessor.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + pp.window(100, TimeUnit.MILLISECONDS, 10) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Flowable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + pp.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + pp.onComplete(); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void exactTimeAndSizeBoundNoInterruptWindowOutputOnError() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishProcessor pp = PublishProcessor.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + pp.window(100, TimeUnit.MILLISECONDS, 10) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Flowable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + pp.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + pp.onError(new TestException()); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void skipTimeAndSizeBoundNoInterruptWindowOutputOnComplete() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishProcessor pp = PublishProcessor.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + pp.window(90, 100, TimeUnit.MILLISECONDS) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Flowable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + pp.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + pp.onComplete(); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void skipTimeAndSizeBoundNoInterruptWindowOutputOnError() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishProcessor pp = PublishProcessor.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + pp.window(90, 100, TimeUnit.MILLISECONDS) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Flowable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + pp.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + pp.onError(new TestException()); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } +} diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java index fbd90088ed..8500d52948 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java @@ -16,8 +16,8 @@ import static org.junit.Assert.*; import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; import org.junit.*; @@ -708,4 +708,244 @@ public void countRestartsOnTimeTick() { .assertNoErrors() .assertNotComplete(); } + + @Test + public void exactTimeBoundNoInterruptWindowOutputOnComplete() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishSubject ps = PublishSubject.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + ps.window(100, TimeUnit.MILLISECONDS) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Observable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + ps.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + ps.onComplete(); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void exactTimeBoundNoInterruptWindowOutputOnError() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishSubject ps = PublishSubject.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + ps.window(100, TimeUnit.MILLISECONDS) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Observable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + ps.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + ps.onError(new TestException()); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void exactTimeAndSizeBoundNoInterruptWindowOutputOnComplete() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishSubject ps = PublishSubject.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + ps.window(100, TimeUnit.MILLISECONDS, 10) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Observable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + ps.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + ps.onComplete(); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void exactTimeAndSizeBoundNoInterruptWindowOutputOnError() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishSubject ps = PublishSubject.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + ps.window(100, TimeUnit.MILLISECONDS, 10) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Observable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + ps.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + ps.onError(new TestException()); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void skipTimeAndSizeBoundNoInterruptWindowOutputOnComplete() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishSubject ps = PublishSubject.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + ps.window(90, 100, TimeUnit.MILLISECONDS) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Observable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + ps.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + ps.onComplete(); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } + + @Test + public void skipTimeAndSizeBoundNoInterruptWindowOutputOnError() throws Exception { + final AtomicBoolean isInterrupted = new AtomicBoolean(); + + final PublishSubject ps = PublishSubject.create(); + + final CountDownLatch doOnNextDone = new CountDownLatch(1); + final CountDownLatch secondWindowProcessing = new CountDownLatch(1); + + ps.window(90, 100, TimeUnit.MILLISECONDS) + .doOnNext(new Consumer>() { + int count; + @Override + public void accept(Observable v) throws Exception { + System.out.println(Thread.currentThread()); + if (count++ == 1) { + secondWindowProcessing.countDown(); + try { + Thread.sleep(200); + isInterrupted.set(Thread.interrupted()); + } catch (InterruptedException ex) { + isInterrupted.set(true); + } + doOnNextDone.countDown(); + } + } + }) + .test(); + + ps.onNext(1); + + assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS)); + + ps.onError(new TestException()); + + assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS)); + + assertFalse("The doOnNext got interrupted!", isInterrupted.get()); + } } From d0a59e13daabfb227a290d2253b2fcf27e2bb246 Mon Sep 17 00:00:00 2001 From: Seungmin Date: Fri, 1 Nov 2019 14:40:20 -0700 Subject: [PATCH 185/211] Update Backpressure.md (#6685) Fixes Backpressure.md on https://github.com/ReactiveX/RxJava/issues/6132 Fix Images on Backpressure.md crashed on wrong address. Put full address of images. --- docs/Backpressure.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/Backpressure.md b/docs/Backpressure.md index d9e7bfa65a..8feec0d487 100644 --- a/docs/Backpressure.md +++ b/docs/Backpressure.md @@ -20,7 +20,7 @@ Cold Observables are ideal for the reactive pull model of backpressure described Your first line of defense against the problems of over-producing Observables is to use some of the ordinary set of Observable operators to reduce the number of emitted items to a more manageable number. The examples in this section will show how you might use such operators to handle a bursty Observable like the one illustrated in the following marble diagram: -​ +​ By fine-tuning the parameters to these operators you can ensure that a slow-consuming observer is not overwhelmed by a fast-producing Observable. @@ -33,7 +33,7 @@ The following diagrams show how you could use each of these operators on the bur ### sample (or throttleLast) The `sample` operator periodically "dips" into the sequence and emits only the most recently emitted item during each dip: -​ +​ ````groovy Observable burstySampled = bursty.sample(500, TimeUnit.MILLISECONDS); ```` @@ -41,7 +41,7 @@ Observable burstySampled = bursty.sample(500, TimeUnit.MILLISECONDS); ### throttleFirst The `throttleFirst` operator is similar, but emits not the most recently emitted item, but the first item that was emitted after the previous "dip": -​ +​ ````groovy Observable burstyThrottled = bursty.throttleFirst(500, TimeUnit.MILLISECONDS); ```` @@ -49,7 +49,7 @@ Observable burstyThrottled = bursty.throttleFirst(500, TimeUnit.MILLISE ### debounce (or throttleWithTimeout) The `debounce` operator emits only those items from the source Observable that are not followed by another item within a specified duration: -​ +​ ````groovy Observable burstyDebounced = bursty.debounce(10, TimeUnit.MILLISECONDS); ```` @@ -64,14 +64,14 @@ The following diagrams show how you could use each of these operators on the bur You could, for example, close and emit a buffer of items from the bursty Observable periodically, at a regular interval of time: -​ +​ ````groovy Observable> burstyBuffered = bursty.buffer(500, TimeUnit.MILLISECONDS); ```` Or you could get fancy, and collect items in buffers during the bursty periods and emit them at the end of each burst, by using the `debounce` operator to emit a buffer closing indicator to the `buffer` operator: -​ +​ ````groovy // we have to multicast the original bursty Observable so we can use it // both as our source and as the source for our buffer closing selector: @@ -86,14 +86,14 @@ Observable> burstyBuffered = burstyMulticast.buffer(burstyDebounce `window` is similar to `buffer`. One variant of `window` allows you to periodically emit Observable windows of items at a regular interval of time: -​ +​ ````groovy Observable> burstyWindowed = bursty.window(500, TimeUnit.MILLISECONDS); ```` You could also choose to emit a new window each time you have collected a particular number of items from the source Observable: -​ +​ ````groovy Observable> burstyWindowed = bursty.window(5); ```` @@ -158,11 +158,11 @@ For this to work, though, Observables _A_ and _B_ must respond correctly to the
          onBackpressureBuffer
          -
          maintains a buffer of all emissions from the source Observable and emits them to downstream Subscribers according to the requests they generate

          an experimental version of this operator (not available in RxJava 1.0) allows you to set the capacity of the buffer; applying this operator will cause the resulting Observable to terminate with an error if this buffer is overrun​
          +
          maintains a buffer of all emissions from the source Observable and emits them to downstream Subscribers according to the requests they generate

          an experimental version of this operator (not available in RxJava 1.0) allows you to set the capacity of the buffer; applying this operator will cause the resulting Observable to terminate with an error if this buffer is overrun​
          onBackpressureDrop
          -
          drops emissions from the source Observable unless there is a pending request from a downstream Subscriber, in which case it will emit enough items to fulfill the request
          +
          drops emissions from the source Observable unless there is a pending request from a downstream Subscriber, in which case it will emit enough items to fulfill the request
          onBackpressureBlock (experimental, not in RxJava 1.0)
          -
          blocks the thread on which the source Observable is operating until such time as a Subscriber issues a request for items, and then unblocks the thread only so long as there are pending requests
          +
          blocks the thread on which the source Observable is operating until such time as a Subscriber issues a request for items, and then unblocks the thread only so long as there are pending requests
          If you do not apply any of these operators to an Observable that does not support backpressure, _and_ if either you as the Subscriber or some operator between you and the Observable attempts to apply reactive pull backpressure, you will encounter a `MissingBackpressureException` which you will be notified of via your `onError()` callback. @@ -172,4 +172,4 @@ If you do not apply any of these operators to an Observable that does not suppor If the standard operators are providing the expected behavior, [one can write custom operators in RxJava](https://github.com/ReactiveX/RxJava/wiki/Implementing-custom-operators-(draft)). # See also -* [RxJava 0.20.0-RC1 release notes](https://github.com/ReactiveX/RxJava/releases/tag/0.20.0-RC1) \ No newline at end of file +* [RxJava 0.20.0-RC1 release notes](https://github.com/ReactiveX/RxJava/releases/tag/0.20.0-RC1) From 5f01b089340623369ec7c5c556695f7e75518d56 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sat, 2 Nov 2019 15:05:42 +0100 Subject: [PATCH 186/211] Release 2.2.14 --- CHANGES.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index af5f1d3074..5e6bac5bc0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,17 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.14 - November 2, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.14%7C)) + +#### Bugfixes + + - [Pull 6677](https://github.com/ReactiveX/RxJava/pull/6677): Fix concurrent `clear()` calls when fused chains are canceled. + - [Pull 6684](https://github.com/ReactiveX/RxJava/pull/6684): Fix `window(time)` possible interrupts while terminating. + +#### Documentation changes + + - [Pull 6681](https://github.com/ReactiveX/RxJava/pull/6681): Backport marble diagrams for `Single` from 3.x. + ### Version 2.2.13 - October 3, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.13%7C)) #### Dependencies From ca0f2d7467e7d89b94e1688ae770d7dc745d17b1 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 7 Nov 2019 22:13:03 +0100 Subject: [PATCH 187/211] 2.x: Add ProGuard rule to avoid j.u.c.Flow warnings due to RS 1.0.3 (#6704) --- src/main/resources/META-INF/proguard/rxjava2.pro | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/resources/META-INF/proguard/rxjava2.pro diff --git a/src/main/resources/META-INF/proguard/rxjava2.pro b/src/main/resources/META-INF/proguard/rxjava2.pro new file mode 100644 index 0000000000..aafc7262f1 --- /dev/null +++ b/src/main/resources/META-INF/proguard/rxjava2.pro @@ -0,0 +1 @@ +-dontwarn java.util.concurrent.Flow \ No newline at end of file From 3cb610f498be27770c45a8ce2964bb9f813c7b05 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 8 Nov 2019 07:27:52 +0100 Subject: [PATCH 188/211] 2.x: ProGuard R8 dont warn Flow* classes (#6705) --- src/main/resources/META-INF/proguard/rxjava2.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/META-INF/proguard/rxjava2.pro b/src/main/resources/META-INF/proguard/rxjava2.pro index aafc7262f1..d51378e562 100644 --- a/src/main/resources/META-INF/proguard/rxjava2.pro +++ b/src/main/resources/META-INF/proguard/rxjava2.pro @@ -1 +1 @@ --dontwarn java.util.concurrent.Flow \ No newline at end of file +-dontwarn java.util.concurrent.Flow* \ No newline at end of file From 52dee7dbcd03ff1f6b7fa3fbc1ebdd8663d9213b Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 12 Nov 2019 12:05:45 +0100 Subject: [PATCH 189/211] 2.x: Fix concurrent clear in observeOn while output-fused (#6710) --- .../operators/flowable/FlowableObserveOn.java | 2 +- .../observable/ObservableObserveOn.java | 2 +- .../flowable/FlowableObserveOnTest.java | 35 +++++++++++++++++++ .../observable/ObservableObserveOnTest.java | 35 ++++++++++++++++++- 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java index 2a7d499d1a..3431f3a50b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableObserveOn.java @@ -154,7 +154,7 @@ public final void cancel() { upstream.cancel(); worker.dispose(); - if (getAndIncrement() == 0) { + if (!outputFused && getAndIncrement() == 0) { queue.clear(); } } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java index abf1f0bb85..56de30041e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableObserveOn.java @@ -145,7 +145,7 @@ public void dispose() { disposed = true; upstream.dispose(); worker.dispose(); - if (getAndIncrement() == 0) { + if (!outputFused && getAndIncrement() == 0) { queue.clear(); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java index ba640c3e5a..a5abff03ef 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; @@ -34,6 +35,7 @@ import io.reactivex.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber; import io.reactivex.internal.schedulers.ImmediateThinScheduler; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; import io.reactivex.schedulers.*; @@ -1940,4 +1942,37 @@ public void workerNotDisposedPrematurelyNormalInAsyncOutConditional() { assertEquals(1, s.disposedCount.get()); } + + @Test + public void fusedNoConcurrentCleanDueToCancel() { + for (int j = 0; j < TestHelper.RACE_LONG_LOOPS; j++) { + List errors = TestHelper.trackPluginErrors(); + try { + final UnicastProcessor up = UnicastProcessor.create(); + + TestObserver to = up.hide() + .observeOn(Schedulers.io()) + .observeOn(Schedulers.single()) + .unsubscribeOn(Schedulers.computation()) + .firstOrError() + .test(); + + for (int i = 0; up.hasSubscribers() && i < 10000; i++) { + up.onNext(i); + } + + to + .awaitDone(5, TimeUnit.SECONDS) + ; + + if (!errors.isEmpty()) { + throw new CompositeException(errors); + } + + to.assertResult(0); + } finally { + RxJavaPlugins.reset(); + } + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java index a60328a899..48cbe91908 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; @@ -28,7 +29,7 @@ import io.reactivex.Observer; import io.reactivex.annotations.Nullable; import io.reactivex.disposables.*; -import io.reactivex.exceptions.TestException; +import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.fuseable.*; import io.reactivex.internal.operators.flowable.FlowableObserveOnTest.DisposeTrackingScheduler; @@ -813,4 +814,36 @@ public void workerNotDisposedPrematurelyNormalInAsyncOut() { assertEquals(1, s.disposedCount.get()); } + @Test + public void fusedNoConcurrentCleanDueToCancel() { + for (int j = 0; j < TestHelper.RACE_LONG_LOOPS; j++) { + List errors = TestHelper.trackPluginErrors(); + try { + final UnicastSubject us = UnicastSubject.create(); + + TestObserver to = us.hide() + .observeOn(Schedulers.io()) + .observeOn(Schedulers.single()) + .unsubscribeOn(Schedulers.computation()) + .firstOrError() + .test(); + + for (int i = 0; us.hasObservers() && i < 10000; i++) { + us.onNext(i); + } + + to + .awaitDone(5, TimeUnit.SECONDS) + ; + + if (!errors.isEmpty()) { + throw new CompositeException(errors); + } + + to.assertResult(0); + } finally { + RxJavaPlugins.reset(); + } + } + } } From aeb5f2c703a0126cf51ca4520e2c4a725cb1e752 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 15 Nov 2019 00:06:56 +0100 Subject: [PATCH 190/211] 2.x: Fix MulticastProcessor not requesting more after limit is reached (#6715) --- .../processors/MulticastProcessor.java | 1 + .../processors/MulticastProcessorTest.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/main/java/io/reactivex/processors/MulticastProcessor.java b/src/main/java/io/reactivex/processors/MulticastProcessor.java index 317244313f..31b7a64fea 100644 --- a/src/main/java/io/reactivex/processors/MulticastProcessor.java +++ b/src/main/java/io/reactivex/processors/MulticastProcessor.java @@ -569,6 +569,7 @@ void drain() { } } + consumed = c; missed = wip.addAndGet(-missed); if (missed == 0) { break; diff --git a/src/test/java/io/reactivex/processors/MulticastProcessorTest.java b/src/test/java/io/reactivex/processors/MulticastProcessorTest.java index 63a7b1a60b..d541dffb3e 100644 --- a/src/test/java/io/reactivex/processors/MulticastProcessorTest.java +++ b/src/test/java/io/reactivex/processors/MulticastProcessorTest.java @@ -783,4 +783,41 @@ public void noUpstream() { assertTrue(mp.hasSubscribers()); } + @Test + public void requestUpstreamPrefetchNonFused() { + for (int j = 1; j < 12; j++) { + MulticastProcessor mp = MulticastProcessor.create(j, true); + + TestSubscriber ts = mp.test(0).withTag("Prefetch: " + j); + + Flowable.range(1, 10).hide().subscribe(mp); + + ts.assertEmpty() + .requestMore(3) + .assertValuesOnly(1, 2, 3) + .requestMore(3) + .assertValuesOnly(1, 2, 3, 4, 5, 6) + .requestMore(4) + .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + } + } + + @Test + public void requestUpstreamPrefetchNonFused2() { + for (int j = 1; j < 12; j++) { + MulticastProcessor mp = MulticastProcessor.create(j, true); + + TestSubscriber ts = mp.test(0).withTag("Prefetch: " + j); + + Flowable.range(1, 10).hide().subscribe(mp); + + ts.assertEmpty() + .requestMore(2) + .assertValuesOnly(1, 2) + .requestMore(2) + .assertValuesOnly(1, 2, 3, 4) + .requestMore(6) + .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + } + } } From 170f9522a7d5e1c58f38b727d542bed954ee5617 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 21 Nov 2019 09:55:23 +0100 Subject: [PATCH 191/211] 2.x: Fix parallel() on grouped flowable not replenishing properly (#6720) --- .../operators/flowable/FlowableGroupBy.java | 20 +++++++++---- .../flowable/FlowableGroupByTest.java | 30 +++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java index 11ec41a0f2..8fd358c26e 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java @@ -709,17 +709,25 @@ public T poll() { produced++; return v; } - int p = produced; - if (p != 0) { - produced = 0; - parent.upstream.request(p); - } + tryReplenish(); return null; } @Override public boolean isEmpty() { - return queue.isEmpty(); + if (queue.isEmpty()) { + tryReplenish(); + return true; + } + return false; + } + + void tryReplenish() { + int p = produced; + if (p != 0) { + produced = 0; + parent.upstream.request(p); + } } @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java index 85501e2578..0db7abc639 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java @@ -2286,4 +2286,34 @@ public void run() { } } } + + @Test + public void fusedParallelGroupProcessing() { + Flowable.range(0, 500000) + .subscribeOn(Schedulers.single()) + .groupBy(new Function() { + @Override + public Integer apply(Integer i) { + return i % 2; + } + }) + .flatMap(new Function, Publisher>() { + @Override + public Publisher apply(GroupedFlowable g) { + return g.getKey() == 0 + ? g + .parallel() + .runOn(Schedulers.computation()) + .map(Functions.identity()) + .sequential() + : g.map(Functions.identity()) // no need to use hide + ; + } + }) + .test() + .awaitDone(20, TimeUnit.SECONDS) + .assertValueCount(500000) + .assertComplete() + .assertNoErrors(); + } } From 5e1bc1780726419b765b983d693fa17fad7ef8a9 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 21 Nov 2019 09:55:39 +0100 Subject: [PATCH 192/211] 2.x: Update javadoc for observeOn to mention its eagerness (#6722) --- src/main/java/io/reactivex/Flowable.java | 18 ++++++++++++++++++ src/main/java/io/reactivex/Observable.java | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 91333947e9..0490daf3c2 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -11590,6 +11590,11 @@ public final Flowable mergeWith(@NonNull CompletableSource other) { * asynchronous. If strict event ordering is required, consider using the {@link #observeOn(Scheduler, boolean)} overload. *

          * + *

          + * This operator keeps emitting as many signals as it can on the given Scheduler's Worker thread, + * which may result in a longer than expected occupation of this thread. In other terms, + * it does not allow per-signal fairness in case the worker runs on a shared underlying thread. + * If such fairness and signal/work interleaving is preferred, use the delay operator with zero time instead. *

          *
          Backpressure:
          *
          This operator honors backpressure from downstream and expects it from the source {@code Publisher}. Violating this @@ -11610,6 +11615,7 @@ public final Flowable mergeWith(@NonNull CompletableSource other) { * @see #subscribeOn * @see #observeOn(Scheduler, boolean) * @see #observeOn(Scheduler, boolean, int) + * @see #delay(long, TimeUnit, Scheduler) */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @@ -11623,6 +11629,11 @@ public final Flowable observeOn(Scheduler scheduler) { * asynchronously with a bounded buffer and optionally delays onError notifications. *

          * + *

          + * This operator keeps emitting as many signals as it can on the given Scheduler's Worker thread, + * which may result in a longer than expected occupation of this thread. In other terms, + * it does not allow per-signal fairness in case the worker runs on a shared underlying thread. + * If such fairness and signal/work interleaving is preferred, use the delay operator with zero time instead. *

          *
          Backpressure:
          *
          This operator honors backpressure from downstream and expects it from the source {@code Publisher}. Violating this @@ -11647,6 +11658,7 @@ public final Flowable observeOn(Scheduler scheduler) { * @see #subscribeOn * @see #observeOn(Scheduler) * @see #observeOn(Scheduler, boolean, int) + * @see #delay(long, TimeUnit, Scheduler, boolean) */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @@ -11660,6 +11672,11 @@ public final Flowable observeOn(Scheduler scheduler, boolean delayError) { * asynchronously with a bounded buffer of configurable size and optionally delays onError notifications. *

          * + *

          + * This operator keeps emitting as many signals as it can on the given Scheduler's Worker thread, + * which may result in a longer than expected occupation of this thread. In other terms, + * it does not allow per-signal fairness in case the worker runs on a shared underlying thread. + * If such fairness and signal/work interleaving is preferred, use the delay operator with zero time instead. *

          *
          Backpressure:
          *
          This operator honors backpressure from downstream and expects it from the source {@code Publisher}. Violating this @@ -11685,6 +11702,7 @@ public final Flowable observeOn(Scheduler scheduler, boolean delayError) { * @see #subscribeOn * @see #observeOn(Scheduler) * @see #observeOn(Scheduler, boolean) + * @see #delay(long, TimeUnit, Scheduler, boolean) */ @CheckReturnValue @NonNull diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index d2f11d2b5b..865b5563cc 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -9902,6 +9902,11 @@ public final Observable mergeWith(@NonNull CompletableSource other) { * asynchronous. If strict event ordering is required, consider using the {@link #observeOn(Scheduler, boolean)} overload. *

          * + *

          + * This operator keeps emitting as many signals as it can on the given Scheduler's Worker thread, + * which may result in a longer than expected occupation of this thread. In other terms, + * it does not allow per-signal fairness in case the worker runs on a shared underlying thread. + * If such fairness and signal/work interleaving is preferred, use the delay operator with zero time instead. *

          *
          Scheduler:
          *
          You specify which {@link Scheduler} this operator will use.
          @@ -9918,6 +9923,7 @@ public final Observable mergeWith(@NonNull CompletableSource other) { * @see #subscribeOn * @see #observeOn(Scheduler, boolean) * @see #observeOn(Scheduler, boolean, int) + * @see #delay(long, TimeUnit, Scheduler) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) @@ -9930,6 +9936,11 @@ public final Observable observeOn(Scheduler scheduler) { * asynchronously with an unbounded buffer with {@link Flowable#bufferSize()} "island size" and optionally delays onError notifications. *

          * + *

          + * This operator keeps emitting as many signals as it can on the given Scheduler's Worker thread, + * which may result in a longer than expected occupation of this thread. In other terms, + * it does not allow per-signal fairness in case the worker runs on a shared underlying thread. + * If such fairness and signal/work interleaving is preferred, use the delay operator with zero time instead. *

          *
          Scheduler:
          *
          You specify which {@link Scheduler} this operator will use.
          @@ -9950,6 +9961,7 @@ public final Observable observeOn(Scheduler scheduler) { * @see #subscribeOn * @see #observeOn(Scheduler) * @see #observeOn(Scheduler, boolean, int) + * @see #delay(long, TimeUnit, Scheduler, boolean) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) @@ -9962,6 +9974,11 @@ public final Observable observeOn(Scheduler scheduler, boolean delayError) { * asynchronously with an unbounded buffer of configurable "island size" and optionally delays onError notifications. *

          * + *

          + * This operator keeps emitting as many signals as it can on the given Scheduler's Worker thread, + * which may result in a longer than expected occupation of this thread. In other terms, + * it does not allow per-signal fairness in case the worker runs on a shared underlying thread. + * If such fairness and signal/work interleaving is preferred, use the delay operator with zero time instead. *

          *
          Scheduler:
          *
          You specify which {@link Scheduler} this operator will use.
          @@ -9983,6 +10000,7 @@ public final Observable observeOn(Scheduler scheduler, boolean delayError) { * @see #subscribeOn * @see #observeOn(Scheduler) * @see #observeOn(Scheduler, boolean) + * @see #delay(long, TimeUnit, Scheduler, boolean) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) From 56d6e91e310113a2f3a529993f3c51983a022a85 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sun, 24 Nov 2019 09:37:35 +0100 Subject: [PATCH 193/211] Release 2.2.15 --- CHANGES.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5e6bac5bc0..43d7a65dba 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,22 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.15 - November 24, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.15%7C)) + +#### Bugfixes + + - [Pull 6715](https://github.com/ReactiveX/RxJava/pull/6715): Fix `MulticastProcessor` not requesting more after limit is reached. + - [Pull 6710](https://github.com/ReactiveX/RxJava/pull/6710): Fix concurrent `clear` in `observeOn` while output-fused. + - [Pull 6720](https://github.com/ReactiveX/RxJava/pull/6720): Fix `parallel()` on grouped flowable not replenishing properly. + +#### Documentation changes + + - [Pull 6722](https://github.com/ReactiveX/RxJava/pull/6722): Update javadoc for `observeOn` to mention its eagerness. + +#### Other changes + + - [Pull 6704](https://github.com/ReactiveX/RxJava/pull/6704): Add ProGuard rule to avoid `j.u.c.Flow` warnings due to RS 1.0.3. + ### Version 2.2.14 - November 2, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.14%7C)) #### Bugfixes From 31b407f3d66a1c36dcadd37a85f89b68ec62ff16 Mon Sep 17 00:00:00 2001 From: Lugduni Desrosiers <36016544+ddunig2@users.noreply.github.com> Date: Fri, 6 Dec 2019 02:58:12 -0500 Subject: [PATCH 194/211] backporting #6729 to 2.x branch. (#6746) --- src/main/java/io/reactivex/Flowable.java | 10 +++++++--- src/main/java/io/reactivex/Observable.java | 11 ++++++++--- .../io/reactivex/disposables/ActionDisposable.java | 3 +++ .../flowable/BlockingFlowableMostRecent.java | 4 ---- .../observable/BlockingObservableMostRecent.java | 4 ---- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 0490daf3c2..41cde991a7 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -8266,7 +8266,6 @@ public final Single contains(final Object item) { * @return a Single that emits a single item: the number of items emitted by the source Publisher as a * 64-bit Long item * @see ReactiveX operators documentation: Count - * @see #count() */ @CheckReturnValue @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @@ -15121,6 +15120,7 @@ public final Flowable switchIfEmpty(Publisher other) { * Publisher * @return a Flowable that emits the items emitted by the Publisher returned from applying {@code func} to the most recently emitted item emitted by the source Publisher * @see ReactiveX operators documentation: FlatMap + * @see #switchMapDelayError(Function) */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @@ -15156,6 +15156,7 @@ public final Flowable switchMap(FunctionReactiveX operators documentation: FlatMap + * @see #switchMapDelayError(Function, int) */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @@ -15245,7 +15246,7 @@ public final Completable switchMapCompletable(@NonNull FunctionReactiveX operators documentation: FlatMap + * @see #switchMap(Function) * @since 2.0 */ @CheckReturnValue @@ -15320,6 +15322,7 @@ public final Flowable switchMapDelayError(FunctionReactiveX operators documentation: FlatMap + * @see #switchMap(Function, int) * @since 2.0 */ @CheckReturnValue @@ -15373,6 +15376,7 @@ Flowable switchMap0(Function> * and get subscribed to. * @return the new Flowable instance * @see #switchMapMaybe(Function) + * @see #switchMapMaybeDelayError(Function) * @since 2.2 */ @CheckReturnValue @@ -15444,7 +15448,7 @@ public final Flowable switchMapMaybeDelayError(@NonNull Function contains(final Object element) { * @return a Single that emits a single item: the number of items emitted by the source ObservableSource as a * 64-bit Long item * @see ReactiveX operators documentation: Count - * @see #count() */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @@ -12405,6 +12404,7 @@ public final Observable switchIfEmpty(ObservableSource other) { * ObservableSource * @return an Observable that emits the items emitted by the ObservableSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource * @see ReactiveX operators documentation: FlatMap + * @see #switchMapDelayError(Function) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @@ -12434,6 +12434,7 @@ public final Observable switchMap(FunctionReactiveX operators documentation: FlatMap + * @see #switchMapDelayError(Function, int) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @@ -12524,7 +12525,7 @@ public final Completable switchMapCompletable(@NonNull Function Observable switchMapMaybeDelayError(@NonNull FunctionReactiveX operators documentation: FlatMap + * @see #switchMapSingleDelayError(Function) * @since 2.2 */ @CheckReturnValue @@ -12647,6 +12649,7 @@ public final Observable switchMapSingle(@NonNull FunctionReactiveX operators documentation: FlatMap + * @see #switchMapSingle(Function) * @since 2.2 */ @CheckReturnValue @@ -12678,6 +12681,7 @@ public final Observable switchMapSingleDelayError(@NonNull FunctionReactiveX operators documentation: FlatMap + * @see #switchMap(Function) * @since 2.0 */ @CheckReturnValue @@ -12709,6 +12713,7 @@ public final Observable switchMapDelayError(FunctionReactiveX operators documentation: FlatMap + * @see #switchMap(Function, int) * @since 2.0 */ @CheckReturnValue diff --git a/src/main/java/io/reactivex/disposables/ActionDisposable.java b/src/main/java/io/reactivex/disposables/ActionDisposable.java index 447dfe2e34..f553f8b58e 100644 --- a/src/main/java/io/reactivex/disposables/ActionDisposable.java +++ b/src/main/java/io/reactivex/disposables/ActionDisposable.java @@ -16,6 +16,9 @@ import io.reactivex.functions.Action; import io.reactivex.internal.util.ExceptionHelper; +/** + * A Disposable container that manages an Action instance. + */ final class ActionDisposable extends ReferenceDisposable { private static final long serialVersionUID = -8219729196779211169L; diff --git a/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecent.java b/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecent.java index 298a3f21be..235d8507dc 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecent.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecent.java @@ -42,10 +42,6 @@ public BlockingFlowableMostRecent(Flowable source, T initialValue) { public Iterator iterator() { MostRecentSubscriber mostRecentSubscriber = new MostRecentSubscriber(initialValue); - /** - * Subscribe instead of unsafeSubscribe since this is the final subscribe in the chain - * since it is for BlockingObservable. - */ source.subscribe(mostRecentSubscriber); return mostRecentSubscriber.getIterable(); diff --git a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecent.java b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecent.java index 90a603f65c..04940be5e6 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecent.java +++ b/src/main/java/io/reactivex/internal/operators/observable/BlockingObservableMostRecent.java @@ -42,10 +42,6 @@ public BlockingObservableMostRecent(ObservableSource source, T initialValue) public Iterator iterator() { MostRecentObserver mostRecentObserver = new MostRecentObserver(initialValue); - /** - * Subscribe instead of unsafeSubscribe since this is the final subscribe in the chain - * since it is for BlockingObservable. - */ source.subscribe(mostRecentObserver); return mostRecentObserver.getIterable(); From 52346a140c29b659023f87e348c26889b6b39b13 Mon Sep 17 00:00:00 2001 From: Mark Sholte Date: Wed, 11 Dec 2019 02:20:42 -0600 Subject: [PATCH 195/211] 2.x: Zip, CombineLatest, and Amb operators throw when supplied with ObservableSource implementation that doesn't subclass Observable (#6754) * 2.x: Zip, CombineLatest, and Amb operators throw when supplied with ObservableSource implementation that doesn't subclass Observable #6753 * 2.x: add tests for allowing arbitrary ObservableSource implementations --- .../operators/observable/ObservableAmb.java | 2 +- .../observable/ObservableCombineLatest.java | 2 +- .../operators/observable/ObservableZip.java | 2 +- .../observable/ObservableAmbTest.java | 17 +++++++++++ .../ObservableCombineLatestTest.java | 29 +++++++++++++++++++ .../observable/ObservableZipTest.java | 29 +++++++++++++++++++ 6 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java index 2ed4fcd93b..53068e7a91 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableAmb.java @@ -36,7 +36,7 @@ public void subscribeActual(Observer observer) { ObservableSource[] sources = this.sources; int count = 0; if (sources == null) { - sources = new Observable[8]; + sources = new ObservableSource[8]; try { for (ObservableSource p : sourcesIterable) { if (p == null) { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java index ccbfc8e6d3..56b62cdfeb 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java @@ -49,7 +49,7 @@ public void subscribeActual(Observer observer) { ObservableSource[] sources = this.sources; int count = 0; if (sources == null) { - sources = new Observable[8]; + sources = new ObservableSource[8]; for (ObservableSource p : sourcesIterable) { if (count == sources.length) { ObservableSource[] b = new ObservableSource[count + (count >> 2)]; diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java index af465c43c6..7f00383834 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java @@ -50,7 +50,7 @@ public void subscribeActual(Observer observer) { ObservableSource[] sources = this.sources; int count = 0; if (sources == null) { - sources = new Observable[8]; + sources = new ObservableSource[8]; for (ObservableSource p : sourcesIterable) { if (count == sources.length) { ObservableSource[] b = new ObservableSource[count + (count >> 2)]; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java index 6e2c737f75..a76b8f22e6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java @@ -264,6 +264,23 @@ public void singleIterable() { .assertResult(1); } + /** + * Ensures that an ObservableSource implementation can be supplied that doesn't subclass Observable + */ + @Test + public void singleIterableNotSubclassingObservable() { + final ObservableSource s1 = new ObservableSource() { + @Override + public void subscribe (final Observer observer) { + Observable.just(1).subscribe(observer); + } + }; + + Observable.amb(Collections.singletonList(s1)) + .test() + .assertResult(1); + } + @SuppressWarnings("unchecked") @Test public void disposed() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java index 418a19678e..736a0bd9b5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java @@ -787,6 +787,34 @@ public Object apply(Object[] a) throws Exception { .assertResult("[1, 2]"); } + /** + * Ensures that an ObservableSource implementation can be supplied that doesn't subclass Observable + */ + @Test + public void combineLatestIterableOfSourcesNotSubclassingObservable() { + final ObservableSource s1 = new ObservableSource() { + @Override + public void subscribe (final Observer observer) { + Observable.just(1).subscribe(observer); + } + }; + final ObservableSource s2 = new ObservableSource() { + @Override + public void subscribe (final Observer observer) { + Observable.just(2).subscribe(observer); + } + }; + + Observable.combineLatest(Arrays.asList(s1, s2), new Function() { + @Override + public Object apply(Object[] a) throws Exception { + return Arrays.toString(a); + } + }) + .test() + .assertResult("[1, 2]"); + } + @Test @SuppressWarnings("unchecked") public void combineLatestDelayErrorArrayOfSources() { @@ -1216,4 +1244,5 @@ public Object apply(Object[] a) throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class, 42); } + } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java index 14fda0058d..eca18c71b3 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java @@ -1350,6 +1350,34 @@ public Object apply(Object[] a) throws Exception { .assertResult("[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]"); } + /** + * Ensures that an ObservableSource implementation can be supplied that doesn't subclass Observable + */ + @Test + public void zipIterableNotSubclassingObservable() { + final ObservableSource s1 = new ObservableSource() { + @Override + public void subscribe (final Observer observer) { + Observable.just(1).subscribe(observer); + } + }; + final ObservableSource s2 = new ObservableSource() { + @Override + public void subscribe (final Observer observer) { + Observable.just(2).subscribe(observer); + } + }; + + Observable.zip(Arrays.asList(s1, s2), new Function() { + @Override + public Object apply(Object[] a) throws Exception { + return Arrays.toString(a); + } + }) + .test() + .assertResult("[1, 2]"); + } + @Test public void dispose() { TestHelper.checkDisposed(Observable.zip(Observable.just(1), Observable.just(1), new BiFunction() { @@ -1457,4 +1485,5 @@ public Object apply(Object[] a) throws Exception { assertEquals(0, counter.get()); } + } From ea2c79654accfdfaef580389a12086a1dfacc3eb Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sun, 15 Dec 2019 08:15:28 +0100 Subject: [PATCH 196/211] Release 2.2.16 --- CHANGES.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 43d7a65dba..c37f51f161 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,16 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.16 - December 15, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.16%7C)) + +#### Bugfixes + + - [Pull 6754](https://github.com/ReactiveX/RxJava/pull/6754): Fix `amb`, `combineLatest` and `zip` `Iterable` overloads throwing `ArrayStoreException` for `ObservableSource`s. + +#### Documentation changes + + - [Pull 6746](https://github.com/ReactiveX/RxJava/pull/6746): Fix self-see references, some comments. + ### Version 2.2.15 - November 24, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.15%7C)) #### Bugfixes From 0b3b300425c3ae471ad5136a2bbeb9bd50f58849 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Thu, 9 Jan 2020 08:57:22 +0100 Subject: [PATCH 197/211] 2.x: Fix Flowable.flatMap not canceling the inner sources on outer error (#6827) --- .../operators/flowable/FlowableFlatMap.java | 5 +++ .../flowable/FlowableFlatMapTest.java | 34 +++++++++++++++++++ .../observable/ObservableFlatMapTest.java | 34 +++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java index c68e82bb93..a7631de8b8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableFlatMap.java @@ -322,6 +322,11 @@ public void onError(Throwable t) { } if (errs.addThrowable(t)) { done = true; + if (!delayErrors) { + for (InnerSubscriber a : subscribers.getAndSet(CANCELLED)) { + a.dispose(); + } + } drain(); } else { RxJavaPlugins.onError(t); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java index 953a5f44dc..d121eea54e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java @@ -1123,4 +1123,38 @@ public void accept(Integer v) throws Exception { assertFalse(pp3.hasSubscribers()); assertFalse(pp4.hasSubscribers()); } + + @Test + public void mainErrorsInnerCancelled() { + PublishProcessor pp1 = PublishProcessor.create(); + PublishProcessor pp2 = PublishProcessor.create(); + + pp1 + .flatMap(Functions.justFunction(pp2)) + .test(); + + pp1.onNext(1); + assertTrue("No subscribers?", pp2.hasSubscribers()); + + pp1.onError(new TestException()); + + assertFalse("Has subscribers?", pp2.hasSubscribers()); + } + + @Test + public void innerErrorsMainCancelled() { + PublishProcessor pp1 = PublishProcessor.create(); + PublishProcessor pp2 = PublishProcessor.create(); + + pp1 + .flatMap(Functions.justFunction(pp2)) + .test(); + + pp1.onNext(1); + assertTrue("No subscribers?", pp2.hasSubscribers()); + + pp2.onError(new TestException()); + + assertFalse("Has subscribers?", pp1.hasSubscribers()); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index b4da14e9a1..5e0fa7cf8a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -1084,4 +1084,38 @@ public void accept(Integer v) throws Exception { assertFalse(ps3.hasObservers()); assertFalse(ps4.hasObservers()); } + + @Test + public void mainErrorsInnerCancelled() { + PublishSubject ps1 = PublishSubject.create(); + PublishSubject ps2 = PublishSubject.create(); + + ps1 + .flatMap(Functions.justFunction(ps2)) + .test(); + + ps1.onNext(1); + assertTrue("No subscribers?", ps2.hasObservers()); + + ps1.onError(new TestException()); + + assertFalse("Has subscribers?", ps2.hasObservers()); + } + + @Test + public void innerErrorsMainCancelled() { + PublishSubject ps1 = PublishSubject.create(); + PublishSubject ps2 = PublishSubject.create(); + + ps1 + .flatMap(Functions.justFunction(ps2)) + .test(); + + ps1.onNext(1); + assertTrue("No subscribers?", ps2.hasObservers()); + + ps2.onError(new TestException()); + + assertFalse("Has subscribers?", ps1.hasObservers()); + } } From 030528bcd1c7202c7c20b7f4a7f7ee102833540e Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sun, 12 Jan 2020 16:50:06 +0100 Subject: [PATCH 198/211] Release 2.2.17 --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c37f51f161..9af1b4f879 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,12 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.17 - January 12, 2020 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.17%7C)) + +#### Bugfixes + + - [Pull 6827](https://github.com/ReactiveX/RxJava/pull/6827): Fix `Flowable.flatMap` not canceling the inner sources on outer error. + ### Version 2.2.16 - December 15, 2019 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.16%7C)) #### Bugfixes From e7538584a4a066241bc64480a96ff9066b0a1b17 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 29 Jan 2020 11:57:11 +0100 Subject: [PATCH 199/211] 2.x: Fig groupBy not requesting more if a group is cancelled with buffered items (#6894) --- .../operators/flowable/FlowableGroupBy.java | 23 +++++++--- .../flowable/FlowableGroupByTest.java | 46 ++++++++++++++++--- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java index 8fd358c26e..99a63c7b91 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java @@ -518,6 +518,7 @@ public void request(long n) { public void cancel() { if (cancelled.compareAndSet(false, true)) { parent.cancel(key); + drain(); } } @@ -568,7 +569,6 @@ void drainFused() { for (;;) { if (a != null) { if (cancelled.get()) { - q.clear(); return; } @@ -623,7 +623,7 @@ void drainNormal() { T v = q.poll(); boolean empty = v == null; - if (checkTerminated(d, empty, a, delayError)) { + if (checkTerminated(d, empty, a, delayError, e)) { return; } @@ -636,7 +636,7 @@ void drainNormal() { e++; } - if (e == r && checkTerminated(done, q.isEmpty(), a, delayError)) { + if (e == r && checkTerminated(done, q.isEmpty(), a, delayError, e)) { return; } @@ -658,9 +658,15 @@ void drainNormal() { } } - boolean checkTerminated(boolean d, boolean empty, Subscriber a, boolean delayError) { + boolean checkTerminated(boolean d, boolean empty, Subscriber a, boolean delayError, long emitted) { if (cancelled.get()) { - queue.clear(); + // make sure buffered items can get replenished + while (queue.poll() != null) { + emitted++; + } + if (emitted != 0) { + parent.upstream.request(emitted); + } return true; } @@ -732,7 +738,12 @@ void tryReplenish() { @Override public void clear() { - queue.clear(); + // make sure buffered items can get replenished + SpscLinkedArrayQueue q = queue; + while (q.poll() != null) { + produced++; + } + tryReplenish(); } } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java index 0db7abc639..cb52621bac 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java @@ -2215,20 +2215,20 @@ public void fusedNoConcurrentCleanDueToCancel() { try { final PublishProcessor pp = PublishProcessor.create(); - final AtomicReference>> qs = new AtomicReference>>(); + final AtomicReference>> qs = new AtomicReference>>(); final TestSubscriber ts2 = new TestSubscriber(); - pp.groupBy(Functions.identity(), Functions.identity(), false, 4) - .subscribe(new FlowableSubscriber>() { + pp.groupBy(Functions.identity(), Functions.identity(), false, 4) + .subscribe(new FlowableSubscriber>() { boolean once; @Override - public void onNext(GroupedFlowable g) { + public void onNext(GroupedFlowable g) { if (!once) { try { - GroupedFlowable t = qs.get().poll(); + GroupedFlowable t = qs.get().poll(); if (t != null) { once = true; t.subscribe(ts2); @@ -2250,7 +2250,7 @@ public void onComplete() { @Override public void onSubscribe(Subscription s) { @SuppressWarnings("unchecked") - QueueSubscription> q = (QueueSubscription>)s; + QueueSubscription> q = (QueueSubscription>)s; qs.set(q); q.requestFusion(QueueFuseable.ANY); q.request(1); @@ -2316,4 +2316,38 @@ public Publisher apply(GroupedFlowable g) { .assertComplete() .assertNoErrors(); } + + @Test + public void cancelledGroupResumesRequesting() { + final List> tss = new ArrayList>(); + final AtomicInteger counter = new AtomicInteger(); + final AtomicBoolean done = new AtomicBoolean(); + Flowable.range(1, 1000) + .doOnNext(new Consumer() { + @Override + public void accept(Integer v) throws Exception { + counter.getAndIncrement(); + } + }) + .groupBy(Functions.justFunction(1)) + .subscribe(new Consumer>() { + @Override + public void accept(GroupedFlowable v) throws Exception { + TestSubscriber ts = TestSubscriber.create(0L); + tss.add(ts); + v.subscribe(ts); + } + }, Functions.emptyConsumer(), new Action() { + @Override + public void run() throws Exception { + done.set(true); + } + }); + + while (!done.get()) { + tss.remove(0).cancel(); + } + + assertEquals(1000, counter.get()); + } } From 32653cc4079df726fb33cb9ff9674bd5997e4bc9 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 14 Feb 2020 15:12:13 +0100 Subject: [PATCH 200/211] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fd53e02083..21e4679a44 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ RxJava is a Java VM implementation of [Reactive Extensions](http://reactivex.io) It extends the [observer pattern](http://en.wikipedia.org/wiki/Observer_pattern) to support sequences of data/events and adds operators that allow you to compose sequences together declaratively while abstracting away concerns about things like low-level threading, synchronization, thread-safety and concurrent data structures. +:warning: The 2.x version is now in **maintenance mode** and will be supported only through bugfixes until **February 28, 2021**. No new features, behavior changes or documentation adjustments will be accepted or applied to 2.x. It is recommended to migrate to [3.x](https://github.com/ReactiveX/RxJava/tree/3.x) within this time period. + #### Version 2.x ([Javadoc](http://reactivex.io/RxJava/2.x/javadoc/)) - single dependency: [Reactive Streams](https://github.com/reactive-streams/reactive-streams-jvm) From e2b7816f2bcf89491cad68cb35a9e36368a29d97 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 21 Feb 2020 18:17:32 +0100 Subject: [PATCH 201/211] Release 2.2.18 --- CHANGES.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 9af1b4f879..9e5980180b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,14 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.18 - February 21, 2020 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.18%7C)) + +:warning: The 2.x version line is now in **maintenance mode** and will be supported only through bugfixes until **February 28, 2021**. No new features, behavior changes or documentation adjustments will be accepted or applied to 2.x. It is recommended to migrate to [3.x](https://github.com/ReactiveX/RxJava/tree/3.x) within this time period. + +#### Bugfixes + + - [Pull 6894](https://github.com/ReactiveX/RxJava/pull/6894): Fix `groupBy` not requesting more if a group is cancelled with buffered items. + ### Version 2.2.17 - January 12, 2020 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.17%7C)) #### Bugfixes From 7980c85b18dd46ec2cd2cf49477363f1268d3a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Karnok?= Date: Thu, 27 Feb 2020 20:47:36 +0100 Subject: [PATCH 202/211] 2.x: Fix switchMap not canceling properly during onNext-cancel races --- .../operators/flowable/FlowableSwitchMap.java | 1 - .../flowable/FlowableSwitchTest.java | 73 ++++++++++++++++++- .../observable/ObservableSwitchTest.java | 72 +++++++++++++++++- 3 files changed, 143 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java index 4d0bc47158..caf8c235c4 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableSwitchMap.java @@ -199,7 +199,6 @@ void drain() { for (;;) { if (cancelled) { - active.lazySet(null); return; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java index b4880d4ff6..794e43e273 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java @@ -14,11 +14,12 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.*; import org.junit.*; import org.mockito.InOrder; @@ -1229,4 +1230,74 @@ public Publisher apply(Integer v) .test() .assertResult(10, 20); } + + @Test + public void cancellationShouldTriggerInnerCancellationRace() throws Throwable { + final AtomicInteger outer = new AtomicInteger(); + final AtomicInteger inner = new AtomicInteger(); + + int n = 10000; + for (int i = 0; i < n; i++) { + Flowable.create(new FlowableOnSubscribe() { + @Override + public void subscribe(FlowableEmitter it) + throws Exception { + it.onNext(0); + } + }, BackpressureStrategy.MISSING) + .switchMap(new Function>() { + @Override + public Publisher apply(Integer v) + throws Exception { + return createFlowable(inner); + } + }) + .observeOn(Schedulers.computation()) + .doFinally(new Action() { + @Override + public void run() throws Exception { + outer.incrementAndGet(); + } + }) + .take(1) + .blockingSubscribe(Functions.emptyConsumer(), new Consumer() { + @Override + public void accept(Throwable e) throws Exception { + e.printStackTrace(); + } + }); + } + + Thread.sleep(100); + assertEquals(inner.get(), outer.get()); + assertEquals(n, inner.get()); + } + + Flowable createFlowable(final AtomicInteger inner) { + return Flowable.unsafeCreate(new Publisher() { + @Override + public void subscribe(Subscriber s) { + final SerializedSubscriber it = new SerializedSubscriber(s); + it.onSubscribe(new BooleanSubscription()); + Schedulers.io().scheduleDirect(new Runnable() { + @Override + public void run() { + it.onNext(1); + } + }, 0, TimeUnit.MILLISECONDS); + Schedulers.io().scheduleDirect(new Runnable() { + @Override + public void run() { + it.onNext(2); + } + }, 0, TimeUnit.MILLISECONDS); + } + }) + .doFinally(new Action() { + @Override + public void run() throws Exception { + inner.incrementAndGet(); + } + }); + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java index 100052f028..83b5a51270 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java @@ -33,7 +33,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.internal.schedulers.ImmediateThinScheduler; import io.reactivex.internal.util.ExceptionHelper; -import io.reactivex.observers.TestObserver; +import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; @@ -1222,4 +1222,74 @@ public Observable apply(Integer v) .test() .assertResult(10, 20); } + + @Test + public void cancellationShouldTriggerInnerCancellationRace() throws Throwable { + final AtomicInteger outer = new AtomicInteger(); + final AtomicInteger inner = new AtomicInteger(); + + int n = 10000; + for (int i = 0; i < n; i++) { + Observable.create(new ObservableOnSubscribe() { + @Override + public void subscribe(ObservableEmitter it) + throws Exception { + it.onNext(0); + } + }) + .switchMap(new Function>() { + @Override + public ObservableSource apply(Integer v) + throws Exception { + return createObservable(inner); + } + }) + .observeOn(Schedulers.computation()) + .doFinally(new Action() { + @Override + public void run() throws Exception { + outer.incrementAndGet(); + } + }) + .take(1) + .blockingSubscribe(Functions.emptyConsumer(), new Consumer() { + @Override + public void accept(Throwable e) throws Exception { + e.printStackTrace(); + } + }); + } + + Thread.sleep(100); + assertEquals(inner.get(), outer.get()); + assertEquals(n, inner.get()); + } + + Observable createObservable(final AtomicInteger inner) { + return Observable.unsafeCreate(new ObservableSource() { + @Override + public void subscribe(Observer observer) { + final SerializedObserver it = new SerializedObserver(observer); + it.onSubscribe(Disposables.empty()); + Schedulers.io().scheduleDirect(new Runnable() { + @Override + public void run() { + it.onNext(1); + } + }, 0, TimeUnit.MILLISECONDS); + Schedulers.io().scheduleDirect(new Runnable() { + @Override + public void run() { + it.onNext(2); + } + }, 0, TimeUnit.MILLISECONDS); + } + }) + .doFinally(new Action() { + @Override + public void run() throws Exception { + inner.incrementAndGet(); + } + }); + } } From 7ca43c7398810ee87c57f7f2165104822c0a4662 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Fri, 13 Mar 2020 09:01:13 +0100 Subject: [PATCH 203/211] Update CHANGES.md --- CHANGES.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 9e5980180b..6ac577fdb0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,16 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.19 - March 14, 2020 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.19%7C)) +[JavaDocs](http://reactivex.io/RxJava/2.x/javadoc/2.2.19) + +:warning: The 2.x version line is now in **maintenance mode** and will be supported only through bugfixes until **February 28, 2021**. No new features, behavior changes or documentation adjustments will be accepted or applied to 2.x. It is recommended to migrate to [3.x](https://github.com/ReactiveX/RxJava/tree/3.x) within this time period. + +#### Bugfixes + + - [Commit 7980c85b](https://github.com/ReactiveX/RxJava/commit/7980c85b18dd46ec2cd2cf49477363f1268d3a98): Fix `switchMap` not canceling properly during `onNext`-`cancel` races. + + ### Version 2.2.18 - February 21, 2020 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.18%7C)) :warning: The 2.x version line is now in **maintenance mode** and will be supported only through bugfixes until **February 28, 2021**. No new features, behavior changes or documentation adjustments will be accepted or applied to 2.x. It is recommended to migrate to [3.x](https://github.com/ReactiveX/RxJava/tree/3.x) within this time period. From 2cb20bd41efe70556ef7d346ee60f70e20548bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Juli=C3=A1n=20Garc=C3=ADa=20Granado?= Date: Wed, 15 Apr 2020 09:50:58 +0200 Subject: [PATCH 204/211] 2.x: Fix Observable.flatMap with maxConcurrency hangs (#6947) (#6960) --- .../observable/ObservableFlatMap.java | 39 +++++++++++++------ .../flowable/FlowableFlatMapTest.java | 23 +++++++++++ .../observable/ObservableFlatMapTest.java | 23 +++++++++++ 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java index a4766f389d..73a5306513 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableFlatMap.java @@ -334,6 +334,7 @@ void drainLoop() { if (checkTerminate()) { return; } + int innerCompleted = 0; SimplePlainQueue svq = queue; if (svq != null) { @@ -349,9 +350,18 @@ void drainLoop() { } child.onNext(o); + innerCompleted++; } } + if (innerCompleted != 0) { + if (maxConcurrency != Integer.MAX_VALUE) { + subscribeMore(innerCompleted); + innerCompleted = 0; + } + continue; + } + boolean d = done; svq = queue; InnerObserver[] inner = observers.get(); @@ -376,7 +386,6 @@ void drainLoop() { return; } - int innerCompleted = 0; if (n != 0) { long startId = lastId; int index = lastIndex; @@ -463,20 +472,12 @@ void drainLoop() { if (innerCompleted != 0) { if (maxConcurrency != Integer.MAX_VALUE) { - while (innerCompleted-- != 0) { - ObservableSource p; - synchronized (this) { - p = sources.poll(); - if (p == null) { - wip--; - continue; - } - } - subscribeInner(p); - } + subscribeMore(innerCompleted); + innerCompleted = 0; } continue; } + missed = addAndGet(-missed); if (missed == 0) { break; @@ -484,6 +485,20 @@ void drainLoop() { } } + void subscribeMore(int innerCompleted) { + while (innerCompleted-- != 0) { + ObservableSource p; + synchronized (this) { + p = sources.poll(); + if (p == null) { + wip--; + continue; + } + } + subscribeInner(p); + } + } + boolean checkTerminate() { if (cancelled) { return true; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java index d121eea54e..e232af7bd4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java @@ -1157,4 +1157,27 @@ public void innerErrorsMainCancelled() { assertFalse("Has subscribers?", pp1.hasSubscribers()); } + + @Test(timeout = 5000) + public void mixedScalarAsync() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + Flowable + .range(0, 20) + .flatMap(new Function>() { + @Override + public Publisher apply(Integer integer) throws Exception { + if (integer % 5 != 0) { + return Flowable + .just(integer); + } + + return Flowable + .just(-integer) + .observeOn(Schedulers.computation()); + } + }, false, 1) + .ignoreElements() + .blockingAwait(); + } + } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index 5e0fa7cf8a..61fbd21c7f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -1118,4 +1118,27 @@ public void innerErrorsMainCancelled() { assertFalse("Has subscribers?", ps1.hasObservers()); } + + @Test(timeout = 5000) + public void mixedScalarAsync() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + Observable + .range(0, 20) + .flatMap(new Function>() { + @Override + public ObservableSource apply(Integer integer) throws Exception { + if (integer % 5 != 0) { + return Observable + .just(integer); + } + + return Observable + .just(-integer) + .observeOn(Schedulers.computation()); + } + }, false, 1) + .ignoreElements() + .blockingAwait(); + } + } } From b13a45e161f37c927e99d8def5f156834a83befb Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 23 Sep 2020 09:22:50 +0200 Subject: [PATCH 205/211] 2.x: Fix toFlowable(ERROR) not cancelling upon MBE (#7084) --- .../flowable/FlowableOnBackpressureError.java | 1 + .../FlowableOnBackpressureErrorTest.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java index f60c43bc31..556e54b8c3 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureError.java @@ -65,6 +65,7 @@ public void onNext(T t) { downstream.onNext(t); BackpressureHelper.produced(this, 1); } else { + upstream.cancel(); onError(new MissingBackpressureException("could not emit value due to lack of requests")); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureErrorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureErrorTest.java index 3be409e862..9afb864d40 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureErrorTest.java @@ -13,11 +13,16 @@ package io.reactivex.internal.operators.flowable; +import static org.junit.Assert.*; + import org.junit.Test; import org.reactivestreams.Publisher; import io.reactivex.*; +import io.reactivex.exceptions.MissingBackpressureException; import io.reactivex.functions.Function; +import io.reactivex.subjects.PublishSubject; +import io.reactivex.subscribers.TestSubscriber; public class FlowableOnBackpressureErrorTest { @@ -50,4 +55,20 @@ public Object apply(Flowable f) throws Exception { } }, false, 1, 1, 1); } + + @Test + public void overflowCancels() { + PublishSubject ps = PublishSubject.create(); + + TestSubscriber ts = ps.toFlowable(BackpressureStrategy.ERROR) + .test(0L); + + assertTrue(ps.hasObservers()); + + ps.onNext(1); + + assertFalse(ps.hasObservers()); + + ts.assertFailure(MissingBackpressureException.class); + } } From 3d6403be8d9ada65016762a6bec417e268f482e3 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Mon, 5 Oct 2020 17:49:36 +0200 Subject: [PATCH 206/211] 2.x: Fix Flowable.concatMap backpressure w/ scalars (#7091) * 2.x: Fix Flowable.concatMap backpressure w/ scalars * Replace Java 8 constructs --- .../operators/flowable/FlowableConcatMap.java | 16 ++--- .../flowable/FlowableConcatMapTest.java | 68 ++++++++++++++++++- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java index f3dc0c58b8..64df7cc122 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java @@ -13,7 +13,7 @@ package io.reactivex.internal.operators.flowable; import java.util.concurrent.Callable; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.*; import org.reactivestreams.*; @@ -332,7 +332,7 @@ void drain() { continue; } else { active = true; - inner.setSubscription(new WeakScalarSubscription(vr, inner)); + inner.setSubscription(new SimpleScalarSubscription(vr, inner)); } } else { @@ -349,20 +349,20 @@ void drain() { } } - static final class WeakScalarSubscription implements Subscription { + static final class SimpleScalarSubscription + extends AtomicBoolean + implements Subscription { final Subscriber downstream; final T value; - boolean once; - WeakScalarSubscription(T value, Subscriber downstream) { + SimpleScalarSubscription(T value, Subscriber downstream) { this.value = value; this.downstream = downstream; } @Override public void request(long n) { - if (n > 0 && !once) { - once = true; + if (n > 0 && compareAndSet(false, true)) { Subscriber a = downstream; a.onNext(value); a.onComplete(); @@ -538,7 +538,7 @@ void drain() { continue; } else { active = true; - inner.setSubscription(new WeakScalarSubscription(vr, inner)); + inner.setSubscription(new SimpleScalarSubscription(vr, inner)); } } else { active = true; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java index d9fe79977f..8bd29121a0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java @@ -24,7 +24,9 @@ import io.reactivex.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; -import io.reactivex.internal.operators.flowable.FlowableConcatMap.WeakScalarSubscription; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.operators.flowable.FlowableConcatMap.SimpleScalarSubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; @@ -33,7 +35,7 @@ public class FlowableConcatMapTest { @Test public void weakSubscriptionRequest() { TestSubscriber ts = new TestSubscriber(0); - WeakScalarSubscription ws = new WeakScalarSubscription(1, ts); + SimpleScalarSubscription ws = new SimpleScalarSubscription(1, ts); ts.onSubscribe(ws); ws.request(0); @@ -105,6 +107,68 @@ public Publisher apply(String v) .assertResult("RxSingleScheduler"); } + @Test + public void innerScalarRequestRace() { + final Flowable just = Flowable.just(1); + final int n = 1000; + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishProcessor> source = PublishProcessor.create(); + + final TestSubscriber ts = source + .concatMap(Functions.>identity(), n + 1) + .test(1L); + + TestHelper.race(new Runnable() { + @Override + public void run() { + for (int j = 0; j < n; j++) { + source.onNext(just); + } + } + }, new Runnable() { + @Override + public void run() { + for (int j = 0; j < n; j++) { + ts.request(1); + } + } + }); + + ts.assertValueCount(n); + } + } + + @Test + public void innerScalarRequestRaceDelayError() { + final Flowable just = Flowable.just(1); + final int n = 1000; + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishProcessor> source = PublishProcessor.create(); + + final TestSubscriber ts = source + .concatMapDelayError(Functions.>identity(), n + 1, true) + .test(1L); + + TestHelper.race(new Runnable() { + @Override + public void run() { + for (int j = 0; j < n; j++) { + source.onNext(just); + } + } + }, new Runnable() { + @Override + public void run() { + for (int j = 0; j < n; j++) { + ts.request(1); + } + } + }); + + ts.assertValueCount(n); + } + } + @Test public void pollThrows() { Flowable.just(1) From 947b05fb9d44de2231aa148ef2eb3a6edc07fcfd Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 6 Oct 2020 09:07:35 +0200 Subject: [PATCH 207/211] Release 2.2.20 --- CHANGES.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6ac577fdb0..3321e0f855 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,17 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.20 - October 6, 2020 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.20%7C)) +[JavaDocs](http://reactivex.io/RxJava/2.x/javadoc/2.2.20) + +:warning: The 2.x version line is now in **maintenance mode** and will be supported only through bugfixes until **February 28, 2021**. No new features, behavior changes or documentation adjustments will be accepted or applied to 2.x. It is recommended to migrate to [3.x](https://github.com/ReactiveX/RxJava/tree/3.x) within this time period. + +#### Bugfixes + +- Fix `Observable.flatMap` with `maxConcurrency` hangs (#6960) +- Fix `Observable.toFlowable(ERROR)` not cancelling upon `MissingBackpressureException` (#7084) +- Fix `Flowable.concatMap` backpressure with scalars. (#7091) + ### Version 2.2.19 - March 14, 2020 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.19%7C)) [JavaDocs](http://reactivex.io/RxJava/2.x/javadoc/2.2.19) From f31aed36fd9d47edf0177164c54c64d4dc28c818 Mon Sep 17 00:00:00 2001 From: Sergio Garcia Date: Tue, 26 Jan 2021 06:47:29 +0000 Subject: [PATCH 208/211] Support for scheduled release of threads in Io Scheduler (#7162) --- .../internal/schedulers/IoScheduler.java | 22 +++++-- .../io/reactivex/schedulers/Schedulers.java | 19 ++++++ .../schedulers/IoScheduledReleaseTest.java | 58 +++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 src/test/java/io/reactivex/internal/schedulers/IoScheduledReleaseTest.java diff --git a/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java b/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java index d806321bf3..02cb44a1d3 100644 --- a/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/IoScheduler.java @@ -48,6 +48,10 @@ public final class IoScheduler extends Scheduler { /** The name of the system property for setting the thread priority for this Scheduler. */ private static final String KEY_IO_PRIORITY = "rx2.io-priority"; + /** The name of the system property for setting the release behaviour for this Scheduler. */ + private static final String KEY_SCHEDULED_RELEASE = "rx2.io-scheduled-release"; + static boolean USE_SCHEDULED_RELEASE; + static final CachedWorkerPool NONE; static { @@ -63,6 +67,8 @@ public final class IoScheduler extends Scheduler { EVICTOR_THREAD_FACTORY = new RxThreadFactory(EVICTOR_THREAD_NAME_PREFIX, priority); + USE_SCHEDULED_RELEASE = Boolean.getBoolean(KEY_SCHEDULED_RELEASE); + NONE = new CachedWorkerPool(0, null, WORKER_THREAD_FACTORY); NONE.shutdown(); } @@ -200,7 +206,7 @@ public int size() { return pool.get().allWorkers.size(); } - static final class EventLoopWorker extends Scheduler.Worker { + static final class EventLoopWorker extends Scheduler.Worker implements Runnable { private final CompositeDisposable tasks; private final CachedWorkerPool pool; private final ThreadWorker threadWorker; @@ -217,12 +223,20 @@ static final class EventLoopWorker extends Scheduler.Worker { public void dispose() { if (once.compareAndSet(false, true)) { tasks.dispose(); - - // releasing the pool should be the last action - pool.release(threadWorker); + if (USE_SCHEDULED_RELEASE) { + threadWorker.scheduleActual(this, 0, TimeUnit.NANOSECONDS, null); + } else { + // releasing the pool should be the last action + pool.release(threadWorker); + } } } + @Override + public void run() { + pool.release(threadWorker); + } + @Override public boolean isDisposed() { return once.get(); diff --git a/src/main/java/io/reactivex/schedulers/Schedulers.java b/src/main/java/io/reactivex/schedulers/Schedulers.java index 9e070690b8..dfd6bfe756 100644 --- a/src/main/java/io/reactivex/schedulers/Schedulers.java +++ b/src/main/java/io/reactivex/schedulers/Schedulers.java @@ -31,6 +31,8 @@ *
            *
          • {@code rx2.io-keep-alive-time} (long): sets the keep-alive time of the {@link #io()} Scheduler workers, default is {@link IoScheduler#KEEP_ALIVE_TIME_DEFAULT}
          • *
          • {@code rx2.io-priority} (int): sets the thread priority of the {@link #io()} Scheduler, default is {@link Thread#NORM_PRIORITY}
          • + *
          • {@code rx2.io-scheduled-release} (boolean): {@code true} sets the worker release mode of the + * {@link #io()} Scheduler to scheduled, default is {@code false} for eager mode.
          • *
          • {@code rx2.computation-threads} (int): sets the number of threads in the {@link #computation()} Scheduler, default is the number of available CPUs
          • *
          • {@code rx2.computation-priority} (int): sets the thread priority of the {@link #computation()} Scheduler, default is {@link Thread#NORM_PRIORITY}
          • *
          • {@code rx2.newthread-priority} (int): sets the thread priority of the {@link #newThread()} Scheduler, default is {@link Thread#NORM_PRIORITY}
          • @@ -113,6 +115,8 @@ private Schedulers() { *
              *
            • {@code rx2.computation-threads} (int): sets the number of threads in the {@link #computation()} Scheduler, default is the number of available CPUs
            • *
            • {@code rx2.computation-priority} (int): sets the thread priority of the {@link #computation()} Scheduler, default is {@link Thread#NORM_PRIORITY}
            • + *
            • {@code rx2.io-scheduled-release} (boolean): {@code true} sets the worker release mode of the + * {@code #io()} Scheduler to scheduled, default is {@code false} for eager mode.
            • *
            *

            * The default value of this scheduler can be overridden at initialization time via the @@ -129,6 +133,21 @@ private Schedulers() { *

            Operators on the base reactive classes that use this scheduler are marked with the * @{@link io.reactivex.annotations.SchedulerSupport SchedulerSupport}({@link io.reactivex.annotations.SchedulerSupport#COMPUTATION COMPUTATION}) * annotation. + *

            + * When the {@link Scheduler.Worker} is disposed, the underlying worker can be released to the cached worker pool in two modes: + *

              + *
            • In eager mode (default), the underlying worker is returned immediately to the cached worker pool + * and can be reused much quicker by operators. The drawback is that if the currently running task doesn't + * respond to interruption in time or at all, this may lead to delays or deadlock with the reuse use of the + * underlying worker. + *
            • + *
            • In scheduled mode (enabled via the system parameter {@code rx2.io-scheduled-release} + * set to {@code true}), the underlying worker is returned to the cached worker pool only after the currently running task + * has finished. This can help prevent premature reuse of the underlying worker and likely won't lead to delays or + * deadlock with such reuses. The drawback is that the delay in release may lead to an excess amount of underlying + * workers being created. + *
            • + *
            * @return a {@link Scheduler} meant for computation-bound work */ @NonNull diff --git a/src/test/java/io/reactivex/internal/schedulers/IoScheduledReleaseTest.java b/src/test/java/io/reactivex/internal/schedulers/IoScheduledReleaseTest.java new file mode 100644 index 0000000000..7eaaa377c0 --- /dev/null +++ b/src/test/java/io/reactivex/internal/schedulers/IoScheduledReleaseTest.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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.schedulers; + +import io.reactivex.Completable; +import io.reactivex.Flowable; +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.Function; +import io.reactivex.schedulers.Schedulers; +import org.junit.Test; + +import java.util.concurrent.TimeUnit; + +public class IoScheduledReleaseTest { + + /* This test will be stuck in a deadlock if IoScheduler.USE_SCHEDULED_RELEASE is not set */ + @Test + public void scheduledRelease() { + boolean savedScheduledRelease = IoScheduler.USE_SCHEDULED_RELEASE; + IoScheduler.USE_SCHEDULED_RELEASE = true; + try { + Flowable.just("item") + .observeOn(Schedulers.io()) + .firstOrError() + .map(new Function() { + @Override + public String apply(@NonNull final String item) throws Exception { + for (int i = 0; i < 50; i++) { + Completable.complete() + .observeOn(Schedulers.io()) + .blockingAwait(); + } + return "Done"; + } + }) + .ignoreElement() + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertComplete(); + } finally { + IoScheduler.USE_SCHEDULED_RELEASE = savedScheduledRelease; + } + } +} From 776f0e55d97432799def8927c0e770154500686b Mon Sep 17 00:00:00 2001 From: SergejIsbrecht <4427685+SergejIsbrecht@users.noreply.github.com> Date: Thu, 28 Jan 2021 16:49:51 +0100 Subject: [PATCH 209/211] 2.x: Introduce property rx2.scheduler.use-nanotime (#7154) (#7170) Co-authored-by: Sergej Isbrecht --- src/main/java/io/reactivex/Scheduler.java | 42 +++++++++++-- .../io/reactivex/schedulers/Schedulers.java | 2 + src/test/java/io/reactivex/SchedulerTest.java | 61 +++++++++++++++++++ 3 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 src/test/java/io/reactivex/SchedulerTest.java diff --git a/src/main/java/io/reactivex/Scheduler.java b/src/main/java/io/reactivex/Scheduler.java index 2e99e288f1..882fdaa060 100644 --- a/src/main/java/io/reactivex/Scheduler.java +++ b/src/main/java/io/reactivex/Scheduler.java @@ -61,8 +61,9 @@ * interface which can grant access to the original or hooked {@code Runnable}, thus, a repeated {@code RxJavaPlugins.onSchedule} * can detect the earlier hook and not apply a new one over again. *

            - * The default implementation of {@link #now(TimeUnit)} and {@link Worker#now(TimeUnit)} methods to return current - * {@link System#currentTimeMillis()} value in the desired time unit. Custom {@code Scheduler} implementations can override this + * The default implementation of {@link #now(TimeUnit)} and {@link Worker#now(TimeUnit)} methods to return current {@link System#currentTimeMillis()} + * value in the desired time unit, unless {@code rx2.scheduler.use-nanotime} (boolean) is set. When the property is set to + * {@code true}, the method uses {@link System#nanoTime()} as its basis instead. Custom {@code Scheduler} implementations can override this * to provide specialized time accounting (such as virtual time to be advanced programmatically). * Note that operators requiring a {@code Scheduler} may rely on either of the {@code now()} calls provided by * {@code Scheduler} or {@code Worker} respectively, therefore, it is recommended they represent a logically @@ -89,6 +90,34 @@ * All methods on the {@code Scheduler} and {@code Worker} classes should be thread safe. */ public abstract class Scheduler { + /** + * Value representing whether to use {@link System#nanoTime()}, or default as clock for {@link #now(TimeUnit)} + * and {@link Scheduler.Worker#now(TimeUnit)} + *

            + * Associated system parameter: + *

              + *
            • {@code rx2.scheduler.use-nanotime}, boolean, default {@code false} + *
            + */ + static boolean IS_DRIFT_USE_NANOTIME = Boolean.getBoolean("rx2.scheduler.use-nanotime"); + + /** + * Returns the current clock time depending on state of {@link Scheduler#IS_DRIFT_USE_NANOTIME} in given {@code unit} + *

            + * By default {@link System#currentTimeMillis()} will be used as the clock. When the property is set + * {@link System#nanoTime()} will be used. + *

            + * @param unit the time unit + * @return the 'current time' in given unit + * @throws NullPointerException if {@code unit} is {@code null} + */ + static long computeNow(TimeUnit unit) { + if(!IS_DRIFT_USE_NANOTIME) { + return unit.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS); + } + return unit.convert(System.nanoTime(), TimeUnit.NANOSECONDS); + } + /** * The tolerance for a clock drift in nanoseconds where the periodic scheduler will rebase. *

            @@ -131,7 +160,7 @@ public static long clockDriftTolerance() { * @since 2.0 */ public long now(@NonNull TimeUnit unit) { - return unit.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS); + return computeNow(unit); } /** @@ -332,8 +361,9 @@ public S when(@NonNull Function - * The default implementation of the {@link #now(TimeUnit)} method returns current - * {@link System#currentTimeMillis()} value in the desired time unit. Custom {@code Worker} implementations can override this + * The default implementation of the {@link #now(TimeUnit)} method returns current {@link System#currentTimeMillis()} + * value in the desired time unit, unless {@code rx2.scheduler.use-nanotime} (boolean) is set. When the property is set to + * {@code true}, the method uses {@link System#nanoTime()} as its basis instead. Custom {@code Worker} implementations can override this * to provide specialized time accounting (such as virtual time to be advanced programmatically). * Note that operators requiring a scheduler may rely on either of the {@code now()} calls provided by * {@code Scheduler} or {@code Worker} respectively, therefore, it is recommended they represent a logically @@ -448,7 +478,7 @@ public Disposable schedulePeriodically(@NonNull Runnable run, final long initial * @since 2.0 */ public long now(@NonNull TimeUnit unit) { - return unit.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS); + return computeNow(unit); } /** diff --git a/src/main/java/io/reactivex/schedulers/Schedulers.java b/src/main/java/io/reactivex/schedulers/Schedulers.java index dfd6bfe756..5af187c121 100644 --- a/src/main/java/io/reactivex/schedulers/Schedulers.java +++ b/src/main/java/io/reactivex/schedulers/Schedulers.java @@ -39,6 +39,8 @@ *

          • {@code rx2.single-priority} (int): sets the thread priority of the {@link #single()} Scheduler, default is {@link Thread#NORM_PRIORITY}
          • *
          • {@code rx2.purge-enabled} (boolean): enables periodic purging of all Scheduler's backing thread pools, default is false
          • *
          • {@code rx2.purge-period-seconds} (int): specifies the periodic purge interval of all Scheduler's backing thread pools, default is 1 second
          • + *
          • {@code rx2.scheduler.use-nanotime} (boolean): {@code true} instructs {@code Scheduler} to use {@link System#nanoTime()} for {@link Scheduler#now(TimeUnit)}, + * instead of default {@link System#currentTimeMillis()} ({@code false})
          • *
          */ public final class Schedulers { diff --git a/src/test/java/io/reactivex/SchedulerTest.java b/src/test/java/io/reactivex/SchedulerTest.java new file mode 100644 index 0000000000..39bcb0ae4b --- /dev/null +++ b/src/test/java/io/reactivex/SchedulerTest.java @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * 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 org.junit.After; +import org.junit.Test; + +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.*; + +/** + * Same as {@link io.reactivex.schedulers.SchedulerTest}, but different package, to access + * package-private fields. + */ +public class SchedulerTest { + private static final String DRIFT_USE_NANOTIME = "rx2.scheduler.use-nanotime"; + + @After + public void cleanup() { + // reset value to default in order to not influence other tests + Scheduler.IS_DRIFT_USE_NANOTIME = false; + } + + @Test + public void driftUseNanoTimeNotSetByDefault() { + assertFalse(Scheduler.IS_DRIFT_USE_NANOTIME); + assertFalse(Boolean.getBoolean(DRIFT_USE_NANOTIME)); + } + + @Test + public void computeNow_currentTimeMillis() { + TimeUnit unit = TimeUnit.MILLISECONDS; + assertTrue(isInRange(System.currentTimeMillis(), Scheduler.computeNow(unit), unit, 250, TimeUnit.MILLISECONDS)); + } + + @Test + public void computeNow_nanoTime() { + TimeUnit unit = TimeUnit.NANOSECONDS; + Scheduler.IS_DRIFT_USE_NANOTIME = true; + + assertFalse(isInRange(System.currentTimeMillis(), Scheduler.computeNow(unit), unit, 250, TimeUnit.MILLISECONDS)); + assertTrue(isInRange(System.nanoTime(), Scheduler.computeNow(unit), TimeUnit.NANOSECONDS, 250, TimeUnit.MILLISECONDS)); + } + + private boolean isInRange(long start, long stop, TimeUnit source, long maxDiff, TimeUnit diffUnit) { + long diff = Math.abs(stop - start); + return diffUnit.convert(diff, source) <= maxDiff; + } +} From 725ea89629568301ab7d9b21cafdf8c648a14da9 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Sat, 13 Feb 2021 10:13:43 +0100 Subject: [PATCH 210/211] Update CHANGES.md --- CHANGES.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 3321e0f855..8842673756 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,17 @@ The changelog of version 1.x can be found at https://github.com/ReactiveX/RxJava/blob/1.x/CHANGES.md +### Version 2.2.21 - February 10, 2021 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.21%7C)) +[JavaDocs](http://reactivex.io/RxJava/2.x/javadoc/2.2.21) + +:warning: This is the last planned update for the 2.x version line. After **February 28, 2021**, 2.x becomes **End-of-Life** (EoL); no further patches, bugfixes, enhancements, documentation or support will be provided by the project. + + +#### Enhancements + +- Add a system parameter to allow scheduled worker release in the Io `Scheduler`. (#7162) +- Add a system parameter to allow `Scheduler`s to use `System.nanoTime()` for `now()`. (#7170) + ### Version 2.2.20 - October 6, 2020 ([Maven](http://search.maven.org/#artifactdetails%7Cio.reactivex.rxjava2%7Crxjava%7C2.2.20%7C)) [JavaDocs](http://reactivex.io/RxJava/2.x/javadoc/2.2.20) From 24df131ecc012aa0591b9123b79a1f0f6a14a4f9 Mon Sep 17 00:00:00 2001 From: David Karnok Date: Tue, 2 Mar 2021 13:01:19 +0100 Subject: [PATCH 211/211] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 21e4679a44..1cd82b7f63 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # RxJava: Reactive Extensions for the JVM +## End-of-Life notice + +As of February 28, 2021, The RxJava 2.x branch and version is end-of-life (EOL). No further development, bugfixes, documentation changes, PRs, releases or maintenance will be performed by the project on the 2.x line. + +Users are encouraged to migrate to [3.x](https://github.com/ReactiveX/RxJava) which is currently the only official RxJava version being managed. + +---- + [![codecov.io](http://codecov.io/github/ReactiveX/RxJava/coverage.svg?branch=2.x)](https://codecov.io/gh/ReactiveX/RxJava/branch/2.x) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava2/rxjava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava2/rxjava) @@ -8,8 +16,6 @@ RxJava is a Java VM implementation of [Reactive Extensions](http://reactivex.io) It extends the [observer pattern](http://en.wikipedia.org/wiki/Observer_pattern) to support sequences of data/events and adds operators that allow you to compose sequences together declaratively while abstracting away concerns about things like low-level threading, synchronization, thread-safety and concurrent data structures. -:warning: The 2.x version is now in **maintenance mode** and will be supported only through bugfixes until **February 28, 2021**. No new features, behavior changes or documentation adjustments will be accepted or applied to 2.x. It is recommended to migrate to [3.x](https://github.com/ReactiveX/RxJava/tree/3.x) within this time period. - #### Version 2.x ([Javadoc](http://reactivex.io/RxJava/2.x/javadoc/)) - single dependency: [Reactive Streams](https://github.com/reactive-streams/reactive-streams-jvm)