Extend wait time for connection to Solr
Resolves: https://jira.duraspace.org/browse/VIVO-1612
This commit is contained in:
parent
48df6fa4ac
commit
19a5d60c50
1 changed files with 9 additions and 10 deletions
|
@ -5,7 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.SocketTimeoutException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
@ -205,6 +204,8 @@ public class SolrSmokeTest {
|
||||||
*/
|
*/
|
||||||
private static class SolrHomePager {
|
private static class SolrHomePager {
|
||||||
private static final long SLEEP_INTERVAL = 20000; // 20 seconds
|
private static final long SLEEP_INTERVAL = 20000; // 20 seconds
|
||||||
|
private static final long SLEEP_MAX = 300000; // maximum sleep time: 5 minutes
|
||||||
|
private static long SLEEP_DURATION = 0; // how long have we been sleeping?
|
||||||
|
|
||||||
private final URL solrUrl;
|
private final URL solrUrl;
|
||||||
private final HttpClient httpClient = HttpClientFactory.getHttpClient();
|
private final HttpClient httpClient = HttpClientFactory.getHttpClient();
|
||||||
|
@ -218,12 +219,7 @@ public class SolrSmokeTest {
|
||||||
public void connect() throws SolrProblemException {
|
public void connect() throws SolrProblemException {
|
||||||
tryToConnect();
|
tryToConnect();
|
||||||
|
|
||||||
if (!isDone()) {
|
while (!isDone() && SLEEP_DURATION < SLEEP_MAX) {
|
||||||
sleep();
|
|
||||||
tryToConnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isDone()) {
|
|
||||||
sleep();
|
sleep();
|
||||||
tryToConnect();
|
tryToConnect();
|
||||||
}
|
}
|
||||||
|
@ -234,17 +230,19 @@ public class SolrSmokeTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToConnect() throws SolrProblemException {
|
private void tryToConnect() throws SolrProblemException {
|
||||||
|
SolrSmokeTest.log.debug("Trying to connect to Solr, wait up to " + SLEEP_MAX / 60000 + " minutes - " +
|
||||||
|
(int)(SLEEP_DURATION * 100.0 / SLEEP_MAX) + "%");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpGet method = new HttpGet(solrUrl.toExternalForm() + "/select");
|
HttpGet method = new HttpGet(solrUrl.toExternalForm() + "/select");
|
||||||
SolrSmokeTest.log.debug("Trying to connect to Solr");
|
HttpResponse response = httpClient.execute(method);
|
||||||
HttpResponse response = httpClient.execute(method);
|
|
||||||
try {
|
try {
|
||||||
statusCode = response.getStatusLine().getStatusCode();
|
statusCode = response.getStatusLine().getStatusCode();
|
||||||
SolrSmokeTest.log.debug("HTTP status was " + statusCode);
|
SolrSmokeTest.log.debug("HTTP status was " + statusCode);
|
||||||
} finally {
|
} finally {
|
||||||
EntityUtils.consume(response.getEntity());
|
EntityUtils.consume(response.getEntity());
|
||||||
}
|
}
|
||||||
} catch (SocketTimeoutException e) {
|
} catch (IOException e) {
|
||||||
// Catch the exception so we can retry this.
|
// Catch the exception so we can retry this.
|
||||||
// Save the status so we know why we failed.
|
// Save the status so we know why we failed.
|
||||||
statusCode = SolrSmokeTest.SOCKET_TIMEOUT_STATUS;
|
statusCode = SolrSmokeTest.SOCKET_TIMEOUT_STATUS;
|
||||||
|
@ -264,6 +262,7 @@ public class SolrSmokeTest {
|
||||||
|
|
||||||
private void sleep() {
|
private void sleep() {
|
||||||
try {
|
try {
|
||||||
|
SLEEP_DURATION += SLEEP_INTERVAL;
|
||||||
Thread.sleep(SLEEP_INTERVAL);
|
Thread.sleep(SLEEP_INTERVAL);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace(); // Should never happen
|
e.printStackTrace(); // Should never happen
|
||||||
|
|
Loading…
Add table
Reference in a new issue