Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x: Implement as() #5729

Merged
merged 17 commits into from
Nov 19, 2017
Merged

2.x: Implement as() #5729

merged 17 commits into from
Nov 19, 2017

Conversation

ZacSweers
Copy link
Contributor

@ZacSweers ZacSweers commented Nov 16, 2017

This implement as() support as discussed in #5654

I took the opportunity to try to standardize the docs and tests for it (which vary a little bit across implementations of to())

Related: #5654

@ZacSweers
Copy link
Contributor Author

Let me know if you want to add more tests. Some usages of to() were mixed in other tests and wasn't sure if they were specifically targeting testing it.

@ZacSweers
Copy link
Contributor Author

I'm not sure I understand the remaining CI errors, as the parameters have the NonNull annotation

@Experimental
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> R as(@NonNull CompletableConverter<? extends R> converter) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add @Experimental and @since 2.1.7 - experimental to all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* value fluently.
*
* @param <R> the output type
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add @since 2.1.7 - experimental to these as well.

@akarnokd
Copy link
Member

Some style checks failed: https://travis-ci.org/ReactiveX/RxJava/builds/302962901#L974

Please add as to ParallelFlowable.

Please add a unit test that has a converter class which combines all interfaces and is applied to the 6 types of sources.

@ZacSweers
Copy link
Contributor Author

Could you explain what the style checks fix is? I didn't quite understand the message in the log

@ZacSweers
Copy link
Contributor Author

ParallelFlowable - 8adb583

Started on more converter tests in ConverterTest in c1f26ee, composite converter test is in there. Only thing I'm stuck on is the GenericsSignatureTest tests (borrowed from TransformersTest). Currently they don't compile, but I'm not sure what the goal is (or if it even makes sense to match the checks TransformersTest does). Let me know what you think

@akarnokd
Copy link
Member

You have to extend the ParamValidationCheckerTest with instances of your new converter types. Put something like the following into L562.

defaultValues.put(ObservableConverter.class, new ObservableConverter() {
    @Override public Object apply(Observable o) { return o; }
});

@akarnokd
Copy link
Member

akarnokd commented Nov 16, 2017

As for these, you are using the wrong generic types.

ObservableConverter<A<T, ?>, B<T>> is applied to Observable<Integer> in the test where Integer is unrelated to A<T, ?>.

I overlooked the test using A. I'll check code locally.

@akarnokd akarnokd added this to the 2.2 milestone Nov 16, 2017
@akarnokd
Copy link
Member

The wildcard definition in those compile errors and the wrong <Integer> parameter confuses the compiler. I suggest going raw-types with these converters and using SuppressWarnings({"unchecked", "rawtypes"}) on the problematic tests.

@akarnokd
Copy link
Member

Posted a patch for your PR.

as(): Fix tests and update validator
@codecov
Copy link

codecov bot commented Nov 16, 2017

Codecov Report

Merging #5729 into 2.x will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #5729      +/-   ##
============================================
+ Coverage     96.24%   96.29%   +0.04%     
- Complexity     5823     5831       +8     
============================================
  Files           634      634              
  Lines         41609    41615       +6     
  Branches       5761     5761              
============================================
+ Hits          40047    40073      +26     
+ Misses          626      615      -11     
+ Partials        936      927       -9
Impacted Files Coverage Δ Complexity Δ
src/main/java/io/reactivex/Observable.java 100% <100%> (ø) 509 <1> (+1) ⬆️
src/main/java/io/reactivex/Flowable.java 100% <100%> (ø) 526 <1> (+1) ⬆️
src/main/java/io/reactivex/Single.java 100% <100%> (ø) 136 <1> (+1) ⬆️
src/main/java/io/reactivex/Maybe.java 100% <100%> (ø) 170 <1> (+1) ⬆️
src/main/java/io/reactivex/Completable.java 100% <100%> (ø) 114 <1> (+1) ⬆️
...n/java/io/reactivex/parallel/ParallelFlowable.java 100% <100%> (ø) 50 <1> (+1) ⬆️
...in/java/io/reactivex/subjects/BehaviorSubject.java 86.97% <0%> (-5.73%) 57% <0%> (ø)
...l/operators/observable/ObservableFlatMapMaybe.java 84.96% <0%> (-2.62%) 2% <0%> (ø)
...activex/internal/observers/QueueDrainObserver.java 61.53% <0%> (-2.57%) 12% <0%> (-1%)
...ex/internal/subscribers/InnerQueuedSubscriber.java 96.07% <0%> (-1.97%) 18% <0%> (-1%)
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9521512...e0d793f. Read the comment docs.

* @throws Exception on error
*/
@NonNull
R apply(@NonNull Completable upstream) throws Exception;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transformer variants don't define any throws Exception. I'd think we can live without them in these interfaces as well and thus no need to try-catch apply in the base classes' as() methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZacSweers
Copy link
Contributor Author

ZacSweers commented Nov 17, 2017

Out of curiosity, would this be a candidate for @Beta in 2.2.0 since it's so close? Or would it stay @Experimental for a time period after?

@akarnokd
Copy link
Member

2.2.0 is a bit in the future as I'd like to have #5319 finished before it. An experimental component can be promoted to stable regardless.

@ZacSweers
Copy link
Contributor Author

Cool 👍

Copy link
Collaborator

@vanniktech vanniktech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the copy right for the new files contain 2016 or 2017?

@@ -560,6 +560,46 @@ public void checkParallelFlowable() {

defaultValues.put(ParallelFailureHandling.class, ParallelFailureHandling.ERROR);

@SuppressWarnings("rawtypes")
class MixedConverters implements FlowableConverter, ObservableConverter, SingleConverter,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename this to IdentityConverters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly about it since this is just a stub for a test

}
});

flow.blockingForEach(new Consumer<Object>() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not assertion is this wanted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferring to @akarnokd on this as I was matching the analogous to() test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change these into proper assertions such as .test().assertResult().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would I assert for these since there's no value? Or just rewrite the rest in general?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there is the onComplete event.

Copy link
Contributor Author

@ZacSweers ZacSweers Nov 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is but completable.normal doesn't complete. I wasn't sure if you wanted me to change it to just use Completable.complete() or something similar since the original test didn't seem to be testing completion

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normal.completable does complete otherwise blockingForEach would block indefinitely and the test would have failed a long a go. A .test().assertResult(/* no values */) should suffice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, I missed that line 🙄

Done in e0d793f

public Object apply(Flowable<Object> onSubscribe) {
onSubscribe.subscribe(subscriber);
subscriber.assertNoErrors();
subscriber.assertComplete();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not this run through without asserting if the Converter is never called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True... I could add something after this to assert that subscriber is complete?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about an AtomicBoolean that you set to true once it's called and you fail the test when it's set to false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got a better one - 5c3bdf3

Observable.just(value).as(new ObservableConverter<Object, Object>() {
@Override
public Object apply(Observable<Object> onSubscribe) {
onSubscribe.subscribe(subscriber);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akarnokd akarnokd merged commit 6a44e5d into ReactiveX:2.x Nov 19, 2017
@ZacSweers
Copy link
Contributor Author

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants