Skip to content
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

ZOOKEEPER-4232: InvalidSnapshotTest corrupts its own test data #1622

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

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;
import org.apache.zookeeper.ZooKeeper;
Expand Down Expand Up @@ -61,13 +64,36 @@ 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
*/
@Test
public void testSnapshot() throws Exception {
File snapDir = new File(testData, "invalidsnap");
File origSnapDir = new File(testData, "invalidsnap");

// This test otherwise updates the resources directory.
File snapDir = ClientBase.createTmpDir();
FileUtils.copyDirectory(origSnapDir, snapDir);

ZooKeeperServer zks = new ZooKeeperServer(snapDir, snapDir, 3000);
SyncRequestProcessor.setSnapCount(1000);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
Expand Down
Binary file not shown.