Search in sources :

Example 11 with JobInstance

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

the class LoanArrearsTaskIntegrationTest method testExecute.

@Test
public void testExecute() throws Exception {
    int statusChangeHistorySize = loanAccount.getAccountStatusChangeHistory().size();
    mifosScheduler.runIndividualTask(jobName);
    Thread.sleep(1500);
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 10);
    Assert.assertEquals(1, jobInstances.size());
    JobInstance lastInstance = jobInstances.get(0);
    List<JobExecution> jobExecutions = explorer.getJobExecutions(lastInstance);
    Assert.assertEquals(1, jobExecutions.size());
    JobExecution lastExecution = jobExecutions.get(0);
    Assert.assertEquals(BatchStatus.COMPLETED, lastExecution.getStatus());
    StaticHibernateUtil.getSessionTL().refresh(loanAccount);
    loanAccount = legacyAccountDao.getAccount(loanAccount.getAccountId());
    Assert.assertEquals(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, loanAccount.getState());
    Assert.assertEquals(statusChangeHistorySize + 1, loanAccount.getAccountStatusChangeHistory().size());
}
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 12 with JobInstance

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

the class ProductStatusHelperIntegrationTest method testExecuteTask.

@Test
public void testExecuteTask() throws Exception {
    createInactiveLoanOffering();
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/productStatusTestTask.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.COMPLETED, lastExecution.getStatus());
    product = (LoanOfferingBO) TestObjectFactory.getObject(LoanOfferingBO.class, product.getPrdOfferingId());
    Assert.assertEquals(PrdStatus.LOAN_ACTIVE, 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 13 with JobInstance

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

the class LoanArrearsAndPortfolioAtRiskIntegrationTest method testLoanArrearsTaskRunFailed.

@Test
@Ignore
public void testLoanArrearsTaskRunFailed() throws Exception {
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/loanArrearsAndPortfolioTask2.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());
    Collection<StepExecution> stepExecutions = lastExecution.getStepExecutions();
    Assert.assertEquals(1, stepExecutions.size());
    for (StepExecution stepExecution : stepExecutions) {
        Assert.assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer) StepExecution(org.springframework.batch.core.StepExecution) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with JobInstance

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

the class LoanArrearsAndPortfolioAtRiskIntegrationTest method testLoanArrearsTaskRunSuccessfull.

@Test
@Ignore
public void testLoanArrearsTaskRunSuccessfull() throws Exception {
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/loanArrearsAndPortfolioTask.xml");
    mifosScheduler.runIndividualTask(jobName);
    Thread.sleep(2000);
    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.COMPLETED, lastExecution.getStatus());
    Collection<StepExecution> stepExecutions = lastExecution.getStepExecutions();
    Assert.assertEquals(2, stepExecutions.size());
    for (StepExecution stepExecution : stepExecutions) {
        Assert.assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer) StepExecution(org.springframework.batch.core.StepExecution) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with JobInstance

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

the class JobLauncherCommandLineRunner method getNextJobParameters.

private JobParameters getNextJobParameters(Job job, JobParameters additionalParameters) {
    String name = job.getName();
    JobParameters parameters = new JobParameters();
    List<JobInstance> lastInstances = this.jobExplorer.getJobInstances(name, 0, 1);
    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    Map<String, JobParameter> additionals = additionalParameters.getParameters();
    if (lastInstances.isEmpty()) {
        // Start from a completely clean sheet
        if (incrementer != null) {
            parameters = incrementer.getNext(new JobParameters());
        }
    } else {
        List<JobExecution> previousExecutions = this.jobExplorer.getJobExecutions(lastInstances.get(0));
        JobExecution previousExecution = previousExecutions.get(0);
        if (previousExecution == null) {
            // Normally this will not happen - an instance exists with no executions
            if (incrementer != null) {
                parameters = incrementer.getNext(new JobParameters());
            }
        } else if (isStoppedOrFailed(previousExecution) && job.isRestartable()) {
            // Retry a failed or stopped execution
            parameters = previousExecution.getJobParameters();
            // Non-identifying additional parameters can be removed to a retry
            removeNonIdentifying(additionals);
        } else if (incrementer != null) {
            // New instance so increment the parameters if we can
            parameters = incrementer.getNext(previousExecution.getJobParameters());
        }
    }
    return merge(parameters, additionals);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobParameters(org.springframework.batch.core.JobParameters) JobParametersIncrementer(org.springframework.batch.core.JobParametersIncrementer) JobParameter(org.springframework.batch.core.JobParameter)

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