use of io.camunda.zeebe.protocol.record.Record in project zeebe by camunda.
the class MultiInstanceActivityTest method shouldTriggerInterruptingBoundaryEvent.
@Test
public void shouldTriggerInterruptingBoundaryEvent() {
// given
final ServiceTask task = process(miBuilder).getModelElementById(ELEMENT_ID);
final var process = task.builder().boundaryEvent("boundary-event", b -> b.cancelActivity(true).message(MESSAGE_BUILDER)).sequenceFlowId("to-canceled").endEvent("canceled").done();
ENGINE.deployment().withXmlResource(process).deploy();
final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).withVariables(Map.of(INPUT_COLLECTION_EXPRESSION, INPUT_COLLECTION, MESSAGE_CORRELATION_KEY_VARIABLE, MESSAGE_CORRELATION_KEY)).create();
completeJobs(processInstanceKey, INPUT_COLLECTION.size() - 1);
// make sure message subcription is opened, before publishing
RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.CREATED).withProcessInstanceKey(processInstanceKey).await();
// when
ENGINE.message().withName(MESSAGE_NAME).withCorrelationKey(MESSAGE_CORRELATION_KEY).withTimeToLive(// must be 0 because engine is re-used in tests
0).publish();
// then
assertThat(RecordingExporter.messageSubscriptionRecords().withProcessInstanceKey(processInstanceKey).limit(5)).extracting(Record::getIntent).containsExactly(MessageSubscriptionIntent.CREATE, MessageSubscriptionIntent.CREATED, MessageSubscriptionIntent.CORRELATING, MessageSubscriptionIntent.CORRELATE, MessageSubscriptionIntent.CORRELATED);
assertThat(RecordingExporter.processInstanceRecords().withProcessInstanceKey(processInstanceKey).limitToProcessInstanceCompleted()).extracting(r -> tuple(r.getValue().getElementId(), r.getValue().getBpmnElementType(), r.getIntent())).containsSubsequence(tuple(ELEMENT_ID, BpmnElementType.MULTI_INSTANCE_BODY, ProcessInstanceIntent.TERMINATE_ELEMENT), tuple(ELEMENT_ID, BpmnElementType.MULTI_INSTANCE_BODY, ProcessInstanceIntent.ELEMENT_TERMINATING), tuple(ELEMENT_ID, BpmnElementType.SERVICE_TASK, ProcessInstanceIntent.ELEMENT_TERMINATING), tuple(ELEMENT_ID, BpmnElementType.SERVICE_TASK, ProcessInstanceIntent.ELEMENT_TERMINATED), tuple(ELEMENT_ID, BpmnElementType.MULTI_INSTANCE_BODY, ProcessInstanceIntent.ELEMENT_TERMINATED), tuple("to-canceled", BpmnElementType.SEQUENCE_FLOW, ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("canceled", BpmnElementType.END_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETED), tuple(PROCESS_ID, BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETED));
assertThat(RecordingExporter.records().limitToProcessInstance(processInstanceKey).variableRecords().withScopeKey(processInstanceKey)).extracting(r -> r.getValue().getName()).doesNotContain(OUTPUT_COLLECTION_VARIABLE);
}
use of io.camunda.zeebe.protocol.record.Record in project zeebe by camunda.
the class MultiInstanceSubProcessTest method shouldCreateMessageSubscriptionForEachSubProcess.
@Test
public void shouldCreateMessageSubscriptionForEachSubProcess() {
// given
final BpmnModelInstance process = process(b -> b.intermediateCatchEvent().message(m -> m.name("message").zeebeCorrelationKeyExpression(INPUT_ELEMENT)));
ENGINE.deployment().withXmlResource(process).deploy();
final List<String> inputCollection = Arrays.asList("a", "b", "c");
final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable(INPUT_COLLECTION, inputCollection).create();
// then
assertThat(RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.CREATED).withProcessInstanceKey(processInstanceKey).limit(3)).hasSize(3).extracting(r -> r.getValue().getCorrelationKey()).containsExactly("a", "b", "c");
// and
inputCollection.forEach(element -> ENGINE.message().withName("message").withCorrelationKey(element).publish());
// then
assertThat(RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).filterRootScope().limitToProcessInstanceCompleted()).extracting(Record::getIntent).containsExactly(ProcessInstanceIntent.ELEMENT_COMPLETED);
}
use of io.camunda.zeebe.protocol.record.Record in project zeebe by camunda.
the class MultiInstanceSubProcessTest method shouldCreateTimerForEachSubProcess.
@Test
public void shouldCreateTimerForEachSubProcess() {
// given
final BpmnModelInstance process = process(b -> b.intermediateCatchEvent("timer").timerWithDuration("PT1S"));
ENGINE.deployment().withXmlResource(process).deploy();
final List<String> inputCollection = Arrays.asList("a", "b", "c");
final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable(INPUT_COLLECTION, inputCollection).create();
// then
assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).withProcessInstanceKey(processInstanceKey).limit(3)).hasSize(3).extracting(r -> r.getValue().getTargetElementId()).containsOnly("timer");
// and
ENGINE.getClock().addTime(Duration.ofSeconds(1));
// then
assertThat(RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).filterRootScope().limitToProcessInstanceCompleted()).extracting(Record::getIntent).containsExactly(ProcessInstanceIntent.ELEMENT_COMPLETED);
}
use of io.camunda.zeebe.protocol.record.Record in project zeebe by camunda.
the class MultiInstanceSubProcessTest method shouldCreateJobForEachSubProcess.
@Test
public void shouldCreateJobForEachSubProcess() {
// given
ENGINE.deployment().withXmlResource(SERVICE_TASK_SUB_PROCESS).deploy();
final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable(INPUT_COLLECTION, Arrays.asList(10, 20, 30)).create();
// then
assertThat(RecordingExporter.jobRecords(JobIntent.CREATED).withProcessInstanceKey(processInstanceKey).limit(3)).hasSize(3);
// and
final JobBatchRecordValue jobActivation = ENGINE.jobs().withType(JOB_TYPE).activate().getValue();
jobActivation.getJobKeys().forEach(jobKey -> ENGINE.job().withKey(jobKey).complete());
// then
assertThat(jobActivation.getJobs()).extracting(j -> j.getVariables().get(INPUT_ELEMENT)).containsExactly(10, 20, 30);
assertThat(RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).filterRootScope().limitToProcessInstanceCompleted()).extracting(Record::getIntent).containsExactly(ProcessInstanceIntent.ELEMENT_COMPLETED);
}
use of io.camunda.zeebe.protocol.record.Record in project zeebe by camunda.
the class MultiPartitionDeploymentLifecycleTest method shouldTestLifecycle.
@Test
public void shouldTestLifecycle() {
// given - reprocess
final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("shouldReDistributeAfterRecovery").startEvent().endEvent().done();
// when
engine.deployment().withXmlResource("process.bpmn", modelInstance).deploy();
// then
final var deploymentPartitionRecords = RecordingExporter.records().withPartitionId(1).limit(10).collect(Collectors.toList());
assertThat(deploymentPartitionRecords).extracting(Record::getIntent, Record::getRecordType).hasSize(10).containsExactly(tuple(DeploymentIntent.CREATE, RecordType.COMMAND), tuple(ProcessIntent.CREATED, RecordType.EVENT), tuple(DeploymentIntent.CREATED, RecordType.EVENT), tuple(DeploymentDistributionIntent.DISTRIBUTING, RecordType.EVENT), tuple(DeploymentDistributionIntent.DISTRIBUTING, RecordType.EVENT), tuple(DeploymentDistributionIntent.COMPLETE, RecordType.COMMAND), tuple(DeploymentDistributionIntent.COMPLETE, RecordType.COMMAND), tuple(DeploymentDistributionIntent.COMPLETED, RecordType.EVENT), tuple(DeploymentDistributionIntent.COMPLETED, RecordType.EVENT), tuple(DeploymentIntent.FULLY_DISTRIBUTED, RecordType.EVENT));
assertThat(RecordingExporter.records().withPartitionId(2).limit(2).collect(Collectors.toList())).extracting(Record::getIntent).containsExactly(DeploymentIntent.DISTRIBUTE, DeploymentIntent.DISTRIBUTED);
assertThat(RecordingExporter.records().withPartitionId(3).limit(2).collect(Collectors.toList())).extracting(Record::getIntent).containsExactly(DeploymentIntent.DISTRIBUTE, DeploymentIntent.DISTRIBUTED);
}
Aggregations