@ServiceActivator public JobExecution launch(JobLaunchRequest request) throws JobExecutionException { Job job = request.getJob(); JobParameters jobParameters = request.getJobParameters(); return jobLauncher.run(job, jobParameters); }
@Test public void testResourceNotExists() throws Exception { JobExecution jobExecution = jobLauncher.run(job2, new JobParameters()); Assert.isTrue(jobExecution.getExitStatus().getExitCode().equals("FAILED"), "The job exit status is not FAILED."); Assert.isTrue(jobExecution.getAllFailureExceptions().get(0).getMessage().contains("Failed to initialize the reader"), "The job failed for the wrong reason."); }
@Test public void testValidRun() throws Exception { JobExecution jobExecution = launcher.run(job1, new JobParameters()); //Ensure job completed successfully. Assert.isTrue(jobExecution.getExitStatus().equals(ExitStatus.COMPLETED), "Step Execution did not complete normally: " + jobExecution.getExitStatus()); //Check output. Assert.isTrue(actual.exists(), "Actual does not exist."); Assert.isTrue(compareFiles(expected.getFile(), actual.getFile()), "Files were not equal"); }
@Test public void test() throws Exception { // Run 1 JobExecution jobExecution1 = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.STOPPED, jobExecution1.getStatus()); // Run 2 JobExecution jobExecution2 = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.STOPPED, jobExecution2.getStatus()); }
@Test public void testLaunchJob() throws Exception { int before = jobExplorer.getJobInstances(job.getName(), 0, 100).size(); assertNotNull(jobLauncher.run(job, new JobParameters())); List<JobInstance> jobInstances = jobExplorer.getJobInstances(job.getName(), 0, 100); int after = jobInstances.size(); assertEquals(1, after-before); JobExecution jobExecution = jobExplorer.getJobExecutions(jobInstances.get(jobInstances.size()-1)).get(0); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); assertEquals(3, jobExecution.getStepExecutions().size()); }
@Test public void testLaunchJob() throws Exception { int before = jobExplorer.getJobInstances(job.getName(), 0, 100).size(); assertNotNull(jobLauncher.run(job, new JobParameters())); List<JobInstance> jobInstances = jobExplorer.getJobInstances(job.getName(), 0, 100); int after = jobInstances.size(); assertEquals(1, after-before); JobExecution jobExecution = jobExplorer.getJobExecutions(jobInstances.get(jobInstances.size()-1)).get(0); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); assertEquals(3, jobExecution.getStepExecutions().size()); }
@Test public void testLaunchJobTwice() throws Exception { int first = jdbcTemplate.queryForObject("select count(0) from CUSTOMER where credit>1000", Integer.class); JobExecution jobExecution = launcher.run(this.job, getJobParameters(1000.)); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); assertEquals(first, jobExecution.getStepExecutions().iterator().next().getWriteCount()); int second = jdbcTemplate.queryForObject("select count(0) from CUSTOMER where credit>1000000", Integer.class); assertNotSame("The number of records above the threshold did not change", first, second); jobExecution = launcher.run(this.job, getJobParameters(1000000.)); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); assertEquals(second, jobExecution.getStepExecutions().iterator().next().getWriteCount()); }
@Test public void testSunnyDaySimpleStep() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", new JobParameter("3")))); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); assertEquals(9, stepExecution.getReadCount()); assertEquals(9, stepExecution.getWriteCount()); }
@Test public void testFailedStep() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", new JobParameter("unsupported")))); assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); assertEquals(9, stepExecution.getReadCount()); // In principle the write count could be more than 2 and less than 9... assertEquals(7, stepExecution.getWriteCount()); }
@Test public void testFailedStepOnError() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", new JobParameter("error")))); assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); assertEquals(9, stepExecution.getReadCount()); // In principle the write count could be more than 2 and less than 9... assertEquals(7, stepExecution.getWriteCount()); }
@Test public void testFailedStep() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", new JobParameter("fail")))); assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); assertEquals(9, stepExecution.getReadCount()); // In principle the write count could be more than 2 and less than 9... assertEquals(7, stepExecution.getWriteCount()); }
@Test public void testFileSent() throws Exception { JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("time.stamp", System.currentTimeMillis()).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); // 2 chunks sent to channel (5 items and commit-interval=3) assertEquals(2, count); }
@Test public void testSunnyDayFaultTolerant() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", new JobParameter("3")))); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); assertEquals(9, stepExecution.getReadCount()); assertEquals(9, stepExecution.getWriteCount()); }
@Test @DirtiesContext public void testFailedStep() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", new JobParameter("unsupported")))); assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); assertEquals(9, stepExecution.getReadCount()); // In principle the write count could be more than 2 and less than 9... assertEquals(7, stepExecution.getWriteCount()); }
@Test @DirtiesContext public void testFailedStepOnError() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", new JobParameter("error")))); assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); assertEquals(9, stepExecution.getReadCount()); // In principle the write count could be more than 2 and less than 9... assertEquals(7, stepExecution.getWriteCount()); }
@Test public void testJobLaunch() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); assertEquals(1, JdbcTestUtils.countRowsInTable(jdbcTemplate, "PREFIX_JOB_INSTANCE")); }
@Test public void testPropertySubstitutionSimple() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder() .addString("testParam", "testParamValue") .addString("file.name.junit", "myfile2") .toJobParameters()); assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); }
@Test public void testSkipsInWriter() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addString("item.three", "fail") .addLong("run.id", 1L).toJobParameters()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); assertEquals(9, stepExecution.getReadCount()); assertEquals(7, stepExecution.getWriteCount()); assertEquals(2, stepExecution.getWriteSkipCount()); } }
@Test public void testSkipsInWriter() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addString("item.three", "fail") .addLong("run.id", 1L).toJobParameters()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); assertEquals(9, stepExecution.getReadCount()); assertEquals(7, stepExecution.getWriteCount()); // The whole chunk gets skipped... assertEquals(2, stepExecution.getWriteSkipCount()); } }
@Test public void testLaunchFailedJob() throws Exception { tasklet.setFail(true); JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addLong("run.id", 2L).toJobParameters()); assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); assertEquals(ExitStatus.FAILED, jobExecution.getExitStatus()); }