org.camunda.bpm.engine.impl.util.ClockUtil Java Examples
The following examples show how to use
org.camunda.bpm.engine.impl.util.ClockUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetHistoricOperationLogsForOptimizeTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void occurredAfterAndOccurredAtParameterWorks() { // given Date now = new Date(); ClockUtil.setCurrentTime(now); final ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("process"); runtimeService.suspendProcessInstanceById(processInstance.getProcessInstanceId()); Date nowPlus2Seconds = new Date(now.getTime() + 2000L); ClockUtil.setCurrentTime(nowPlus2Seconds); runtimeService.activateProcessInstanceById(processInstance.getProcessInstanceId()); // when List<UserOperationLogEntry> userOperationsLog = optimizeService.getHistoricUserOperationLogs(now, now, 10); // then assertThat(userOperationsLog.size(), is(0)); }
Example #2
Source File: RemovalTimeStrategyStartTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void shouldNotResolveJobLog() { // given ClockUtil.setCurrentTime(START_DATE); testRule.deploy(CALLED_PROCESS); repositoryService.suspendProcessDefinitionByKey(CALLED_PROCESS_KEY, true, new Date(1363608000000L)); // when HistoricJobLog jobLog = historyService.createHistoricJobLogQuery().singleResult(); // assume assertThat(jobLog, notNullValue()); // then assertThat(jobLog.getRemovalTime(), nullValue()); // cleanup managementService.deleteJob(jobLog.getJobId()); clearJobLog(jobLog.getJobId()); }
Example #3
Source File: HistoricBatchManagerBatchesForCleanupTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private String prepareHistoricBatches(int batchesCount) { 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(helper.migrateProcessInstancesAsync(1)); } Batch batch1 = list.get(0); String batchType = batch1.getType(); helper.completeSeedJobs(batch1); helper.executeJobs(batch1); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, batch1EndTime)); helper.executeMonitorJob(batch1); Batch batch2 = list.get(1); helper.completeSeedJobs(batch2); helper.executeJobs(batch2); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, batch2EndTime)); helper.executeMonitorJob(batch2); ClockUtil.setCurrentTime(new Date()); return batchType; }
Example #4
Source File: TaskServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Deployment(resources={ "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT) @Test public void testCreateTaskAttachmentWithNullTaskId() throws ParseException { Date fixedDate = SDF.parse("01/01/2001 01:01:01.000"); ClockUtil.setCurrentTime(fixedDate); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); Attachment attachment = taskService.createAttachment("web page", null, processInstance.getId(), "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes())); Attachment fetched = taskService.getAttachment(attachment.getId()); assertThat(fetched).isNotNull(); assertThat(fetched.getTaskId()).isNull(); assertThat(fetched.getProcessInstanceId()).isNotNull(); assertThat(fetched.getCreateTime()).isEqualTo(fixedDate); taskService.deleteAttachment(attachment.getId()); }
Example #5
Source File: HistoricProcessInstanceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testHistoricProcInstExecutedActivityAfter() { // given Calendar now = Calendar.getInstance(); ClockUtil.setCurrentTime(now.getTime()); BpmnModelInstance model = Bpmn.createExecutableProcess("proc").startEvent().endEvent().done(); deployment(model); Calendar hourFromNow = (Calendar) now.clone(); hourFromNow.add(Calendar.HOUR_OF_DAY, 1); runtimeService.startProcessInstanceByKey("proc"); //when query historic process instance which has executed an activity after the start time HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().executedActivityAfter(now.getTime()).singleResult(); //then query returns result assertNotNull(historicProcessInstance); //when query historic proc inst with execute activity after a hour of the starting time historicProcessInstance = historyService.createHistoricProcessInstanceQuery().executedActivityAfter(hourFromNow.getTime()).singleResult(); //then query returns no result assertNull(historicProcessInstance); }
Example #6
Source File: GetRunningHistoricActivityInstancesForOptimizeTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void startedAfterParameterWorks() { // given BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process") .startEvent("startEvent") .userTask("userTask") .endEvent("endEvent") .done(); testHelper.deploy(simpleDefinition); Date now = new Date(); Date nowPlus2Seconds = new Date(now.getTime() + 2000L); ClockUtil.setCurrentTime(now); engineRule.getRuntimeService().startProcessInstanceByKey("process"); // when ClockUtil.setCurrentTime(nowPlus2Seconds); ProcessInstance secondProcessInstance = engineRule.getRuntimeService().startProcessInstanceByKey("process"); List<HistoricActivityInstance> runningHistoricActivityInstances = optimizeService.getRunningHistoricActivityInstances(now, null, 10); // then assertThat(runningHistoricActivityInstances.size(), is(1)); assertThat(runningHistoricActivityInstances.get(0).getProcessInstanceId(), is(secondProcessInstance.getId())); }
Example #7
Source File: RetryIntervalsConfigurationTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testSingleRetryInterval() throws ParseException { // given BpmnModelInstance bpmnModelInstance = prepareProcessFailingServiceTaskWithRetryCycle("PT8M "); testRule.deploy(bpmnModelInstance); ClockUtil.setCurrentTime(SIMPLE_DATE_FORMAT.parse("2017-01-01T09:55:00")); ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); assertNotNull(pi); Date currentTime = SIMPLE_DATE_FORMAT.parse("2017-01-01T10:00:00"); ClockUtil.setCurrentTime(currentTime); String processInstanceId = pi.getProcessInstanceId(); int jobRetries = executeJob(processInstanceId); assertEquals(1, jobRetries); currentTime = DateUtils.addMinutes(currentTime, 8); assertDueDateTime(currentTime); ClockUtil.setCurrentTime(currentTime); jobRetries = executeJob(processInstanceId); assertEquals(0, jobRetries); }
Example #8
Source File: IdentityServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @WatchLogger(loggerNames = {INDENTITY_LOGGER}, level = "INFO") public void testUnsuccessfulLoginAfterFailureWithoutDelay() { // given User user = identityService.newUser("johndoe"); user.setPassword("xxx"); identityService.saveUser(user); Date now = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(now); assertFalse(identityService.checkPassword("johndoe", "invalid pwd")); ClockUtil.setCurrentTime(DateUtils.addSeconds(now, 1)); Date expectedLockExpitation = DateUtils.addSeconds(now, 3); // when try again before exprTime assertFalse(identityService.checkPassword("johndoe", "invalid pwd")); // then assertThat(loggingRule.getFilteredLog(INDENTITY_LOGGER, "The lock will expire at " + expectedLockExpitation).size()).isEqualTo(1); }
Example #9
Source File: CleanableHistoricCaseInstanceReportTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private void prepareCaseInstances(String key, int daysInThePast, Integer historyTimeToLive, int instanceCount) { // update time to live List<CaseDefinition> caseDefinitions = repositoryService.createCaseDefinitionQuery().caseDefinitionKey(key).list(); assertEquals(1, caseDefinitions.size()); repositoryService.updateCaseDefinitionHistoryTimeToLive(caseDefinitions.get(0).getId(), historyTimeToLive); Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, daysInThePast)); for (int i = 0; i < instanceCount; i++) { CaseInstance caseInstance = caseService.createCaseInstanceByKey(key); caseService.terminateCaseExecution(caseInstance.getId()); caseService.closeCaseInstance(caseInstance.getId()); } ClockUtil.setCurrentTime(oldCurrentTime); }
Example #10
Source File: GetHistoricVariableUpdatesForOptimizeTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void occurredAtParameterWorks() { // given BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process") .startEvent() .endEvent() .done(); testHelper.deploy(simpleDefinition); Date now = new Date(); ClockUtil.setCurrentTime(now); Map<String, Object> variables = new HashMap<>(); variables.put("stringVar", "value1"); runtimeService.startProcessInstanceByKey("process", variables); Date nowPlus2Seconds = new Date(now.getTime() + 2000L); ClockUtil.setCurrentTime(nowPlus2Seconds); variables.put("stringVar", "value2"); runtimeService.startProcessInstanceByKey("process", variables); // when List<HistoricVariableUpdate> variableUpdates = optimizeService.getHistoricVariableUpdates(null, now, 10); // then assertThat(variableUpdates.size()).isEqualTo(1); assertThat(variableUpdates.get(0).getValue().toString()).isEqualTo("value1"); }
Example #11
Source File: CleanableHistoricBatchReportTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testReportZeroTTL() { Map<String, String> map = new HashMap<>(); int modOperationsTTL = 0; map.put("instance-modification", "P0D"); processEngineConfiguration.setBatchOperationsForHistoryCleanup(map); processEngineConfiguration.initHistoryCleanup(); Date startDate = ClockUtil.getCurrentTime(); int daysInThePast = -11; ClockUtil.setCurrentTime(DateUtils.addDays(startDate, daysInThePast)); Batch modificationBatch = createModificationBatch(); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -7)); managementService.deleteBatch(modificationBatch.getId(), false); CleanableHistoricBatchReportResult result = historyService.createCleanableHistoricBatchReport().singleResult(); assertNotNull(result); checkResultNumbers(result, 1, 1, modOperationsTTL); }
Example #12
Source File: HistoricVariableInstanceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testVariableCreateTime() throws ParseException { // given SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); Date fixedDate = sdf.parse("01/01/2001 01:01:01.000"); ClockUtil.setCurrentTime(fixedDate); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("stringVar", "test"); // when runtimeService.startProcessInstanceByKey("oneTaskProcess", variables); // then HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertEquals(fixedDate, variable.getCreateTime()); // clean up ClockUtil.setCurrentTime(new Date()); }
Example #13
Source File: HistoryCleanupTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "org/camunda/bpm/engine/test/dmn/businessruletask/DmnBusinessRuleTaskTest.testDecisionRef.bpmn20.xml", "org/camunda/bpm/engine/test/api/history/testDmnWithPojo.dmn11.xml", "org/camunda/bpm/engine/test/api/authorization/oneTaskCase.cmmn" }) public void testHistoryCleanupOnlyCaseInstancesRemoved() { // given prepareInstances(null, null, HISTORY_TIME_TO_LIVE); ClockUtil.setCurrentTime(new Date()); // when runHistoryCleanup(true); // then assertEquals(PROCESS_INSTANCES_COUNT, historyService.createHistoricProcessInstanceQuery().count()); assertEquals(DECISION_INSTANCES_COUNT + DECISIONS_IN_PROCESS_INSTANCES, historyService.createHistoricDecisionInstanceQuery().count()); assertEquals(0, historyService.createHistoricCaseInstanceQuery().count()); }
Example #14
Source File: ProcessInstanceSuspensionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/ProcessInstanceSuspensionTest.testJobNotExecutedAfterProcessInstanceSuspend.bpmn20.xml"}) public void testJobNotExecutedAfterProcessInstanceSuspendByProcessDefinitionId() { Date now = new Date(); ClockUtil.setCurrentTime(now); // Suspending the process instance should also stop the execution of jobs for that process instance ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); runtimeService.startProcessInstanceById(processDefinition.getId()); assertEquals(1, managementService.createJobQuery().count()); runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinition.getId()); assertEquals(1, managementService.createJobQuery().count()); // The jobs should not be executed now ClockUtil.setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000))); // Timer is set to fire on 5 minutes assertEquals(0, managementService.createJobQuery().executable().count()); // Activation of the process instance should now allow for job execution runtimeService.activateProcessInstanceByProcessDefinitionId(processDefinition.getId()); assertEquals(1, managementService.createJobQuery().executable().count()); managementService.executeJob(managementService.createJobQuery().singleResult().getId()); assertEquals(0, managementService.createJobQuery().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().count()); }
Example #15
Source File: JobQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testQueryByExecutable() { long testTime = ensureJobDueDateSet? messageDueDate.getTime() : timerThreeFireTime.getTime(); int expectedCount = ensureJobDueDateSet? 0 : 1; ClockUtil.setCurrentTime(new Date(testTime + ONE_SECOND)); // all jobs should be executable at t3 + 1hour.1second JobQuery query = managementService.createJobQuery().executable(); verifyQueryResults(query, 4); // Setting retries of one job to 0, makes it non-executable setRetries(processInstanceIdOne, 0); verifyQueryResults(query, 3); // Setting the clock before the start of the process instance, makes none of the jobs executable ClockUtil.setCurrentTime(testStartTime); verifyQueryResults(query, expectedCount); // 1, since a message is always executable when retries > 0 }
Example #16
Source File: AbstractRemovalTimeTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@AfterClass public static void tearDownAfterAll() { if (processEngineConfiguration != null) { processEngineConfiguration .setHistoryRemovalTimeProvider(null) .setHistoryRemovalTimeStrategy(null) .initHistoryRemovalTime(); processEngineConfiguration.setBatchOperationHistoryTimeToLive(null); processEngineConfiguration.setBatchOperationsForHistoryCleanup(null); processEngineConfiguration.initHistoryCleanup(); DefaultDmnEngineConfiguration dmnEngineConfiguration = processEngineConfiguration.getDmnEngineConfiguration(); ResetDmnConfigUtil.reset(dmnEngineConfiguration) .enableFeelLegacyBehavior(false) .init(); processEngineConfiguration.setEnableHistoricInstancePermissions(false); processEngineConfiguration.setAuthorizationEnabled(false); } ClockUtil.reset(); }
Example #17
Source File: MigrationTimerBoundryEventTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testMigrationNonTriggeredInterruptingTimerEvent() { // given Date futureDueDate = DateUtils.addYears(ClockUtil.getCurrentTime(), 1); BpmnModelInstance model = createModel(true, sdf.format(futureDueDate)); ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(model); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(model); ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId()); MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapEqualActivities() .build(); // when testHelper.migrateProcessInstance(migrationPlan, processInstance); // then List<Job> list = managementService.createJobQuery().list(); assertEquals(1, list.size()); assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("afterTimer").count()); assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); }
Example #18
Source File: HistoryCleanupRemovalTimeTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@AfterClass public static void tearDownAfterAll() { if (engineConfiguration != null) { engineConfiguration .setHistoryRemovalTimeProvider(null) .setHistoryRemovalTimeStrategy(null) .initHistoryRemovalTime(); engineConfiguration.setHistoryCleanupStrategy(HISTORY_CLEANUP_STRATEGY_REMOVAL_TIME_BASED); engineConfiguration.setHistoryCleanupBatchSize(MAX_BATCH_SIZE); engineConfiguration.setHistoryCleanupBatchWindowStartTime(null); engineConfiguration.setHistoryCleanupDegreeOfParallelism(1); engineConfiguration.setBatchOperationHistoryTimeToLive(null); engineConfiguration.setBatchOperationsForHistoryCleanup(null); engineConfiguration.initHistoryCleanup(); engineConfiguration.setAuthorizationEnabled(false); engineConfiguration.setEnableHistoricInstancePermissions(false); } ClockUtil.reset(); }
Example #19
Source File: HistoryCleanupRemovalTimeTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void shouldSeeCleanableButNoFinishedProcessInstancesInReport() { // given engineConfiguration .setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_START) .initHistoryRemovalTime(); testRule.deploy(PROCESS); ClockUtil.setCurrentTime(END_DATE); for (int i = 0; i < 5; i++) { runtimeService.startProcessInstanceByKey(PROCESS_KEY); } ClockUtil.setCurrentTime(addDays(END_DATE, 5)); // when CleanableHistoricProcessInstanceReportResult report = historyService.createCleanableHistoricProcessInstanceReport() .compact() .singleResult(); // then assertThat(report.getCleanableProcessInstanceCount(), is(5L)); assertThat(report.getFinishedProcessInstanceCount(), is(0L)); }
Example #20
Source File: RemovalTimeStrategyStartTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void shouldResolveUserOperationLog_CreateAttachment() { // given ClockUtil.setCurrentTime(START_DATE); testRule.deploy(CALLING_PROCESS); testRule.deploy(CALLED_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); // when identityService.setAuthenticatedUserId("aUserId"); taskService.createAttachment(null, null, runtimeService.createProcessInstanceQuery().activityIdIn("userTask").singleResult().getId(), null, null, "http://camunda.com"); identityService.clearAuthentication(); UserOperationLogEntry userOperationLog = historyService.createUserOperationLogQuery().singleResult(); // assume assertThat(userOperationLog, notNullValue()); Date removalTime = addDays(START_DATE, 5); // then assertThat(userOperationLog.getRemovalTime(), is(removalTime)); }
Example #21
Source File: RemovalTimeStrategyStartTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void shouldResolveVariableInstance() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(CALLED_PROCESS); ClockUtil.setCurrentTime(START_DATE); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY, Variables.createVariables() .putValue("aVariableName", Variables.stringValue("aVariableValue"))); // when runtimeService.setVariable(processInstance.getId(), "aVariableName", Variables.stringValue("anotherVariableValue")); HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().singleResult(); Date removalTime = addDays(START_DATE, 5); // then assertThat(historicVariableInstance.getRemovalTime(), is(removalTime)); }
Example #22
Source File: HistoryCleanupTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test @Ignore("CAM-10055") public void testLessThanThresholdOutsideBatchWindowAfterMidnightDaylightSaving() throws ParseException { //given prepareData(5); //we're outside batch window, batch window passes midnight ClockUtil.setCurrentTime(sdf.parse("2019-05-28T01:10:00")); // 01:10 processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00CET"); processEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00CET"); processEngineConfiguration.initHistoryCleanup(); //when String jobId = historyService.cleanUpHistoryAsync().getId(); managementService.executeJob(jobId); //then JobEntity jobEntity = getJobEntity(jobId); HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity); //job rescheduled till next batch window start Date nextRun = getNextRunWithinBatchWindow(ClockUtil.getCurrentTime()); assertTrue(jobEntity.getDuedate().equals(nextRun)); assertTrue(nextRun.after(ClockUtil.getCurrentTime())); //countEmptyRuns canceled assertEquals(0, configuration.getCountEmptyRuns()); //nothing was removed assertResult(5); }
Example #23
Source File: HistoryCleanupSchedulerIncidentsTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void shouldScheduleToNow() { // given testRule.deploy(PROCESS); ClockUtil.setCurrentTime(END_DATE); runtimeService.startProcessInstanceByKey(PROCESS_KEY); for (int i = 0; i < 3; i++) { String jobId = managementService.createJobQuery() .singleResult() .getId(); managementService.setJobRetries(jobId, 0); try { managementService.executeJob(jobId); } catch (Exception ignored) { } } String taskId = taskService.createTaskQuery().singleResult().getId(); taskService.complete(taskId); engineConfiguration.setHistoryCleanupBatchSize(3); engineConfiguration.initHistoryCleanup(); Date removalTime = addDays(END_DATE, 5); ClockUtil.setCurrentTime(removalTime); // when runHistoryCleanup(); Job job = historyService.findHistoryCleanupJobs().get(0); // then assertThat(job.getDuedate(), is(removalTime)); }
Example #24
Source File: HistoryCleanupRemovalTimeTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void shouldSeeCleanableBatchesInReport() { // given engineConfiguration .setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_START) .initHistoryRemovalTime(); engineConfiguration.setBatchOperationHistoryTimeToLive("P5D"); engineConfiguration.initHistoryCleanup(); testRule.deploy(PROCESS); String processInstanceId = runtimeService.startProcessInstanceByKey(PROCESS_KEY).getId(); ClockUtil.setCurrentTime(END_DATE); Batch batch = runtimeService.deleteProcessInstancesAsync(Collections.singletonList(processInstanceId), "aDeleteReason"); ClockUtil.setCurrentTime(addDays(END_DATE, 5)); // when CleanableHistoricBatchReportResult report = historyService.createCleanableHistoricBatchReport().singleResult(); // then assertThat(report.getCleanableBatchesCount(), is(1L)); assertThat(report.getFinishedBatchesCount(), is(0L)); // cleanup managementService.deleteBatch(batch.getId(), true); }
Example #25
Source File: IntermediateTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment public void testExpressionRecalculateCurrentDateBased() throws Exception { // Set the clock fixed HashMap<String, Object> variables = new HashMap<String, Object>(); variables.put("duration", "PT1H"); // After process start, there should be timer created ProcessInstanceWithVariables pi1 = (ProcessInstanceWithVariables) runtimeService.startProcessInstanceByKey("intermediateTimerEventExample", variables); JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi1.getId()); assertEquals(1, jobQuery.count()); Job job = jobQuery.singleResult(); Date firstDate = job.getDuedate(); // After variable change and recalculation, there should still be one timer only, with a changed due date moveByMinutes(1); Date currentTime = ClockUtil.getCurrentTime(); runtimeService.setVariable(pi1.getProcessInstanceId(), "duration", "PT15M"); processEngine.getManagementService().recalculateJobDuedate(job.getId(), false); assertEquals(1, jobQuery.count()); job = jobQuery.singleResult(); assertNotEquals(firstDate, job.getDuedate()); assertTrue(firstDate.after(job.getDuedate())); Date expectedDate = LocalDateTime.fromDateFields(currentTime).plusMinutes(15).toDate(); assertThat(job.getDuedate()).isCloseTo(expectedDate, 1000l); // After waiting for sixteen minutes the timer should fire ClockUtil.setCurrentTime(new Date(firstDate.getTime() + TimeUnit.MINUTES.toMillis(16L))); waitForJobExecutorToProcessAllJobs(5000L); assertEquals(0, managementService.createJobQuery().processInstanceId(pi1.getId()).count()); assertProcessEnded(pi1.getProcessInstanceId()); }
Example #26
Source File: HistoryCleanupSchedulerExternalTaskLogsTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void shouldScheduleToLater() { // given testRule.deploy(Bpmn.createExecutableProcess("process") .camundaHistoryTimeToLive(5) .startEvent() .serviceTask().camundaExternalTask("anExternalTaskTopic") .multiInstance() .cardinality("5") .multiInstanceDone() .endEvent().done()); ClockUtil.setCurrentTime(END_DATE); runtimeService.startProcessInstanceByKey("process"); for (int i = 0; i < 5; i++) { LockedExternalTask externalTask = externalTaskService.fetchAndLock(1, "aWorkerId") .topic("anExternalTaskTopic", 2000) .execute() .get(0); externalTaskService.complete(externalTask.getId(), "aWorkerId"); } engineConfiguration.setHistoryCleanupBatchSize(6); engineConfiguration.initHistoryCleanup(); Date removalTime = addDays(END_DATE, 5); ClockUtil.setCurrentTime(removalTime); // when runHistoryCleanup(); Job job = historyService.findHistoryCleanupJobs().get(0); // then assertThat(job.getDuedate(), is(addSeconds(removalTime, START_DELAY))); }
Example #27
Source File: RemovalTimeStrategyEndTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void shouldResolveBatch() { // given processEngineConfiguration.setBatchOperationHistoryTimeToLive("P5D"); processEngineConfiguration.initHistoryCleanup(); testRule.deploy(CALLED_PROCESS); testRule.deploy(CALLING_PROCESS); String processInstanceId = runtimeService.startProcessInstanceByKey(CALLED_PROCESS_KEY).getId(); Batch batch = runtimeService.deleteProcessInstancesAsync(Collections.singletonList(processInstanceId), "aDeleteReason"); ClockUtil.setCurrentTime(END_DATE); String jobId = managementService.createJobQuery().singleResult().getId(); managementService.executeJob(jobId); List<Job> jobs = managementService.createJobQuery().list(); for (Job job : jobs) { managementService.executeJob(job.getId()); } HistoricBatch historicBatch = historyService.createHistoricBatchQuery().singleResult(); // then assertThat(historicBatch.getRemovalTime(), is(addDays(END_DATE, 5))); // cleanup historyService.deleteHistoricBatch(batch.getId()); }
Example #28
Source File: HistoricActivityInstanceTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment(resources = {"org/camunda/bpm/engine/test/history/oneTaskProcess.bpmn20.xml"}) public void testHistoricActivityInstanceQueryStartFinishAfterBefore() { Calendar startTime = Calendar.getInstance(); ClockUtil.setCurrentTime(startTime.getTime()); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "businessKey123"); Calendar hourAgo = Calendar.getInstance(); hourAgo.add(Calendar.HOUR_OF_DAY, -1); Calendar hourFromNow = Calendar.getInstance(); hourFromNow.add(Calendar.HOUR_OF_DAY, 1); // Start/end dates assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finishedBefore(hourAgo.getTime()).count()); assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finishedBefore(hourFromNow.getTime()).count()); assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finishedAfter(hourAgo.getTime()).count()); assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finishedAfter(hourFromNow.getTime()).count()); assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("theTask").startedBefore(hourFromNow.getTime()).count()); assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").startedBefore(hourAgo.getTime()).count()); assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("theTask").startedAfter(hourAgo.getTime()).count()); assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").startedAfter(hourFromNow.getTime()).count()); assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").startedAfter(hourFromNow.getTime()).startedBefore(hourAgo.getTime()).count()); // After finishing process taskService.complete(taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult().getId()); assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finished().count()); assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finishedBefore(hourAgo.getTime()).count()); assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finishedBefore(hourFromNow.getTime()).count()); assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finishedAfter(hourAgo.getTime()).count()); assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finishedAfter(hourFromNow.getTime()).count()); assertEquals(0, historyService.createHistoricActivityInstanceQuery().activityId("theTask").finishedBefore(hourAgo.getTime()).finishedAfter(hourFromNow.getTime()).count()); }
Example #29
Source File: HistoricProcessInstanceTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testHistoricProcInstExecutedJobBefore() { // given BpmnModelInstance asyncModel = Bpmn.createExecutableProcess("async").startEvent().camundaAsyncBefore().endEvent().done(); deployment(asyncModel); BpmnModelInstance model = Bpmn.createExecutableProcess("proc").startEvent().endEvent().done(); deployment(model); Calendar now = Calendar.getInstance(); ClockUtil.setCurrentTime(now.getTime()); Calendar hourBeforeNow = (Calendar) now.clone(); hourBeforeNow.add(Calendar.HOUR_OF_DAY, -1); runtimeService.startProcessInstanceByKey("async"); Job job = managementService.createJobQuery().singleResult(); managementService.executeJob(job.getId()); runtimeService.startProcessInstanceByKey("proc"); //when query historic process instance which has executed an job before the start time HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() .executedJobBefore(now.getTime()).singleResult(); //then query returns only a single process instance since before is less-then-equal assertNotNull(historicProcessInstance); //when query historic proc inst with executed job before an hour of the starting time historicProcessInstance = historyService.createHistoricProcessInstanceQuery().executedJobBefore(hourBeforeNow.getTime()).singleResult(); //then query returns no result assertNull(historicProcessInstance); }
Example #30
Source File: HistoryCleanupTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
private void prepareDMNData(int instanceCount) { Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(new Date(), DAYS_IN_THE_PAST)); for (int i = 0; i < instanceCount; i++) { //spread end_time between different "minutes" ClockUtil.setCurrentTime(DateUtils.setMinutes(ClockUtil.getCurrentTime(), random.nextInt(60))); engineRule.getDecisionService().evaluateDecisionByKey(DECISION).variables(getDMNVariables()).evaluate(); } ClockUtil.setCurrentTime(oldCurrentTime); }