From aa53e7177a2fc6de125a64077f8f6ea6a7e5d750 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 24 Nov 2016 11:49:44 +0100 Subject: [PATCH] wait for the allocation to be added before sending data Original commit: elastic/x-pack-elasticsearch@504a75a2f291be3b9f041020e423ec9bb783a4ce --- .../xpack/prelert/action/GetJobsAction.java | 22 ++++++++++++++++++- .../prelert/integration/TooManyJobsIT.java | 20 ++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetJobsAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetJobsAction.java index 1ee22cbb71a..fa430738844 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetJobsAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/action/GetJobsAction.java @@ -245,7 +245,7 @@ public class GetJobsAction extends Action { + try { + GetJobsAction.Request getJobRequest = new GetJobsAction.Request(); + getJobRequest.setJobId(job.getId()); + getJobRequest.status(true); + GetJobsAction.Response response = client().execute(GetJobsAction.INSTANCE, getJobRequest).get(); + GetJobsAction.Response.JobInfo jobInfo = response.getResponse().results().get(0); + assertNotNull(jobInfo); + assertEquals(JobStatus.CLOSED, jobInfo.getStatus()); + } catch (Exception e) { + fail("failure " + e.getMessage()); + } + }); // triggers creating autodetect process: PostDataAction.Request postDataRequest = new PostDataAction.Request(job.getId()); @@ -60,8 +76,10 @@ public class TooManyJobsIT extends ESIntegTestCase { assertEquals(1, postDataResponse.getDataCounts().getInputRecordCount()); logger.info("Posted data {} times", i); } catch (Exception e) { - logger.info("Handling exception", e); Throwable cause = ExceptionsHelper.unwrapCause(e.getCause()); + if (ElasticsearchStatusException.class.equals(cause.getClass()) == false) { + logger.warn("Unexpected cause", e); + } assertEquals(ElasticsearchStatusException.class, cause.getClass()); assertEquals(RestStatus.TOO_MANY_REQUESTS, ((ElasticsearchStatusException) cause).status()); logger.info("good news everybody --> reached threadpool capacity after starting {}th analytical process", i);