File directory = new File(System.getProperty("tempDir", System.getProperty("java.io.tmpdir")));
assert directory.exists() &&
directory.isDirectory() &&
directory.canWrite();
RandomizedContext ctx = RandomizedContext.current();
Class<?> clazz = ctx.getTargetClass();
String prefix = clazz.getName();
prefix = prefix.replaceFirst("^org.apache.lucene.", "lucene.");
prefix = prefix.replaceFirst("^org.apache.solr.", "solr.");
int attempt = 0;
File f;
do {
if (attempt++ >= TEMP_NAME_RETRY_THRESHOLD) {
throw new RuntimeException(
"Failed to get a temporary name too many times, check your temp directory and consider manually cleaning it: "
+ directory.getAbsolutePath());
}
f = new File(directory, prefix + "-" + ctx.getRunnerSeedAsString()
+ "-" + String.format(Locale.ENGLISH, "%03d", attempt));
} while (!f.mkdirs());
tempDirBase = f;
registerToRemoveAfterSuite(tempDirBase);