Skip to content

Commit 40d3c60

Browse files
authored
Make testDatafeedTimingStats_DatafeedJobIdUpdated test easier to debug (#44206) (#44268)
1 parent 475752b commit 40d3c60

File tree

1 file changed

+21
-11
lines changed
  • x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration

1 file changed

+21
-11
lines changed

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.elasticsearch.action.admin.cluster.node.hotthreads.NodeHotThreads;
1111
import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse;
1212
import org.elasticsearch.action.support.master.AcknowledgedResponse;
13+
import org.elasticsearch.common.CheckedConsumer;
14+
import org.elasticsearch.common.CheckedRunnable;
1315
import org.elasticsearch.common.unit.TimeValue;
1416
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
1517
import org.elasticsearch.common.util.concurrent.ConcurrentMapLong;
@@ -106,15 +108,15 @@ public void testDatafeedTimingStats_DatafeedRecreated() throws Exception {
106108
Instant now = Instant.now();
107109
indexDocs(logger, "data", numDocs, now.minus(Duration.ofDays(14)).toEpochMilli(), now.toEpochMilli());
108110

109-
Job.Builder job = createScheduledJob("lookback-job");
111+
Job.Builder job = createScheduledJob("lookback-job-datafeed-recreated");
110112

111-
String datafeedId = "lookback-datafeed";
113+
String datafeedId = "lookback-datafeed-datafeed-recreated";
112114
DatafeedConfig datafeedConfig = createDatafeed(datafeedId, job.getId(), Arrays.asList("data"));
113115

114116
registerJob(job);
115117
putJob(job);
116118

117-
for (int i = 0; i < 2; ++i) {
119+
CheckedRunnable<Exception> openAndRunJob = () -> {
118120
openJob(job.getId());
119121
assertBusy(() -> assertEquals(getJobStats(job.getId()).get(0).getState(), JobState.OPENED));
120122
registerDatafeed(datafeedConfig);
@@ -129,7 +131,10 @@ public void testDatafeedTimingStats_DatafeedRecreated() throws Exception {
129131
}, 60, TimeUnit.SECONDS);
130132
deleteDatafeed(datafeedId);
131133
waitUntilJobIsClosed(job.getId());
132-
}
134+
};
135+
136+
openAndRunJob.run();
137+
openAndRunJob.run();
133138
}
134139

135140
public void testDatafeedTimingStats_DatafeedJobIdUpdated() throws Exception {
@@ -140,8 +145,8 @@ public void testDatafeedTimingStats_DatafeedJobIdUpdated() throws Exception {
140145
Instant now = Instant.now();
141146
indexDocs(logger, "data", numDocs, now.minus(Duration.ofDays(14)).toEpochMilli(), now.toEpochMilli());
142147

143-
Job.Builder jobA = createScheduledJob("lookback-job");
144-
Job.Builder jobB = createScheduledJob("other-lookback-job");
148+
Job.Builder jobA = createScheduledJob("lookback-job-jobid-updated");
149+
Job.Builder jobB = createScheduledJob("other-lookback-job-jobid-updated");
145150
for (Job.Builder job : Arrays.asList(jobA, jobB)) {
146151
registerJob(job);
147152
putJob(job);
@@ -152,11 +157,10 @@ public void testDatafeedTimingStats_DatafeedJobIdUpdated() throws Exception {
152157
registerDatafeed(datafeedConfig);
153158
putDatafeed(datafeedConfig);
154159

155-
for (Job.Builder job : Arrays.asList(jobA, jobB, jobA)) {
160+
CheckedConsumer<Job.Builder, Exception> openAndRunJob = job -> {
156161
openJob(job.getId());
157162
assertBusy(() -> assertEquals(getJobStats(job.getId()).get(0).getState(), JobState.OPENED));
158163
// Bind datafeedId to the current job on the list, timing stats are wiped out.
159-
updateDatafeed(new DatafeedUpdate.Builder(datafeedId).setJobId(job.getId()).build());
160164
// Datafeed did not do anything yet, hence search_count is equal to 0.
161165
assertDatafeedStats(datafeedId, DatafeedState.STOPPED, job.getId(), equalTo(0L));
162166
startDatafeed(datafeedId, 0L, now.toEpochMilli());
@@ -166,7 +170,13 @@ public void testDatafeedTimingStats_DatafeedJobIdUpdated() throws Exception {
166170
assertDatafeedStats(datafeedId, DatafeedState.STOPPED, job.getId(), greaterThan(0L));
167171
}, 60, TimeUnit.SECONDS);
168172
waitUntilJobIsClosed(job.getId());
169-
}
173+
};
174+
175+
openAndRunJob.accept(jobA);
176+
updateDatafeed(new DatafeedUpdate.Builder(datafeedId).setJobId(jobB.getId()).build()); // wipes out timing stats
177+
openAndRunJob.accept(jobB);
178+
updateDatafeed(new DatafeedUpdate.Builder(datafeedId).setJobId(jobA.getId()).build()); // wipes out timing stats
179+
openAndRunJob.accept(jobA);
170180
}
171181

172182
public void testDatafeedTimingStats_QueryDelayUpdated_TimingStatsNotReset() throws Exception {
@@ -177,11 +187,11 @@ public void testDatafeedTimingStats_QueryDelayUpdated_TimingStatsNotReset() thro
177187
Instant now = Instant.now();
178188
indexDocs(logger, "data", numDocs, now.minus(Duration.ofDays(14)).toEpochMilli(), now.toEpochMilli());
179189

180-
Job.Builder job = createScheduledJob("lookback-job");
190+
Job.Builder job = createScheduledJob("lookback-job-query-delay-updated");
181191
registerJob(job);
182192
putJob(job);
183193

184-
String datafeedId = "lookback-datafeed";
194+
String datafeedId = "lookback-datafeed-query-delay-updated";
185195
DatafeedConfig datafeedConfig = createDatafeed(datafeedId, job.getId(), Arrays.asList("data"));
186196
registerDatafeed(datafeedConfig);
187197
putDatafeed(datafeedConfig);

0 commit comments

Comments
 (0)