|
35 | 35 | import org.elasticsearch.client.RestHighLevelClient;
|
36 | 36 | import org.elasticsearch.client.ml.CloseJobRequest;
|
37 | 37 | import org.elasticsearch.client.ml.CloseJobResponse;
|
| 38 | +import org.elasticsearch.client.ml.DeleteCalendarJobRequest; |
38 | 39 | import org.elasticsearch.client.ml.DeleteCalendarRequest;
|
39 | 40 | import org.elasticsearch.client.ml.DeleteDatafeedRequest;
|
40 | 41 | import org.elasticsearch.client.ml.DeleteFilterRequest;
|
@@ -2214,6 +2215,60 @@ public void onFailure(Exception e) {
|
2214 | 2215 | }
|
2215 | 2216 | }
|
2216 | 2217 |
|
| 2218 | + public void testDeleteCalendarJob() throws IOException, InterruptedException { |
| 2219 | + RestHighLevelClient client = highLevelClient(); |
| 2220 | + |
| 2221 | + Calendar calendar = new Calendar("holidays", |
| 2222 | + Arrays.asList("job_1", "job_group_1", "job_2"), |
| 2223 | + "A calendar for public holidays"); |
| 2224 | + PutCalendarRequest putRequest = new PutCalendarRequest(calendar); |
| 2225 | + client.machineLearning().putCalendar(putRequest, RequestOptions.DEFAULT); |
| 2226 | + { |
| 2227 | + // tag::delete-calendar-job-request |
| 2228 | + DeleteCalendarJobRequest request = new DeleteCalendarJobRequest("holidays", // <1> |
| 2229 | + "job_1", "job_group_1"); // <2> |
| 2230 | + // end::delete-calendar-job-request |
| 2231 | + |
| 2232 | + // tag::delete-calendar-job-execute |
| 2233 | + PutCalendarResponse response = client.machineLearning().deleteCalendarJob(request, RequestOptions.DEFAULT); |
| 2234 | + // end::delete-calendar-job-execute |
| 2235 | + |
| 2236 | + // tag::delete-calendar-job-response |
| 2237 | + Calendar updatedCalendar = response.getCalendar(); // <1> |
| 2238 | + // end::delete-calendar-job-response |
| 2239 | + |
| 2240 | + assertThat(updatedCalendar.getJobIds(), containsInAnyOrder("job_2")); |
| 2241 | + } |
| 2242 | + { |
| 2243 | + DeleteCalendarJobRequest request = new DeleteCalendarJobRequest("holidays", "job_2"); |
| 2244 | + |
| 2245 | + // tag::delete-calendar-job-execute-listener |
| 2246 | + ActionListener<PutCalendarResponse> listener = |
| 2247 | + new ActionListener<PutCalendarResponse>() { |
| 2248 | + @Override |
| 2249 | + public void onResponse(PutCalendarResponse deleteCalendarsResponse) { |
| 2250 | + // <1> |
| 2251 | + } |
| 2252 | + |
| 2253 | + @Override |
| 2254 | + public void onFailure(Exception e) { |
| 2255 | + // <2> |
| 2256 | + } |
| 2257 | + }; |
| 2258 | + // end::delete-calendar-job-execute-listener |
| 2259 | + |
| 2260 | + // Replace the empty listener by a blocking listener in test |
| 2261 | + final CountDownLatch latch = new CountDownLatch(1); |
| 2262 | + listener = new LatchedActionListener<>(listener, latch); |
| 2263 | + |
| 2264 | + // tag::delete-calendar-job-execute-async |
| 2265 | + client.machineLearning().deleteCalendarJobAsync(request, RequestOptions.DEFAULT, listener); // <1> |
| 2266 | + // end::delete-calendar-job-execute-async |
| 2267 | + |
| 2268 | + assertTrue(latch.await(30L, TimeUnit.SECONDS)); |
| 2269 | + } |
| 2270 | + } |
| 2271 | + |
2217 | 2272 | public void testGetCalendar() throws IOException, InterruptedException {
|
2218 | 2273 | RestHighLevelClient client = highLevelClient();
|
2219 | 2274 |
|
|
0 commit comments