public void testPropagateTenantIdToIntermediateMessageEventSubscription() { deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY) .startEvent() .intermediateCatchEvent() .message("start") .endEvent() .done()); startProcessInstance(PROCESS_DEFINITION_KEY); EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult(); assertThat(eventSubscription, is(notNullValue())); // inherit the tenant id from process instance assertThat(eventSubscription.getTenantId(), is(TENANT_ID)); }
/** * On execution, the MockProcess will wait for the given message * * @param message * @return */ public CallActivityMock onExecutionWaitForMessage(final String message) { flowNodeBuilder = flowNodeBuilder.intermediateCatchEvent() .message(message); return this; }
public void testIntermediateCatchEvent() throws Exception { BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent() .message("foo") .camundaAsyncBefore() .camundaFailedJobRetryTimeCycle("R5/PT5M") .camundaExecutionListenerClass("start", "foo") .endEvent() .done(); deployment(bpmnModelInstance); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date startDate = simpleDateFormat.parse("2018-01-01T10:00:00"); ClockUtil.setCurrentTime(startDate); runtimeService.startProcessInstanceByKey("process"); Job job = managementService.createJobQuery().singleResult(); // assume Assert.assertEquals(3, job.getRetries()); // when job fails try { managementService.executeJob(job.getId()); } catch (Exception e) { // ignore } // then job = managementService.createJobQuery().singleResult(); Assert.assertEquals(4, job.getRetries()); Date expectedDate = simpleDateFormat.parse("2018-01-01T10:05:00"); assertEquals(expectedDate, ((JobEntity) job).getLockExpirationTime()); }
@Test public void testIntermediateCatchEventMessageCorrelation() { //given BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1") .startEvent() .subProcess("SubProcess_1").embeddedSubProcess() .startEvent() .intermediateCatchEvent("MessageReceiver_1").message(TEST_MESSAGE_NAME) .camundaInputParameter("localVar", "${loopVar}") .userTask("UserTask_1") .endEvent() .subProcessDone() .multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone() .endEvent().done(); testHelper.deploy(model); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("vars", Arrays.asList(1, 2, 3)); ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables); //when correlated by local variables String messageName = TEST_MESSAGE_NAME; int correlationKey = 1; MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName) .localVariableEquals("localVar", correlationKey).setVariables(Variables.createVariables().putValue("newVar", "newValue")).correlateWithResult(); //then one message is correlated, two others continue waiting checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "MessageReceiver_1"); //uncorrelated executions List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list(); assertEquals(2, uncorrelatedExecutions.size()); }
.startEvent() .intermediateCatchEvent("message_1") .message("1") .camundaOutputParameter(outputVarName, "${testLocalVar}") .userTask("UserTask_1")
.startEvent() .intermediateCatchEvent("message_1") .message("1") .camundaOutputParameter(outputVarName, "${testLocalVar}") .userTask("UserTask_1")
@Test public void testMigrateGatewayRemoveMessageEvent() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(modify(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS) .flowNodeBuilder("eventBasedGateway") .intermediateCatchEvent("oldMessageCatch") .message("old" + EventBasedGatewayModels.MESSAGE_NAME) .endEvent() .done()); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("eventBasedGateway", "eventBasedGateway") .mapActivities("messageCatch", "messageCatch") .build(); // when testHelper.createProcessInstanceAndMigrate(migrationPlan); // then testHelper.assertEventSubscriptionRemoved("oldMessageCatch", "old" + EventBasedGatewayModels.MESSAGE_NAME); testHelper.assertEventSubscriptionMigrated("messageCatch", "messageCatch", EventBasedGatewayModels.MESSAGE_NAME); }
@Test public void testMigrateEventSubscriptionPreserveMessageName() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(MessageReceiveModels.ONE_MESSAGE_CATCH_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.newModel() .startEvent() .intermediateCatchEvent("messageCatch") .message("new" + MessageReceiveModels.MESSAGE_NAME) .userTask("userTask") .endEvent() .done()); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("messageCatch", "messageCatch") .build(); // when ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan); // then the message event subscription's event name has not changed testHelper.assertEventSubscriptionMigrated("messageCatch", "messageCatch", MessageReceiveModels.MESSAGE_NAME); // and it is possible to trigger the receive task rule.getRuntimeService().correlateMessage(MessageReceiveModels.MESSAGE_NAME); testHelper.completeTask("userTask"); testHelper.assertProcessEnded(processInstance.getId()); }
@Test public void testMigrateGatewayAddMessageEvent() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS) .flowNodeBuilder("eventBasedGateway") .intermediateCatchEvent("newMessageCatch") .message("new" + EventBasedGatewayModels.MESSAGE_NAME) .userTask("afterNewMessageCatch") .endEvent() .done()); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("eventBasedGateway", "eventBasedGateway") .mapActivities("messageCatch", "messageCatch") .build(); // when ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan); // then testHelper.assertEventSubscriptionCreated("newMessageCatch", "new" + EventBasedGatewayModels.MESSAGE_NAME); testHelper.assertEventSubscriptionMigrated("messageCatch", "messageCatch", EventBasedGatewayModels.MESSAGE_NAME); rule.getRuntimeService().correlateMessage("new" + EventBasedGatewayModels.MESSAGE_NAME); testHelper.completeTask("afterNewMessageCatch"); testHelper.assertProcessEnded(processInstance.getId()); }
@Test public void testMessageCorrelationWithTransientVariable() { // given BpmnModelInstance instance = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent() .message("message") .scriptTask("scriptTask") .scriptFormat("javascript") .camundaResultVariable("abc") .scriptText("execution.setVariable('abc', blob);") .endEvent() .done(); testRule.deploy(instance); runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValueTyped("foo", Variables.stringValue("foo", false))); // when VariableMap correlationKeys = Variables.createVariables().putValueTyped("foo", Variables.stringValue("foo", true)); VariableMap variables = Variables.createVariables().putValueTyped("blob", Variables.stringValue("blob", true)); runtimeService.correlateMessage("message", correlationKeys, variables); // then VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult(); assertNull(variableInstance); HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery() .variableName("abc").singleResult(); assertNotNull(historicVariableInstance); assertEquals("blob", historicVariableInstance.getValue()); }
public void testPropagateTenantIdToIntermediateMessageEventSubscription() { deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY) .startEvent() .intermediateCatchEvent() .message("start") .endEvent() .done()); startProcessInstance(PROCESS_DEFINITION_KEY); EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult(); assertThat(eventSubscription, is(notNullValue())); // inherit the tenant id from process instance assertThat(eventSubscription.getTenantId(), is(TENANT_ID)); }
public void testIntermediateCatchEvent() throws Exception { BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent() .message("foo") .camundaAsyncBefore() .camundaFailedJobRetryTimeCycle("R5/PT5M") .camundaExecutionListenerClass("start", "foo") .endEvent() .done(); deployment(bpmnModelInstance); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date startDate = simpleDateFormat.parse("2018-01-01T10:00:00"); ClockUtil.setCurrentTime(startDate); runtimeService.startProcessInstanceByKey("process"); Job job = managementService.createJobQuery().singleResult(); // assume Assert.assertEquals(3, job.getRetries()); // when job fails try { managementService.executeJob(job.getId()); } catch (Exception e) { // ignore } // then job = managementService.createJobQuery().singleResult(); Assert.assertEquals(4, job.getRetries()); Date expectedDate = simpleDateFormat.parse("2018-01-01T10:05:00"); assertEquals(expectedDate, ((JobEntity) job).getLockExpirationTime()); }
@Test public void testIntermediateCatchEventMessageCorrelation() { //given BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1") .startEvent() .subProcess("SubProcess_1").embeddedSubProcess() .startEvent() .intermediateCatchEvent("MessageReceiver_1").message(TEST_MESSAGE_NAME) .camundaInputParameter("localVar", "${loopVar}") .userTask("UserTask_1") .endEvent() .subProcessDone() .multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone() .endEvent().done(); testHelper.deploy(model); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("vars", Arrays.asList(1, 2, 3)); ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables); //when correlated by local variables String messageName = TEST_MESSAGE_NAME; int correlationKey = 1; MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName) .localVariableEquals("localVar", correlationKey).setVariables(Variables.createVariables().putValue("newVar", "newValue")).correlateWithResult(); //then one message is correlated, two others continue waiting checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "MessageReceiver_1"); //uncorrelated executions List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list(); assertEquals(2, uncorrelatedExecutions.size()); }
.startEvent() .intermediateCatchEvent("message_1") .message("1") .camundaOutputParameter(outputVarName, "${testLocalVar}") .userTask("UserTask_1")
.startEvent() .intermediateCatchEvent("message_1") .message("1") .camundaOutputParameter(outputVarName, "${testLocalVar}") .userTask("UserTask_1")
@Test public void testMigrateGatewayRemoveMessageEvent() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(modify(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS) .flowNodeBuilder("eventBasedGateway") .intermediateCatchEvent("oldMessageCatch") .message("old" + EventBasedGatewayModels.MESSAGE_NAME) .endEvent() .done()); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("eventBasedGateway", "eventBasedGateway") .mapActivities("messageCatch", "messageCatch") .build(); // when testHelper.createProcessInstanceAndMigrate(migrationPlan); // then testHelper.assertEventSubscriptionRemoved("oldMessageCatch", "old" + EventBasedGatewayModels.MESSAGE_NAME); testHelper.assertEventSubscriptionMigrated("messageCatch", "messageCatch", EventBasedGatewayModels.MESSAGE_NAME); }
@Test public void testMigrateEventSubscriptionPreserveMessageName() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(MessageReceiveModels.ONE_MESSAGE_CATCH_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.newModel() .startEvent() .intermediateCatchEvent("messageCatch") .message("new" + MessageReceiveModels.MESSAGE_NAME) .userTask("userTask") .endEvent() .done()); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("messageCatch", "messageCatch") .build(); // when ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan); // then the message event subscription's event name has not changed testHelper.assertEventSubscriptionMigrated("messageCatch", "messageCatch", MessageReceiveModels.MESSAGE_NAME); // and it is possible to trigger the receive task rule.getRuntimeService().correlateMessage(MessageReceiveModels.MESSAGE_NAME); testHelper.completeTask("userTask"); testHelper.assertProcessEnded(processInstance.getId()); }
@Test public void testMigrateGatewayAddMessageEvent() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS) .flowNodeBuilder("eventBasedGateway") .intermediateCatchEvent("newMessageCatch") .message("new" + EventBasedGatewayModels.MESSAGE_NAME) .userTask("afterNewMessageCatch") .endEvent() .done()); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("eventBasedGateway", "eventBasedGateway") .mapActivities("messageCatch", "messageCatch") .build(); // when ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan); // then testHelper.assertEventSubscriptionCreated("newMessageCatch", "new" + EventBasedGatewayModels.MESSAGE_NAME); testHelper.assertEventSubscriptionMigrated("messageCatch", "messageCatch", EventBasedGatewayModels.MESSAGE_NAME); rule.getRuntimeService().correlateMessage("new" + EventBasedGatewayModels.MESSAGE_NAME); testHelper.completeTask("afterNewMessageCatch"); testHelper.assertProcessEnded(processInstance.getId()); }
@Test public void testMessageCorrelationWithTransientVariable() { // given BpmnModelInstance instance = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent() .message("message") .scriptTask("scriptTask") .scriptFormat("javascript") .camundaResultVariable("abc") .scriptText("execution.setVariable('abc', blob);") .endEvent() .done(); testRule.deploy(instance); runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValueTyped("foo", Variables.stringValue("foo", false))); // when VariableMap correlationKeys = Variables.createVariables().putValueTyped("foo", Variables.stringValue("foo", true)); VariableMap variables = Variables.createVariables().putValueTyped("blob", Variables.stringValue("blob", true)); runtimeService.correlateMessage("message", correlationKeys, variables); // then VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult(); assertNull(variableInstance); HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery() .variableName("abc").singleResult(); assertNotNull(historicVariableInstance); assertEquals("blob", historicVariableInstance.getValue()); }