mirror of https://github.com/apache/lucene.git
SOLR-9570: Fix test failures and start using SolrTestCaseJ4's createTempDir mm
This commit is contained in:
parent
a4952b11fe
commit
af88e7f54d
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue