/** * Create a {@link StepExecution} and all its parent entities with default * values, but using the {@link JobParameters} provided. * * @param jobParameters some {@link JobParameters} * @return a {@link StepExecution} with the job parameters provided */ public static StepExecution createStepExecution(JobParameters jobParameters) { JobExecution jobExecution = createJobExecution(DEFAULT_JOB_NAME, DEFAULT_JOB_INSTANCE_ID, DEFAULT_JOB_EXECUTION_ID, jobParameters); return jobExecution.createStepExecution(DEFAULT_STEP_NAME); }
@Override public Set<StepExecution> split(StepExecution stepExecution, int gridSize) throws JobExecutionException { HashSet<StepExecution> result = new HashSet<>(); for (int i = gridSize; i-- > 0;) { result.add(stepExecution.getJobExecution().createStepExecution("foo" + i)); } return result; } };
@Override public FlowExecutionStatus handle(FlowExecutor executor) throws Exception { JobExecution jobExecution = executor.getJobExecution(); jobExecution.createStepExecution(getName()); if (fail) { return FlowExecutionStatus.FAILED; } else { return FlowExecutionStatus.COMPLETED; } } };
@Override public FlowExecutionStatus handle(FlowExecutor executor) throws Exception { JobExecution jobExecution = executor.getJobExecution(); if (jobExecution != null) { jobExecution.createStepExecution(getName()); } return this.status; }
@Test public void testFindRunningJobExecutions() throws Exception { StepExecution stepExecution = jobExecution.createStepExecution("step"); when(jobExecutionDao.findRunningJobExecutions("job")).thenReturn( Collections.singleton(jobExecution)); when(jobInstanceDao.getJobInstance(jobExecution)).thenReturn( jobInstance); stepExecutionDao.addStepExecutions(jobExecution); when(ecDao.getExecutionContext(jobExecution)).thenReturn(null); when(ecDao.getExecutionContext(stepExecution)).thenReturn(null); jobExplorer.findRunningJobExecutions("job"); }
@Test public void testFindJobExecutions() throws Exception { StepExecution stepExecution = jobExecution.createStepExecution("step"); when(jobExecutionDao.findJobExecutions(jobInstance)).thenReturn( Collections.singletonList(jobExecution)); when(jobInstanceDao.getJobInstance(jobExecution)).thenReturn( jobInstance); stepExecutionDao.addStepExecutions(jobExecution); when(ecDao.getExecutionContext(jobExecution)).thenReturn(null); when(ecDao.getExecutionContext(stepExecution)).thenReturn(null); jobExplorer.getJobExecutions(jobInstance); }
@Test public void testStepExecutionsWithSameName() throws Exception { assertEquals(0, execution.getStepExecutions().size()); execution.createStepExecution("step"); assertEquals(1, execution.getStepExecutions().size()); execution.createStepExecution("step"); assertEquals(2, execution.getStepExecutions().size()); }
@Test public void testGetStepExecutionSummariesSunnyDay() throws Exception { jobParameters = new JobParameters(); JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters, null); jobExecution.createStepExecution("step1"); jobExecution.createStepExecution("step2"); jobExecution.getStepExecutions().iterator().next().setId(21L); when(jobExplorer.getJobExecution(111L)).thenReturn(jobExecution); Map<Long, String> value = jobOperator.getStepExecutionSummaries(111L); assertEquals(2, value.size()); }
@Override public FlowExecutionStatus handle(FlowExecutor executor) throws Exception { JobExecution jobExecution = executor.getJobExecution(); StepExecution stepExecution = jobExecution.createStepExecution(getName()); jobRepository.add(stepExecution); if (fail) { return FlowExecutionStatus.FAILED; } else { return FlowExecutionStatus.COMPLETED; } } };
@Before public void init() throws Exception { MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); JobRepository jobRepository = factory.getObject(); aggregator.setJobExplorer(new MapJobExplorerFactoryBean(factory).getObject()); jobExecution = jobRepository.createJobExecution("job", new JobParameters()); result = jobExecution.createStepExecution("aggregate"); stepExecution1 = jobExecution.createStepExecution("foo:1"); stepExecution2 = jobExecution.createStepExecution("foo:2"); jobRepository.add(stepExecution1); jobRepository.add(stepExecution2); }
/** * 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(expected=IllegalStateException.class) public void testAggregateStatusMissingExecution() { stepExecution2 = jobExecution.createStepExecution("foo:3"); stepExecution1.setStatus(BatchStatus.COMPLETED); stepExecution2.setStatus(BatchStatus.COMPLETED); aggregator.aggregate(result, Arrays.<StepExecution> asList(stepExecution1, stepExecution2)); assertNotNull(result); assertEquals(BatchStatus.STARTING, result.getStatus()); }
@Override public StepExecution call() throws Exception { final StepExecution stepExecution = jobExecution.createStepExecution("step"); stepExecution.getExecutionContext().put("foo.bar.spam", 123); StepExecution result = getCopy(stepExecution); assertEquals(stepExecution.getExecutionContext(), result.getExecutionContext()); return result; } });
@Test public void testStop() throws Exception { StepExecution stepExecution = execution.createStepExecution("step"); assertFalse(stepExecution.isTerminateOnly()); execution.stop(); assertTrue(stepExecution.isTerminateOnly()); }
public StepExecution getStepExecution() { JobExecution jobExecution = MetaDataInstanceFactory.createJobExecution("job", 11L, 123L, new JobParametersBuilder().addString("foo", "spam").toJobParameters()); StepExecution stepExecution = jobExecution.createStepExecution("step"); stepExecution.getExecutionContext().putString("foo", "bar"); return stepExecution; } }
@Before public void setUp() throws Exception { step = new TaskletStep("step"); MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); jobRepository = factory.getObject(); stepExecution = jobRepository.createJobExecution("job", new JobParameters()).createStepExecution("bar"); jobRepository.add(stepExecution); }
@Test public void testSerialization() { byte[] serialized = SerializationUtils.serialize(execution); JobExecution deserialize = (JobExecution) SerializationUtils.deserialize(serialized); assertEquals(execution, deserialize); assertNotNull(deserialize.createStepExecution("foo")); assertNotNull(deserialize.getFailureExceptions()); }
@SuppressWarnings({"unchecked", "rawtypes"}) private GenericMessage<ChunkRequest> getSimpleMessage(String string, Long jobId) { StepContribution stepContribution = new JobExecution(new JobInstance(0L, "job"), new JobParameters()) .createStepExecution("step").createStepContribution(); ChunkRequest chunk = new ChunkRequest(0, StringUtils.commaDelimitedListToSet(string), jobId, stepContribution); GenericMessage<ChunkRequest> message = new GenericMessage<>(chunk); return message; }
@Test public void testGetStepExecution() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobInterruptedException, UnexpectedJobExecutionException { // Prepare the jobRepository for the test JobExecution jobExecution = jobRepository.createJobExecution("myJob", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution("flowStep"); jobRepository.add(stepExecution); // Executed on the remote end in remote partitioning use case StepExecution jobExplorerStepExecution = jobExplorer.getStepExecution(jobExecution.getId(), stepExecution.getId()); flowStep.execute(jobExplorerStepExecution); assertEquals(BatchStatus.COMPLETED, jobExplorerStepExecution.getStatus()); }
@Test public void test() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution( "step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); TaskletStepBuilder builder = new StepBuilder("step").repository(jobRepository) .transactionManager(transactionManager).tasklet((contribution, chunkContext) -> null); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); }