-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
HADOOP-17868. Add more tests for BuiltInGzipCompressor #3336
Conversation
cc @sunchao I added some more compatibility tests between So far, I don't see any incompatibility. |
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.
Looks good, new tests which work reliably are always welcome.
We're adopting AssertJ in new code as part of the move to JUnit 5...it'd be good to use it here. And include error text in each assertion failure.
Imagine you are trying to debug a test for earlier from nothing but the error message. What would you provide in it?
LOG.info("output: " + outputOff); | ||
LOG.info("dflchk: " + dflchk.length); | ||
|
||
assertEquals(outputOff, dflchk.length); |
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.
nit: add an error string in the assert
} | ||
|
||
DataOutputBuffer dflbuf = new DataOutputBuffer(); | ||
GZIPOutputStream gzout = new GZIPOutputStream(dflbuf); |
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.
nit: use try-with-resources so the streams are automatically/always closed
Random r = new Random(); | ||
long seed = r.nextLong(); | ||
r.setSeed(seed); | ||
LOG.info("seed: " + seed); |
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.
nit, use LOG.info("seed {}", seed)
here and the same elsewhere
gzbuf.reset(output, outputLen); | ||
|
||
Decompressor decom = codec.createDecompressor(); | ||
assertNotNull(decom); |
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.
+exception text here and below. Ideally, use AssertJ assertions for new tests
Thanks @steveloughran. I will address the comments. |
Addressed the comments. Use AssertJ assertions and add exception message. |
🎊 +1 overall
This message was automatically generated. |
@steveloughran @sunchao Please take another look. Thanks! |
byte[] b = new byte[inputSize]; | ||
r.nextBytes(b); | ||
|
||
compressor.setInput(b,0, b.length); |
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.
nit: spaces
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);) { |
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.
nit: extra ;
at the end
assertThat(decom).withFailMessage("should be BuiltInGzipDecompressor") | ||
.isInstanceOf(BuiltInGzipDecompressor.class); | ||
try (InputStream gzin = codec.createInputStream(gzbuf, decom);) { | ||
|
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.
nit: remove extra line
.isInstanceOf(BuiltInGzipDecompressor.class); | ||
try (InputStream gzin = codec.createInputStream(gzbuf, decom);) { | ||
|
||
DataOutputBuffer dflbuf = new DataOutputBuffer(); |
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.
nit: put this into the try block too? since it is also a resource that should be closed with a finally block
Configuration conf = new Configuration(); | ||
CompressionCodec codec = ReflectionUtils.newInstance(GzipCodec.class, conf); | ||
|
||
for (int i = 0; i < 100; i++){ |
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 share this code across the 3 tests?
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.
they are somehow different a bit. seems not too much to share between them.
} | ||
|
||
try (DataOutputBuffer dflbuf = new DataOutputBuffer(); | ||
GZIPOutputStream gzout = new GZIPOutputStream(dflbuf);) { |
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.
nit: extra ;
at the end
🎊 +1 overall
This message was automatically generated. |
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.
LGTM. Ping @steveloughran to take another look.
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/compress/TestCodec.java
Outdated
Show resolved
Hide resolved
@steveloughran Is this good for you now? Please take another look. Thanks. |
kindly ping @steveloughran |
As this is test-only change, as I think I should address all comments. If @steveloughran is too busy to response, could we just move forward? @sunchao |
LGTM. @viirya could you address the check style issues - I'll merge this after |
Thanks @sunchao ! Updated. |
🎊 +1 overall
This message was automatically generated. |
@viirya there are still two more tiny style issues |
Fixed. Weird, I didn't see the two in last report. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
No style issue anymore. |
Merged to trunk. Thanks @viirya and @steveloughran ! |
Thank you @sunchao @steveloughran ! |
We added BuiltInGzipCompressor recently. It is better to add more compatibility tests for the compressor.