Search in sources :

Example 6 with JobInstance

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

the class BatchJobCatchUpIntegrationTest method testFailureDuringIncompleteTaskHandling.

@Test
public void testFailureDuringIncompleteTaskHandling() throws Exception {
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/catchUpTask3.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(5000);
    }
    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);
    explorer = mifosScheduler.getBatchJobExplorer();
    jobInstances = explorer.getJobInstances(jobName, 0, 10);
    Assert.assertEquals(4, jobInstances.size());
    JobInstance jobInstance = jobInstances.get(0);
    JobExecution jobExecution = explorer.getJobExecutions(jobInstance).get(0);
    Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    jobInstance = jobInstances.get(1);
    jobExecution = explorer.getJobExecutions(jobInstance).get(0);
    Assert.assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
    Assert.assertEquals(ExitStatus.FAILED, jobExecution.getExitStatus());
    jobInstance = jobInstances.get(2);
    jobExecution = explorer.getJobExecutions(jobInstance).get(0);
    Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    jobInstance = jobInstances.get(3);
    jobExecution = explorer.getJobExecutions(jobInstance).get(0);
    Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
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 JobInstance

use of org.springframework.batch.core.JobInstance 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 8 with JobInstance

use of org.springframework.batch.core.JobInstance 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 9 with JobInstance

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

the class MifosScheduler method getJobsPreviousRunStatus.

public String getJobsPreviousRunStatus(String jobName) {
    JobExplorer explorer = getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 1);
    if (jobInstances.size() == 0) {
        return "Never executed yet";
    }
    List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstances.get(0));
    if (jobExecutions.size() == 0) {
        return "Never executed yet";
    }
    String runStatus = jobExecutions.get(0).getStatus().toString();
    runStatus = runStatus.substring(0, 1) + runStatus.substring(1).toLowerCase();
    return runStatus;
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer)

Example 10 with JobInstance

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

the class MifosBatchJob method checkAndLaunchJob.

/**
     * This method is a wrapper around launchJob method. It checks whether previous
     * runs of the job executed successfully and attempts to re-run them in case they did not.
     * @param job Job class
     * @param jobParameters Job parameters
     * @param lookUpDepth Counter used to track current recurrence depth
     * @return Batch computation status
     * @throws BatchJobException when something goes wrong
     */
public BatchStatus checkAndLaunchJob(Job job, JobParameters jobParameters, int lookUpDepth) throws BatchJobException {
    List<JobInstance> jobInstances = jobExplorer.getJobInstances(job.getName(), lookUpDepth, lookUpDepth + 1);
    if (jobInstances.size() == 0) {
        return launchJob(job, jobParameters);
    }
    JobInstance jobInstance = jobInstances.get(0);
    List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
    // latest execution
    JobExecution jobExecution = jobExecutions.get(0);
    if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
        return launchJob(job, jobParameters);
    }
    checkAndLaunchJob(job, jobExecution.getJobInstance().getJobParameters(), lookUpDepth + 1);
    return launchJob(job, jobParameters);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance)

Aggregations

JobInstance (org.springframework.batch.core.JobInstance)15 JobExecution (org.springframework.batch.core.JobExecution)13 JobExplorer (org.springframework.batch.core.explore.JobExplorer)12 Test (org.junit.Test)8 Date (java.util.Date)6 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 CronTrigger (org.quartz.CronTrigger)2 JobParameters (org.springframework.batch.core.JobParameters)2 Calendar (java.util.Calendar)1 ProductStatus (org.mifos.framework.components.batchjobs.helpers.ProductStatus)1 DateTimeService (org.mifos.framework.util.DateTimeService)1 JobDataMap (org.quartz.JobDataMap)1 JobDetail (org.quartz.JobDetail)1 JobExecutionContext (org.quartz.JobExecutionContext)1 Scheduler (org.quartz.Scheduler)1 SimpleTrigger (org.quartz.SimpleTrigger)1 Trigger (org.quartz.Trigger)1