mirror of https://github.com/apache/lucene.git
SOLR-13036 Fix retry logic in JettySolrRunner
This commit is contained in:
parent
e14432efd8
commit
59919b4ac0
|
@ -113,6 +113,8 @@ Other Changes
|
||||||
* SOLR-12775: LowerCaseTokenizer is deprecated, and should be replaced by LetterTokenizer and
|
* SOLR-12775: LowerCaseTokenizer is deprecated, and should be replaced by LetterTokenizer and
|
||||||
LowerCaseFilter (Alan Woodward)
|
LowerCaseFilter (Alan Woodward)
|
||||||
|
|
||||||
|
* SOLR-13036: Fix retry logic in JettySolrRunner (Gus Heck)
|
||||||
|
|
||||||
================== 7.7.0 ==================
|
================== 7.7.0 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
@ -172,6 +174,9 @@ Other Changes
|
||||||
|
|
||||||
* SOLR-12932: ant test (without badapples=false) should pass easily for developers. (Mark Miller)
|
* SOLR-12932: ant test (without badapples=false) should pass easily for developers. (Mark Miller)
|
||||||
|
|
||||||
|
* SOLR-13036: Fix retry logic in JettySolrRunner (Gus Heck)
|
||||||
|
|
||||||
|
|
||||||
================== 7.6.0 ==================
|
================== 7.6.0 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
|
|
@ -509,12 +509,15 @@ public class JettySolrRunner {
|
||||||
log.info("Trying to start Jetty on port {} try number {} ...", port, tryCnt++);
|
log.info("Trying to start Jetty on port {} try number {} ...", port, tryCnt++);
|
||||||
server.start();
|
server.start();
|
||||||
break;
|
break;
|
||||||
} catch (BindException e) {
|
} catch (IOException ioe) {
|
||||||
log.info("Port is in use, will try again until timeout of " + timeout);
|
Exception e = lookForBindException(ioe);
|
||||||
server.stop();
|
if (e instanceof BindException) {
|
||||||
Thread.sleep(3000);
|
log.info("Port is in use, will try again until timeout of " + timeout);
|
||||||
if (!timeout.hasTimedOut()) {
|
server.stop();
|
||||||
continue;
|
Thread.sleep(3000);
|
||||||
|
if (!timeout.hasTimedOut()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -522,6 +525,26 @@ public class JettySolrRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Traverses the cause chain looking for a BindException. Returns either a bind exception
|
||||||
|
* that was found in the chain or the original argument.
|
||||||
|
*
|
||||||
|
* @param ioe An IOException that might wrap a BindException
|
||||||
|
* @return A bind exception if present otherwise ioe
|
||||||
|
*/
|
||||||
|
Exception lookForBindException(IOException ioe) {
|
||||||
|
Exception e = ioe;
|
||||||
|
while(e.getCause() != null && !(e == e.getCause()) && ! (e instanceof BindException)) {
|
||||||
|
if (e.getCause() instanceof Exception) {
|
||||||
|
e = (Exception) e.getCause();
|
||||||
|
if (e instanceof BindException) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ioe;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop the Jetty server
|
* Stop the Jetty server
|
||||||
*
|
*
|
||||||
|
|
|
@ -19,8 +19,12 @@ package org.apache.solr.client.solrj.embedded;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
||||||
|
import org.apache.solr.cloud.MiniSolrCloudCluster;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.BindException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -62,11 +66,56 @@ public class TestJettySolrRunner extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
assertTrue(Files.exists(coresDir.resolve("newcore").resolve("core.properties")));
|
assertTrue(Files.exists(coresDir.resolve("newcore").resolve("core.properties")));
|
||||||
|
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
runner.stop();
|
runner.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("ThrowableNotThrown")
|
||||||
|
@Test
|
||||||
|
public void testLookForBindException() throws IOException {
|
||||||
|
Path solrHome = createTempDir();
|
||||||
|
Files.write(solrHome.resolve("solr.xml"), MiniSolrCloudCluster.DEFAULT_CLOUD_SOLR_XML.getBytes(Charset.defaultCharset()));
|
||||||
|
|
||||||
|
JettyConfig config = JettyConfig.builder().build();
|
||||||
|
|
||||||
|
JettySolrRunner jetty = new JettySolrRunner(solrHome.toString(), config);
|
||||||
|
|
||||||
|
Exception result;
|
||||||
|
BindException be = new BindException();
|
||||||
|
IOException test = new IOException();
|
||||||
|
|
||||||
|
result = jetty.lookForBindException(test);
|
||||||
|
assertEquals(result, test);
|
||||||
|
|
||||||
|
test = new IOException();
|
||||||
|
result = jetty.lookForBindException(test);
|
||||||
|
assertEquals(result, test);
|
||||||
|
|
||||||
|
test = new IOException((Throwable) null);
|
||||||
|
result = jetty.lookForBindException(test);
|
||||||
|
assertEquals(result, test);
|
||||||
|
|
||||||
|
test = new IOException() {
|
||||||
|
@Override
|
||||||
|
public synchronized Throwable getCause() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
result = jetty.lookForBindException(test);
|
||||||
|
assertEquals(result, test);
|
||||||
|
|
||||||
|
test = new IOException(new RuntimeException());
|
||||||
|
result = jetty.lookForBindException(test);
|
||||||
|
assertEquals(result, test);
|
||||||
|
|
||||||
|
test = new IOException(new RuntimeException(be));
|
||||||
|
result = jetty.lookForBindException(test);
|
||||||
|
assertEquals(result, be);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue