Search in sources :

Example 11 with JobEntity

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

the class IncidentTest method testDoNotSetNegativeRetries.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateOneIncident.bpmn" })
public void testDoNotSetNegativeRetries() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("failingProcess");
    executeAvailableJobs();
    // it exists a job with 0 retries and an incident
    Job job = managementService.createJobQuery().singleResult();
    assertEquals(0, job.getRetries());
    assertEquals(1, runtimeService.createIncidentQuery().count());
    // it should not be possible to set negative retries
    final JobEntity jobEntity = (JobEntity) job;
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            jobEntity.setRetries(-100);
            return null;
        }
    });
    assertEquals(0, job.getRetries());
    // retries should still be 0 after execution this job again
    try {
        managementService.executeJob(job.getId());
        fail("Exception expected");
    } catch (ProcessEngineException e) {
    // expected
    }
    job = managementService.createJobQuery().singleResult();
    assertEquals(0, job.getRetries());
    // also no new incident was created
    assertEquals(1, runtimeService.createIncidentQuery().count());
    // it should not be possible to set the retries to a negative number with the management service
    try {
        managementService.setJobRetries(job.getId(), -200);
        fail("Exception expected");
    } catch (ProcessEngineException e) {
    // expected
    }
    try {
        managementService.setJobRetriesByJobDefinitionId(job.getJobDefinitionId(), -300);
        fail("Exception expected");
    } catch (ProcessEngineException e) {
    // expected
    }
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 12 with JobEntity

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

the class HistoryCleanupBatchWindowTest method clearDatabase.

@After
public void clearDatabase() {
    // reset configuration changes
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(defaultStartTime);
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime(defaultEndTime);
    processEngineConfiguration.setHistoryCleanupBatchSize(defaultBatchSize);
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            List<Job> jobs = managementService.createJobQuery().list();
            if (jobs.size() > 0) {
                assertEquals(1, jobs.size());
                String jobId = jobs.get(0).getId();
                commandContext.getJobManager().deleteJob((JobEntity) jobs.get(0));
                commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(jobId);
            }
            List<HistoricIncident> historicIncidents = historyService.createHistoricIncidentQuery().list();
            for (HistoricIncident historicIncident : historicIncidents) {
                commandContext.getDbEntityManager().delete((HistoricIncidentEntity) historicIncident);
            }
            commandContext.getMeterLogManager().deleteAll();
            return null;
        }
    });
    List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().list();
    for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
        historyService.deleteHistoricProcessInstance(historicProcessInstance.getId());
    }
    List<HistoricDecisionInstance> historicDecisionInstances = historyService.createHistoricDecisionInstanceQuery().list();
    for (HistoricDecisionInstance historicDecisionInstance : historicDecisionInstances) {
        historyService.deleteHistoricDecisionInstanceByInstanceId(historicDecisionInstance.getId());
    }
    List<HistoricCaseInstance> historicCaseInstances = historyService.createHistoricCaseInstanceQuery().list();
    for (HistoricCaseInstance historicCaseInstance : historicCaseInstances) {
        historyService.deleteHistoricCaseInstance(historicCaseInstance.getId());
    }
    clearMetrics();
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricDecisionInstance(org.camunda.bpm.engine.history.HistoricDecisionInstance) JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) HistoricIncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) List(java.util.List) After(org.junit.After)

Example 13 with JobEntity

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

the class HistoryCleanupTest method testLessThanThresholdWithinBatchWindowMaxDelayReached.

@Test
public void testLessThanThresholdWithinBatchWindowMaxDelayReached() {
    // 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.addHours(now, 2)));
    processEngineConfiguration.initHistoryCleanup();
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    for (int i = 1; i <= 11; i++) {
        managementService.executeJob(jobId);
    }
    // then
    JobEntity jobEntity = getJobEntity(jobId);
    HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity);
    // job rescheduled till current time + max delay
    Date nextRun = getNextRunWithDelay(ClockUtil.getCurrentTime(), 10);
    assertTrue(jobEntity.getDuedate().equals(nextRun) || jobEntity.getDuedate().after(nextRun));
    assertTrue(jobEntity.getDuedate().before(getNextRunWithinBatchWindow(now)));
    // countEmptyRuns incremented
    assertEquals(11, 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 14 with JobEntity

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

the class HistoryCleanupTest method testLessThanThresholdWithinBatchWindowAgain.

@Test
public void testLessThanThresholdWithinBatchWindowAgain() {
    // 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.addHours(now, 1)));
    processEngineConfiguration.initHistoryCleanup();
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    for (int i = 1; i <= 6; i++) {
        managementService.executeJob(jobId);
    }
    // then
    JobEntity jobEntity = getJobEntity(jobId);
    HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity);
    // job rescheduled till current time + (2 power count)*delay
    Date nextRun = getNextRunWithDelay(ClockUtil.getCurrentTime(), HISTORY_TIME_TO_LIVE);
    assertTrue(jobEntity.getDuedate().equals(nextRun) || jobEntity.getDuedate().after(nextRun));
    Date nextRunMax = DateUtils.addSeconds(ClockUtil.getCurrentTime(), HistoryCleanupJobHandlerConfiguration.MAX_DELAY);
    assertTrue(jobEntity.getDuedate().before(nextRunMax));
    // countEmptyRuns incremented
    assertEquals(6, 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 15 with JobEntity

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

the class HistoryCleanupTest method testHistoryCleanupJobResolveIncident.

@Test
public void testHistoryCleanupJobResolveIncident() {
    // given
    String jobId = historyService.cleanUpHistoryAsync(true).getId();
    imitateFailedJob(jobId);
    assertEquals(5, processEngineConfiguration.getDefaultNumberOfRetries());
    // when
    // call to cleanup history means that incident was resolved
    jobId = historyService.cleanUpHistoryAsync(true).getId();
    // then
    JobEntity jobEntity = getJobEntity(jobId);
    assertEquals(5, jobEntity.getRetries());
    assertEquals(null, jobEntity.getExceptionByteArrayId());
    assertEquals(null, jobEntity.getExceptionMessage());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Test(org.junit.Test)

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