private void executeAvailableJobs(int jobsExecuted, int expectedExecutions, boolean ignoreLessExecutions) { List<Job> jobs = managementService.createJobQuery().withRetriesLeft().list(); if (jobs.isEmpty()) { assertTrue("executed less jobs than expected. expected <" + expectedExecutions + "> actual <" + jobsExecuted + ">", jobsExecuted == expectedExecutions || ignoreLessExecutions); return; } for (Job job : jobs) { try { managementService.executeJob(job.getId()); jobsExecuted += 1; } catch (Exception e) {} } assertTrue("executed more jobs than expected. expected <" + expectedExecutions + "> actual <" + jobsExecuted + ">", jobsExecuted <= expectedExecutions); executeAvailableJobs(jobsExecuted, expectedExecutions, ignoreLessExecutions); }
private void executeAvailableJobs(int jobsExecuted, int expectedExecutions, boolean ignoreLessExecutions) { List<Job> jobs = managementService.createJobQuery().withRetriesLeft().list(); if (jobs.isEmpty()) { assertTrue("executed less jobs than expected. expected <" + expectedExecutions + "> actual <" + jobsExecuted + ">", jobsExecuted == expectedExecutions || ignoreLessExecutions); return; } for (Job job : jobs) { try { managementService.executeJob(job.getId()); jobsExecuted += 1; } catch (Exception e) {} } assertTrue("executed more jobs than expected. expected <" + expectedExecutions + "> actual <" + jobsExecuted + ">", jobsExecuted <= expectedExecutions); executeAvailableJobs(jobsExecuted, expectedExecutions, ignoreLessExecutions); }
private void verifyParameterQueryInvocations() { Map<String, Object> parameters = getCompleteParameters(); verify(mockQuery).jobId((String) parameters.get("jobId")); verify(mockQuery).processInstanceId((String) parameters.get("processInstanceId")); verify(mockQuery).processDefinitionId((String) parameters.get("processDefinitionId")); verify(mockQuery).processDefinitionKey((String) parameters.get("processDefinitionKey")); verify(mockQuery).executionId((String) parameters.get("executionId")); verify(mockQuery).activityId((String) parameters.get("activityId")); verify(mockQuery).withRetriesLeft(); verify(mockQuery).executable(); verify(mockQuery).timers(); verify(mockQuery).withException(); verify(mockQuery).exceptionMessage((String) parameters.get("exceptionMessage")); verify(mockQuery).noRetriesLeft(); verify(mockQuery).active(); verify(mockQuery).suspended(); verify(mockQuery).priorityLowerThanOrEquals(JOB_QUERY_MAX_PRIORITY); verify(mockQuery).priorityHigherThanOrEquals(JOB_QUERY_MIN_PRIORITY); verify(mockQuery).jobDefinitionId(MockProvider.EXAMPLE_JOB_DEFINITION_ID); }
protected void executeAvailableJobs() { List<Job> jobs = managementService.createJobQuery().withRetriesLeft().list(); if (jobs.isEmpty()) { return; } for (Job job : jobs) { try { managementService.executeJob(job.getId()); } catch (Exception e) {} } executeAvailableJobs(); }
private static void causeIncident(ProcessEngine processEngine, String processInstanceId) { Job job = processEngine.getManagementService() .createJobQuery() .processInstanceId(processInstanceId) .withRetriesLeft() .singleResult(); if (job == null) { return; } try { processEngine.getManagementService().executeJob(job.getId()); } catch (Exception ex) { // noop } causeIncident(processEngine, processInstanceId); }
private static void causeIncident(ProcessEngine processEngine, String processInstanceId) { Job job = processEngine.getManagementService() .createJobQuery() .processInstanceId(processInstanceId) .withRetriesLeft() .singleResult(); if (job == null) { return; } try { processEngine.getManagementService().executeJob(job.getId()); } catch (Exception ex) { // noop } causeIncident(processEngine, processInstanceId); }
@Test public void testQueryByRetriesLeft() { JobQuery query = managementService.createJobQuery().withRetriesLeft(); verifyQueryResults(query, 4); setRetries(processInstanceIdOne, 0); // Re-running the query should give only 3 jobs now, since one job has retries=0 verifyQueryResults(query, 3); }
public Void call() throws Exception { List<Job> jobs = managementService.createJobQuery().processDefinitionKey(key).withRetriesLeft().list(); if (jobs.isEmpty()) { enableAuthorization(); return null; } for (Job job : jobs) { try { managementService.executeJob(job.getId()); } catch (Exception e) {} } executeAvailableJobs(key); return null; } });
@Test public void testJobRetriesDecremented_multiple() { for(int i = 0; i < 50; i++) { runtimeService.startProcessInstanceByKey("theProcess"); } Assert.assertEquals(50, managementService.createJobQuery().withRetriesLeft().count()); waitForJobExecutorToProcessAllJobs(6 * 60 * 1000); // now the retries = 0 Assert.assertEquals(0, managementService.createJobQuery().withRetriesLeft().count()); Assert.assertEquals(51, managementService.createJobQuery().noRetriesLeft().count()); }
@Test public void testJobRetriesDecremented() { runtimeService.startProcessInstanceByKey("theProcess"); Assert.assertEquals(1, managementService.createJobQuery().withRetriesLeft().count()); waitForJobExecutorToProcessAllJobs(); // now the retries = 0 Assert.assertEquals(0, managementService.createJobQuery().withRetriesLeft().count()); Assert.assertEquals(1, managementService.createJobQuery().noRetriesLeft().count()); }
private void executeAvailableJobs(int jobsExecuted, int expectedExecutions) { List<Job> jobs = processEngine.getManagementService().createJobQuery().withRetriesLeft().list(); if (jobs.isEmpty()) { if (expectedExecutions != Integer.MAX_VALUE) { assertThat("executed less jobs than expected.", jobsExecuted, is(expectedExecutions)); } return; } for (Job job : jobs) { try { processEngine.getManagementService().executeJob(job.getId()); jobsExecuted += 1; } catch (Exception e) {} } assertThat("executed more jobs than expected.", jobsExecuted, lessThanOrEqualTo(expectedExecutions)); executeAvailableJobs(jobsExecuted, expectedExecutions); }
protected void stillOneJobWithExceptionAndRetriesLeft() { assertEquals(1, managementService.createJobQuery().withException().count()); assertEquals(1, managementService.createJobQuery().withRetriesLeft().count()); }
protected void stillOneJobWithExceptionAndRetriesLeft(String jobId) { assertEquals(1, managementService.createJobQuery().jobId(jobId).withException().count()); assertEquals(1, managementService.createJobQuery().jobId(jobId).withRetriesLeft().count()); }
@Deployment public void testMultipleAsyncEndEvents() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("multipleAsyncEndEvent"); assertEquals(1, runtimeService.createProcessInstanceQuery().count()); // should stop at both end events List<Job> jobs = managementService.createJobQuery().withRetriesLeft().list(); assertEquals(2, jobs.size()); // execute one of the end events managementService.executeJob(jobs.get(0).getId()); jobs = managementService.createJobQuery().withRetriesLeft().list(); assertEquals(1, jobs.size()); // execute the second one managementService.executeJob(jobs.get(0).getId()); // assert that we have finished our instance now assertEquals(0, runtimeService.createProcessInstanceQuery().count()); if(processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) { // after the end event we have a event listener HistoricVariableInstanceQuery name = historyService.createHistoricVariableInstanceQuery() .processInstanceId(pi.getId()) .variableName("message"); Assert.assertNotNull(name); Assert.assertEquals(true, name.singleResult().getValue()); } }
repositoryService.suspendProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY, true, new Date()); String firstJobId = null; List<Job> jobs = managementService.createJobQuery().withRetriesLeft().list(); for (Job job : jobs) { if (job.getProcessDefinitionKey() == null) { jobs = managementService.createJobQuery().withRetriesLeft().list(); for (Job job : jobs) { if (job.getProcessDefinitionKey() == null) {
repositoryService.suspendProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY, true, new Date()); String firstJobId = null; List<Job> jobs = managementService.createJobQuery().withRetriesLeft().list(); for (Job job : jobs) { if (job.getProcessDefinitionKey() == null) { jobs = managementService.createJobQuery().withRetriesLeft().list(); for (Job job : jobs) { if (job.getProcessDefinitionKey() == null) {
@Test public void resolveIncidentOfTypeFailedJob() { // given testRule.deploy("org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateOneIncident.bpmn"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("failingProcess"); // when List<Job> jobs = engineRule.getManagementService().createJobQuery().withRetriesLeft().list(); for (Job job : jobs) { engineRule.getManagementService().setJobRetries(job.getId(), 1); try { engineRule.getManagementService().executeJob(job.getId()); } catch (Exception e) {} } // then Incident incident = runtimeService.createIncidentQuery().processInstanceId(processInstance.getId()).singleResult(); try { runtimeService.resolveIncident(incident.getId()); fail("Exception expected"); } catch (BadUserRequestException e) { assertThat(e.getMessage(), containsString("Cannot resolve an incident of type failedJob")); } }
assertEquals(2, managementService.createJobQuery().withRetriesLeft().count()); assertEquals(2, managementService.createJobQuery().withRetriesLeft().count());
assertEquals(0, job.getRetries()); assertEquals(1, managementService.createJobQuery().withException().count()); assertEquals(0, managementService.createJobQuery().jobId(jobId).withRetriesLeft().count()); assertEquals(1, managementService.createJobQuery().noRetriesLeft().count());
assertEquals(0, job.getRetries()); assertEquals(1, managementService.createJobQuery().withException().count()); assertEquals(0, managementService.createJobQuery().withRetriesLeft().count()); assertEquals(1, managementService.createJobQuery().noRetriesLeft().count());