-
Notifications
You must be signed in to change notification settings - Fork 174
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
Better visibility on transport errors #278
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bb62b9c
Better visibility on transport errors
jayv adc8a3e
Address PR comments
jayv 17a9a11
Address PR comments
jayv 40f9e3a
Address PR comments - fix Offloader for Throwable
jayv 6fec36b
Make note of temporary hack
jayv 4bd9095
Errmsg got lost in the revert
jayv File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
134 changes: 0 additions & 134 deletions
134
...pi-internal/src/test/java/io/servicetalk/concurrent/api/internal/SingleProcessorTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
...etalk-concurrent-api/src/test/java/io/servicetalk/concurrent/api/SingleProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/* | ||
* Copyright © 2018-2019 Apple Inc. and the ServiceTalk project authors | ||
* | ||
* 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.servicetalk.concurrent.api; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import static io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION; | ||
|
||
public class SingleProcessorTest { | ||
@Rule | ||
public final MockedSingleListenerRule<?> rule = new MockedSingleListenerRule<>(); | ||
@Rule | ||
public final MockedSingleListenerRule<?> rule2 = new MockedSingleListenerRule<>(); | ||
|
||
@SuppressWarnings("unchecked") | ||
private <T> MockedSingleListenerRule<T> rule() { | ||
return (MockedSingleListenerRule<T>) rule; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private <T> MockedSingleListenerRule<T> rule2() { | ||
return (MockedSingleListenerRule<T>) rule2; | ||
} | ||
|
||
@Test | ||
public void testSuccessBeforeListen() { | ||
testSuccessBeforeListen("foo"); | ||
} | ||
|
||
@Test | ||
public void testSuccessThrowableBeforeListen() { | ||
testSuccessBeforeListen(DELIBERATE_EXCEPTION); | ||
} | ||
|
||
@Test | ||
public void testSuccessNullBeforeListen() { | ||
testSuccessBeforeListen(null); | ||
} | ||
|
||
private <T> void testSuccessBeforeListen(@Nullable T expected) { | ||
SingleProcessor<T> processor = new SingleProcessor<>(); | ||
processor.onSuccess(expected); | ||
rule().listen(processor).verifySuccess(expected); | ||
} | ||
|
||
@Test | ||
public void testErrorBeforeListen() { | ||
SingleProcessor<String> processor = new SingleProcessor<>(); | ||
processor.onError(DELIBERATE_EXCEPTION); | ||
rule().listen(processor).verifyFailure(DELIBERATE_EXCEPTION); | ||
} | ||
|
||
@Test | ||
public void testSuccessAfterListen() { | ||
testSuccessAfterListen("foo"); | ||
} | ||
|
||
@Test | ||
public void testSuccessNullAfterListen() { | ||
testSuccessAfterListen(null); | ||
} | ||
|
||
@Test | ||
public void testSuccessThrowableAfterListen() { | ||
testSuccessAfterListen(DELIBERATE_EXCEPTION); | ||
} | ||
|
||
private <T> void testSuccessAfterListen(@Nullable T expected) { | ||
SingleProcessor<T> processor = new SingleProcessor<>(); | ||
rule().listen(processor).verifyNoEmissions(); | ||
processor.onSuccess(expected); | ||
rule().verifySuccess(expected); | ||
} | ||
|
||
@Test | ||
public void testErrorAfterListen() { | ||
SingleProcessor<String> processor = new SingleProcessor<>(); | ||
rule().listen(processor).verifyNoEmissions(); | ||
processor.onError(DELIBERATE_EXCEPTION); | ||
rule().verifyFailure(DELIBERATE_EXCEPTION); | ||
} | ||
|
||
@Test | ||
public void testSuccessThenError() { | ||
testSuccessThenError("foo"); | ||
} | ||
|
||
@Test | ||
public void testSuccessThrowableThenError() { | ||
testSuccessThenError(DELIBERATE_EXCEPTION); | ||
} | ||
|
||
@Test | ||
public void testSuccessNullThenError() { | ||
testSuccessThenError(null); | ||
} | ||
|
||
private <T> void testSuccessThenError(@Nullable T expected) { | ||
SingleProcessor<T> processor = new SingleProcessor<>(); | ||
processor.onSuccess(expected); | ||
processor.onError(DELIBERATE_EXCEPTION); | ||
rule().listen(processor).verifySuccess(expected); | ||
} | ||
|
||
@Test | ||
public void testErrorThenSuccess() { | ||
testErrorThenSuccess("foo"); | ||
} | ||
|
||
@Test | ||
public void testErrorThenSuccessThrowable() { | ||
testErrorThenSuccess(DELIBERATE_EXCEPTION); | ||
} | ||
|
||
@Test | ||
public void testErrorThenSuccessNull() { | ||
testErrorThenSuccess(null); | ||
} | ||
|
||
private <T> void testErrorThenSuccess(@Nullable T expected) { | ||
SingleProcessor<T> processor = new SingleProcessor<>(); | ||
processor.onError(DELIBERATE_EXCEPTION); | ||
processor.onSuccess(expected); | ||
rule().listen(processor).verifyFailure(DELIBERATE_EXCEPTION); | ||
} | ||
|
||
@Test | ||
public void cancelRemovesListenerAndStillAllowsOtherListenersToBeNotified() { | ||
cancelRemovesListenerAndStillAllowsOtherListenersToBeNotified("foo"); | ||
} | ||
|
||
@Test | ||
public void cancelRemovesListenerAndStillAllowsOtherListenersToBeNotifiedWithNull() { | ||
cancelRemovesListenerAndStillAllowsOtherListenersToBeNotified(null); | ||
} | ||
|
||
@Test | ||
public void cancelRemovesListenerAndStillAllowsOtherListenersToBeNotifiedWithThrowable() { | ||
cancelRemovesListenerAndStillAllowsOtherListenersToBeNotified(DELIBERATE_EXCEPTION); | ||
} | ||
|
||
private <T> void cancelRemovesListenerAndStillAllowsOtherListenersToBeNotified(@Nullable T expected) { | ||
SingleProcessor<T> processor = new SingleProcessor<>(); | ||
rule().listen(processor).verifyNoEmissions(); | ||
rule2().listen(processor).verifyNoEmissions(); | ||
rule().cancel(); | ||
processor.onSuccess(expected); | ||
rule().verifyNoEmissions(); | ||
rule2().verifySuccess(expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@jayv - one thing I forgot to ask was that does
SingleProcessor
need to be part of theapi
? We have a few internal packages now where I imagine this class could live.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.
Reasoning:
CompletableProcessor
was alreadypublic
so we decided to make this onepublic
too. I think it's a useful API to have, what is your concern?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 don't think we had the same
internal
package structure whenCompletableProcessor
was first introduced/moved into the current package. I agree this class is useful, and we use it throughout ServiceTalk for our internal implementations. We should be restricting what goes in theapi
package as what is necessary to use theapi
, and I don't thinkSingleProcessor
orCompletableProcessor
are necessary for our users to interact withconcurrent.api
.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.
We use
CompletableProcessor
in concurrent-api hence we can't move it to concurrent-api-internal. However,SingleProcessor
isn't used in concurrent-api so can be moved to concurrent-api-internal if we are OK with one residing in concurrent-api and other doesn't.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.
#325