BATCH-1616: added PartitionNameProvider
This commit is contained in:
@@ -19,7 +19,9 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -102,6 +104,53 @@ public class PartitionStepTests {
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartStepExecution() throws Exception {
|
||||
final AtomicBoolean started = new AtomicBoolean(false);
|
||||
step.setStepExecutionSplitter(new SimpleStepExecutionSplitter(jobRepository, remote, new SimplePartitioner()));
|
||||
step.setPartitionHandler(new PartitionHandler() {
|
||||
public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution)
|
||||
throws Exception {
|
||||
Set<StepExecution> executions = stepSplitter.split(stepExecution, 2);
|
||||
if (!started.get()) {
|
||||
started.set(true);
|
||||
for (StepExecution execution : executions) {
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
execution.setExitStatus(ExitStatus.FAILED);
|
||||
execution.getExecutionContext().putString("foo", execution.getStepName());
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (StepExecution execution : executions) {
|
||||
// On restart the execution context should have been restored
|
||||
assertEquals(execution.getStepName(), execution.getExecutionContext().getString("foo"));
|
||||
}
|
||||
}
|
||||
for (StepExecution execution : executions) {
|
||||
jobRepository.update(execution);
|
||||
jobRepository.updateExecutionContext(execution);
|
||||
}
|
||||
return executions;
|
||||
}
|
||||
});
|
||||
step.afterPropertiesSet();
|
||||
JobExecution jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters());
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("foo");
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
jobExecution.setStatus(BatchStatus.FAILED);
|
||||
jobExecution.setEndTime(new Date());
|
||||
jobRepository.update(jobExecution);
|
||||
// Now restart...
|
||||
jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters());
|
||||
stepExecution = jobExecution.createStepExecution("foo");
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
// one master and two workers
|
||||
assertEquals(3, stepExecution.getJobExecution().getStepExecutions().size());
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoppedStepExecution() throws Exception {
|
||||
step.setStepExecutionSplitter(new SimpleStepExecutionSplitter(jobRepository, remote, new SimplePartitioner()));
|
||||
|
||||
@@ -4,6 +4,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
@@ -71,6 +73,26 @@ public class SimpleStepExecutionSplitterTests {
|
||||
assertEquals(2, provider.split(stepExecution, 3).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRememberPartitionNames() throws Exception {
|
||||
class CustomPartitioner implements Partitioner, PartitionNameProvider {
|
||||
public Map<String, ExecutionContext> partition(int gridSize) {
|
||||
return Collections.singletonMap("foo", new ExecutionContext());
|
||||
}
|
||||
public Collection<String> getPartitionNames(int gridSize) {
|
||||
return Arrays.asList("foo");
|
||||
}
|
||||
}
|
||||
SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step,
|
||||
new CustomPartitioner());
|
||||
Set<StepExecution> split = provider.split(stepExecution, 2);
|
||||
assertEquals(1, split.size());
|
||||
assertEquals("step:foo", split.iterator().next().getStepName());
|
||||
stepExecution = update(split, stepExecution, BatchStatus.FAILED);
|
||||
split = provider.split(stepExecution, 2);
|
||||
assertEquals("step:foo", split.iterator().next().getStepName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepName() {
|
||||
SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step,
|
||||
|
||||
Reference in New Issue
Block a user