Search in sources :

Example 6 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class BatchJobCatchUpIntegrationTest method testIncompleteTaskHandling.

@Test
public void testIncompleteTaskHandling() throws Exception {
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/catchUpTask2.xml");
    JobLauncher jobLauncher = mifosScheduler.getBatchJobLauncher();
    JobLocator jobLocator = mifosScheduler.getBatchJobLocator();
    for (int i = 0; i < 3; i++) {
        jobLauncher.run(jobLocator.getJob(jobName), MifosBatchJob.createJobParameters(new Date().getTime()));
        Thread.sleep(1500);
    }
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 10);
    Assert.assertEquals(3, jobInstances.size());
    for (JobInstance jobInstance : jobInstances) {
        List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstance);
        Assert.assertEquals(1, jobExecutions.size());
        Assert.assertEquals(BatchStatus.FAILED, jobExecutions.get(0).getStatus());
    }
    mifosScheduler.runIndividualTask(jobName);
    Thread.sleep(5000);
    jobInstances = explorer.getJobInstances(jobName, 0, 10);
    Assert.assertEquals(4, jobInstances.size());
    for (JobInstance jobInstance : jobInstances) {
        List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstance);
        Assert.assertEquals(BatchStatus.COMPLETED, jobExecutions.get(0).getStatus());
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobLauncher(org.springframework.batch.core.launch.JobLauncher) JobInstance(org.springframework.batch.core.JobInstance) JobLocator(org.springframework.batch.core.configuration.JobLocator) JobExplorer(org.springframework.batch.core.explore.JobExplorer) Date(java.util.Date) Test(org.junit.Test)

Example 7 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class ProductStatusHelperIntegrationTest method testExecuteTaskFailure.

@Test
public void testExecuteTaskFailure() throws Exception {
    createInactiveLoanOffering();
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/productStatusTestTask2.xml");
    mifosScheduler.runIndividualTask(jobName);
    Thread.sleep(1000);
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 10);
    Assert.assertTrue(jobInstances.size() > 0);
    JobInstance lastInstance = jobInstances.get(0);
    List<JobExecution> jobExecutions = explorer.getJobExecutions(lastInstance);
    Assert.assertEquals(1, jobExecutions.size());
    JobExecution lastExecution = jobExecutions.get(0);
    Assert.assertEquals(BatchStatus.FAILED, lastExecution.getStatus());
    product = (LoanOfferingBO) TestObjectFactory.getObject(LoanOfferingBO.class, product.getPrdOfferingId());
    Assert.assertEquals(PrdStatus.LOAN_INACTIVE, product.getStatus());
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer) Test(org.junit.Test)

Example 8 with JobExecution

use of org.springframework.batch.core.JobExecution in project pinpoint by naver.

the class AlarmJobTest method main.

public static void main(String[] args) throws Exception {
    GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext("/applicationContext-test.xml");
    JobLauncherTestUtils testLauncher = applicationContext.getBean(JobLauncherTestUtils.class);
    JobExecution jobExecution = testLauncher.launchJob(getParameters());
    BatchStatus status = jobExecution.getStatus();
    assertEquals(BatchStatus.COMPLETED, status);
    applicationContext.close();
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) BatchStatus(org.springframework.batch.core.BatchStatus) JobLauncherTestUtils(org.springframework.batch.test.JobLauncherTestUtils) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext)

Example 9 with JobExecution

use of org.springframework.batch.core.JobExecution in project spring-boot by spring-projects.

the class JobExecutionExitCodeGeneratorTests method testExitCodeForCompleted.

@Test
public void testExitCodeForCompleted() {
    JobExecution execution = new JobExecution(0L);
    execution.setStatus(BatchStatus.COMPLETED);
    this.generator.onApplicationEvent(new JobExecutionEvent(execution));
    assertThat(this.generator.getExitCode()).isEqualTo(0);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) Test(org.junit.Test)

Example 10 with JobExecution

use of org.springframework.batch.core.JobExecution in project camel by apache.

the class SpringBatchProducer method process.

@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) {
        if (jobRegistry != null) {
            job2run = jobRegistry.getJob(messageJobName);
        } else {
            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);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) CamelExchangeException(org.apache.camel.CamelExchangeException) JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job)

Aggregations

JobExecution (org.springframework.batch.core.JobExecution)19 JobInstance (org.springframework.batch.core.JobInstance)13 Test (org.junit.Test)11 JobExplorer (org.springframework.batch.core.explore.JobExplorer)11 Date (java.util.Date)4 JobParameters (org.springframework.batch.core.JobParameters)3 StepExecution (org.springframework.batch.core.StepExecution)3 JobLocator (org.springframework.batch.core.configuration.JobLocator)3 JobLauncher (org.springframework.batch.core.launch.JobLauncher)3 Ignore (org.junit.Ignore)2 BatchStatus (org.springframework.batch.core.BatchStatus)2 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 CamelExchangeException (org.apache.camel.CamelExchangeException)1 BatchJobException (org.mifos.framework.components.batchjobs.exceptions.BatchJobException)1 ProductStatus (org.mifos.framework.components.batchjobs.helpers.ProductStatus)1 CronTrigger (org.quartz.CronTrigger)1 JobDataMap (org.quartz.JobDataMap)1 JobDetail (org.quartz.JobDetail)1 JobExecutionContext (org.quartz.JobExecutionContext)1