Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,11 @@ void runCloudExample(CloudExampleParams params) throws Exception {
Locale.ROOT, "Please enter the port for node%d [%d]: ", (n + 1), cloudPorts[n]);
int port = promptForPort(readInput, n + 1, promptMsg, cloudPorts[n]);
while (!isPortAvailable(port)) {
if (usingScriptInputs) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's gnarly bug. Though the fix is good, both for making CI easier but also locally. I've been bit by running a script not realizing I had a zombied solr on port 8984 or was already running it in docker on 8983... and then getting my scripted run blows up obsucrely...

// a retry would consume the next scripted answer as the port
throw new IllegalStateException(
"Port " + port + " from --script-inputs is already being used by another process.");
}
port =
promptForPort(
readInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ public void testSolrCloudExampleWithScriptInputs() throws Exception {

RunExampleTool tool = new RunExampleTool(executor, System.in, runtime);
try {
runTool(tool, toolArgs);
int status = runTool(tool, toolArgs);
assertEquals("tool output: " + runtime.getOutput(), 0, status);
} catch (Exception e) {
System.err.println(
"RunExampleTool failed due to: "
Expand Down Expand Up @@ -635,6 +636,32 @@ public void testSolrCloudExampleWithScriptInputs() throws Exception {
executor.execute(CommandLine.parse("bin/solr stop -p " + bindPort));
}

/** A scripted port that is already in use fails fast instead of consuming later answers. */
@Test
public void testScriptInputsPortInUse() throws Exception {
Path solrHomeDir = ExternalPaths.SERVER_HOME;
if (!Files.isDirectory(solrHomeDir))
fail(solrHomeDir + " not found and is required to run this test!");

try (ServerSocket busy = new ServerSocket(0)) {
String[] toolArgs =
new String[] {
"--example",
"cloud",
"--server-dir",
solrHomeDir.getParent().toString(),
"--example-dir",
createTempDir().toString(),
"--script-inputs",
"1," + busy.getLocalPort() + ",\"coll\",2,2,_default"
};
RunExampleTool tool =
new RunExampleTool(
new RunExampleExecutor(), System.in, new CLITestHelper.TestingRuntime(true));
assertEquals(1, runTool(tool, toolArgs));
}
}

@Test
public void testFailExecuteScript() throws Exception {
Path solrHomeDir = ExternalPaths.SERVER_HOME;
Expand Down
Loading