/** * @param step the step that will be executed */ public StepState(Step step) { super(step.getName()); this.step = step; }
@Override public Step getStep(String stepName) throws NoSuchStepException { Step result = null; if(step.getName().equals(stepName)) { result = step; } else if(step instanceof StepLocator) { result = ((StepLocator) step).getStep(stepName); } return result; } }
@Override public Collection<String> getStepNames() { List<String> names = new ArrayList<>(); names.add(step.getName()); if(step instanceof StepLocator) { names.addAll(((StepLocator)step).getStepNames()); } return names; }
@Nullable public String getMostRecentStepName() { if(currentStep != null) { return currentStep.getStep().getName(); } else { return null; } }
public void setSteps(List<Step> steps) { this.steps.clear(); for (Step step : steps) { this.steps.put(step.getName(), step); } }
protected void assertStepsNotRegistered(StepRegistry stepRegistry, String jobName, Collection<Step> steps) { for (Step step : steps) { assertStepNameNotRegistered(stepRegistry, jobName, step.getName()); } }
protected void assertStepsRegistered(StepRegistry stepRegistry, String jobName, Collection<Step> steps) { for (Step step : steps) { try { stepRegistry.getStep(jobName, step.getName()); } catch (NoSuchJobException e) { Assert.fail("Unexpected exception " + e); } } }
@Test @SuppressWarnings("resource") public void testStepParserBeanName() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/StepParserBeanNameTests-context.xml"); Map<String, Step> beans = ctx.getBeansOfType(Step.class); assertTrue("'s1' bean not found", beans.containsKey("s1")); Step s1 = (Step) ctx.getBean("s1"); assertEquals("wrong name", "s1", s1.getName()); }
@Test public void testSimpleStepExecutionProviderJobRepositoryStepPartitioner() throws Exception { final Map<String, ExecutionContext> map = Collections.singletonMap("foo", new ExecutionContext()); SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new Partitioner() { @Override public Map<String, ExecutionContext> partition(int gridSize) { return map; } }); assertEquals(1, splitter.split(stepExecution, 2).size()); }
/** * mock step context */ @Override protected void setUp() throws Exception { JobParameters jobParameters = new JobParametersBuilder().addLong("commit.interval", 2L).toJobParameters(); jobInstance = new JobInstance(new Long(0), "testJob"); JobExecution jobExecution = new JobExecution(jobInstance, jobParameters); Step step = new StepSupport("bar"); stepExecution = jobExecution.createStepExecution(step.getName()); policy.beforeStep(stepExecution); }
@Test public void testCompleteStatusAfterFailure() throws Exception { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, false, step.getName(), new SimplePartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(2, split.size()); StepExecution nextExecution = update(split, stepExecution, BatchStatus.COMPLETED, false); // If already complete in another JobExecution we don't execute again assertEquals(0, provider.split(nextExecution, 2).size()); }
@Test public void testRememberGridSize() throws Exception { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(2, split.size()); stepExecution = update(split, stepExecution, BatchStatus.FAILED); assertEquals(2, provider.split(stepExecution, 3).size()); }
@Test public void testGetStepExists() { step1 = new StubStep("step1", jobRepository); step2 = new StubStep("step2", jobRepository); job.setSteps(Arrays.asList(new Step[] { step1, step2 })); Step step = job.getStep("step2"); assertNotNull(step); assertEquals("step2", step.getName()); }
@Test public void testCompleteStatusSameJobExecution() throws Exception { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, false, step.getName(), new SimplePartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(2, split.size()); stepExecution = update(split, stepExecution, BatchStatus.COMPLETED); // If already complete in the same JobExecution we should execute again assertEquals(2, provider.split(stepExecution, 2).size()); }
@Test public void testDeciderDeciderState() throws Exception { factoryBean.setDecider(new DeciderSupport()); factoryBean.setName("IL"); factoryBean.afterPropertiesSet(); Step step = factoryBean.getObject(); assertEquals("IL", step.getName()); assertEquals(DecisionStep.class, step.getClass()); }
@Test public void testSimpleStepExecutionProviderJobRepositoryStep() throws Exception { SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); Set<StepExecution> execs = splitter.split(stepExecution, 2); assertEquals(2, execs.size()); for (StepExecution execution : execs) { assertNotNull("step execution partition is saved", execution.getId()); } }
@Test public void testGetStepName() { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); assertEquals("step", provider.getStepName()); }
private StepExecution newStepExecution(Step step, Long jobExecutionId, long stepExecutionId) { JobInstance job = new JobInstance(3L, "testJob"); StepExecution execution = new StepExecution(step.getName(), new JobExecution(job, jobExecutionId, new JobParameters(), null), stepExecutionId); return execution; }
@Before public void onSetUp() throws Exception { repository = getJobRepository(); jobExecution = repository.createJobExecution("job", new JobParameters()); jobInstance = jobExecution.getJobInstance(); step = new StepSupport("foo"); stepExecution = new StepExecution(step.getName(), jobExecution); dao = getStepExecutionDao(); }
private StepExecution getStepExecution(Step step) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException { SimpleJob job = new SimpleJob(); job.setName("job"); JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParametersBuilder().addLong( "job.counter", jobCounter++).toJobParameters()); StepExecution stepExecution = jobExecution.createStepExecution(step.getName()); jobRepository.add(stepExecution); return stepExecution; }