|
32 | 32 | import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction;
|
33 | 33 | import org.elasticsearch.xpack.core.ml.action.KillProcessAction;
|
34 | 34 | import org.elasticsearch.xpack.core.ml.action.PutJobAction;
|
| 35 | +import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction; |
35 | 36 | import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction;
|
36 | 37 | import org.elasticsearch.xpack.core.ml.datafeed.ChunkingConfig;
|
37 | 38 | import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
|
@@ -832,4 +833,36 @@ private void startRealtime(String jobId, Integer maxEmptySearches) throws Except
|
832 | 833 | assertThat(dataCounts.getOutOfOrderTimeStampCount(), equalTo(0L));
|
833 | 834 | }, 30, TimeUnit.SECONDS);
|
834 | 835 | }
|
| 836 | + |
| 837 | + public void testStartDatafeed_GivenNegativeStartTime_Returns408() throws Exception { |
| 838 | + client().admin().indices().prepareCreate("data-1").addMapping("type", "time", "type=date").get(); |
| 839 | + long numDocs = 100; |
| 840 | + long now = System.currentTimeMillis(); |
| 841 | + long oneWeekAgo = now - 604800000; |
| 842 | + long negativeStartTime = -1000; |
| 843 | + indexDocs(logger, "data-1", numDocs, oneWeekAgo, now); |
| 844 | + |
| 845 | + String jobId = "job-for-start-datafeed-timeout"; |
| 846 | + String datafeedId = jobId + "-datafeed"; |
| 847 | + |
| 848 | + Job.Builder job = createScheduledJob(jobId); |
| 849 | + putJob(job); |
| 850 | + openJob(job.getId()); |
| 851 | + assertBusy(() -> assertEquals(getJobStats(job.getId()).get(0).getState(), JobState.OPENED)); |
| 852 | + |
| 853 | + DatafeedConfig.Builder datafeedConfigBuilder = createDatafeedBuilder( |
| 854 | + job.getId() + "-datafeed", |
| 855 | + job.getId(), |
| 856 | + Collections.singletonList("data-1") |
| 857 | + ); |
| 858 | + DatafeedConfig datafeedConfig = datafeedConfigBuilder.build(); |
| 859 | + putDatafeed(datafeedConfig); |
| 860 | + |
| 861 | + IllegalArgumentException e = expectThrows( |
| 862 | + IllegalArgumentException.class, |
| 863 | + () -> new StartDatafeedAction.Request(datafeedId, negativeStartTime) |
| 864 | + ); |
| 865 | + |
| 866 | + assertThat(e.getMessage(), equalTo("[start] must not be negative [-1000].")); |
| 867 | + } |
835 | 868 | }
|
0 commit comments