Author: hashutosh Date: Fri Dec 20 23:11:07 2013 New Revision: 1552839 URL: http://svn.apache.org/r1552839 Log: HIVE-4831 : QTestUtil based test exiting abnormally on windows fails startup of other QTestUtil tests ( Thejas Nair, Jason Dere via Ashutosh Chauhan)
Modified: hive/trunk/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java Modified: hive/trunk/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java URL: http://svn.apache.org/viewvc/hive/trunk/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java?rev=1552839&r1=1552838&r2=1552839&view=diff ============================================================================== --- hive/trunk/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java (original) +++ hive/trunk/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java Fri Dec 20 23:11:07 2013 @@ -1357,9 +1357,12 @@ public class QTestUtil { public void preTest(HiveConf conf) throws Exception { if (zooKeeperCluster == null) { - String tmpdir = System.getProperty("test.tmp.dir"); + //create temp dir + String tmpBaseDir = System.getProperty("test.tmp.dir"); + File tmpDir = Utilities.createTempDir(tmpBaseDir); + zooKeeperCluster = new MiniZooKeeperCluster(); - zkPort = zooKeeperCluster.startup(new File(tmpdir, "zookeeper")); + zkPort = zooKeeperCluster.startup(tmpDir); } if (zooKeeper != null) { Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java?rev=1552839&r1=1552838&r2=1552839&view=diff ============================================================================== --- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java (original) +++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java Fri Dec 20 23:11:07 2013 @@ -3087,5 +3087,31 @@ public final class Utilities { } } } + + /** + * Create a temp dir in specified baseDir + * This can go away once hive moves to support only JDK 7 + * and can use Files.createTempDirectory + * Guava Files.createTempDir() does not take a base dir + * @param baseDir - directory under which new temp dir will be created + * @return File object for new temp dir + */ + public static File createTempDir(String baseDir){ + //try creating the temp dir MAX_ATTEMPTS times + final int MAX_ATTEMPS = 30; + for(int i = 0; i < MAX_ATTEMPS; i++){ + //pick a random file name + String tempDirName = "tmp_" + ((int)(100000 * Math.random())); + + //return if dir could successfully be created with that file name + File tempDir = new File(baseDir, tempDirName); + if(tempDir.mkdir()){ + return tempDir; + } + } + throw new IllegalStateException("Failed to create a temp dir under " + + baseDir + " Giving up after " + MAX_ATTEMPS + " attemps"); + + } }