-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-17887. Remove the wrapper class GzipOutputStream #3377
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| */ | ||
| package org.apache.hadoop.io.compress; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.Assert.assertArrayEquals; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
|
|
@@ -1051,4 +1052,45 @@ public void testCodecPoolAndGzipDecompressor() { | |
| } | ||
| } | ||
| } | ||
|
|
||
| @Test(timeout=20000) | ||
| public void testGzipCompressorWithEmptyInput() throws IOException { | ||
|
Comment on lines
+1056
to
+1057
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In current trunk, this test will cause: |
||
| // don't use native libs | ||
| ZlibFactory.setNativeZlibLoaded(false); | ||
| Configuration conf = new Configuration(); | ||
| CompressionCodec codec = ReflectionUtils.newInstance(GzipCodec.class, conf); | ||
|
|
||
| Compressor compressor = codec.createCompressor(); | ||
| assertThat(compressor).withFailMessage("should be BuiltInGzipCompressor") | ||
| .isInstanceOf(BuiltInGzipCompressor.class); | ||
|
|
||
| byte[] b = new byte[0]; | ||
| compressor.setInput(b, 0, b.length); | ||
| compressor.finish(); | ||
|
|
||
| byte[] output = new byte[100]; | ||
| int outputOff = 0; | ||
|
|
||
| while (!compressor.finished()) { | ||
| byte[] buf = new byte[100]; | ||
| int compressed = compressor.compress(buf, 0, buf.length); | ||
| System.arraycopy(buf, 0, output, outputOff, compressed); | ||
| outputOff += compressed; | ||
| } | ||
|
|
||
| DataInputBuffer gzbuf = new DataInputBuffer(); | ||
| gzbuf.reset(output, outputOff); | ||
|
|
||
| Decompressor decom = codec.createDecompressor(); | ||
| assertThat(decom).as("decompressor should not be null").isNotNull(); | ||
| assertThat(decom).withFailMessage("should be BuiltInGzipDecompressor") | ||
| .isInstanceOf(BuiltInGzipDecompressor.class); | ||
| try (InputStream gzin = codec.createInputStream(gzbuf, decom); | ||
| DataOutputBuffer dflbuf = new DataOutputBuffer()) { | ||
| dflbuf.reset(); | ||
| IOUtils.copyBytes(gzin, dflbuf, 4096); | ||
| final byte[] dflchk = Arrays.copyOf(dflbuf.getData(), dflbuf.getLength()); | ||
| assertThat(b).as("check decompressed output").isEqualTo(dflchk); | ||
| } | ||
| } | ||
| } | ||
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.
Also, found this bug. If we set an empty input to the compress stream, it will cause endless loop.
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.
can we add a test case for this?
Uh oh!
There was an error while loading. Please reload this page.
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.
Without removing the condition, current test will timeout after removing GzipOutputStream.
Uh oh!
There was an error while loading. Please reload this page.
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.
Do we still need another test for it? We currently have test coverage for it.
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.
Which test is failing before removing the condition? so it passes with the wrapper class but fails after?
Also, we can remove the
currentBufLenvariable now since it is no longer used anywhere else.Uh oh!
There was an error while loading. Please reload this page.
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.
testGzipCodecwill cause timeout after removingGzipOutputStream.Because of this line:
It writes an empty input to the compress stream. Due to this
currentBufLencheck,compresswill return 0 endlessly.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 think it's still good to have a dedicated test for this edge case. We can use
@Test(timeout=<value>)to check the timeout.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 see. let me add one then.
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.
Thanks!
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 one test for empty input case.