BryanDavis has uploaded a new change for review. https://gerrit.wikimedia.org/r/254350
Change subject: Create and cleanup temp dirs in TestCamusPartitionChecker.scala ...................................................................... Create and cleanup temp dirs in TestCamusPartitionChecker.scala Add a proper temp directory factory for use in tests that modify the file system rather than relying on a shared testing directory and cleanup at the start of the test. Each test invocation will securely create a temporary directory and hang on to it in a class variable so that it can be cleaned up by afterEach(). Bug: T119101 Change-Id: I399aff9f3a0b928cc0ab0c2e78278526778a0db7 --- M refinery-job/src/test/scala/org/wikimedia/analytics/refinery/job/TestCamusPartitionChecker.scala 1 file changed, 27 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/analytics/refinery/source refs/changes/50/254350/1 diff --git a/refinery-job/src/test/scala/org/wikimedia/analytics/refinery/job/TestCamusPartitionChecker.scala b/refinery-job/src/test/scala/org/wikimedia/analytics/refinery/job/TestCamusPartitionChecker.scala index 1ac4c62..44c9e7a 100644 --- a/refinery-job/src/test/scala/org/wikimedia/analytics/refinery/job/TestCamusPartitionChecker.scala +++ b/refinery-job/src/test/scala/org/wikimedia/analytics/refinery/job/TestCamusPartitionChecker.scala @@ -15,9 +15,27 @@ val noHourRunFolder = "2015-09-29-15-20-08" val hourSpanRunFolder = "2015-10-02-08-00-07" val wrongFolder = "wrong-folder" + var tmpDir:File = null override def beforeEach(): Unit = { CamusPartitionChecker.props.clear() + } + + override def afterEach(): Unit = { + if (tmpDir != null && tmpDir.exists()) { + val d = new Directory(tmpDir) + d.deleteRecursively() + } + } + + def createTempDir(): File = { + val baseDir:File = new File(System.getProperty("java.io.tmpdir")) + val baseName:String = "testcamus-" + System.currentTimeMillis() + "-"; + for (i <- 0 to 10000) { + val tempDir:File = new File(baseDir, baseName + i) + if (tempDir.mkdir()) return tempDir + } + throw new IllegalStateException("Failed to create temp directory"); } "A CamusChecker" should "find hours in between timestamps" in { @@ -156,32 +174,30 @@ } it should "write the file flag for a given partition hour" in { - val partitionFolder = "/tmp/testcamus/testtopic/hourly/2015/10/02/08" - val d = new Directory(new File(partitionFolder)) - if (d.exists) - d.deleteRecursively() + tmpDir = createTempDir() + val partitionFolder = "testtopic/hourly/2015/10/02/08" + val d = new Directory(new File(tmpDir, partitionFolder)) d.createDirectory() d.list shouldBe empty // correct partition base path config - CamusPartitionChecker.props.setProperty(CamusPartitionChecker.PARTITION_BASE_PATH, "/tmp/testcamus/") + CamusPartitionChecker.props.setProperty(CamusPartitionChecker.PARTITION_BASE_PATH, tmpDir.getAbsolutePath()) CamusPartitionChecker.flagFullyImportedPartitions("_TESTFLAG", false, Map("testtopic" -> Seq((2015, 10, 2, 8)))) d.list should not be empty - d.list.toSeq.map(_.toString()) should contain ("/tmp/testcamus/testtopic/hourly/2015/10/02/08/_TESTFLAG") + d.list.toSeq.map(_.toString()) should contain (tmpDir.getAbsolutePath() + "/testtopic/hourly/2015/10/02/08/_TESTFLAG") } it should "fail writing the file flag if the given partition hour folder doesn't exist" in { - val partitionFolder = "/tmp/testcamus/testtopic/hourly/2015/10/02/08" - val d = new Directory (new File(partitionFolder)) - if (d.exists) - d.deleteRecursively() + tmpDir = createTempDir() + val partitionFolder = "testtopic/hourly/2015/10/02/08" + val d = new Directory (new File(tmpDir, partitionFolder)) // correct partition base path config - CamusPartitionChecker.props.setProperty(CamusPartitionChecker.PARTITION_BASE_PATH, "/tmp/testcamus/") + CamusPartitionChecker.props.setProperty(CamusPartitionChecker.PARTITION_BASE_PATH, tmpDir.getAbsolutePath()) intercept[IllegalStateException] { CamusPartitionChecker.flagFullyImportedPartitions("_TESTFLAG", false, Map("testtopic" -> Seq((2015, 10, 2, 8)))) -- To view, visit https://gerrit.wikimedia.org/r/254350 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I399aff9f3a0b928cc0ab0c2e78278526778a0db7 Gerrit-PatchSet: 1 Gerrit-Project: analytics/refinery/source Gerrit-Branch: master Gerrit-Owner: BryanDavis <bda...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits