You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by gu...@apache.org on 2015/11/21 00:37:17 UTC
kafka git commit: KAFKA-2718: Avoid reusing temporary directories in
core unit tests
Repository: kafka
Updated Branches:
refs/heads/trunk a7726ee65 -> 0d68eb73f
KAFKA-2718: Avoid reusing temporary directories in core unit tests
Retry to find new directory and cleanup on exit.
Author: Rajini Sivaram <ra...@googlemail.com>
Reviewers: Ismael Juma, Guozhang Wang
Closes #399 from rajinisivaram/KAFKA-2718
Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/0d68eb73
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/0d68eb73
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/0d68eb73
Branch: refs/heads/trunk
Commit: 0d68eb73f3af8d0e8e32a1e61d8a569c615c3c8c
Parents: a7726ee
Author: Rajini Sivaram <ra...@googlemail.com>
Authored: Fri Nov 20 15:36:59 2015 -0800
Committer: Guozhang Wang <gu...@Guozhang-Macbook.local>
Committed: Fri Nov 20 15:36:59 2015 -0800
----------------------------------------------------------------------
.../test/scala/unit/kafka/utils/TestUtils.scala | 27 ++++++++++----------
1 file changed, 14 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kafka/blob/0d68eb73/core/src/test/scala/unit/kafka/utils/TestUtils.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/utils/TestUtils.scala b/core/src/test/scala/unit/kafka/utils/TestUtils.scala
index 4059512..2f734f6 100755
--- a/core/src/test/scala/unit/kafka/utils/TestUtils.scala
+++ b/core/src/test/scala/unit/kafka/utils/TestUtils.scala
@@ -85,17 +85,7 @@ object TestUtils extends Logging {
* Create a temporary directory
*/
def tempDir(): File = {
- val f = new File(IoTmpDir, "kafka-" + random.nextInt(1000000))
- f.mkdirs()
- f.deleteOnExit()
-
- Runtime.getRuntime().addShutdownHook(new Thread() {
- override def run() = {
- CoreUtils.rm(f)
- }
- })
-
- f
+ tempRelativeDir(IoTmpDir)
}
def tempTopic(): String = "testTopic" + random.nextInt(1000000)
@@ -104,12 +94,23 @@ object TestUtils extends Logging {
* Create a temporary relative directory
*/
def tempRelativeDir(parent: String): File = {
- val f = new File(parent, "kafka-" + random.nextInt(1000000))
- f.mkdirs()
+ new File(parent).mkdirs()
+ val attempts = 1000
+ val f = Iterator.continually(new File(parent, "kafka-" + random.nextInt(1000000)))
+ .take(attempts).find(_.mkdir())
+ .getOrElse(sys.error(s"Failed to create directory after $attempts attempts"))
f.deleteOnExit()
+
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ override def run() = {
+ CoreUtils.rm(f)
+ }
+ })
+
f
}
+
/**
* Create a temporary file
*/