Search in sources :

Example 6 with CleanableHistoricBatchReportResult

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

the class CleanableHistoricBatchReportServiceTest method setupHistoryReportMock.

private void setupHistoryReportMock() {
    CleanableHistoricBatchReport report = mock(CleanableHistoricBatchReport.class);
    CleanableHistoricBatchReportResult reportResult = mock(CleanableHistoricBatchReportResult.class);
    when(reportResult.getBatchType()).thenReturn(EXAMPLE_TYPE);
    when(reportResult.getHistoryTimeToLive()).thenReturn(EXAMPLE_TTL);
    when(reportResult.getFinishedBatchesCount()).thenReturn(EXAMPLE_FINISHED_COUNT);
    when(reportResult.getCleanableBatchesCount()).thenReturn(EXAMPLE_CLEANABLE_COUNT);
    CleanableHistoricBatchReportResult anotherReportResult = mock(CleanableHistoricBatchReportResult.class);
    when(anotherReportResult.getBatchType()).thenReturn("batchId2");
    when(anotherReportResult.getHistoryTimeToLive()).thenReturn(null);
    when(anotherReportResult.getFinishedBatchesCount()).thenReturn(13l);
    when(anotherReportResult.getCleanableBatchesCount()).thenReturn(0l);
    List<CleanableHistoricBatchReportResult> mocks = new ArrayList<CleanableHistoricBatchReportResult>();
    mocks.add(reportResult);
    mocks.add(anotherReportResult);
    when(report.list()).thenReturn(mocks);
    when(report.count()).thenReturn((long) mocks.size());
    historicBatchReport = report;
    when(processEngine.getHistoryService().createCleanableHistoricBatchReport()).thenReturn(historicBatchReport);
}
Also used : CleanableHistoricBatchReportResult(org.camunda.bpm.engine.history.CleanableHistoricBatchReportResult) ArrayList(java.util.ArrayList) CleanableHistoricBatchReport(org.camunda.bpm.engine.history.CleanableHistoricBatchReport)

Example 7 with CleanableHistoricBatchReportResult

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

the class HistoricBatchRestServiceImpl method getCleanableHistoricBatchesReport.

@SuppressWarnings("unchecked")
@Override
public List<CleanableHistoricBatchReportResultDto> getCleanableHistoricBatchesReport(UriInfo uriInfo, Integer firstResult, Integer maxResults) {
    CleanableHistoricBatchReportDto queryDto = new CleanableHistoricBatchReportDto(objectMapper, uriInfo.getQueryParameters());
    CleanableHistoricBatchReport query = queryDto.toQuery(processEngine);
    List<CleanableHistoricBatchReportResult> reportResult;
    if (firstResult != null || maxResults != null) {
        reportResult = (List<CleanableHistoricBatchReportResult>) executePaginatedQuery(query, firstResult, maxResults);
    } else {
        reportResult = query.list();
    }
    return CleanableHistoricBatchReportResultDto.convert(reportResult);
}
Also used : CleanableHistoricBatchReportDto(org.camunda.bpm.engine.rest.dto.history.batch.CleanableHistoricBatchReportDto) CleanableHistoricBatchReportResult(org.camunda.bpm.engine.history.CleanableHistoricBatchReportResult) CleanableHistoricBatchReport(org.camunda.bpm.engine.history.CleanableHistoricBatchReport)

Example 8 with CleanableHistoricBatchReportResult

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

the class CleanableHistoricBatchReportTest method testReportNoDefaultConfiguration.

@Test
public void testReportNoDefaultConfiguration() {
    Map<String, String> map = new HashMap<String, String>();
    int modOperationsTTL = 5;
    map.put("instance-modification", "P5D");
    int delOperationsTTL = 7;
    map.put("instance-deletion", "P7D");
    processEngineConfiguration.setBatchOperationsForHistoryCleanup(map);
    processEngineConfiguration.initHistoryCleanup();
    assertNull(processEngineConfiguration.getBatchOperationHistoryTimeToLive());
    Date startDate = new Date();
    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;
    List<String> batchIds1 = new ArrayList<String>();
    batchIds1.addAll(createMigrationBatchList(migrationCountBatch));
    int cancelationCountBatch = 20;
    List<String> batchIds2 = new ArrayList<String>();
    batchIds2.addAll(createCancelationBatchList(cancelationCountBatch));
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -8));
    for (String batchId : batchIds) {
        managementService.deleteBatch(batchId, false);
    }
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -2));
    for (int i = 0; i < 4; i++) {
        managementService.deleteBatch(batchIds1.get(i), false);
    }
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -7));
    for (int i = 6; i < batchIds1.size(); i++) {
        managementService.deleteBatch(batchIds1.get(i), false);
    }
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -10));
    for (int i = 0; i < 7; i++) {
        managementService.deleteBatch(batchIds2.get(i), false);
    }
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -5));
    for (int i = 7; i < 11; i++) {
        managementService.deleteBatch(batchIds2.get(i), false);
    }
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -1));
    for (int i = 13; i < batchIds2.size(); i++) {
        managementService.deleteBatch(batchIds2.get(i), false);
    }
    ClockUtil.setCurrentTime(DateUtils.addSeconds(startDate, 1));
    // when
    List<HistoricBatch> historicList = historyService.createHistoricBatchQuery().list();
    assertEquals(31, historicList.size());
    List<CleanableHistoricBatchReportResult> list = historyService.createCleanableHistoricBatchReport().list();
    assertEquals(3, list.size());
    for (CleanableHistoricBatchReportResult result : list) {
        if (result.getBatchType().equals("instance-migration")) {
            checkResultNumbers(result, 0, 8, null);
        } else if (result.getBatchType().equals("instance-modification")) {
            checkResultNumbers(result, 1, 1, modOperationsTTL);
        } else if (result.getBatchType().equals("instance-deletion")) {
            checkResultNumbers(result, delOperationsTTL, 18, delOperationsTTL);
        }
    }
}
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) CleanableHistoricBatchReportResult(org.camunda.bpm.engine.history.CleanableHistoricBatchReportResult) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Aggregations

CleanableHistoricBatchReportResult (org.camunda.bpm.engine.history.CleanableHistoricBatchReportResult)8 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 Date (java.util.Date)4 Batch (org.camunda.bpm.engine.batch.Batch)4 HistoricBatch (org.camunda.bpm.engine.batch.history.HistoricBatch)4 HashMap (java.util.HashMap)3 CleanableHistoricBatchReport (org.camunda.bpm.engine.history.CleanableHistoricBatchReport)2 CleanableHistoricBatchReportDto (org.camunda.bpm.engine.rest.dto.history.batch.CleanableHistoricBatchReportDto)1