|
1 | 1 | /* |
2 | | - * Copyright 2008-2025 the original author or authors. |
| 2 | + * Copyright 2008-present the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -201,6 +201,108 @@ void testAbandonedStatus() throws Exception { |
201 | 201 | } |
202 | 202 | } |
203 | 203 |
|
| 204 | + @Test |
| 205 | + void testCompletedPartitionsSkippedByDefault() throws Exception { |
| 206 | + SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step.getName(), |
| 207 | + new SimplePartitioner()); |
| 208 | + Set<StepExecution> split = provider.split(stepExecution, 2); |
| 209 | + assertEquals(2, split.size()); |
| 210 | + |
| 211 | + stepExecution = update(split, stepExecution, BatchStatus.COMPLETED, false); |
| 212 | + |
| 213 | + Set<StepExecution> restartSplit = provider.split(stepExecution, 2); |
| 214 | + assertEquals(0, restartSplit.size()); |
| 215 | + } |
| 216 | + |
| 217 | + @Test |
| 218 | + void testCompletedPartitionsRestartWithAllowStartIfComplete() throws Exception { |
| 219 | + SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step.getName(), |
| 220 | + new SimplePartitioner()); |
| 221 | + provider.setAllowStartIfComplete(true); |
| 222 | + |
| 223 | + Set<StepExecution> split = provider.split(stepExecution, 2); |
| 224 | + assertEquals(2, split.size()); |
| 225 | + |
| 226 | + stepExecution = update(split, stepExecution, BatchStatus.COMPLETED, false); |
| 227 | + |
| 228 | + Set<StepExecution> restartSplit = provider.split(stepExecution, 2); |
| 229 | + assertEquals(2, restartSplit.size()); |
| 230 | + } |
| 231 | + |
| 232 | + @Test |
| 233 | + void testCompletedPartitionsRestartInSameJobExecution() throws Exception { |
| 234 | + SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step.getName(), |
| 235 | + new SimplePartitioner()); |
| 236 | + |
| 237 | + Set<StepExecution> split = provider.split(stepExecution, 2); |
| 238 | + assertEquals(2, split.size()); |
| 239 | + |
| 240 | + stepExecution = update(split, stepExecution, BatchStatus.COMPLETED, true); |
| 241 | + |
| 242 | + Set<StepExecution> restartSplit = provider.split(stepExecution, 2); |
| 243 | + assertEquals(2, restartSplit.size()); |
| 244 | + } |
| 245 | + |
| 246 | + @Test |
| 247 | + void testMixedStatusPartitionsRestartWithAllowStartIfComplete() throws Exception { |
| 248 | + SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step.getName(), |
| 249 | + new SimplePartitioner()); |
| 250 | + provider.setAllowStartIfComplete(true); |
| 251 | + |
| 252 | + Set<StepExecution> split = provider.split(stepExecution, 2); |
| 253 | + assertEquals(2, split.size()); |
| 254 | + |
| 255 | + StepExecution restartStepExecution = updateMixedStatus(split, stepExecution); |
| 256 | + |
| 257 | + Set<StepExecution> restartSplit = provider.split(restartStepExecution, 2); |
| 258 | + assertEquals(2, restartSplit.size()); |
| 259 | + } |
| 260 | + |
| 261 | + @Test |
| 262 | + void testMixedStatusPartitionsRestartWithoutAllowStartIfComplete() throws Exception { |
| 263 | + SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step.getName(), |
| 264 | + new SimplePartitioner()); |
| 265 | + // allowStartIfComplete = false (default) |
| 266 | + |
| 267 | + Set<StepExecution> split = provider.split(stepExecution, 2); |
| 268 | + assertEquals(2, split.size()); |
| 269 | + |
| 270 | + StepExecution restartStepExecution = updateMixedStatus(split, stepExecution); |
| 271 | + |
| 272 | + // Only FAILED partition should restart, COMPLETED should be skipped |
| 273 | + Set<StepExecution> restartSplit = provider.split(restartStepExecution, 2); |
| 274 | + assertEquals(1, restartSplit.size()); |
| 275 | + } |
| 276 | + |
| 277 | + private StepExecution updateMixedStatus(Set<StepExecution> split, StepExecution stepExecution) throws Exception { |
| 278 | + boolean first = true; |
| 279 | + for (StepExecution child : split) { |
| 280 | + child.setEndTime(LocalDateTime.now()); |
| 281 | + child.setStatus(first ? BatchStatus.COMPLETED : BatchStatus.FAILED); |
| 282 | + jobRepository.update(child); |
| 283 | + first = false; |
| 284 | + } |
| 285 | + |
| 286 | + stepExecution.setEndTime(LocalDateTime.now()); |
| 287 | + stepExecution.setStatus(BatchStatus.FAILED); |
| 288 | + jobRepository.update(stepExecution); |
| 289 | + |
| 290 | + JobExecution jobExecution = stepExecution.getJobExecution(); |
| 291 | + jobExecution.setStatus(BatchStatus.FAILED); |
| 292 | + jobExecution.setEndTime(LocalDateTime.now()); |
| 293 | + jobRepository.update(jobExecution); |
| 294 | + |
| 295 | + JobInstance jobInstance = jobExecution.getJobInstance(); |
| 296 | + JobExecution newJobExecution = jobRepository.createJobExecution(jobInstance, jobExecution.getJobParameters(), |
| 297 | + jobExecution.getExecutionContext()); |
| 298 | + StepExecution newStepExecution = jobRepository.createStepExecution(stepExecution.getStepName(), |
| 299 | + newJobExecution); |
| 300 | + newStepExecution.setExecutionContext(stepExecution.getExecutionContext()); |
| 301 | + jobRepository.updateExecutionContext(newStepExecution); |
| 302 | + |
| 303 | + return newStepExecution; |
| 304 | + } |
| 305 | + |
204 | 306 | private StepExecution update(Set<StepExecution> split, StepExecution stepExecution, BatchStatus status) |
205 | 307 | throws Exception { |
206 | 308 | return update(split, stepExecution, status, true); |
|
0 commit comments