-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Add doOnTerminate to Single/Maybe for consistency #6386
Add doOnTerminate to Single/Maybe for consistency #6386
Conversation
Codecov Report
@@ Coverage Diff @@
## 2.x #6386 +/- ##
============================================
+ Coverage 98.23% 98.28% +0.05%
- Complexity 6287 6299 +12
============================================
Files 673 675 +2
Lines 45092 45156 +64
Branches 6239 6239
============================================
+ Hits 44297 44383 +86
+ Misses 256 238 -18
+ Partials 539 535 -4
Continue to review full report at Codecov.
|
@@ -2892,6 +2892,31 @@ public final T blockingGet(T defaultValue) { | |||
)); | |||
} | |||
|
|||
/** | |||
* Calls the shared consumer with the given onTerminate callback for each |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence makes no sense. Please word it like the other similar operators: http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html#doOnTerminate-io.reactivex.functions.Action-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@@ -826,6 +827,53 @@ public void accept(Disposable v) throws Exception { | |||
.assertFailure(TestException.class); | |||
} | |||
|
|||
@Test(expected = NullPointerException.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put these unit test into their own files and also verify the cases when the onTerminate callback fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented
onTerminate.run(); | ||
} catch (Throwable ex) { | ||
Exceptions.throwIfFatal(ex); | ||
downstream.onError(ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a composite error with the original error followed by the handler crash. Example: https://github.com/ReactiveX/RxJava/blob/2.x/src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java#L92
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented
*/ | ||
@CheckReturnValue | ||
@NonNull | ||
@SchedulerSupport(SchedulerSupport.NONE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add @Experimental
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
* @return the new Maybe instance | ||
* @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a> | ||
* @see #doOnTerminate(Action) | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add @since 2.2.7 - experimental
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
* @return the new Single instance | ||
* @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a> | ||
* @see #doOnTerminate(Action) | ||
* @since 2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the next minor version: @since 2.2.7 - experimental
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
@CheckReturnValue | ||
@NonNull | ||
@SchedulerSupport(SchedulerSupport.NONE) | ||
public final Single<T> doOnTerminate(final Action onTerminate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add @Experimental
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
public void run() { | ||
atomicBoolean.set(true); | ||
} | ||
}).subscribe(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use .test().assertResult(1);
instead of just subscribing blindly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
atomicBoolean.set(true); | ||
} | ||
}) | ||
.subscribe(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use .test().assertResult(1);
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
public void run() throws Exception { | ||
atomicBoolean.set(true); | ||
} | ||
}).subscribe(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use .test().assertResult(1);
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
} | ||
}); | ||
|
||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the testing style change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored to match the rest of the testing style
} | ||
}) | ||
.test() | ||
.assertResult(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think about it a bit. You have an empty source and you want to verify it is still empty at the end.
} | ||
}) | ||
.test() | ||
.assertFailure(CompositeException.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please verify that the correct inner exceptions are received. Example: https://github.com/ReactiveX/RxJava/blob/2.x/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java#L52
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
} | ||
}) | ||
.test() | ||
.assertFailure(CompositeException.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please verify that the correct inner exceptions are received. Example: https://github.com/ReactiveX/RxJava/blob/2.x/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java#L52
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
} | ||
}) | ||
.test() | ||
.assertNoValues(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I came to a conclusion that assertNoValues()
would be the right choice. I also considered assertEmpty()
method, but this one will not work as onComplete
event is triggered.
Thanks for pointing me in a right direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssertNoValues doesn't verify the lack of errors. Please put assertResult back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought your previous comment mentioned that it was a wrong approach. Maybe I misunderstood. Is it still correct to use assertResult()
?
I put it back anyways according to your last review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You misunderstood me. If a source has no values, there is no reason to put any value into the parameter of assertResult()
. A no-arg assertResult
verifies exactly that the outcome is no items and no errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Sorry for the for the back and forth from my side.
All improvements and fixes have been implemented |
This PR adds doOnTerminate operator to Single and Maybe.
Resolves: #6379.