Skip to content

Commit

Permalink
Fix non-corruption in testCurrentHeaderVersion (elastic#50883)
Browse files Browse the repository at this point in the history
Today we make multiple attempts to corrupt the translog header in
`TranslogHeaderTests#testCurrentHeaderVersion`, but if we are extraordinarily
unlucky then this sequence of corruptions may restore the file to its original
state. This change adjusts the test to only corrupt the file once, which is
certain not to leave the file in its original state.
  • Loading branch information
DaveCTurner authored and SivagurunathanV committed Jan 21, 2020
1 parent 842a208 commit c289beb
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ public void testCurrentHeaderVersion() throws Exception {
}
final TranslogCorruptedException mismatchUUID = expectThrows(TranslogCorruptedException.class, () -> {
try (FileChannel channel = FileChannel.open(translogFile, StandardOpenOption.READ)) {
TranslogHeader.read(UUIDs.randomBase64UUID(), translogFile, channel);
TranslogHeader.read(randomValueOtherThan(translogUUID, UUIDs::randomBase64UUID), translogFile, channel);
}
});
assertThat(mismatchUUID.getMessage(), containsString("this translog file belongs to a different translog"));
int corruptions = between(1, 10);
for (int i = 0; i < corruptions && Files.size(translogFile) > 0; i++) {
TestTranslog.corruptFile(logger, random(), translogFile, false);
}
TestTranslog.corruptFile(logger, random(), translogFile, false);
final TranslogCorruptedException corruption = expectThrows(TranslogCorruptedException.class, () -> {
try (FileChannel channel = FileChannel.open(translogFile, StandardOpenOption.READ)) {
TranslogHeader.read(randomBoolean() ? outHeader.getTranslogUUID() : UUIDs.randomBase64UUID(), translogFile, channel);
Expand Down

0 comments on commit c289beb

Please sign in to comment.