Skip to content

Commit

Permalink
ZOOKEEPER-4232: Ensure that ZOOKEEPER-367 test data fails to parse
Browse files Browse the repository at this point in the history
  • Loading branch information
ztzg committed Mar 9, 2021
1 parent 42a5a0b commit c18a895
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.zookeeper.PortAssignment;
import org.apache.zookeeper.ZKTestCase;
Expand Down Expand Up @@ -62,6 +64,24 @@ public void testSnapshotFormatterWithNull() throws Exception {
SnapshotFormatter.main(args);
}

/**
* Verify the SnapshotFormatter fails as expected on corrupted snapshot.
*/
@Test
public void testSnapshotFormatterWithInvalidSnap() throws Exception {
File snapDir = new File(testData, "invalidsnap");
// Broken snapshot introduced by ZOOKEEPER-367, and used to
// demonstrate recovery in testSnapshot below.
File snapfile = new File(new File(snapDir, "version-2"), "snapshot.83f");
String[] args = {snapfile.getCanonicalFile().toString()};
try {
SnapshotFormatter.main(args);
fail("Snapshot '" + snapfile + "' unexpectedly parsed without error.");
} catch (IOException e) {
assertTrue(e.getMessage().contains("Unreasonable length = 977468229"));
}
}

/**
* test the snapshot
* @throws Exception an exception could be expected
Expand Down

0 comments on commit c18a895

Please sign in to comment.