Search in sources :

Example 26 with HistoricBatch

use of org.camunda.bpm.engine.batch.history.HistoricBatch in project camunda-bpm-platform by camunda.

the class HistoryCleanupHistoricBatchTest method testCleanupHistoricJobLog.

@Test
public void testCleanupHistoricJobLog() {
    initBatchOperationHistoryTimeToLive(DEFAULT_TTL_DAYS);
    int daysInThePast = -11;
    // given
    prepareHistoricBatches(1, daysInThePast);
    HistoricBatch batch = historyService.createHistoricBatchQuery().singleResult();
    String batchId = batch.getId();
    // when
    String jobId = historyService.cleanUpHistoryAsync(true).getId();
    managementService.executeJob(jobId);
    // then
    assertEquals(0, historyService.createHistoricBatchQuery().count());
    assertEquals(0, historyService.createHistoricJobLogQuery().jobDefinitionConfiguration(batchId).count());
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Test(org.junit.Test)

Example 27 with HistoricBatch

use of org.camunda.bpm.engine.batch.history.HistoricBatch in project camunda-bpm-platform by camunda.

the class HistoryCleanupHistoricBatchTest method testMixedConfiguration.

@Test
public void testMixedConfiguration() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("instance-modification", "P20D");
    processEngineConfiguration.setBatchOperationHistoryTimeToLive(DEFAULT_TTL_DAYS);
    processEngineConfiguration.setBatchOperationsForHistoryCleanup(map);
    processEngineConfiguration.initHistoryCleanup();
    Date startDate = ClockUtil.getCurrentTime();
    int daysInThePast = -11;
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, daysInThePast));
    Batch modificationBatch = createModificationBatch();
    List<String> batchIds = new ArrayList<String>();
    batchIds.add(modificationBatch.getId());
    int migrationCountBatch = 10;
    batchIds.addAll(createMigrationBatchList(migrationCountBatch));
    int cancelationCountBatch = 20;
    batchIds.addAll(createCancelationBatchList(cancelationCountBatch));
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -8));
    for (String batchId : batchIds) {
        managementService.deleteBatch(batchId, false);
    }
    ClockUtil.setCurrentTime(new Date());
    // when
    List<HistoricBatch> historicList = historyService.createHistoricBatchQuery().list();
    assertEquals(31, historicList.size());
    String jobId = historyService.cleanUpHistoryAsync(true).getId();
    managementService.executeJob(jobId);
    // then
    // the other batches should be cleaned
    HistoricBatch modificationHistoricBatch = historyService.createHistoricBatchQuery().singleResult();
    assertEquals(modificationBatch.getId(), modificationHistoricBatch.getId());
    assertEquals(2, historyService.createHistoricJobLogQuery().jobDefinitionConfiguration(modificationBatch.getId()).count());
    batchIds.remove(modificationBatch.getId());
    for (String batchId : batchIds) {
        assertEquals(0, historyService.createHistoricJobLogQuery().jobDefinitionConfiguration(batchId).count());
    }
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) HashMap(java.util.HashMap) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 28 with HistoricBatch

use of org.camunda.bpm.engine.batch.history.HistoricBatch in project camunda-bpm-platform by camunda.

the class HistoryCleanupHistoricBatchTest method testCleanupHistoricIncident.

