public void scheduleBatchJob(Notification notification, long delay) throws Exception { JobData jobData = new JobData(); jobData.setProperty("applicationId", sm.getApplicationId()); jobData.setProperty("notificationId", notification.getUuid()); jobData.setProperty("deliver", notification.getDeliver()); long soonestPossible = System.currentTimeMillis() + SCHEDULER_GRACE_PERIOD + delay; SchedulerService scheduler = getSchedulerService(); scheduler.createJob("notificationBatchJob", soonestPossible, jobData); if (logger.isTraceEnabled()) { logger.trace("notification {} batch scheduled for delivery", notification.getUuid()); } } public boolean scheduleQueueJob(Notification notification) throws Exception {
@Test public void testExportEmptyJobData() throws Exception { JobData jobData = new JobData(); JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); when( jobExecution.getJobId() ).thenReturn( UUID.randomUUID() ); ExportJob job = new ExportJob(); S3Export s3Export = mock( S3Export.class ); //setup.getExportService().setS3Export( s3Export ); job.setExportService( setup.getExportService() ); try { job.doJob( jobExecution ); } catch ( Exception e ) { assert ( false ); } assert ( true ); }
@Test public void testNullJobExecution() { JobData jobData = new JobData(); JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); when( jobExecution.getJobId() ).thenReturn( UUID.randomUUID() ); ExportJob job = new ExportJob(); S3Export s3Export = mock( S3Export.class ); // setup.getExportService().setS3Export( s3Export ); job.setExportService( setup.getExportService() ); try { job.doJob( jobExecution ); } catch ( Exception e ) { assert ( false ); } assert ( true ); }
public boolean scheduleQueueJob(Notification notification, boolean forceSchedule) throws Exception { boolean scheduleInFuture = notification.getDeliver() != null; long scheduleAt = (notification.getDeliver() != null) ? notification.getDeliver() : 0; long soonestPossible = System.currentTimeMillis() + SCHEDULER_GRACE_PERIOD; if (scheduleAt < soonestPossible) { scheduleAt = soonestPossible; scheduleInFuture = false; } boolean scheduled = scheduleInFuture || forceSchedule; if(scheduled) { JobData jobData = new JobData(); jobData.setProperty("applicationId", sm.getApplicationId()); jobData.setProperty("notificationId", notification.getUuid()); jobData.setProperty("deliver", notification.getDeliver()); SchedulerService scheduler = getSchedulerService(); scheduler.createJob("queueJob", scheduleAt, jobData); if (logger.isTraceEnabled()) { logger.trace("notification {} scheduled for queuing", notification.getUuid()); } } return scheduled; } private SchedulerService getSchedulerService() {
public JobData jobExportDataCreator(HashMap<String, Object> payload,UUID exportUUID,S3Export s3Export) { JobData jobData = new JobData(); jobData.setProperty( "jobName", "exportJob" ); jobData.setProperty( "exportInfo", payload ); jobData.setProperty( "exportId", exportUUID ); jobData.setProperty( "s3Export", s3Export); return jobData; }
public JobData jobDataCreator(HashMap<String, Object> payload,UUID exportUUID, S3Export s3Export) { JobData jobData = new JobData(); jobData.setProperty( "jobName", "exportJob" ); jobData.setProperty( "exportInfo", payload ); jobData.setProperty( "exportId", exportUUID ); jobData.setProperty( "s3Export", s3Export ); return jobData; }
public JobData jobImportDataCreator(HashMap<String, Object> payload,UUID importUUID,S3Import s3Import) { JobData jobData = new JobData(); jobData.setProperty( "jobName", "importJob" ); jobData.setProperty( "importInfo", payload ); jobData.setProperty( "importId", importUUID ); jobData.setProperty( "s3Import", s3Import ); return jobData; }
@Test public void testExportDoJob() throws Exception { String appName = newOrgAppAdminRule.getApplicationInfo().getName(); HashMap<String, Object> payload = payloadBuilder(appName); payload.put( "organizationId", organization.getUuid() ); payload.put( "applicationId", applicationId ); JobData jobData = new JobData(); jobData.setProperty( "jobName", "exportJob" ); // this needs to be populated with properties of export info jobData.setProperty( "exportInfo", payload ); JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); when( jobExecution.getJobId() ).thenReturn( UUID.randomUUID() ); ExportJob job = new ExportJob(); ExportService eS = mock( ExportService.class ); job.setExportService( eS ); try { job.doJob( jobExecution ); } catch ( Exception e ) { logger.error("Error doing job", e); assert ( false ); } assert ( true ); }
@Test public void transitionsOk() { JobData data = new JobData(); JobStat stat = new JobStat(); JobDescriptor jobDescriptor = new JobDescriptor( "", UUID.randomUUID(), UUID.randomUUID(), data, stat, null ); JobExecution bje = new JobExecutionImpl( jobDescriptor ); assertEquals( JobExecution.Status.NOT_STARTED, bje.getStatus() ); bje.start( 1 ); assertEquals( JobExecution.Status.IN_PROGRESS, bje.getStatus() ); bje.completed(); assertEquals( JobExecution.Status.COMPLETED, bje.getStatus() ); }
@Test public void transitionsDead() { JobData data = new JobData(); JobStat stat = new JobStat(); JobDescriptor jobDescriptor = new JobDescriptor( "", UUID.randomUUID(), UUID.randomUUID(), data, stat, null ); JobExecution bje = new JobExecutionImpl( jobDescriptor ); assertEquals( JobExecution.Status.NOT_STARTED, bje.getStatus() ); bje.start( 1 ); assertEquals( JobExecution.Status.IN_PROGRESS, bje.getStatus() ); bje.killed(); assertEquals( JobExecution.Status.DEAD, bje.getStatus() ); }
@Test public void transitionsRetry() { JobData data = new JobData(); JobStat stat = new JobStat(); JobDescriptor jobDescriptor = new JobDescriptor( "", UUID.randomUUID(), UUID.randomUUID(), data, stat, null ); JobExecution bje = new JobExecutionImpl( jobDescriptor ); assertEquals( JobExecution.Status.NOT_STARTED, bje.getStatus() ); bje.start( JobExecution.FOREVER ); assertEquals( JobExecution.Status.IN_PROGRESS, bje.getStatus() ); bje.failed(); assertEquals( JobExecution.Status.FAILED, bje.getStatus() ); }
@Test public void doubleInvokeFail() { JobData data = new JobData(); JobStat stat = new JobStat(); JobDescriptor jobDescriptor = new JobDescriptor( "", UUID.randomUUID(), UUID.randomUUID(), data, stat, null ); JobExecution bje = new JobExecutionImpl( jobDescriptor ); bje.start( 1 ); try { bje.start( 1 ); fail( "Should have failed on double start() call" ); } catch ( IllegalStateException ise ) { } bje.completed(); try { bje.completed(); fail( "Should have failed on double complete call" ); } catch ( IllegalStateException ise ) { } } }
@Test public void transitionFail() { JobData data = new JobData(); JobStat stat = new JobStat(); JobDescriptor jobDescriptor = new JobDescriptor( "", UUID.randomUUID(), UUID.randomUUID(), data, stat, null ); JobExecution bje = new JobExecutionImpl( jobDescriptor ); try { bje.completed(); fail( "Should have throw ISE on NOT_STARTED to IN_PROGRESS" ); } catch ( IllegalStateException ise ) { } try { bje.failed(); fail( "Should have thrown ISE on NOT_STARTED to FAILED" ); } catch ( IllegalStateException ise ) { } bje.start( 1 ); bje.completed(); try { bje.failed(); fail( "Should have failed failed after complete call" ); } catch ( IllegalStateException ise ) { } }
@Test public void transitionFailOnDeath() { JobData data = new JobData(); JobStat stat = new JobStat(); JobDescriptor jobDescriptor = new JobDescriptor( "", UUID.randomUUID(), UUID.randomUUID(), data, stat, null ); JobExecution bje = new JobExecutionImpl( jobDescriptor ); try { bje.completed(); fail( "Should have throw ISE on NOT_STARTED to IN_PROGRESS" ); } catch ( IllegalStateException ise ) { } try { bje.failed(); fail( "Should have thrown ISE on NOT_STARTED to FAILED" ); } catch ( IllegalStateException ise ) { } bje.start( 1 ); bje.killed(); try { bje.killed(); fail( "Should have failed failed after complete call" ); } catch ( IllegalStateException ise ) { } }
JobData returned = scheduler.createJob( "delayHeartbeat", System.currentTimeMillis(), new JobData() );
scheduler.createJob( "onlyOnceUnlockOnFailExceution", System.currentTimeMillis(), new JobData() );
@Test public void failureTriggerCount() { JobData data = new JobData(); JobStat stat = new JobStat(); JobDescriptor jobDescriptor = new JobDescriptor( "", UUID.randomUUID(), UUID.randomUUID(), data, stat, null ); JobExecution bje = new JobExecutionImpl( jobDescriptor ); bje.start( 1 ); assertEquals( Status.IN_PROGRESS, bje.getStatus() ); assertEquals( 1, stat.getRunCount() ); bje.failed(); assertEquals( Status.FAILED, bje.getStatus() ); assertEquals( 1, stat.getRunCount() ); // now fail again, we should trigger a state change bje = new JobExecutionImpl( jobDescriptor ); bje.start( 1 ); assertEquals( Status.DEAD, bje.getStatus() ); assertEquals( 2, stat.getRunCount() ); }
JobData returned = scheduler.createJob( "delayExecution", System.currentTimeMillis(), new JobData() );
@Test public void failureTriggerNoTrip() { JobData data = new JobData(); JobStat stat = new JobStat(); JobDescriptor jobDescriptor = new JobDescriptor( "", UUID.randomUUID(), UUID.randomUUID(), data, stat, null ); JobExecution bje = new JobExecutionImpl( jobDescriptor ); bje.start( JobExecution.FOREVER ); assertEquals( Status.IN_PROGRESS, bje.getStatus() ); assertEquals( 1, stat.getRunCount() ); bje.failed(); assertEquals( Status.FAILED, bje.getStatus() ); assertEquals( 1, stat.getRunCount() ); // now fail again, we should trigger a state change bje = new JobExecutionImpl( jobDescriptor ); bje.start( JobExecution.FOREVER ); assertEquals( Status.IN_PROGRESS, bje.getStatus() ); assertEquals( 2, stat.getRunCount() ); bje.failed(); assertEquals( Status.FAILED, bje.getStatus() ); assertEquals( 2, stat.getRunCount() ); }
scheduler.createJob( "countdownLatch", System.currentTimeMillis(), new JobData() );