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); }
@Test public void testQueryByActive() { JobQuery query = managementService.createJobQuery().active(); verifyQueryResults(query, 4); }
@Test public void suspendProcessInstanceIncludingJobForNonTenant() { // given activated jobs JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getRuntimeService() .updateProcessInstanceSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionWithoutTenantId() .suspend(); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().singleResult().getTenantId(), is(nullValue())); }
@Test public void activateProcessInstanceIncludingJobForNonTenant() { // given suspended jobs engineRule.getRuntimeService() .updateProcessInstanceSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(0L)); assertThat(query.suspended().count(), is(3L)); engineRule.getRuntimeService() .updateProcessInstanceSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionWithoutTenantId() .activate(); assertThat(query.suspended().count(), is(2L)); assertThat(query.active().count(), is(1L)); assertThat(query.active().singleResult().getTenantId(), is(nullValue())); }
@Test public void suspendProcessInstanceIncludingJobForTenant() { // given activated jobs JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getRuntimeService() .updateProcessInstanceSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .suspend(); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void suspendJobForTenant() { // given activated jobs JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getManagementService() .updateJobSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .suspend(); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void suspendJobsForNonTenant() { // given activated jobs JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getManagementService() .updateJobSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionWithoutTenantId() .suspend(); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().withoutTenantId().count(), is(1L)); }
@Test public void suspendJobWithAuthenticatedTenant() { // given activated jobs JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getIdentityService().setAuthentication("user", null, Arrays.asList(TENANT_ONE)); engineRule.getManagementService() .updateJobSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); engineRule.getIdentityService().clearAuthentication(); assertThat(query.active().count(), is(1L)); assertThat(query.suspended().count(), is(2L)); assertThat(query.active().tenantIdIn(TENANT_TWO).count(), is(1L)); assertThat(query.suspended().withoutTenantId().count(), is(1L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void activateJobsForNonTenant() { // given suspend jobs engineRule.getManagementService() .updateJobSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.suspended().count(), is(3L)); assertThat(query.active().count(), is(0L)); engineRule.getManagementService() .updateJobSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionWithoutTenantId() .activate(); assertThat(query.suspended().count(), is(2L)); assertThat(query.active().count(), is(1L)); assertThat(query.active().withoutTenantId().count(), is(1L)); }
@Test public void activateProcessInstanceIncludingJobForTenant() { // given suspended job engineRule.getRuntimeService() .updateProcessInstanceSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(0L)); assertThat(query.suspended().count(), is(3L)); engineRule.getRuntimeService() .updateProcessInstanceSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .activate(); assertThat(query.suspended().count(), is(2L)); assertThat(query.active().count(), is(1L)); assertThat(query.active().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void activateJobsForTenant() { // given suspend jobs engineRule.getManagementService() .updateJobSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.suspended().count(), is(3L)); assertThat(query.active().count(), is(0L)); engineRule.getManagementService() .updateJobSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .activate(); assertThat(query.suspended().count(), is(2L)); assertThat(query.active().count(), is(1L)); assertThat(query.active().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void suspendJobDefinitionIncludingJobsForTenant() { // given activated job definitions JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getManagementService() .updateJobDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .includeJobs(true) .suspend(); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void suspendJobDefinitionIncludingJobsForNonTenant() { // given activated job definitions JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getManagementService() .updateJobDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionWithoutTenantId() .includeJobs(true) .suspend(); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().withoutTenantId().count(), is(1L)); }
@Test public void suspendJobNoAuthenticatedTenants() { // given activated jobs JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getIdentityService().setAuthentication("user", null, null); engineRule.getManagementService() .updateJobSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); engineRule.getIdentityService().clearAuthentication(); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().withoutTenantId().count(), is(1L)); }
@Test public void suspendJobDisabledTenantCheck() { // given activated jobs JobQuery query = engineRule.getManagementService().createJobQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getProcessEngineConfiguration().setTenantCheckEnabled(false); engineRule.getIdentityService().setAuthentication("user", null, null); engineRule.getManagementService() .updateJobSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); assertThat(query.active().count(), is(0L)); assertThat(query.suspended().count(), is(3L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE, TENANT_TWO).includeJobsWithoutTenantId().count(), is(3L)); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"}) public void testSuspensionByProcessDefinitionKeyUsingBuilder() { // given // a running process instance with a failed job runtimeService.startProcessInstanceByKey("suspensionProcess", Variables.createVariables().putValue("fail", true)); // the failed job JobQuery jobQuery = managementService.createJobQuery(); assertEquals(1, jobQuery.active().count()); // when // the job will be suspended managementService .updateJobSuspensionState() .byProcessDefinitionKey("suspensionProcess") .suspend(); // then // the job should be suspended assertEquals(0, jobQuery.active().count()); assertEquals(1, jobQuery.suspended().count()); }
@Test public void testCreateJobInstanceActive() { testRule.deploy(SIMPLE_ASYNC_PROCESS); // given that the job definition is not suspended: // if I start a new instance runtimeService.startProcessInstanceByKey("simpleAsyncProcess"); // then the new job instance is created as active: assertNull(managementService.createJobQuery().suspended().singleResult()); assertNotNull(managementService.createJobQuery().active().singleResult()); }
@Test public void testCreateJobInstanceSuspended() { testRule.deploy(SIMPLE_ASYNC_PROCESS); // given suspended job definition: managementService.suspendJobDefinitionByProcessDefinitionKey("simpleAsyncProcess"); // if I start a new instance runtimeService.startProcessInstanceByKey("simpleAsyncProcess"); // then the new job instance is created as suspended: assertNotNull(managementService.createJobQuery().suspended().singleResult()); assertNull(managementService.createJobQuery().active().singleResult()); }
public void testSetVariableInEndListenerOfAsyncStartEvent () throws Exception { //given BpmnModelInstance subProcess = Bpmn.createExecutableProcess("process") .startEvent() .camundaAsyncBefore() .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, SubProcessActivityStartListener.class.getName()) .endEvent() .done(); org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment() .addModelInstance("process.bpmn", subProcess) .deploy(); //when runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValue("executionListenerCounter",1)); managementService.executeJob(managementService.createJobQuery().active().singleResult().getId()); //then assertThat(historyService.createHistoricVariableInstanceQuery().count(), is (2L)); repositoryService.deleteDeployment(deployment.getId(),true); }
public void testSetVariableInStartListenerOfAsyncStartEvent () throws Exception { //given BpmnModelInstance subProcess = Bpmn.createExecutableProcess("process") .startEvent() .camundaAsyncBefore() .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_START, SubProcessActivityStartListener.class.getName()) .endEvent() .done(); org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment() .addModelInstance("process.bpmn", subProcess) .deploy(); //when runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValue("executionListenerCounter",1)); managementService.executeJob(managementService.createJobQuery().active().singleResult().getId()); //then assertThat(historyService.createHistoricVariableInstanceQuery().count(), is (2L)); repositoryService.deleteDeployment(deployment.getId(),true); }