mirror of https://github.com/apache/lucene.git
SOLR-9570: Fix test failures and start using SolrTestCaseJ4's createTempDir mm
(cherry picked from commit af88e7f
)
This commit is contained in:
parent
b1e2d02ec3
commit
1b626fa0ca
|
@ -3363,7 +3363,7 @@ public class SolrCLI {
|
||||||
public UtilsTool(PrintStream stdout) { super(stdout); }
|
public UtilsTool(PrintStream stdout) { super(stdout); }
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "prestart";
|
return "utils";
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("static-access")
|
@SuppressWarnings("static-access")
|
||||||
|
@ -3483,7 +3483,7 @@ public class SolrCLI {
|
||||||
-> a.isRegularFile() && String.valueOf(f.getFileName()).endsWith("-console.log"))
|
-> a.isRegularFile() && String.valueOf(f.getFileName()).endsWith("-console.log"))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (files.size() > 0) {
|
if (files.size() > 0) {
|
||||||
out("Archiving " + files.size() + " console log files");
|
out("Archiving " + files.size() + " console log files to " + archivePath);
|
||||||
for (Path p : files) {
|
for (Path p : files) {
|
||||||
Files.move(p, archivePath.resolve(p.getFileName()), StandardCopyOption.REPLACE_EXISTING);
|
Files.move(p, archivePath.resolve(p.getFileName()), StandardCopyOption.REPLACE_EXISTING);
|
||||||
}
|
}
|
||||||
|
@ -3571,7 +3571,7 @@ public class SolrCLI {
|
||||||
throw new Exception("Command requires the -l <log-directory> option");
|
throw new Exception("Command requires the -l <log-directory> option");
|
||||||
}
|
}
|
||||||
if (!logsPath.isAbsolute()) {
|
if (!logsPath.isAbsolute()) {
|
||||||
if (serverPath != null && serverPath.isAbsolute() && serverPath.toFile().exists()) {
|
if (serverPath != null && serverPath.isAbsolute() && Files.exists(serverPath)) {
|
||||||
logsPath = serverPath.resolve(logsPath);
|
logsPath = serverPath.resolve(logsPath);
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Logs directory must be an absolute path, or -s must be supplied");
|
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 java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.apache.solr.util.SolrCLI.findTool;
|
import static org.apache.solr.util.SolrCLI.findTool;
|
||||||
import static org.apache.solr.util.SolrCLI.parseCmdLine;
|
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
|
* Unit test for SolrCLI's UtilsTool
|
||||||
*/
|
*/
|
||||||
public class UtilsToolTest {
|
public class UtilsToolTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
private Path dir;
|
private Path dir;
|
||||||
private SolrCLI.UtilsTool tool;
|
private SolrCLI.UtilsTool tool;
|
||||||
|
@ -60,19 +58,21 @@ public class UtilsToolTest {
|
||||||
"solr_gc_log_2");
|
"solr_gc_log_2");
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws Exception {
|
||||||
dir = Files.createTempDirectory("Utils Tool Test");
|
super.setUp();
|
||||||
files.stream().forEach(f -> {
|
dir = createTempDir("Utils Tool Test").toAbsolutePath();
|
||||||
|
files.forEach(f -> {
|
||||||
try {
|
try {
|
||||||
dir.resolve(f).toFile().createNewFile();
|
Files.createFile(dir.resolve(f));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
assertTrue(false);
|
fail("Error when creating temporary file " + dir.resolve(f));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws IOException {
|
public void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
org.apache.commons.io.FileUtils.deleteDirectory(dir.toFile());
|
org.apache.commons.io.FileUtils.deleteDirectory(dir.toFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class UtilsToolTest {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(false);
|
fail("Should have thrown exception if using relative path without -s");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue