Skip to content

Commit e255de7

Browse files
authored
2.x: test sync from Observable to Flowable 10/16-1 (#4714)
1 parent 788873e commit e255de7

File tree

80 files changed

+5655
-633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+5655
-633
lines changed

src/main/java/io/reactivex/CompletableOperator.java

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public interface CompletableOperator {
2121
* Applies a function to the child CompletableObserver and returns a new parent CompletableObserver.
2222
* @param observer the child CompletableObservable instance
2323
* @return the parent CompletableObserver instance
24+
* @throws Exception on failure
2425
*/
2526
CompletableObserver apply(CompletableObserver observer) throws Exception;
2627
}

src/main/java/io/reactivex/Flowable.java

+23-23
Original file line numberDiff line numberDiff line change
@@ -3500,7 +3500,7 @@ public static Flowable<Long> rangeLong(long start, long count) {
35003500
}
35013501

35023502
/**
3503-
* Returns a Flowable that emits a Boolean value that indicates whether two Publisher sequences are the
3503+
* Returns a Single that emits a Boolean value that indicates whether two Publisher sequences are the
35043504
* same by comparing the items emitted by each Publisher pairwise.
35053505
* <p>
35063506
* <img width="640" height="385" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/sequenceEqual.png" alt="">
@@ -3523,12 +3523,12 @@ public static Flowable<Long> rangeLong(long start, long count) {
35233523
*/
35243524
@BackpressureSupport(BackpressureKind.FULL)
35253525
@SchedulerSupport(SchedulerSupport.NONE)
3526-
public static <T> Flowable<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2) {
3526+
public static <T> Single<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2) {
35273527
return sequenceEqual(source1, source2, ObjectHelper.equalsPredicate(), bufferSize());
35283528
}
35293529

35303530
/**
3531-
* Returns a Flowable that emits a Boolean value that indicates whether two Publisher sequences are the
3531+
* Returns a Single that emits a Boolean value that indicates whether two Publisher sequences are the
35323532
* same by comparing the items emitted by each Publisher pairwise based on the results of a specified
35333533
* equality function.
35343534
* <p>
@@ -3549,19 +3549,19 @@ public static <T> Flowable<Boolean> sequenceEqual(Publisher<? extends T> source1
35493549
* a function used to compare items emitted by each Publisher
35503550
* @param <T>
35513551
* the type of items emitted by each Publisher
3552-
* @return a Flowable that emits a Boolean value that indicates whether the two Publisher sequences
3552+
* @return a Single that emits a Boolean value that indicates whether the two Publisher sequences
35533553
* are the same according to the specified function
35543554
* @see <a href="http://reactivex.io/documentation/operators/sequenceequal.html">ReactiveX operators documentation: SequenceEqual</a>
35553555
*/
35563556
@BackpressureSupport(BackpressureKind.FULL)
35573557
@SchedulerSupport(SchedulerSupport.NONE)
3558-
public static <T> Flowable<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2,
3558+
public static <T> Single<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2,
35593559
BiPredicate<? super T, ? super T> isEqual) {
35603560
return sequenceEqual(source1, source2, isEqual, bufferSize());
35613561
}
35623562

35633563
/**
3564-
* Returns a Flowable that emits a Boolean value that indicates whether two Publisher sequences are the
3564+
* Returns a Single that emits a Boolean value that indicates whether two Publisher sequences are the
35653565
* same by comparing the items emitted by each Publisher pairwise based on the results of a specified
35663566
* equality function.
35673567
* <p>
@@ -3584,23 +3584,23 @@ public static <T> Flowable<Boolean> sequenceEqual(Publisher<? extends T> source1
35843584
* the number of items to prefetch from the first and second source Publisher
35853585
* @param <T>
35863586
* the type of items emitted by each Publisher
3587-
* @return a Flowable that emits a Boolean value that indicates whether the two Publisher sequences
3587+
* @return a Single that emits a Boolean value that indicates whether the two Publisher sequences
35883588
* are the same according to the specified function
35893589
* @see <a href="http://reactivex.io/documentation/operators/sequenceequal.html">ReactiveX operators documentation: SequenceEqual</a>
35903590
*/
35913591
@BackpressureSupport(BackpressureKind.FULL)
35923592
@SchedulerSupport(SchedulerSupport.NONE)
3593-
public static <T> Flowable<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2,
3593+
public static <T> Single<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2,
35943594
BiPredicate<? super T, ? super T> isEqual, int bufferSize) {
35953595
ObjectHelper.requireNonNull(source1, "source1 is null");
35963596
ObjectHelper.requireNonNull(source2, "source2 is null");
35973597
ObjectHelper.requireNonNull(isEqual, "isEqual is null");
35983598
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
3599-
return RxJavaPlugins.onAssembly(new FlowableSequenceEqual<T>(source1, source2, isEqual, bufferSize));
3599+
return RxJavaPlugins.onAssembly(new FlowableSequenceEqualSingle<T>(source1, source2, isEqual, bufferSize));
36003600
}
36013601

36023602
/**
3603-
* Returns a Flowable that emits a Boolean value that indicates whether two Publisher sequences are the
3603+
* Returns a Single that emits a Boolean value that indicates whether two Publisher sequences are the
36043604
* same by comparing the items emitted by each Publisher pairwise.
36053605
* <p>
36063606
* <img width="640" height="385" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/sequenceEqual.png" alt="">
@@ -3620,12 +3620,12 @@ public static <T> Flowable<Boolean> sequenceEqual(Publisher<? extends T> source1
36203620
* the number of items to prefetch from the first and second source Publisher
36213621
* @param <T>
36223622
* the type of items emitted by each Publisher
3623-
* @return a Flowable that emits a Boolean value that indicates whether the two sequences are the same
3623+
* @return a Single that emits a Boolean value that indicates whether the two sequences are the same
36243624
* @see <a href="http://reactivex.io/documentation/operators/sequenceequal.html">ReactiveX operators documentation: SequenceEqual</a>
36253625
*/
36263626
@BackpressureSupport(BackpressureKind.FULL)
36273627
@SchedulerSupport(SchedulerSupport.NONE)
3628-
public static <T> Flowable<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2, int bufferSize) {
3628+
public static <T> Single<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2, int bufferSize) {
36293629
return sequenceEqual(source1, source2, ObjectHelper.equalsPredicate(), bufferSize);
36303630
}
36313631

