Merge pull request #122 from awoods/vivo-1612

Extend wait time for connection to Solr
This commit is contained in:
Ralph O'Flinn 2019-06-21 08:48:22 -05:00 committed by GitHub
commit 279c018a00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,9 +230,11 @@ 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();
@ -244,7 +242,7 @@ public class SolrSmokeTest {
} 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