From 19a5d60c50e94052daa2b4ce73240356b69c8de3 Mon Sep 17 00:00:00 2001 From: Andrew Woods Date: Wed, 15 May 2019 09:40:02 -0400 Subject: [PATCH] Extend wait time for connection to Solr Resolves: https://jira.duraspace.org/browse/VIVO-1612 --- .../webapp/servlet/setup/SolrSmokeTest.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/SolrSmokeTest.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/SolrSmokeTest.java index c75b0ad2b..b962ec33c 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/SolrSmokeTest.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/SolrSmokeTest.java @@ -5,7 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup; import java.io.IOException; import java.net.ConnectException; import java.net.MalformedURLException; -import java.net.SocketTimeoutException; import java.net.URL; import java.net.UnknownHostException; @@ -205,6 +204,8 @@ public class SolrSmokeTest { */ private static class SolrHomePager { 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 HttpClient httpClient = HttpClientFactory.getHttpClient(); @@ -218,12 +219,7 @@ public class SolrSmokeTest { public void connect() throws SolrProblemException { tryToConnect(); - if (!isDone()) { - sleep(); - tryToConnect(); - } - - if (!isDone()) { + while (!isDone() && SLEEP_DURATION < SLEEP_MAX) { sleep(); tryToConnect(); } @@ -234,17 +230,19 @@ public class SolrSmokeTest { } 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 { 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 { statusCode = response.getStatusLine().getStatusCode(); SolrSmokeTest.log.debug("HTTP status was " + statusCode); } finally { EntityUtils.consume(response.getEntity()); } - } catch (SocketTimeoutException e) { + } catch (IOException e) { // Catch the exception so we can retry this. // Save the status so we know why we failed. statusCode = SolrSmokeTest.SOCKET_TIMEOUT_STATUS; @@ -264,6 +262,7 @@ public class SolrSmokeTest { private void sleep() { try { + SLEEP_DURATION += SLEEP_INTERVAL; Thread.sleep(SLEEP_INTERVAL); } catch (InterruptedException e) { e.printStackTrace(); // Should never happen