@@ -5196,7 +5196,7 @@ public final T blockingLast(T defaultItem) {
51965196
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
51975197
@SchedulerSupport(SchedulerSupport.NONE)
51985198
public final Iterable<T> blockingLatest() {
5199-
return BlockingFlowableLatest.latest(this);
5199+
return new BlockingFlowableLatest<T>(this);
52005200
}
52015201

52025202
/**
@@ -5222,7 +5222,7 @@ public final Iterable<T> blockingLatest() {
52225222
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
52235223
@SchedulerSupport(SchedulerSupport.NONE)
52245224
public final Iterable<T> blockingMostRecent(T initialItem) {
5225-
return BlockingFlowableMostRecent.mostRecent(this, initialItem);
5225+
return new BlockingFlowableMostRecent<T>(this, initialItem);
52265226
}
52275227

52285228
/**
@@ -5245,7 +5245,7 @@ public final Iterable<T> blockingMostRecent(T initialItem) {
52455245
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
52465246
@SchedulerSupport(SchedulerSupport.NONE)
52475247
public final Iterable<T> blockingNext() {
5248-
return BlockingFlowableNext.next(this);
5248+
return new BlockingFlowableNext<T>(this);
52495249
}
52505250

52515251
/**
@@ -5267,7 +5267,7 @@ public final Iterable<T> blockingNext() {
52675267
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
52685268
@SchedulerSupport(SchedulerSupport.NONE)
52695269
public final T blockingSingle() {
5270-
return singleElement().blockingGet();
5270+
return singleOrError().blockingGet();
52715271
}
52725272

52735273
/**
@@ -7248,7 +7248,7 @@ public final <K> Flowable<T> distinct(Function<? super T, K> keySelector,
72487248
Callable<? extends Collection<? super K>> collectionSupplier) {
72497249
ObjectHelper.requireNonNull(keySelector, "keySelector is null");
72507250
ObjectHelper.requireNonNull(collectionSupplier, "collectionSupplier is null");
7251-
return FlowableDistinct.withCollection(this, keySelector, collectionSupplier);
7251+
return RxJavaPlugins.onAssembly(new FlowableDistinct<T, K>(this, keySelector, collectionSupplier));
72527252
}
72537253

72547254
/**
@@ -7271,7 +7271,7 @@ public final <K> Flowable<T> distinct(Function<? super T, K> keySelector,
72717271
@BackpressureSupport(BackpressureKind.FULL)
72727272
@SchedulerSupport(SchedulerSupport.NONE)
72737273
public final Flowable<T> distinctUntilChanged() {
7274-
return FlowableDistinct.<T>untilChanged(this);
7274+
return new FlowableDistinctUntilChanged<T>(this, Functions.equalsPredicate());
72757275
}
72767276

72777277
/**
@@ -7299,7 +7299,7 @@ public final Flowable<T> distinctUntilChanged() {
72997299
@SchedulerSupport(SchedulerSupport.NONE)
73007300
public final <K> Flowable<T> distinctUntilChanged(Function<? super T, K> keySelector) {
73017301
ObjectHelper.requireNonNull(keySelector, "keySelector is null");
7302-
return FlowableDistinct.untilChanged(this, keySelector);
7302+
return new FlowableDistinctUntilChanged<T>(this, Functions.equalsPredicate(keySelector));
73037303
}
73047304

73057305
/**
@@ -13734,7 +13734,7 @@ public final Single<List<T>> toList(final int capacityHint) {
1373413734
}
1373513735

1373613736
/**
13737-
* Returns a Flowable that emits a single item, a list composed of all the items emitted by the source
13737+
* Returns a Single that emits a single item, a list composed of all the items emitted by the source
1373813738
* Publisher.
1373913739
* <p>
1374013740
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toList.png" alt="">
@@ -13758,15 +13758,15 @@ public final Single<List<T>> toList(final int capacityHint) {
1375813758
* @param <U> the subclass of a collection of Ts
1375913759
* @param collectionSupplier
1376013760
* the Callable returning the collection (for each individual Subscriber) to be filled in
13761-
* @return a Flowable that emits a single item: a List containing all of the items emitted by the source
13761+
* @return a Single that emits a single item: a List containing all of the items emitted by the source
1376213762
* Publisher
1376313763
* @see <a href="http://reactivex.io/documentation/operators/to.html">ReactiveX operators documentation: To</a>
1376413764
*/
1376513765
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
1376613766
@SchedulerSupport(SchedulerSupport.NONE)
13767-
public final <U extends Collection<? super T>> Flowable<U> toList(Callable<U> collectionSupplier) {
13767+
public final <U extends Collection<? super T>> Single<U> toList(Callable<U> collectionSupplier) {
1376813768
ObjectHelper.requireNonNull(collectionSupplier, "collectionSupplier is null");
13769-
return RxJavaPlugins.onAssembly(new FlowableToList<T, U>(this, collectionSupplier));
13769+
return RxJavaPlugins.onAssembly(new FlowableToListSingle<T, U>(this, collectionSupplier));
1377013770
}
1377113771

1377213772
/**

src/main/java/io/reactivex/FlowableOperator.java

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public interface FlowableOperator<Downstream, Upstream> {
2626
* Applies a function to the child Subscriber and returns a new parent Subscriber.
2727
* @param observer the child Subscriber instance
2828
* @return the parent Subscriber instance
29+
* @throws Exception on failure
2930
*/
3031
Subscriber<? super Upstream> apply(Subscriber<? super Downstream> observer) throws Exception;
3132
}

src/main/java/io/reactivex/MaybeOperator.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public interface MaybeOperator<Downstream, Upstream> {
2424
* Applies a function to the child MaybeObserver and returns a new parent MaybeObserver.
2525
* @param observer the child MaybeObserver instance
2626
* @return the parent MaybeObserver instance
27+
* @throws Exception on failure
2728
*/
2829
MaybeObserver<? super Upstream> apply(MaybeObserver<? super Downstream> observer) throws Exception;
2930
}

src/main/java/io/reactivex/ObservableOperator.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public interface ObservableOperator<Downstream, Upstream> {
2424
* Applies a function to the child Observer and returns a new parent Observer.
2525
* @param observer the child Observer instance
2626
* @return the parent Observer instance
27+
* @throws Exception on failure
2728
*/
2829
Observer<? super Upstream> apply(Observer<? super Downstream> observer) throws Exception;
2930
}

src/main/java/io/reactivex/SingleOperator.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public interface SingleOperator<Downstream, Upstream> {
2424
* Applies a function to the child SingleObserver and returns a new parent SingleObserver.
2525
* @param observer the child SingleObserver instance
2626
* @return the parent SingleObserver instance
27+
* @throws Exception on failure
2728
*/
2829
SingleObserver<? super Upstream> apply(SingleObserver<? super Downstream> observer) throws Exception;
2930
}

src/main/java/io/reactivex/internal/fuseable/QueueDisposable.java

+1-62
Original file line numberDiff line numberDiff line change
@@ -51,66 +51,5 @@
5151
* </ul>
5252
* @param <T> the value type transmitted through the queue
5353
*/
54-
public interface QueueDisposable<T> extends SimpleQueue<T>, Disposable {
55-
/**
56-
* Returned by the {@link #requestFusion(int)} if the upstream doesn't support
57-
* the requested mode.
58-
*/
59-
int NONE = 0;
60-
61-
/**
62-
* Request a synchronous fusion mode and can be returned by {@link #requestFusion(int)}
63-
* for an accepted mode.
64-
* <p>
65-
* In synchronous fusion, all upstream values are either already available or is generated
66-
* when {@link #poll()} is called synchronously. When the {@link #poll()} returns null,
67-
* that is the indication if a terminated stream.
68-
* In this mode, the upstream won't call the onXXX methods and callers of
69-
* {@link #poll()} should be prepared to catch exceptions. Note that {@link #poll()} has
70-
* to be called sequentially (from within a serializing drain-loop).
71-
*/
72-
int SYNC = 1;
73-
74-
/**
75-
* Request an asynchronous fusion mode and can be returned by {@link #requestFusion(int)}
76-
* for an accepted mode.
77-
* <p>
78-
* In asynchronous fusion, upstream values may become available to {@link #poll()} eventually.
79-
* Upstream signals onError() and onComplete() as usual but onNext may not actually contain
80-
* the upstream value but have {@code null} instead. Downstream should treat such onNext as indication
81-
* that {@link #poll()} can be called. Note that {@link #poll()} has to be called sequentially
82-
* (from within a serializing drain-loop). In addition, callers of {@link #poll()} should be
83-
* prepared to catch exceptions.
84-
*/
85-
int ASYNC = 2;
86-
87-
/**
88-
* Request any of the {@link #SYNC} or {@link #ASYNC} modes.
89-
*/
90-
int ANY = SYNC | ASYNC;
91-
92-
/**
93-
* Used in binary or combination with the other constants as an input to {@link #requestFusion(int)}
94-
* indicating that the {@link #poll()} will be called behind an asynchronous boundary and thus
95-
* may change the non-trivial computation locations attached to the {@link #poll()} chain of
96-
* fused operators.
97-
* <p>
98-
* For example, fusing map() and observeOn() may move the computation of the map's function over to
99-
* the thread run after the observeOn(), which is generally unexpected.
100-
*/
101-
int BOUNDARY = 4;
102-
103-
/**
104-
* Request a fusion mode from the upstream.
105-
* <p>
106-
* This should be called before {@code onSubscribe} returns.
107-
* <p>
108-
* Calling this method multiple times or after {@code onSubscribe} finished is not allowed
109-
* and may result in undefined behavior.
110-
* <p>
111-
* @param mode the requested fusion mode, allowed values are {@link #SYNC}, {@link #ASYNC},
112-
* {@link #ANY} combined with {@link #BOUNDARY} (e.g., {@code requestFusion(SYNC | BOUNDARY)}).
113-
* @return the established fusion mode: {@link #NONE}, {@link #SYNC}, {@link #ASYNC}.
114-
*/
115-
int requestFusion(int mode);
54+
public interface QueueDisposable<T> extends QueueFuseable<T>, Disposable {
11655
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright 2016 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.reactivex.internal.fuseable;
15+
16+
17+
/**
18+
* Represents a SimpleQueue plus the means and constants for requesting a fusion mode.
19+
* @param <T> the value type returned by the SimpleQueue.poll()
20+
*/
21+
public interface QueueFuseable<T> extends SimpleQueue<T> {
22+
/**
23+
* Returned by the {@link #requestFusion(int)} if the upstream doesn't support
24+
* the requested mode.
25+
*/
26+
int NONE = 0;
27+
28+
/**
29+
* Request a synchronous fusion mode and can be returned by {@link #requestFusion(int)}
30+
* for an accepted mode.
31+
* <p>
32+
* In synchronous fusion, all upstream values are either already available or is generated
33+
* when {@link #poll()} is called synchronously. When the {@link #poll()} returns null,
34+
* that is the indication if a terminated stream.
35+
* In this mode, the upstream won't call the onXXX methods and callers of
36+
* {@link #poll()} should be prepared to catch exceptions. Note that {@link #poll()} has
37+
* to be called sequentially (from within a serializing drain-loop).
38+
*/
39+
int SYNC = 1;
40+
41+
/**
42+
* Request an asynchronous fusion mode and can be returned by {@link #requestFusion(int)}
43+
* for an accepted mode.
44+
* <p>
45+
* In asynchronous fusion, upstream values may become available to {@link #poll()} eventually.
46+
* Upstream signals onError() and onComplete() as usual but onNext may not actually contain
47+
* the upstream value but have {@code null} instead. Downstream should treat such onNext as indication
48+
* that {@link #poll()} can be called. Note that {@link #poll()} has to be called sequentially
49+
* (from within a serializing drain-loop). In addition, callers of {@link #poll()} should be
50+
* prepared to catch exceptions.
51+
*/
52+
int ASYNC = 2;
53+
54+
/**
55+
* Request any of the {@link #SYNC} or {@link #ASYNC} modes.
56+
*/
57+
int ANY = SYNC | ASYNC;
58+
59+
/**
60+
* Used in binary or combination with the other constants as an input to {@link #requestFusion(int)}
61+
* indicating that the {@link #poll()} will be called behind an asynchronous boundary and thus
62+
* may change the non-trivial computation locations attached to the {@link #poll()} chain of
63+
* fused operators.
64+
* <p>
65+
* For example, fusing map() and observeOn() may move the computation of the map's function over to
66+
* the thread run after the observeOn(), which is generally unexpected.
67+
*/
68+
int BOUNDARY = 4;
69+
70+
/**
71+
* Request a fusion mode from the upstream.
72+
* <p>
73+
* This should be called before {@code onSubscribe} returns.
74+
* <p>
75+
* Calling this method multiple times or after {@code onSubscribe} finished is not allowed
76+
* and may result in undefined behavior.
77+
* <p>
78+
* @param mode the requested fusion mode, allowed values are {@link #SYNC}, {@link #ASYNC},
79+
* {@link #ANY} combined with {@link #BOUNDARY} (e.g., {@code requestFusion(SYNC | BOUNDARY)}).
80+
* @return the established fusion mode: {@link #NONE}, {@link #SYNC}, {@link #ASYNC}.
81+
*/
82+
int requestFusion(int mode);
83+
84+
}

0 commit comments

Comments
 (0)