From 680c57ad24ed654b8260c117735c3e58a8ff418f 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 7de4c175f47..0437555bff3 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,7 +21,7 @@ import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; 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; @@ -82,7 +82,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]);