From a8ce9e5117f6447ea3b7b24caa5f5dec344aed85 Mon Sep 17 00:00:00 2001 From: Damien Diederen Date: Sat, 6 Mar 2021 19:12:05 +0100 Subject: [PATCH] ZOOKEEPER-4232: Run InvalidSnapshotTest on a copy of test data Without this, the ZooKeeperServer "fixes" the 'snapshot.83f' reference file, which: 1. Makes the test ineffective after the first run; 2. Causes the file to show as modified in version control tools; 3. Can end up committed by accident. This patch creates a temporary copy of the data directory. --- .../org/apache/zookeeper/test/InvalidSnapshotTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/InvalidSnapshotTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/InvalidSnapshotTest.java index 9f458cb7776..c9c229289f4 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/InvalidSnapshotTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/InvalidSnapshotTest.java @@ -21,6 +21,7 @@ import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; import static org.junit.Assert.assertTrue; import java.io.File; +import org.apache.commons.io.FileUtils; import org.apache.zookeeper.PortAssignment; import org.apache.zookeeper.ZKTestCase; import org.apache.zookeeper.ZooKeeper; @@ -79,7 +80,12 @@ public void testSnapshotFormatterWithNull() throws Exception { */ @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]);