@Test @DirtiesContext public void testComposedConfiguration() throws Exception { JobExecution jobExecution = this.jobRepository.createJobExecution( "ComposedTest", new JobParameters()); job.execute(jobExecution); Map<String, String> props = new HashMap<>(1); props.put("format", "yyyy"); assertEquals(1010, composedTaskProperties.getMaxWaitTime()); assertEquals(1100, composedTaskProperties.getIntervalTimeBetweenChecks()); assertEquals("http://bar", composedTaskProperties.getDataflowServerUri().toASCIIString()); List<String> args = new ArrayList<>(1); args.add("--baz=boo"); Assert.isNull(job.getJobParametersIncrementer(), "JobParametersIncrementer must be null."); verify(this.taskOperations).launch("AAA", props, args); }
@Test @DirtiesContext public void testComposedConfiguration() throws Exception { JobExecution jobExecution = this.jobRepository.createJobExecution( "ComposedTest", new JobParameters()); job.execute(jobExecution); Assert.isNull(job.getJobParametersIncrementer(), "JobParametersIncrementer must be null."); verify(this.taskOperations).launch("AAA", new HashMap<String, String>(0), new ArrayList<String>(0)); }
@Scheduled(fixedDelayString = "${demo.job.fixed.delay.seconds:60}000") public void runDemoJob() { SimpleDateFormat format = new SimpleDateFormat("M-dd-yy hh:mm:ss"); String startDateTime = format.format(new Date()); JobParameters jobParameters = new JobParametersBuilder() .addLong("iterations", iterations) .addString("username", username) .addLong("time", System.currentTimeMillis()).toJobParameters(); try { logger.info(""); logger.info("STARTING BATCH JOB AT " + startDateTime); JobExecution execution = jobLauncher.run(demoJob, jobParameters); logger.info("JOB STATUS : " + execution.getStatus()); } catch (Exception e) { e.printStackTrace(); logger.info("JOB FAILED!!!"); } }
public void start() throws IOException, InterruptedException { List<JobExecution> jobExecutions = new ArrayList<>(); // launch jobs jobExecutions.addAll(IntStream.range(0, this.cardinality).mapToObj(i -> { Job analysisJob = this.jobFactory.get(); JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(); jobParametersBuilder.addString("id", analysisJob.getName() + "-" + i, true); try { return this.jobLauncher.run(analysisJob, jobParametersBuilder.toJobParameters()); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException exception) { throw new RuntimeException(exception); } }).collect(Collectors.toList())); // wait for termination while (jobExecutions.stream().anyMatch(jobExecution -> jobExecution.getStatus().isRunning())) { Thread.sleep(1000); } }
@Override public void afterJob(final JobExecution jobExecution) { if (ExitStatus.COMPLETED.equals(jobExecution.getExitStatus())) { final ExecutionContext executionContext = jobExecution.getExecutionContext(); final String inputFile = executionContext.getString(LHHuntingClubBatchConfig.KEY_INPUT_FILE, null); if (inputFile != null) { final Path path = Paths.get(inputFile); try { LOG.info("Deleting temporary file: {}", inputFile); Files.deleteIfExists(path); } catch (IOException e) { e.printStackTrace(); } } else { LOG.warn("Input file not found in context"); } } }
@Bean public Job discreteJob() { AbstractJob job = new AbstractJob("discreteRegisteredJob") { @Override public Collection<String> getStepNames() { return Collections.emptySet(); } @Override public Step getStep(String stepName) { return null; } @Override protected void doExecute(JobExecution execution) throws JobExecutionException { execution.setStatus(BatchStatus.COMPLETED); } }; job.setJobRepository(this.jobRepository); return job; }
@Bean public Job discreteJob() { AbstractJob job = new AbstractJob("discreteLocalJob") { @Override public Collection<String> getStepNames() { return Collections.emptySet(); } @Override public Step getStep(String stepName) { return null; } @Override protected void doExecute(JobExecution execution) throws JobExecutionException { execution.setStatus(BatchStatus.COMPLETED); } }; job.setJobRepository(this.jobRepository); return job; }
@Override public void afterJob(JobExecution jobExecution) { LOGGER.info("RUNNING JobCompletion Check."); long cnt = movieRepository.count(); LOGGER.info("Total Movies Saved: {}", cnt); // Shutdown when Job is Finished (for Windows PC) // Runtime runtime = Runtime.getRuntime(); // String command = "shutdown /s"; // try { // Process proc = runtime.exec(command); // } catch (IOException e) { // System.out.println(e.getMessage()); // e.printStackTrace(); // } }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("multiResourceItemReaderJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("customReaderWriterProcesorJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("taskletJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("customListeners"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("flatFileItemWriterJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("parallelStepsJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("chunkJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("secuentialControlFlow"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("xmlReadersWritersJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
@Override public void process(Exchange exchange) throws Exception { JobParameters jobParameters = prepareJobParameters(exchange.getIn().getHeaders()); String messageJobName = jobParameters.getString(SpringBatchConstants.JOB_NAME); Job job2run = this.job; if (messageJobName != null) { job2run = CamelContextHelper.mandatoryLookup(getEndpoint().getCamelContext(), messageJobName, Job.class); } if (job2run == null) { exchange.setException(new CamelExchangeException("jobName was not specified in the endpoint construction " + " and header " + SpringBatchConstants.JOB_NAME + " could not be found", exchange)); return; } JobExecution jobExecution = jobLauncher.run(job2run, jobParameters); exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders()); exchange.getOut().setBody(jobExecution); }
@Test public void testJobParameters() { String[] JOB_PARAM_KEYS = {"A", "B", "C", "D"}; Date testDate = new Date(); JobParameter[] PARAMETERS = {new JobParameter("FOO", true), new JobParameter(1L, true), new JobParameter(1D, true), new JobParameter(testDate, false)}; Map jobParamMap = new LinkedHashMap<>(); for (int paramCount = 0; paramCount < JOB_PARAM_KEYS.length; paramCount++) { jobParamMap.put(JOB_PARAM_KEYS[paramCount], PARAMETERS[paramCount]); } jobParameters = new JobParameters(jobParamMap); JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID, jobParameters, JOB_CONFIGURATION_NAME); JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(jobExecution); assertNotNull("Job Parameter A was expected", jobExecutionEvent.getJobParameters().getString("A")); assertNotNull("Job Parameter B was expected", jobExecutionEvent.getJobParameters().getLong("B")); assertNotNull("Job Parameter C was expected", jobExecutionEvent.getJobParameters().getDouble("C")); assertNotNull("Job Parameter D was expected", jobExecutionEvent.getJobParameters().getDate("D")); assertEquals("Job Parameter A value was not correct", "FOO", jobExecutionEvent.getJobParameters().getString("A")); assertEquals("Job Parameter B value was not correct", new Long(1), jobExecutionEvent.getJobParameters().getLong("B")); assertEquals("Job Parameter C value was not correct", new Double(1), jobExecutionEvent.getJobParameters().getDouble("C")); assertEquals("Job Parameter D value was not correct", testDate, jobExecutionEvent.getJobParameters().getDate("D")); }
@Override public void restartJobExecution(long jobExecutionId) throws NoSuchJobExecutionException { logger.info("Restarting Job with Id " + jobExecutionId); final TaskJobExecution taskJobExecution = this.getJobExecution(jobExecutionId); final JobExecution jobExecution = taskJobExecution.getJobExecution(); if (!JobUtils.isJobExecutionRestartable(taskJobExecution.getJobExecution())) { throw new JobNotRestartableException( String.format("JobExecution with Id '%s' and state '%s' is not " + "restartable.", jobExecution.getId(), taskJobExecution.getJobExecution().getStatus())); } TaskExecution taskExecution = this.taskExplorer.getTaskExecution(taskJobExecution.getTaskId()); TaskDefinition taskDefinition = this.taskDefinitionRepository.findOne(taskExecution.getTaskName()); if (taskDefinition == null) { throw new NoSuchTaskDefinitionException(taskExecution.getTaskName()); } taskService.executeTask(taskDefinition.getName(), taskDefinition.getProperties(), taskExecution.getArguments()); }
@Test public void testWriteChecklistPdf() throws Exception { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); parameters.put("query", new JobParameter("")); parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae")); parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon)))); parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".pdf")); parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString())); parameters.put("download.fieldsTerminatedBy", new JobParameter("\t")); parameters.put("download.fieldsEnclosedBy", new JobParameter("\"")); parameters.put("download.sort", new JobParameter("searchable.label_sort_asc")); parameters.put("download.format", new JobParameter("hierarchicalChecklist")); parameters.put("download.template.filepath", new JobParameter("org/emonocot/job/download/reports/name_report1.jrxml")); JobParameters jobParameters = new JobParameters(parameters); Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation"); assertNotNull("flatFileCreator Job must exist", archiveCreatorJob); JobExecution jobExecution = jobLauncher.run(archiveCreatorJob, jobParameters); assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus()); }
/** * Constructor for the StepExecution to initialize the DTO. * * @param original the StepExecution to build this DTO around. */ public JobExecutionEvent(JobExecution original) { this.jobParameters = new JobParametersEvent(original.getJobParameters().getParameters()); this.jobInstance = new JobInstanceEvent(original.getJobInstance().getId(), original.getJobInstance().getJobName()); for(StepExecution stepExecution : original.getStepExecutions()){ stepExecutions.add(new StepExecutionEvent(stepExecution)); } this.status = original.getStatus(); this.startTime = original.getStartTime(); this.createTime = original.getCreateTime(); this.endTime = original.getEndTime(); this.lastUpdated = original.getLastUpdated(); this.exitStatus = new ExitStatus(original.getExitStatus()); this.executionContext = original.getExecutionContext(); this.failureExceptions = original.getFailureExceptions(); this.jobConfigurationName = original.getJobConfigurationName(); this.setId(original.getId()); this.setVersion(original.getVersion()); }
/** * @throws Exception */ @Test public void testWriteTaxonFile() throws Exception { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); parameters.put("query", new JobParameter("")); parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae")); parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon)))); parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".txt")); parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString())); parameters.put("download.fieldsTerminatedBy", new JobParameter("\t")); parameters.put("download.fieldsEnclosedBy", new JobParameter("\"")); parameters.put("download.format", new JobParameter("taxon")); JobParameters jobParameters = new JobParameters(parameters); Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation"); assertNotNull("flatFileCreatorJob must exist", archiveCreatorJob); JobExecution jobExecution = jobLauncher.run(archiveCreatorJob, jobParameters); assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus()); }
CommandLineRunner runner(JobLauncher launcher, Job job, @Value("${file}") File in, JdbcTemplate jdbcTemplate) { return args -> { JobExecution execution = launcher.run(job, new JobParametersBuilder() .addString("file", in.getAbsolutePath()) .toJobParameters()); System.out.println("execution status: " + execution.getExitStatus().toString()); List<Person> personList = jdbcTemplate.query("select * from PEOPLE", (resultSet, i) -> new Person(resultSet.getString("first"), resultSet.getString("last"), resultSet.getString("email"))); personList.forEach(System.out::println); }; }
/** * Executions should be returned in the reverse order they were saved. */ @Transactional @Test public void testFindExecutionsOrdering() { List<JobExecution> execs = new ArrayList<>(); for (int i = 0; i < 10; i++) { JobExecution exec = new JobExecution(jobInstance, jobParameters); exec.setCreateTime(new Date(i)); execs.add(exec); jobExecutionDao.saveJobExecution(exec); } Collections.reverse(execs); List<JobExecution> retrieved = jobExecutionDao.findJobExecutions(jobInstance); for (int i = 0; i < 10; i++) { assertExecutionsAreEqual(execs.get(i), retrieved.get(i)); } }
public JobExecutionInfo(JobExecution jobExecution) { DateTime sTime = new DateTime(jobExecution.getStartTime()); DateTime eTime = new DateTime(jobExecution.getEndTime()); duration = eTime.minus(sTime.getMillis()); startTime = sTime; exitDescription = jobExecution.getExitStatus().getExitDescription(); exitCode = jobExecution.getExitStatus().getExitCode(); id = jobExecution.getId(); status = jobExecution.getStatus(); jobConfigurationId = jobExecution.getJobParameters().getString("job.configuration.id"); Integer writeSkip = 0; for (StepExecution stepExecution : jobExecution.getStepExecutions()) { recordsRead += stepExecution.getReadCount(); readSkip += stepExecution.getReadSkipCount(); processSkip += stepExecution.getProcessSkipCount(); written += stepExecution.getWriteCount(); writeSkip += stepExecution.getWriteSkipCount(); } }
@Override public void afterJob(JobExecution jobExecution) { StringBuffer exitDescription = new StringBuffer(); if (jobExecution.getJobParameters().getString("job.configuration.id") != null) { JobConfiguration jobConfiguration = jobConfigurationService.get(Long.parseLong(jobExecution.getJobParameters().getString("job.configuration.id"))); exitDescription.append(jobConfiguration.getDescription() + " " + jobExecution.getExitStatus().getExitCode()); exitDescription.append(". " + jobExecution.getStepExecutions().size() + " Steps Completed."); jobExecution.setExitStatus(jobExecution.getExitStatus().addExitDescription(exitDescription.toString())); jobConfiguration.setJobStatus(jobExecution.getStatus()); jobRepository.update(jobExecution); logger.info(jobExecution.getExitStatus().getExitCode() + " " + jobExecution.getExitStatus().getExitDescription()); } }
@Test public final void testBatchReportWriter() throws Exception { JasperReport jasperReport = JasperCompileManager.compileReport( new ClassPathResource("org/emonocot/job/download/reports/name_report1.jrxml").getInputStream()); JRVerticalReportWriter writer = new JRVerticalReportWriter(jasperReport); writer.setDefaultOutputDir("target"); StepExecution se = new StepExecution("testStep", new JobExecution(1L)); writer.beforeStep(se); int chunkSize = 10; for (int i = 0; i <= (itemsToWrite.size()/chunkSize); i++) { List<Taxon> itemList = new ArrayList<Taxon>(); for (int j = 0; j < chunkSize; j++) { try { itemList.add(itemsToWrite.get(i*chunkSize+j)); } catch (IndexOutOfBoundsException e) { break; } } writer.write(itemList); } writer.afterStep(se); }
/** * @param jobExecution * the job instance to save * @return A response entity containing a newly created job execution */ @RequestMapping(value = "/jobExecution", method = RequestMethod.POST) public final ResponseEntity<JobExecution> create( @RequestBody final JobExecution jobExecution) { HttpHeaders httpHeaders = new HttpHeaders(); try { httpHeaders.setLocation(new URI(baseUrl + "/jobExecution/" + jobExecution.getId())); } catch (URISyntaxException e) { logger.error(e.getMessage()); } service.save(jobExecution); ResponseEntity<JobExecution> response = new ResponseEntity<JobExecution>( jobExecution, httpHeaders, HttpStatus.CREATED); return response; }
@Override public JobExecution getJobExecution(Long executionId) { JobExecution jobExec = null; StructuredQueryBuilder qb = new StructuredQueryBuilder(properties.getSearchOptions()); StructuredQueryDefinition querydef = qb.valueConstraint("id", executionId.toString()); QueryManager queryMgr = databaseClient.newQueryManager(); SearchHandle results = queryMgr.search(querydef, new SearchHandle()); DocumentDescriptor desc; if (results.getTotalResults() > 0L) { MatchDocumentSummary[] summaries = results.getMatchResults(); JAXBHandle<AdaptedJobExecution> handle = new JAXBHandle<>(jaxbContext()); AdaptedJobExecution aje = summaries[0].getFirstSnippet(handle).get(); try { jobExec = adapter.unmarshal(aje); } catch (Exception ex) { logger.error(ex.getMessage()); throw new RuntimeException(ex); } desc = databaseClient.newDocumentManager().exists(summaries[0].getUri()); jobExec.setVersion((int) desc.getVersion()); } return jobExec; }
@Test public void testRuntimeException() throws Exception { StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L); when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn(true); when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).thenReturn(true); when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn(true); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn("workerStep"); when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] {"workerStep", "foo", "bar"}); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).thenReturn("2"); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1"); when(this.jobExplorer.getStepExecution(1L, 2L)).thenReturn(workerStep); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn("workerStep"); when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step); doThrow(new RuntimeException("expected")).when(this.step).execute(workerStep); handler.run(); verify(this.jobRepository).update(this.stepExecutionArgumentCaptor.capture()); assertEquals(BatchStatus.FAILED, this.stepExecutionArgumentCaptor.getValue().getStatus()); }
@Scheduled(fixedRate = 5000) public void startJob() throws Exception { JobExecution execution = jobLauncher.run( deptBatchJob(), new JobParametersBuilder().addLong("procId", System.nanoTime()).toJobParameters() ); }
private ChunkContext chunkContext () { final long JOB_EXECUTION_ID = 123L; final String STEP_NAME = "myTestStep"; JobExecution jobExecution = new JobExecution(JOB_EXECUTION_ID); StepExecution stepExecution = new StepExecution(STEP_NAME, jobExecution); StepContext stepContext = new StepContext(stepExecution); return new ChunkContext(stepContext); }
private Collection<StepExecution> getStepExecutions() { JobExplorer jobExplorer = this.applicationContext.getBean(JobExplorer.class); List<JobInstance> jobInstances = jobExplorer.findJobInstancesByJobName("job", 0, 1); assertEquals(1, jobInstances.size()); JobInstance jobInstance = jobInstances.get(0); List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance); assertEquals(1, jobExecutions.size()); JobExecution jobExecution = jobExecutions.get(0); return jobExecution.getStepExecutions(); }
@Test @DirtiesContext public void testComposedConfigurationWithJobIncrementer() throws Exception { JobExecution jobExecution = this.jobRepository.createJobExecution( "ComposedTest", new JobParameters()); Assert.notNull(job.getJobParametersIncrementer(), "JobParametersIncrementer must not be null."); }