[FLINK-6320] fix unit test failing sometimes when deleting a temp directory
This closes #3966. Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/6ad3d140 Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/6ad3d140 Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/6ad3d140 Branch: refs/heads/master Commit: 6ad3d140f35722055c9011dbee88d19319cfbfbe Parents: fe67147 Author: Nico Kruber <[email protected]> Authored: Mon May 22 16:31:08 2017 +0200 Committer: zentol <[email protected]> Committed: Wed May 24 16:46:03 2017 +0200 ---------------------------------------------------------------------- .../JobManagerHAJobGraphRecoveryITCase.java | 36 ++++++-------------- 1 file changed, 10 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/6ad3d140/flink-tests/src/test/java/org/apache/flink/test/recovery/JobManagerHAJobGraphRecoveryITCase.java ---------------------------------------------------------------------- diff --git a/flink-tests/src/test/java/org/apache/flink/test/recovery/JobManagerHAJobGraphRecoveryITCase.java b/flink-tests/src/test/java/org/apache/flink/test/recovery/JobManagerHAJobGraphRecoveryITCase.java index 052195a..80b8e18 100644 --- a/flink-tests/src/test/java/org/apache/flink/test/recovery/JobManagerHAJobGraphRecoveryITCase.java +++ b/flink-tests/src/test/java/org/apache/flink/test/recovery/JobManagerHAJobGraphRecoveryITCase.java @@ -49,7 +49,6 @@ import org.apache.flink.runtime.taskmanager.TaskManager; import org.apache.flink.runtime.testingUtils.TestingCluster; import org.apache.flink.runtime.testingUtils.TestingUtils; import org.apache.flink.runtime.testtasks.BlockingNoOpInvokable; -import org.apache.flink.runtime.testutils.CommonTestUtils; import org.apache.flink.runtime.testutils.JobManagerActorTestUtils; import org.apache.flink.runtime.testutils.JobManagerProcess; import org.apache.flink.runtime.testutils.ZooKeeperTestUtils; @@ -58,7 +57,9 @@ import org.apache.flink.util.TestLogger; import org.apache.zookeeper.data.Stat; import org.junit.AfterClass; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import scala.Option; import scala.Some; import scala.Tuple2; @@ -68,7 +69,6 @@ import scala.concurrent.duration.Deadline; import scala.concurrent.duration.FiniteDuration; import java.io.File; -import java.io.IOException; import java.util.Collection; import java.util.Queue; import java.util.UUID; @@ -88,32 +88,16 @@ public class JobManagerHAJobGraphRecoveryITCase extends TestLogger { private final static FiniteDuration TestTimeOut = new FiniteDuration(5, TimeUnit.MINUTES); - private static final File FileStateBackendBasePath; - - static { - try { - FileStateBackendBasePath = CommonTestUtils.createTempDirectory(); - } - catch (IOException e) { - throw new RuntimeException("Error in test setup. Could not create directory.", e); - } - } + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); @AfterClass public static void tearDown() throws Exception { ZooKeeper.shutdown(); - - if (FileStateBackendBasePath != null) { - FileUtils.deleteDirectory(FileStateBackendBasePath); - } } @Before public void cleanUp() throws Exception { - if (FileStateBackendBasePath != null) { - FileUtils.cleanDirectory(FileStateBackendBasePath); - } - ZooKeeper.deleteAll(); } @@ -125,7 +109,7 @@ public class JobManagerHAJobGraphRecoveryITCase extends TestLogger { @Test public void testJobPersistencyWhenJobManagerShutdown() throws Exception { Configuration config = ZooKeeperTestUtils.createZooKeeperHAConfig( - ZooKeeper.getConnectString(), FileStateBackendBasePath.getPath()); + ZooKeeper.getConnectString(), tempFolder.getRoot().getPath()); // Configure the cluster config.setInteger(ConfigConstants.LOCAL_NUMBER_JOB_MANAGER, 1); @@ -172,7 +156,7 @@ public class JobManagerHAJobGraphRecoveryITCase extends TestLogger { @Test public void testClientNonDetachedListeningBehaviour() throws Exception { Configuration config = ZooKeeperTestUtils.createZooKeeperHAConfig( - ZooKeeper.getConnectString(), FileStateBackendBasePath.getPath()); + ZooKeeper.getConnectString(), tempFolder.getRoot().getPath()); // Test actor system ActorSystem testSystem = null; @@ -397,10 +381,10 @@ public class JobManagerHAJobGraphRecoveryITCase extends TestLogger { /** * Fails the test if the recovery state (file state backend and ZooKeeper) is not clean. */ - private static void verifyCleanRecoveryState(Configuration config) throws Exception { + private void verifyCleanRecoveryState(Configuration config) throws Exception { // File state backend empty Collection<File> stateHandles = FileUtils.listFiles( - FileStateBackendBasePath, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); + tempFolder.getRoot(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); if (!stateHandles.isEmpty()) { fail("File state backend is not clean: " + stateHandles); @@ -429,10 +413,10 @@ public class JobManagerHAJobGraphRecoveryITCase extends TestLogger { /** * Fails the test if the recovery state (file state backend and ZooKeeper) has been cleaned. */ - private static void verifyRecoveryState(Configuration config) throws Exception { + private void verifyRecoveryState(Configuration config) throws Exception { // File state backend empty Collection<File> stateHandles = FileUtils.listFiles( - FileStateBackendBasePath, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); + tempFolder.getRoot(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); if (stateHandles.isEmpty()) { fail("File state backend has been cleaned: " + stateHandles);
