Skip to content

Commit

Permalink
[java] Use TEST_TMPDIR environment variable in MiniKuduCluster
Browse files Browse the repository at this point in the history
In order to match the functionality of the C++
MiniCluster, this change repects the TEST_TMPDIR
environment variable when creating a temporary
cluster root directory in MiniKuduCluster.java.

Change-Id: I1e3a8bb4e91680a00a0d70f9ad9d29ac6802751c
Reviewed-on: http://gerrit.cloudera.org:8080/10978
Reviewed-by: Adar Dembo <[email protected]>
Tested-by: Grant Henke <[email protected]>
  • Loading branch information
granthenke committed Jul 18, 2018
1 parent 296b05e commit c2cecb0
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -115,7 +115,7 @@ private MiniKuduCluster(boolean enableKerberos,
// If a cluster root was not set, create a unique temp directory to use.
// The mini cluster will clean this directory up on exit.
try {
File tempRoot = Files.createTempDirectory("mini-kudu-cluster").toFile();
File tempRoot = getTempDirectory("mini-kudu-cluster");
this.clusterRoot = tempRoot.toString();
} catch (IOException ex) {
throw new RuntimeException("Could not create cluster root directory", ex);
Expand All @@ -125,6 +125,20 @@ private MiniKuduCluster(boolean enableKerberos,
}
}

// Match the C++ MiniCluster test functionality for overriding the tmp directory used.
// See MakeClusterRoot in src/kudu/tools/tool_action_test.cc.
// If the TEST_TMPDIR environment variable is defined that directory will be used
// instead of the default temp directory.
private File getTempDirectory(String prefix) throws IOException {
String testTmpdir = System.getenv("TEST_TMPDIR");
if (testTmpdir != null) {
LOG.info("Using the temp directory defined by TEST_TMPDIR: " + testTmpdir);
return Files.createTempDirectory(Paths.get(testTmpdir), prefix).toFile();
} else {
return Files.createTempDirectory(prefix).toFile();
}
}

/**
* Sends a command to the control shell and receives its response.
* <p>
Expand Down

0 comments on commit c2cecb0

Please sign in to comment.