@Test
public void testCleanupHistoricIncident() {
    initBatchOperationHistoryTimeToLive(DEFAULT_TTL_DAYS);
    ClockUtil.setCurrentTime(DateUtils.addDays(new Date(), -11));
    BatchEntity batch = (BatchEntity) createFailingMigrationBatch();
    migrationHelper.executeSeedJob(batch);
    List<Job> list = managementService.createJobQuery().list();
    for (Job job : list) {
        if (((JobEntity) job).getJobHandlerType().equals("instance-migration")) {
            managementService.setJobRetries(job.getId(), 1);
        }
    }
    migrationHelper.executeJobs(batch);
    List<String> byteArrayIds = findExceptionByteArrayIds();
    ClockUtil.setCurrentTime(DateUtils.addDays(new Date(), -10));
    managementService.deleteBatch(batch.getId(), false);
    ClockUtil.setCurrentTime(new Date());
    // given
    HistoricBatch historicBatch = historyService.createHistoricBatchQuery().singleResult();
    String batchId = historicBatch.getId();
    // when
    String jobId = historyService.cleanUpHistoryAsync(true).getId();
    managementService.executeJob(jobId);
    assertEquals(0, historyService.createHistoricBatchQuery().count());
    assertEquals(0, historyService.createHistoricJobLogQuery().jobDefinitionConfiguration(batchId).count());
    assertEquals(0, historyService.createHistoricIncidentQuery().count());
    verifyByteArraysWereRemoved(byteArrayIds.toArray(new String[] {}));
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) BatchEntity(org.camunda.bpm.engine.impl.batch.BatchEntity) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) Test(org.junit.Test)

Example 29 with HistoricBatch

use of org.camunda.bpm.engine.batch.history.HistoricBatch in project camunda-bpm-platform by camunda.

the class HistoricBatchQueryTest method testBatchQueryOrderByEndTimeAsc.

@Test
public void testBatchQueryOrderByEndTimeAsc() {
    // given
    ClockTestUtil.setClockToDateWithoutMilliseconds();
    Batch batch1 = helper.migrateProcessInstancesAsync(1);
    helper.completeBatch(batch1);
    ClockTestUtil.incrementClock(1000);
    Batch batch2 = helper.migrateProcessInstancesAsync(1);
    helper.completeBatch(batch2);
    // when
    List<HistoricBatch> orderedBatches = historyService.createHistoricBatchQuery().orderByEndTime().asc().list();
    // then
    verifySorting(orderedBatches, historicBatchByEndTime());
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) Test(org.junit.Test)

Example 30 with HistoricBatch

use of org.camunda.bpm.engine.batch.history.HistoricBatch in project camunda-bpm-platform by camunda.

the class HistoricBatchQueryTest method testBatchQuery.

@Test
public void testBatchQuery() {
    // given
    Batch batch1 = helper.migrateProcessInstancesAsync(1);
    Batch batch2 = helper.migrateProcessInstancesAsync(1);
    // when
    List<HistoricBatch> list = historyService.createHistoricBatchQuery().list();
    // then
    assertEquals(2, list.size());
    List<String> batchIds = new ArrayList<String>();
    for (HistoricBatch resultBatch : list) {
        batchIds.add(resultBatch.getId());
    }
    Assert.assertTrue(batchIds.contains(batch1.getId()));
    Assert.assertTrue(batchIds.contains(batch2.getId()));
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

HistoricBatch (org.camunda.bpm.engine.batch.history.HistoricBatch)45 Batch (org.camunda.bpm.engine.batch.Batch)34 Test (org.junit.Test)26 Date (java.util.Date)13 After (org.junit.After)12 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)4 HistoryService (org.camunda.bpm.engine.HistoryService)4 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)4 ManagementService (org.camunda.bpm.engine.ManagementService)3 CleanableHistoricBatchReportResult (org.camunda.bpm.engine.history.CleanableHistoricBatchReportResult)3 HistoricBatchQuery (org.camunda.bpm.engine.batch.history.HistoricBatchQuery)2 HashSet (java.util.HashSet)1 List (java.util.List)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 BatchEntity (org.camunda.bpm.engine.impl.batch.BatchEntity)1 HistoricBatchEntity (org.camunda.bpm.engine.impl.batch.history.HistoricBatchEntity)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1 HistoricBatchManager (org.camunda.bpm.engine.impl.persistence.entity.HistoricBatchManager)1 HistoricBatchDto (org.camunda.bpm.engine.rest.dto.history.batch.HistoricBatchDto)1