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 680c57a commit 5286405
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;

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 @@ -75,7 +76,25 @@ public void testSnapshotFormatterWithNull() throws Exception {
String[] args = {snapfile.getCanonicalFile().toString()};
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);
Assert.fail("Snapshot '" + snapfile + "' unexpectedly parsed without error.");
} catch (IOException e) {
Assert.assertTrue(e.getMessage().contains("Unreasonable length = 977468229"));
}
}

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

0 comments on commit 5286405

Please sign in to comment.