KAFKA-14712: Produce correct error msg with correct metadataversion#13773
Conversation
Fix the confusing error message
|
@mumrah can I ask for your review ? Thanks |
|
@Owen-CH-Leung , thanks for the patch, could you add tests for this change? |
|
@showuon Thanks a lot for your feedback. I've added tests to test the |
mumrah
left a comment
There was a problem hiding this comment.
Hi @Owen-CH-Leung, thanks for the patch! I've made a few suggestions in the PR.
| public final class ImageWriterOptions { | ||
| public static class Builder { | ||
| private MetadataVersion metadataVersion; | ||
| private MetadataVersion orgMetadataVersion; |
There was a problem hiding this comment.
How about "requestedMetadataVersion" ?
There was a problem hiding this comment.
Thanks. Refactored to requestedMetadataVersion
| setOrgMetadataVersion(metadataVersion); | ||
| setRawMetadataVersion(MetadataVersion.MINIMUM_KRAFT_VERSION); | ||
| } else { | ||
| setRawMetadataVersion(metadataVersion); |
There was a problem hiding this comment.
Let's set both metadata versions here as well so we don't have to deal with a null later
There was a problem hiding this comment.
Sure. I've set both fields in this function call. Note that I've also modified the ImageDowngradeTest to use the setMetadataVersion instead of setRawMetadataVersion (Maybe we should change setRawMetadataVersion to private` also ?)
|
@Owen-CH-Leung , please try to rebase to the latest trunk branch, the failed |
|
@showuon Thanks. I just rebase to the latest trunk branch. But I saw there're still tests failed for |
showuon
left a comment
There was a problem hiding this comment.
@Owen-CH-Leung , thanks for the PR. Left a comment to the test.
| for (int i = MetadataVersion.MINIMUM_KRAFT_VERSION.ordinal(); | ||
| i < MetadataVersion.VERSIONS.length; | ||
| i++) { | ||
| ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
| MetadataVersion version = MetadataVersion.VERSIONS[i]; | ||
| ImageWriterOptions options = new ImageWriterOptions.Builder() | ||
| .setMetadataVersion(version) | ||
| .setLossHandler(customLossHandler) | ||
| .build(); | ||
| System.setOut(new PrintStream(outContent)); | ||
| options.handleLoss(expectedMessage); | ||
| System.setOut(originalOut); | ||
| String formattedMessage = String.format("Metadata has been lost because the following could not be represented in metadata version %s: %s", version, expectedMessage); | ||
| assertEquals(formattedMessage, outContent.toString().trim()); | ||
| } |
There was a problem hiding this comment.
I think we can simplify this test as this without relying System.out:
for (int i = MetadataVersion.MINIMUM_KRAFT_VERSION.ordinal();
i < MetadataVersion.VERSIONS.length;
i++) {
MetadataVersion version = MetadataVersion.VERSIONS[i];
String formattedMessage = String.format("Metadata has been lost because the following could not be represented in metadata version %s: %s", version, expectedMessage);
Consumer<UnwritableMetadataException> customLossHandler = e -> {
assertEquals(formattedMessage, e.getMessage());
};
ImageWriterOptions options = new ImageWriterOptions.Builder()
.setMetadataVersion(version)
.setLossHandler(customLossHandler)
.build();
options.handleLoss(expectedMessage);
}
WDYT?
There was a problem hiding this comment.
@showuon Thanks! Yes it's a lot cleaner. I've adopted your suggestion.
| Consumer<UnwritableMetadataException> customLossHandler = e -> { | ||
| assertEquals(formattedMessage, e.getMessage()); | ||
| }; |
There was a problem hiding this comment.
nit: no need curly brackets here.
There was a problem hiding this comment.
ahh yes. Removed it
|
@mumrah , do you want to have another look? I'm going to merge this later this week if no other comments. Thanks. |
|
Failed tests are unrelated: |
…pache#13773) Fix the confusing error message in ImageWriterOptions Reviewers: Luke Chen <showuon@gmail.com>, David Arthur <mumrah@gmail.com>
…pache#13773) Fix the confusing error message in ImageWriterOptions Reviewers: Luke Chen <showuon@gmail.com>, David Arthur <mumrah@gmail.com>
Fix the confusing error message
Committer Checklist (excluded from commit message)