Search in sources :

Example 1 with JobLauncher

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

the class BatchJobCatchUpIntegrationTest method testIncompleteTaskDelay.

@Test
public void testIncompleteTaskDelay() throws Exception {
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/catchUpTask.xml");
    Scheduler scheduler = mifosScheduler.getScheduler();
    ProductStatus productStatusTask = new ProductStatus();
    productStatusTask.setJobExplorer(mifosScheduler.getBatchJobExplorer());
    productStatusTask.setJobLauncher(mifosScheduler.getBatchJobLauncher());
    productStatusTask.setJobLocator(mifosScheduler.getBatchJobLocator());
    productStatusTask.setJobRepository(mifosScheduler.getBatchJobRepository());
    String quartzJobName = "ProductStatusJob";
    String quartzTriggerName = "ProductStatusTrigger2";
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.SECOND, 10);
    Date previousFireTime = calendar.getTime();
    calendar.set(Calendar.SECOND, 21);
    Date quartzFireTime = calendar.getTime();
    calendar.set(Calendar.SECOND, 22);
    Date quartzNextFireTime = calendar.getTime();
    calendar.set(Calendar.SECOND, 20);
    Date quartzPrevFireTime = calendar.getTime();
    JobDetail jobDetail = scheduler.getJobDetail(quartzJobName, Scheduler.DEFAULT_GROUP);
    jobDetail.setJobDataMap(new JobDataMap());
    CronTrigger trigger = new CronTrigger(quartzTriggerName, Scheduler.DEFAULT_GROUP, quartzJobName, Scheduler.DEFAULT_GROUP, "* * * * * ?");
    trigger.setJobDataMap(new JobDataMap());
    TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle(jobDetail, trigger, new BaseCalendar(), false, quartzFireTime, quartzFireTime, quartzPrevFireTime, quartzNextFireTime);
    JobExecutionContext jobExecutionContext = new JobExecutionContext(scheduler, triggerFiredBundle, productStatusTask);
    JobLauncher jobLauncher = mifosScheduler.getBatchJobLauncher();
    JobLocator jobLocator = mifosScheduler.getBatchJobLocator();
    jobLauncher.run(jobLocator.getJob(jobName), MifosBatchJob.createJobParameters(previousFireTime.getTime()));
    Thread.sleep(1500);
    productStatusTask.catchUpMissedLaunches(jobLocator.getJob(jobName), jobExecutionContext);
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 20);
    Assert.assertEquals(11, jobInstances.size());
    for (JobInstance jobInstance : jobInstances) {
        List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstance);
        Assert.assertEquals(BatchStatus.COMPLETED, jobExecutions.get(0).getStatus());
        Assert.assertEquals(calendar.getTimeInMillis(), jobInstance.getJobParameters().getLong(MifosBatchJob.JOB_EXECUTION_TIME_KEY));
        calendar.roll(Calendar.SECOND, false);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) CronTrigger(org.quartz.CronTrigger) JobLauncher(org.springframework.batch.core.launch.JobLauncher) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) JobInstance(org.springframework.batch.core.JobInstance) Scheduler(org.quartz.Scheduler) Calendar(java.util.Calendar) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) JobLocator(org.springframework.batch.core.configuration.JobLocator) ProductStatus(org.mifos.framework.components.batchjobs.helpers.ProductStatus) TriggerFiredBundle(org.quartz.spi.TriggerFiredBundle) Date(java.util.Date) JobExecution(org.springframework.batch.core.JobExecution) JobDetail(org.quartz.JobDetail) JobExecutionContext(org.quartz.JobExecutionContext) JobExplorer(org.springframework.batch.core.explore.JobExplorer) Test(org.junit.Test)

Example 2 with JobLauncher

use of org.springframework.batch.core.launch.JobLauncher 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 3 with JobLauncher

use of org.springframework.batch.core.launch.JobLauncher 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 4 with JobLauncher

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

the class SpringBatchEndpointTest method shouldInjectJobLauncherByReferenceName.

@Test
public void shouldInjectJobLauncherByReferenceName() throws Exception {
    // Given
    context().addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:launcherRefTest").to("spring-batch:mockJob?jobLauncher=#alternativeJobLauncher");
        }
    });
    // When
    template.sendBody("direct:launcherRefTest", "Start the job, please.");
    // Then
    SpringBatchEndpoint batchEndpoint = context().getEndpoint("spring-batch:mockJob?jobLauncher=#alternativeJobLauncher", SpringBatchEndpoint.class);
    JobLauncher batchEndpointJobLauncher = (JobLauncher) FieldUtils.readField(batchEndpoint, "jobLauncher", true);
    assertSame(alternativeJobLauncher, batchEndpointJobLauncher);
}
Also used : JobLauncher(org.springframework.batch.core.launch.JobLauncher) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

Example 5 with JobLauncher

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

the class SpringBatchEndpointTest method shouldResolveAnyJobLauncher.

@Test
public void shouldResolveAnyJobLauncher() throws Exception {
    // Given
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("mockJob", job);
    registry.put("someRandomName", jobLauncher);
    CamelContext camelContext = new DefaultCamelContext(registry);
    camelContext.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("spring-batch:mockJob");
        }
    });
    // When
    camelContext.start();
    // Then
    SpringBatchEndpoint batchEndpoint = camelContext.getEndpoint("spring-batch:mockJob", SpringBatchEndpoint.class);
    JobLauncher batchEndpointJobLauncher = (JobLauncher) FieldUtils.readField(batchEndpoint, "jobLauncher", true);
    assertSame(jobLauncher, batchEndpointJobLauncher);
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) JobLauncher(org.springframework.batch.core.launch.JobLauncher) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

Aggregations

JobLauncher (org.springframework.batch.core.launch.JobLauncher)9 Test (org.junit.Test)6 JobExecution (org.springframework.batch.core.JobExecution)5 Date (java.util.Date)3 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 Job (org.springframework.batch.core.Job)3 JobInstance (org.springframework.batch.core.JobInstance)3 JobParameters (org.springframework.batch.core.JobParameters)3 JobLocator (org.springframework.batch.core.configuration.JobLocator)3 JobExplorer (org.springframework.batch.core.explore.JobExplorer)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Calendar (java.util.Calendar)1 CamelContext (org.apache.camel.CamelContext)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)1 DemoLineAggregator (org.family.aggregator.DemoLineAggregator)1 DeviceCommand (org.family.dto.DeviceCommand)1 DemoLineMapper (org.family.mapper.DemoLineMapper)1 DemoProcessor (org.family.processor.DemoProcessor)1