From fc29fd159a58decb18c16eca162d45739066e456 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 27 Mar 2017 15:23:06 +0200 Subject: [PATCH] [TEST] Don't lose the actual cause of the exception. Original commit: elastic/x-pack-elasticsearch@8720288ef5f733bab03cdb46e9b06888d95bebf0 --- .../integration/MlRestTestStateCleaner.java | 13 ++++++------- .../xpack/ml/support/BaseMlIntegTestCase.java | 19 +++++++++---------- .../integration/MlRestTestStateCleaner.java | 13 ++++++------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/MlRestTestStateCleaner.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/MlRestTestStateCleaner.java index 2813cc04448..32b03c203c8 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/MlRestTestStateCleaner.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/MlRestTestStateCleaner.java @@ -83,19 +83,18 @@ public class MlRestTestStateCleaner { if (statusCode != 200) { logger.error("Got status code " + statusCode + " when closing job " + jobId); } - } catch (Exception e) { - if (e.getMessage().contains("expected job state [opened], but got [closed]") - || e.getMessage().contains("expected job state [opened], but got [closing]")) { - logger.debug("job [" + jobId + "] has already been closed", e); + } catch (Exception e1) { + if (e1.getMessage().contains("expected job state [opened], but got [closed]") + || e1.getMessage().contains("expected job state [opened], but got [closing]")) { + logger.debug("job [" + jobId + "] has already been closed", e1); } else { - logger.warn("failed to close job [" + jobId + "]. Forcing closed.", e); - + logger.warn("failed to close job [" + jobId + "]. Forcing closed.", e1); try { adminClient.performRequest("POST", "/_xpack/ml/anomaly_detectors/" + jobId + "/_close?force=true"); - throw new RuntimeException("Had to resort to force-closing job, something went wrong?"); } catch (Exception e2) { throw new RuntimeException("Force-closing job [" + jobId + "] failed.", e2); } + throw new RuntimeException("Had to resort to force-closing job, something went wrong?", e1); } } int statusCode = adminClient.performRequest("DELETE", "/_xpack/ml/anomaly_detectors/" + jobId).getStatusLine().getStatusCode(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/support/BaseMlIntegTestCase.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/support/BaseMlIntegTestCase.java index fb1260dcd00..687625f7e8c 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/support/BaseMlIntegTestCase.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/support/BaseMlIntegTestCase.java @@ -251,19 +251,19 @@ public abstract class BaseMlIntegTestCase extends ESIntegTestCase { StopDatafeedAction.Response stopResponse = client.execute(StopDatafeedAction.INSTANCE, new StopDatafeedAction.Request(datafeedId)).get(); assertTrue(stopResponse.isStopped()); - } catch (ExecutionException e) { - if (e.getMessage().contains("datafeed already stopped, expected datafeed state [started], but got [stopped]")) { - logger.debug("failed to stop datafeed [" + datafeedId + "], already stopped", e); + } catch (ExecutionException e1) { + if (e1.getMessage().contains("datafeed already stopped, expected datafeed state [started], but got [stopped]")) { + logger.debug("failed to stop datafeed [" + datafeedId + "], already stopped", e1); } else { try { StopDatafeedAction.Request request = new StopDatafeedAction.Request(datafeedId); request.setForce(true); StopDatafeedAction.Response stopResponse = client.execute(StopDatafeedAction.INSTANCE, request).get(); assertTrue(stopResponse.isStopped()); - throw new RuntimeException("Had to resort to force-stopping datafeed, something went wrong?"); } catch (Exception e2) { throw new RuntimeException("Force-stopping datafeed [" + datafeedId + "] failed.", e2); } + throw new RuntimeException("Had to resort to force-stopping datafeed, something went wrong?", e1); } } assertBusy(() -> { @@ -292,10 +292,10 @@ public abstract class BaseMlIntegTestCase extends ESIntegTestCase { CloseJobAction.Response response = client.execute(CloseJobAction.INSTANCE, closeRequest).get(); assertTrue(response.isClosed()); - } catch (Exception e) { - if (e.getMessage().contains("expected job state [opened], but got [closed]") - || e.getMessage().contains("expected job state [opened], but got [closing]")) { - logger.debug("job [" + jobId + "] has already been closed", e); + } catch (Exception e1) { + if (e1.getMessage().contains("expected job state [opened], but got [closed]") + || e1.getMessage().contains("expected job state [opened], but got [closing]")) { + logger.debug("job [" + jobId + "] has already been closed", e1); } else { try { CloseJobAction.Request closeRequest = new CloseJobAction.Request(jobId); @@ -304,11 +304,10 @@ public abstract class BaseMlIntegTestCase extends ESIntegTestCase { CloseJobAction.Response response = client.execute(CloseJobAction.INSTANCE, closeRequest).get(); assertTrue(response.isClosed()); - throw new RuntimeException("Had to resort to force-closing job, something went wrong?"); } catch (Exception e2) { throw new RuntimeException("Force-closing datafeed [" + jobId + "] failed.", e2); } - + throw new RuntimeException("Had to resort to force-closing job, something went wrong?", e1); } } assertBusy(() -> { diff --git a/qa/smoke-test-ml-with-security/src/test/java/org/elasticsearch/xpack/ml/integration/MlRestTestStateCleaner.java b/qa/smoke-test-ml-with-security/src/test/java/org/elasticsearch/xpack/ml/integration/MlRestTestStateCleaner.java index 2813cc04448..32b03c203c8 100644 --- a/qa/smoke-test-ml-with-security/src/test/java/org/elasticsearch/xpack/ml/integration/MlRestTestStateCleaner.java +++ b/qa/smoke-test-ml-with-security/src/test/java/org/elasticsearch/xpack/ml/integration/MlRestTestStateCleaner.java @@ -83,19 +83,18 @@ public class MlRestTestStateCleaner { if (statusCode != 200) { logger.error("Got status code " + statusCode + " when closing job " + jobId); } - } catch (Exception e) { - if (e.getMessage().contains("expected job state [opened], but got [closed]") - || e.getMessage().contains("expected job state [opened], but got [closing]")) { - logger.debug("job [" + jobId + "] has already been closed", e); + } catch (Exception e1) { + if (e1.getMessage().contains("expected job state [opened], but got [closed]") + || e1.getMessage().contains("expected job state [opened], but got [closing]")) { + logger.debug("job [" + jobId + "] has already been closed", e1); } else { - logger.warn("failed to close job [" + jobId + "]. Forcing closed.", e); - + logger.warn("failed to close job [" + jobId + "]. Forcing closed.", e1); try { adminClient.performRequest("POST", "/_xpack/ml/anomaly_detectors/" + jobId + "/_close?force=true"); - throw new RuntimeException("Had to resort to force-closing job, something went wrong?"); } catch (Exception e2) { throw new RuntimeException("Force-closing job [" + jobId + "] failed.", e2); } + throw new RuntimeException("Had to resort to force-closing job, something went wrong?", e1); } } int statusCode = adminClient.performRequest("DELETE", "/_xpack/ml/anomaly_detectors/" + jobId).getStatusLine().getStatusCode();