Skip to content

Apache Lucene open-source search software

SOLR-9570: Fix test failures and start using SolrTestCaseJ4's createTempDir mm

Jan Høydahlaf88e7f54d20
diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.java
index 39bf548e72c..c5a359e08e4 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java
@@ -3362,7 +3362,7 @@ public class SolrCLI {
public UtilsTool(PrintStream stdout) { super(stdout); }
public String getName() {
- return "prestart";
+ return "utils";
}
@SuppressWarnings("static-access")
@@ -3482,7 +3482,7 @@ public class SolrCLI {
-> a.isRegularFile() && String.valueOf(f.getFileName()).endsWith("-console.log"))
.collect(Collectors.toList());
if (files.size() > 0) {
- out("Archiving " + files.size() + " console log files");
+ out("Archiving " + files.size() + " console log files to " + archivePath);
for (Path p : files) {
Files.move(p, archivePath.resolve(p.getFileName()), StandardCopyOption.REPLACE_EXISTING);
}
@@ -3570,7 +3570,7 @@ public class SolrCLI {
throw new Exception("Command requires the -l <log-directory> option");
}
if (!logsPath.isAbsolute()) {
- if (serverPath != null && serverPath.isAbsolute() && serverPath.toFile().exists()) {
+ if (serverPath != null && serverPath.isAbsolute() && Files.exists(serverPath)) {
logsPath = serverPath.resolve(logsPath);
} else {
throw new Exception("Logs directory must be an absolute path, or -s must be supplied");
diff --git a/solr/core/src/test/org/apache/solr/util/UtilsToolTest.java b/solr/core/src/test/org/apache/solr/util/UtilsToolTest.java
index fa39620c21f..6b2d31cdeae 100644
--- a/solr/core/src/test/org/apache/solr/util/UtilsToolTest.java
+++ b/solr/core/src/test/org/apache/solr/util/UtilsToolTest.java
@@ -28,20 +28,18 @@ import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.cli.CommandLine;
+import org.apache.solr.SolrTestCaseJ4;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.apache.solr.util.SolrCLI.findTool;
import static org.apache.solr.util.SolrCLI.parseCmdLine;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
/**
* Unit test for SolrCLI's UtilsTool
*/
-public class UtilsToolTest {
+public class UtilsToolTest extends SolrTestCaseJ4 {
private Path dir;
private SolrCLI.UtilsTool tool;
@@ -60,19 +58,21 @@ public class UtilsToolTest {
"solr_gc_log_2");
@Before
- public void setUp() throws IOException {
- dir = Files.createTempDirectory("Utils Tool Test");
- files.stream().forEach(f -> {
+ public void setUp() throws Exception {
+ super.setUp();
+ dir = createTempDir("Utils Tool Test").toAbsolutePath();
+ files.forEach(f -> {
try {
- dir.resolve(f).toFile().createNewFile();
+ Files.createFile(dir.resolve(f));
} catch (IOException e) {
- assertTrue(false);
+ fail("Error when creating temporary file " + dir.resolve(f));
}
});
}
@After
- public void tearDown() throws IOException {
+ public void tearDown() throws Exception {
+ super.tearDown();
org.apache.commons.io.FileUtils.deleteDirectory(dir.toFile());
}
@@ -128,7 +128,7 @@ public class UtilsToolTest {
} catch (Exception e) {
return;
}
- assertTrue(false);
+ fail("Should have thrown exception if using relative path without -s");
}
@Test