-
Notifications
You must be signed in to change notification settings - Fork 26
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
Improve AutoContinuingInputStream failure case #429
Merged
tjcelaya
merged 8 commits into
TritonDataCenter:master
from
tjcelaya:fix/continuator-self-suppression
Aug 3, 2018
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ccebd29
Make unrecoverable exception handling less confusing
tjcelaya 402cc37
Clean up debug log
tjcelaya d2d62d0
Stop expecting ContinuingInputStream to automatically close the error…
tjcelaya 7f95792
Add a test case verifying that AutoContinuingInputStream does not com…
tjcelaya 2e62f41
It's fine to add other recovery exceptions as suppressed exceptions, …
tjcelaya d9226e3
Changelog
tjcelaya 91cc5f5
Move ApacheHttpGetResponseEntityContentContinuatorIT to the right pac…
tjcelaya e0bb5e2
PR suggestions
tjcelaya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
66 changes: 66 additions & 0 deletions
66
...ta-client-unshaded/src/test/java/com/joyent/manta/util/AutoContinuingInputStreamTest.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,66 @@ | ||
package com.joyent.manta.util; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.io.input.ClosedInputStream; | ||
import org.apache.commons.io.input.ProxyInputStream; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.ArgumentMatchers.same; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertSame; | ||
import static org.testng.Assert.expectThrows; | ||
|
||
@Test | ||
public class AutoContinuingInputStreamTest { | ||
|
||
/** | ||
* We can't use {@link org.apache.commons.io.input.BrokenInputStream} for this test because it will return the same | ||
* exception during close and trigger the | ||
* <a href="https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html#suppressed-exceptions">self-suppression | ||
* issue</a>. | ||
* <p> | ||
* On the other hand, we can't use {@link FailingInputStream} because that generates its own exceptions, so we | ||
* wouldn't be able to use {@link org.testng.Assert#assertSame} and check that no suppressed exceptions were added. | ||
*/ | ||
private static final class ReadExceptionInputStream extends ProxyInputStream { | ||
|
||
private final IOException exception; | ||
|
||
public ReadExceptionInputStream(final IOException exception) { | ||
super(ClosedInputStream.CLOSED_INPUT_STREAM); | ||
this.exception = exception; | ||
} | ||
|
||
@Override | ||
protected void beforeRead(final int n) throws IOException { | ||
throw this.exception; | ||
} | ||
} | ||
|
||
public void rethrowsUnrecoverableExceptionsDirectly() throws Exception { | ||
// the exception to consider fatal | ||
final IOException ex = new IOException("oops"); | ||
|
||
// source stream always throws that exception | ||
final InputStream original = new ReadExceptionInputStream(ex); | ||
|
||
// pretend that it was a fatal exception and should be rethrown | ||
final InputStreamContinuator continuator = mock(InputStreamContinuator.class); | ||
when(continuator.buildContinuation(same(ex), anyLong())).thenThrow(ex); | ||
|
||
final IOException caught = expectThrows(IOException.class, () -> { | ||
try (final AutoContinuingInputStream in = new AutoContinuingInputStream(original, continuator)) { | ||
IOUtils.toByteArray(in); | ||
} | ||
}); | ||
|
||
assertSame(caught, ex); | ||
assertEquals(caught.getSuppressed().length, 0); | ||
} | ||
} |
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
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.
Is there any possibility of
ex
being null?