Search in sources :

Example 56 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdCloseToBatchWindowEndTime.

@Test
public void testLessThanThresholdCloseToBatchWindowEndTime() {
    // given
    prepareData(5);
    // we're within batch window
    Date now = new Date();
    ClockUtil.setCurrentTime(now);
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(new SimpleDateFormat("HH:mm").format(now));
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime(new SimpleDateFormat("HH:mm").format(DateUtils.addMinutes(now, 30)));
    processEngineConfiguration.initHistoryCleanup();
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    for (int i = 1; i <= 9; i++) {
        managementService.executeJob(jobId);
    }
    // then
    JobEntity jobEntity = getJobEntity(jobId);
    HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity);
    // job rescheduled till next batch window start time
    Date nextRun = getNextRunWithinBatchWindow(ClockUtil.getCurrentTime());
    assertTrue(jobEntity.getDuedate().equals(nextRun));
    // countEmptyRuns canceled
    assertEquals(0, configuration.getCountEmptyRuns());
    // data is still removed
    assertResult(0);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoryCleanupJobHandlerConfiguration(org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 57 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdManualRun.

@Test
public void testLessThanThresholdManualRun() {
    // given
    prepareData(5);
    ClockUtil.setCurrentTime(new Date());
    // when
    String jobId = historyService.cleanUpHistoryAsync(true).getId();
    managementService.executeJob(jobId);
    // then
    assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count());
    JobEntity jobEntity = getJobEntity(jobId);
    assertEquals(SuspensionState.SUSPENDED.getStateCode(), jobEntity.getSuspensionState());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Date(java.util.Date) Test(org.junit.Test)

Example 58 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class FoxJobRetryCmdTest method FAILING_testFailedRetryWithTimeShift.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.testFailedServiceTask.bpmn20.xml" })
public void FAILING_testFailedRetryWithTimeShift() throws ParseException {
    // set date to hour before time shift (2015-10-25T03:00:00 CEST =>
    // 2015-10-25T02:00:00 CET)
    Date tenMinutesBeforeTimeShift = createDateFromLocalString("2015-10-25T02:50:00 CEST");
    Date fiveMinutesBeforeTimeShift = createDateFromLocalString("2015-10-25T02:55:00 CEST");
    Date twoMinutesBeforeTimeShift = createDateFromLocalString("2015-10-25T02:58:00 CEST");
    ClockUtil.setCurrentTime(tenMinutesBeforeTimeShift);
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("failedServiceTask");
    assertNotNull(pi);
    // a job is acquirable
    List<JobEntity> acquirableJobs = findAndLockAcquirableJobs();
    assertEquals(1, acquirableJobs.size());
    // execute job
    waitForExecutedJobWithRetriesLeft(4);
    // the job lock time is after the current time but before the time shift
    JobEntity job = (JobEntity) fetchJob(pi.getProcessInstanceId());
    assertTrue(tenMinutesBeforeTimeShift.before(job.getLockExpirationTime()));
    assertEquals(fiveMinutesBeforeTimeShift, job.getLockExpirationTime());
    assertTrue(twoMinutesBeforeTimeShift.after(job.getLockExpirationTime()));
    // the job is not acquirable
    acquirableJobs = findAndLockAcquirableJobs();
    assertEquals(0, acquirableJobs.size());
    // set clock to two minutes before time shift
    ClockUtil.setCurrentTime(twoMinutesBeforeTimeShift);
    // the job is now acquirable
    acquirableJobs = findAndLockAcquirableJobs();
    assertEquals(1, acquirableJobs.size());
    // execute job
    waitForExecutedJobWithRetriesLeft(3);
    // the job lock time is after the current time
    job = (JobEntity) refreshJob(job.getId());
    assertTrue(twoMinutesBeforeTimeShift.before(job.getLockExpirationTime()));
    // the job is not acquirable
    acquirableJobs = findAndLockAcquirableJobs();
    assertEquals("Job shouldn't be acquirable", 0, acquirableJobs.size());
    ClockUtil.reset();
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Date(java.util.Date) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 59 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class AsyncAfterTest method fetchFirstJobByHandlerConfiguration.

protected Job fetchFirstJobByHandlerConfiguration(List<Job> jobs, String configuration) {
    for (Job job : jobs) {
        JobEntity jobEntity = (JobEntity) job;
        String jobConfig = jobEntity.getJobHandlerConfigurationRaw();
        if (configuration.equals(jobConfig)) {
            return job;
        }
    }
    return null;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Job(org.camunda.bpm.engine.runtime.Job)

Example 60 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class RetryIntervalsConfigurationTest method assertLockExpirationTime.

private void assertLockExpirationTime(Date expectedDate) throws ParseException {
    Date lockExpirationTime = ((JobEntity) managementService.createJobQuery().singleResult()).getLockExpirationTime();
    assertEquals(expectedDate, lockExpirationTime);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Date(java.util.Date)

Aggregations

JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)68 Test (org.junit.Test)26 Date (java.util.Date)18 Job (org.camunda.bpm.engine.runtime.Job)13 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)11 HistoryCleanupJobHandlerConfiguration (org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)7 SimpleDateFormat (java.text.SimpleDateFormat)6 List (java.util.List)6 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)6 Page (org.camunda.bpm.engine.impl.Page)5 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)4 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)4 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)4 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3