@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 testResourceNotExists() throws Exception { JobExecution jobExecution = launcher.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 testLaunchJob() throws Exception { int beforeMaster = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME='step1:master'", Integer.class); int beforePartition = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME like 'step1:partition%'", Integer.class); assertNotNull(jobLauncher.run(job, new JobParameters())); int afterMaster = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME='step1:master'", Integer.class); int afterPartition = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME like 'step1:partition%'", Integer.class); assertEquals(1, afterMaster-beforeMaster); // Should be same as grid size in step splitter assertEquals(2, afterPartition-beforePartition); }
@Test public void testValidRun() throws Exception { JobExecution jobExecution = jobLauncher.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."); compareFiles(expected.getFile(), actual.getFile()); }
@Test @SuppressWarnings("resource") public void testReadRetryExhausted() throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/batch/core/jsr/configuration/xml/RetryReadListenerExhausted.xml"); JobLauncher jobLauncher = context.getBean(JobLauncher.class); JobExecution jobExecution = jobLauncher.run(context.getBean(Job.class), new JobParameters()); List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions(); assertTrue("Expected 1 failure exceptions", failureExceptions.size() == 1); assertTrue("Failure exception must be of type RetryException", (failureExceptions.get(0) instanceof RetryException)); assertTrue("Exception cause must be of type IllegalArgumentException", (failureExceptions.get(0).getCause() instanceof IllegalArgumentException)); assertEquals(ExitStatus.FAILED, jobExecution.getExitStatus()); }
@Test @SuppressWarnings("resource") public void testReadRetryExceptionInListener() throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/batch/core/jsr/configuration/xml/RetryReadListenerListenerException.xml"); JobLauncher jobLauncher = context.getBean(JobLauncher.class); JobExecution jobExecution = jobLauncher.run(context.getBean(Job.class), new JobParameters()); List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions(); assertTrue("Failure exceptions must equal one", failureExceptions.size() == 1); assertTrue("Failure exception must be of type RetryException", (failureExceptions.get(0) instanceof RetryException)); assertTrue("Exception cause must be of type BatchRuntimeException", (failureExceptions.get(0).getCause() instanceof BatchRuntimeException)); assertEquals(ExitStatus.FAILED, jobExecution.getExitStatus()); }
private StepExecution launchStep(String stepName) throws Exception { SimpleJob job = new SimpleJob(); job.setName("job"); job.setJobRepository(jobRepository); List<Step> stepsToExecute = new ArrayList<>(); stepsToExecute.add((Step) applicationContext.getBean(stepName)); job.setSteps(stepsToExecute); JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addString("uuid", UUID.randomUUID().toString()).toJobParameters()); return jobExecution.getStepExecutions().iterator().next(); }
@Test public void testJsonReadingAndWriting() throws Exception { ApplicationContext context = new AnnotationConfigApplicationContext(JobConfiguration.class); JobLauncher jobLauncher = context.getBean(JobLauncher.class); Job job = context.getBean(Job.class); JobExecution jobExecution = jobLauncher.run(job, new JobParameters()); Assert.assertEquals(ExitStatus.COMPLETED.getExitCode(), jobExecution.getExitStatus().getExitCode()); assertFileEquals( new File(INPUT_FILE_DIRECTORY + "trades.json"), new File(OUTPUT_FILE_DIRECTORY + "trades.json")); }
@Test public void testInvalidCommitIntervalJobParameter() throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml"); Job job = context.getBean(Job.class); JobLauncher launcher = context.getBean(JobLauncher.class); JobExecution execution = launcher.run(job, new JobParametersBuilder().addLong("commit.intervall", 1l).toJobParameters()); assertEquals(BatchStatus.FAILED, execution.getStatus()); } }
@Test public void testCommitIntervalJobParameter() throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml"); Job job = context.getBean(Job.class); JobLauncher launcher = context.getBean(JobLauncher.class); JobExecution execution = launcher.run(job, new JobParametersBuilder().addLong("commit.interval", 1l).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(2, execution.getStepExecutions().iterator().next().getReadCount()); assertEquals(2, execution.getStepExecutions().iterator().next().getWriteCount()); }
@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 test() throws Exception { JobExecution run1 = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.STOPPED, run1.getStatus()); assertEquals(2, run1.getStepExecutions().size()); JobExecution run2 = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.COMPLETED, run2.getStatus()); assertEquals(6, run2.getStepExecutions().size()); }
@Test public void testChunkTimeoutShouldFail() throws Exception { JobExecution execution = jobLauncher.run(chunkTimeoutJob, new JobParametersBuilder().addLong("id", System.currentTimeMillis()) .toJobParameters()); assertEquals(BatchStatus.FAILED, execution.getStatus()); }
@Test public void test() throws Exception { JobExecution execution = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(3, execution.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()); }