List of usage examples for org.apache.commons.lang.time DateUtils addDays
public static Date addDays(Date date, int amount)
From source file:org.camunda.bpm.engine.test.api.history.HistoricInstanceForCleanupQueryTest.java
@SuppressWarnings("unchecked") @Test/*from ww w . j ava 2 s.c o m*/ 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; } }); }
From source file:org.camunda.bpm.engine.test.api.history.HistoricInstanceForCleanupQueryTest.java
private void startAndCloseCaseInstance(String caseDefinitionKey, int daysToAdd) { Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, daysToAdd)); CaseInstance caseInstance1 = caseService.createCaseInstanceByKey(caseDefinitionKey); caseService.terminateCaseExecution(caseInstance1.getId()); caseService.closeCaseInstance(caseInstance1.getId()); ClockUtil.setCurrentTime(oldCurrentTime); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupDmnDisabledTest.java
private void prepareHistoricProcesses(String businessKey) { Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(new Date(), -6)); List<String> processInstanceIds = new ArrayList<String>(); for (int i = 0; i < 5; i++) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(businessKey); processInstanceIds.add(processInstance.getId()); }// w w w.ja va2s .c om runtimeService.deleteProcessInstances(processInstanceIds, null, true, true); ClockUtil.setCurrentTime(oldCurrentTime); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupHistoricBatchTest.java
@Test public void testCleanupHistoricIncident() { initBatchOperationHistoryTimeToLive(5); 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); }//ww w .j a va 2 s. c o m } 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[] {})); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupHistoricBatchTest.java
@Test public void testBatchOperationTypeConfigurationOnly() { Map<String, Integer> map = new HashMap<String, Integer>(); map.put("instance-migration", 2); map.put("instance-deletion", 5); processEngineConfiguration.setBatchOperationHistoryTimeToLive(null); processEngineConfiguration.setBatchOperationHistoryTimeToLiveMap(map); processEngineConfiguration.initHistoryCleanup(); assertNull(processEngineConfiguration.getBatchOperationHistoryTimeToLive()); Date startDate = ClockUtil.getCurrentTime(); int daysInThePast = -11; ClockUtil.setCurrentTime(DateUtils.addDays(startDate, daysInThePast)); List<String> batchIds = new ArrayList<String>(); int migrationCountBatch = 10; batchIds.addAll(createMigrationBatchList(migrationCountBatch)); int cancelationCountBatch = 20; batchIds.addAll(createCancelationBatchList(cancelationCountBatch)); List<String> byteArrayIds = findExceptionByteArrayIds(); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -7)); for (String batchId : batchIds) { managementService.deleteBatch(batchId, false); }/*from w w w .j a va2s .c o m*/ ClockUtil.setCurrentTime(new Date()); // when List<HistoricBatch> historicList = historyService.createHistoricBatchQuery().list(); assertEquals(30, historicList.size()); String jobId = historyService.cleanUpHistoryAsync(true).getId(); managementService.executeJob(jobId); // then assertEquals(0, historyService.createHistoricBatchQuery().count()); assertEquals(0, historyService.createHistoricIncidentQuery().count()); verifyByteArraysWereRemoved(byteArrayIds.toArray(new String[] {})); for (String batchId : batchIds) { assertEquals(0, historyService.createHistoricJobLogQuery().jobDefinitionConfiguration(batchId).count()); } }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupHistoricBatchTest.java
@Test public void testMixedConfiguration() { Map<String, Integer> map = new HashMap<String, Integer>(); map.put("instance-modification", 20); processEngineConfiguration.setBatchOperationHistoryTimeToLive(5); processEngineConfiguration.setBatchOperationHistoryTimeToLiveMap(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)); List<String> byteArrayIds = findExceptionByteArrayIds(); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -8)); for (String batchId : batchIds) { managementService.deleteBatch(batchId, false); }/*from w w w.j a v a 2s . c o m*/ 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 HistoricBatch modificationHistoricBatch = historyService.createHistoricBatchQuery().singleResult(); // the other batches should be cleaned assertEquals(modificationBatch.getId(), modificationHistoricBatch.getId()); assertEquals(0, historyService.createHistoricIncidentQuery().count()); verifyByteArraysWereRemoved(byteArrayIds.toArray(new String[] {})); assertEquals(2, historyService.createHistoricJobLogQuery() .jobDefinitionConfiguration(modificationBatch.getId()).count()); batchIds.remove(modificationBatch.getId()); for (String batchId : batchIds) { assertEquals(0, historyService.createHistoricJobLogQuery().jobDefinitionConfiguration(batchId).count()); } }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupHistoricBatchTest.java
private void prepareHistoricBatches(int batchesCount, int daysInThePast) { Date startDate = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, daysInThePast)); List<Batch> list = new ArrayList<Batch>(); for (int i = 0; i < batchesCount; i++) { list.add(migrationHelper.migrateProcessInstancesAsync(1)); }//from w ww. ja va 2s . c o m for (Batch batch : list) { migrationHelper.executeSeedJob(batch); migrationHelper.executeJobs(batch); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, ++daysInThePast)); migrationHelper.executeMonitorJob(batch); } ClockUtil.setCurrentTime(new Date()); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java
private void prepareInstances(Integer processInstanceTimeToLive, Integer decisionTimeToLive, Integer caseTimeToLive) { //update time to live List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery() .processDefinitionKey("testProcess").list(); assertEquals(1, processDefinitions.size()); repositoryService.updateProcessDefinitionHistoryTimeToLive(processDefinitions.get(0).getId(), processInstanceTimeToLive);/*www . j ava 2s . c o m*/ final List<DecisionDefinition> decisionDefinitions = repositoryService.createDecisionDefinitionQuery() .decisionDefinitionKey("testDecision").list(); assertEquals(1, decisionDefinitions.size()); repositoryService.updateDecisionDefinitionHistoryTimeToLive(decisionDefinitions.get(0).getId(), decisionTimeToLive); List<CaseDefinition> caseDefinitions = repositoryService.createCaseDefinitionQuery() .caseDefinitionKey("oneTaskCase").list(); assertEquals(1, caseDefinitions.size()); repositoryService.updateCaseDefinitionHistoryTimeToLive(caseDefinitions.get(0).getId(), caseTimeToLive); Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(new Date(), DAYS_IN_THE_PAST)); //create 3 process instances List<String> processInstanceIds = new ArrayList<String>(); Map<String, Object> variables = Variables.createVariables().putValue("pojo", new TestPojo("okay", 13.37)); for (int i = 0; i < PROCESS_INSTANCES_COUNT; i++) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess", variables); processInstanceIds.add(processInstance.getId()); } runtimeService.deleteProcessInstances(processInstanceIds, null, true, true); //+10 standalone decisions for (int i = 0; i < DECISION_INSTANCES_COUNT; i++) { engineRule.getDecisionService().evaluateDecisionByKey("testDecision").variables(variables).evaluate(); } // create 4 case instances for (int i = 0; i < CASE_INSTANCES_COUNT; i++) { CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase", Variables.createVariables().putValue("pojo", new TestPojo("okay", 13.37 + i))); caseService.terminateCaseExecution(caseInstance.getId()); caseService.closeCaseInstance(caseInstance.getId()); } ClockUtil.setCurrentTime(oldCurrentTime); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java
public Date getNextRunWithinBatchWindow(Date date, Date batchWindowStartTime) { Date todayPossibleRun = updateTime(date, batchWindowStartTime); if (todayPossibleRun.after(date)) { return todayPossibleRun; } else {/*from ww w . j a va 2 s. co m*/ //tomorrow return DateUtils.addDays(todayPossibleRun, 1); } }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java
private void prepareBPMNData(int instanceCount, String businesskey) { Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(new Date(), DAYS_IN_THE_PAST)); final List<String> ids = prepareHistoricProcesses(businesskey, getVariables(), instanceCount); runtimeService.deleteProcessInstances(ids, null, true, true); ClockUtil.setCurrentTime(oldCurrentTime); }