mirror of https://github.com/apache/lucene.git
SOLR-9745: fix solr.cmd to print errors from invoked script
This commit is contained in:
parent
52632cfc0c
commit
65b4530fb3
|
@ -190,6 +190,8 @@ Other Changes
|
|||
|
||||
* SOLR-8906: Make transient core cache pluggable (Erick Erickson)
|
||||
|
||||
* SOLR-9745: print errors from solr.cmd (Gopikannan Venugopalsamy via Mikhail Khludnev)
|
||||
|
||||
================== 6.5.1 ==================
|
||||
|
||||
Bug Fixes
|
||||
|
|
|
@ -62,6 +62,7 @@ import org.apache.commons.cli.Options;
|
|||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.commons.exec.DefaultExecuteResultHandler;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.ExecuteException;
|
||||
import org.apache.commons.exec.Executor;
|
||||
import org.apache.commons.exec.OS;
|
||||
import org.apache.commons.exec.environment.EnvironmentUtils;
|
||||
|
@ -2928,18 +2929,25 @@ public class SolrCLI {
|
|||
}
|
||||
}
|
||||
}
|
||||
executor.execute(org.apache.commons.exec.CommandLine.parse(startCmd), startEnv, new DefaultExecuteResultHandler());
|
||||
DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
|
||||
executor.execute(org.apache.commons.exec.CommandLine.parse(startCmd), startEnv, handler);
|
||||
|
||||
// brief wait before proceeding on Windows
|
||||
// wait for execution.
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
handler.waitFor();
|
||||
} catch (InterruptedException ie) {
|
||||
// safe to ignore ...
|
||||
Thread.interrupted();
|
||||
}
|
||||
|
||||
if (handler.getExitValue() != 0) {
|
||||
throw new Exception("Failed to start Solr using command: "+startCmd+" Exception : "+handler.getException());
|
||||
}
|
||||
} else {
|
||||
code = executor.execute(org.apache.commons.exec.CommandLine.parse(startCmd));
|
||||
try {
|
||||
code = executor.execute(org.apache.commons.exec.CommandLine.parse(startCmd));
|
||||
} catch(ExecuteException e){
|
||||
throw new Exception("Failed to start Solr using command: "+startCmd+" Exception : "+ e);
|
||||
}
|
||||
}
|
||||
if (code != 0)
|
||||
throw new Exception("Failed to start Solr using command: "+startCmd);
|
||||
|
|
|
@ -482,4 +482,42 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
|
|||
// stop the test instance
|
||||
executor.execute(org.apache.commons.exec.CommandLine.parse("bin/solr stop -p "+bindPort));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailExecuteScript() throws Exception {
|
||||
File solrHomeDir = new File(ExternalPaths.SERVER_HOME);
|
||||
if (!solrHomeDir.isDirectory())
|
||||
fail(solrHomeDir.getAbsolutePath()+" not found and is required to run this test!");
|
||||
|
||||
Path tmpDir = createTempDir();
|
||||
File solrExampleDir = tmpDir.toFile();
|
||||
File solrServerDir = solrHomeDir.getParentFile();
|
||||
|
||||
// need a port to start the example server on
|
||||
int bindPort = -1;
|
||||
try (ServerSocket socket = new ServerSocket(0)) {
|
||||
bindPort = socket.getLocalPort();
|
||||
}
|
||||
|
||||
File toExecute = new File(tmpDir.toString(), "failExecuteScript");
|
||||
assertTrue("Should have been able to create file '" + toExecute.getAbsolutePath() + "' ", toExecute.createNewFile());
|
||||
|
||||
String[] toolArgs = new String[] {
|
||||
"-e", "techproducts",
|
||||
"-serverDir", solrServerDir.getAbsolutePath(),
|
||||
"-exampleDir", solrExampleDir.getAbsolutePath(),
|
||||
"-p", String.valueOf(bindPort),
|
||||
"-script", toExecute.getAbsolutePath().toString()
|
||||
};
|
||||
|
||||
// capture tool output to stdout
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintStream stdoutSim = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
|
||||
|
||||
DefaultExecutor executor = new DefaultExecutor();
|
||||
|
||||
SolrCLI.RunExampleTool tool = new SolrCLI.RunExampleTool(executor, System.in, stdoutSim);
|
||||
int code = tool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(tool.getOptions()), toolArgs));
|
||||
assertTrue("Execution should have failed with return code 1", code == 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue