Skip to content

Commit 5e482aa

Browse files
tests
1 parent 290dadd commit 5e482aa

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void testSaveStepExecutionSetsLastUpdated() {
202202
assertNotNull(stepExecution.getLastUpdated());
203203

204204
LocalDateTime lastUpdated = stepExecution.getLastUpdated();
205-
assertTrue(lastUpdated.isAfter(before));
205+
assertFalse(lastUpdated.isBefore(before));
206206
}
207207

208208
@Test
@@ -236,7 +236,7 @@ void testUpdateStepExecutionSetsLastUpdated() {
236236
assertNotNull(stepExecution.getLastUpdated());
237237

238238
LocalDateTime lastUpdated = stepExecution.getLastUpdated();
239-
assertTrue(lastUpdated.isAfter(before));
239+
assertFalse(lastUpdated.isBefore(before));
240240
}
241241

242242
@Test

spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandlerTests.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
package org.springframework.batch.integration.partition;
1818

19-
import java.util.Arrays;
2019
import java.util.Collection;
2120
import java.util.Collections;
2221
import java.util.HashSet;
22+
import java.util.Set;
2323
import java.util.concurrent.TimeoutException;
24+
import java.util.stream.Collectors;
2425

2526
import org.junit.jupiter.api.Test;
2627

@@ -175,12 +176,11 @@ void testHandleWithJobRepositoryPolling() throws Exception {
175176
stepExecutions.add(partition2);
176177
stepExecutions.add(partition3);
177178
when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions);
178-
JobExecution runningJobExecution = new JobExecution(5L, new JobParameters());
179-
runningJobExecution.addStepExecutions(Arrays.asList(partition2, partition1, partition3));
180-
JobExecution completedJobExecution = new JobExecution(5L, new JobParameters());
181-
completedJobExecution.addStepExecutions(Arrays.asList(partition2, partition1, partition4));
182-
when(jobExplorer.getJobExecution(5L)).thenReturn(runningJobExecution, runningJobExecution, runningJobExecution,
183-
completedJobExecution);
179+
Set<Long> stepExecutionIds = stepExecutions.stream().map(StepExecution::getId).collect(Collectors.toSet());
180+
when(jobExplorer.getStepExecutionCount(stepExecutionIds, BatchStatus.RUNNING_STATUSES)).thenReturn(3L, 2L, 1L,
181+
0L);
182+
Set<StepExecution> completedStepExecutions = Set.of(partition2, partition1, partition4);
183+
when(jobExplorer.getStepExecutions(jobExecution.getId(), stepExecutionIds)).thenReturn(completedStepExecutions);
184184

185185
// set
186186
messageChannelPartitionHandler.setMessagingOperations(operations);
@@ -200,6 +200,8 @@ void testHandleWithJobRepositoryPolling() throws Exception {
200200
assertTrue(executions.contains(partition4));
201201

202202
// verify
203+
verify(jobExplorer, times(4)).getStepExecutionCount(stepExecutionIds, BatchStatus.RUNNING_STATUSES);
204+
verify(jobExplorer, times(1)).getStepExecutions(jobExecution.getId(), stepExecutionIds);
203205
verify(operations, times(3)).send(any(Message.class));
204206
}
205207

@@ -225,9 +227,8 @@ void testHandleWithJobRepositoryPollingTimeout() throws Exception {
225227
stepExecutions.add(partition2);
226228
stepExecutions.add(partition3);
227229
when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions);
228-
JobExecution runningJobExecution = new JobExecution(5L, new JobParameters());
229-
runningJobExecution.addStepExecutions(Arrays.asList(partition2, partition1, partition3));
230-
when(jobExplorer.getJobExecution(5L)).thenReturn(runningJobExecution);
230+
Set<Long> stepExecutionIds = stepExecutions.stream().map(StepExecution::getId).collect(Collectors.toSet());
231+
when(jobExplorer.getStepExecutionCount(stepExecutionIds, BatchStatus.RUNNING_STATUSES)).thenReturn(1L);
231232

232233
// set
233234
messageChannelPartitionHandler.setMessagingOperations(operations);

0 commit comments

Comments
 (0)