Search in sources :

Example 31 with HistoricBatch

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

the class HistoricBatchQueryTest method testBatchQueryOrderByEndTimeDec.

@Test
public void testBatchQueryOrderByEndTimeDec() {
    // 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().desc().list();
    // then
    verifySorting(orderedBatches, inverted(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 32 with HistoricBatch

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

the class HistoricBatchQueryTest method testBatchByState.

@Test
public void testBatchByState() {
    // given
    Batch batch1 = helper.migrateProcessInstancesAsync(1);
    Batch batch2 = helper.migrateProcessInstancesAsync(1);
    helper.completeBatch(batch1);
    // when
    HistoricBatch historicBatch = historyService.createHistoricBatchQuery().completed(true).singleResult();
    // then
    assertEquals(batch1.getId(), historicBatch.getId());
    // when
    historicBatch = historyService.createHistoricBatchQuery().completed(false).singleResult();
    // then
    assertEquals(batch2.getId(), historicBatch.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) Test(org.junit.Test)

Example 33 with HistoricBatch

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

the class HistoricBatchQueryTest method testBatchQueryById.

@Test
public void testBatchQueryById() {
    // given
    Batch batch1 = helper.migrateProcessInstancesAsync(1);
    helper.migrateProcessInstancesAsync(1);
    // when
    HistoricBatch resultBatch = historyService.createHistoricBatchQuery().batchId(batch1.getId()).singleResult();
    // then
    Assert.assertNotNull(resultBatch);
    assertEquals(batch1.getId(), resultBatch.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) Test(org.junit.Test)

Example 34 with HistoricBatch

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

the class HistoricBatchQueryTest method testBatchQueryResult.

@Test
public void testBatchQueryResult() {
    Date startDate = new Date(10000L);
    Date endDate = new Date(40000L);
    // given
    ClockUtil.setCurrentTime(startDate);
    Batch batch = helper.migrateProcessInstancesAsync(1);
    helper.executeSeedJob(batch);
    helper.executeJobs(batch);
    ClockUtil.setCurrentTime(endDate);
    helper.executeMonitorJob(batch);
    // when
    HistoricBatch resultBatch = historyService.createHistoricBatchQuery().singleResult();
    // then
    Assert.assertNotNull(resultBatch);
    assertEquals(batch.getId(), resultBatch.getId());
    assertEquals(batch.getBatchJobDefinitionId(), resultBatch.getBatchJobDefinitionId());
    assertEquals(batch.getMonitorJobDefinitionId(), resultBatch.getMonitorJobDefinitionId());
    assertEquals(batch.getSeedJobDefinitionId(), resultBatch.getSeedJobDefinitionId());
    assertEquals(batch.getTenantId(), resultBatch.getTenantId());
    assertEquals(batch.getType(), resultBatch.getType());
    assertEquals(batch.getBatchJobsPerSeed(), resultBatch.getBatchJobsPerSeed());
    assertEquals(batch.getInvocationsPerBatchJob(), resultBatch.getInvocationsPerBatchJob());
    assertEquals(batch.getTotalJobs(), resultBatch.getTotalJobs());
    assertEquals(startDate, resultBatch.getStartTime());
    assertEquals(endDate, resultBatch.getEndTime());
}
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) Date(java.util.Date) Test(org.junit.Test)

Example 35 with HistoricBatch

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

the class HistoricInstanceForCleanupQueryTest method testSortHistoricBatchesForCleanup.

@SuppressWarnings("unchecked")
@Test
public void testSortHistoricBatchesForCleanup() {
    Date startDate = ClockUtil.getCurrentTime();
    int daysInThePast = -11;
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, daysInThePast));
    // given
    List<Batch> list = Arrays.asList(helper.migrateProcessInstancesAsync(1), helper.migrateProcessInstancesAsync(1), helper.migrateProcessInstancesAsync(1));
    String batchType = list.get(0).getType();
    final Map<String, Integer> batchOperationsMap = new HashedMap();
    batchOperationsMap.put(batchType, 4);
    for (Batch batch : list) {
        helper.executeSeedJob(batch);
        helper.executeJobs(batch);
        ClockUtil.setCurrentTime(DateUtils.addDays(startDate, ++daysInThePast));
        helper.executeMonitorJob(batch);
    }
    ClockUtil.setCurrentTime(new Date());
    // when
    List<HistoricBatch> historicList = historyService.createHistoricBatchQuery().list();
    assertEquals(3, historicList.size());
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            HistoricBatchManager historicBatchManager = commandContext.getHistoricBatchManager();
            List<String> ids = historicBatchManager.findHistoricBatchIdsForCleanup(7, batchOperationsMap);
            assertEquals(3, ids.size());
            HistoricBatchEntity instance0 = historicBatchManager.findHistoricBatchById(ids.get(0));
            HistoricBatchEntity instance1 = historicBatchManager.findHistoricBatchById(ids.get(1));
            HistoricBatchEntity instance2 = historicBatchManager.findHistoricBatchById(ids.get(2));
            assertTrue(instance0.getEndTime().before(instance1.getEndTime()));
            assertTrue(instance1.getEndTime().before(instance2.getEndTime()));
            return null;
        }
    });
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Date(java.util.Date) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) HistoricBatchEntity(org.camunda.bpm.engine.impl.batch.history.HistoricBatchEntity) List(java.util.List) HashedMap(org.apache.commons.collections.map.HashedMap) HistoricBatchManager(org.camunda.bpm.engine.impl.persistence.entity.HistoricBatchManager) 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