Search in sources :

Example 11 with Record

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);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) MultiInstanceLoopCharacteristicsBuilder(io.camunda.zeebe.model.bpmn.builder.MultiInstanceLoopCharacteristicsBuilder) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) MessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent) Function(java.util.function.Function) Record(io.camunda.zeebe.protocol.record.Record) Map(java.util.Map) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) VariableRecordValue(io.camunda.zeebe.protocol.record.value.VariableRecordValue) ClassRule(org.junit.ClassRule) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) Tuple(org.assertj.core.groups.Tuple) MessageBuilder(io.camunda.zeebe.model.bpmn.builder.zeebe.MessageBuilder) JobBatchIntent(io.camunda.zeebe.protocol.record.intent.JobBatchIntent) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(io.camunda.zeebe.protocol.record.Assertions.assertThat) JsonUtil(io.camunda.zeebe.test.util.JsonUtil) Test(org.junit.Test) BrokerClassRuleHelper(io.camunda.zeebe.test.util.BrokerClassRuleHelper) Assertions.entry(org.assertj.core.api.Assertions.entry) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Collectors(java.util.stream.Collectors) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) Consumer(java.util.function.Consumer) ServiceTask(io.camunda.zeebe.model.bpmn.instance.ServiceTask) List(java.util.List) Rule(org.junit.Rule) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) Maps(io.camunda.zeebe.test.util.collection.Maps) VariableIntent(io.camunda.zeebe.protocol.record.intent.VariableIntent) Collections(java.util.Collections) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) ServiceTask(io.camunda.zeebe.model.bpmn.instance.ServiceTask) Test(org.junit.Test)

Example 12 with Record

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);
}
Also used : TimerIntent(io.camunda.zeebe.protocol.record.intent.TimerIntent) Arrays(java.util.Arrays) JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) Assertions.tuple(org.assertj.core.api.Assertions.tuple) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) Test(org.junit.Test) MessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Collectors(java.util.stream.Collectors) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) Consumer(java.util.function.Consumer) Record(io.camunda.zeebe.protocol.record.Record) List(java.util.List) Rule(org.junit.Rule) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) Duration(java.time.Duration) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ClassRule(org.junit.ClassRule) StartEventBuilder(io.camunda.zeebe.model.bpmn.builder.StartEventBuilder) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 13 with Record

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);
}
Also used : TimerIntent(io.camunda.zeebe.protocol.record.intent.TimerIntent) Arrays(java.util.Arrays) JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) Assertions.tuple(org.assertj.core.api.Assertions.tuple) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) Test(org.junit.Test) MessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Collectors(java.util.stream.Collectors) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) Consumer(java.util.function.Consumer) Record(io.camunda.zeebe.protocol.record.Record) List(java.util.List) Rule(org.junit.Rule) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) Duration(java.time.Duration) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ClassRule(org.junit.ClassRule) StartEventBuilder(io.camunda.zeebe.model.bpmn.builder.StartEventBuilder) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 14 with Record

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);
}
Also used : TimerIntent(io.camunda.zeebe.protocol.record.intent.TimerIntent) Arrays(java.util.Arrays) JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) Assertions.tuple(org.assertj.core.api.Assertions.tuple) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) Test(org.junit.Test) MessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Collectors(java.util.stream.Collectors) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) Consumer(java.util.function.Consumer) Record(io.camunda.zeebe.protocol.record.Record) List(java.util.List) Rule(org.junit.Rule) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) Duration(java.time.Duration) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ClassRule(org.junit.ClassRule) StartEventBuilder(io.camunda.zeebe.model.bpmn.builder.StartEventBuilder) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) Test(org.junit.Test)

Example 15 with Record

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);
}
Also used : Record(io.camunda.zeebe.protocol.record.Record) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Aggregations

Record (io.camunda.zeebe.protocol.record.Record)184 Test (org.junit.Test)157 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)121 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)121 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)120 ProcessInstanceIntent (io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent)109 RecordingExporter (io.camunda.zeebe.test.util.record.RecordingExporter)109 List (java.util.List)109 Rule (org.junit.Rule)106 EngineRule (io.camunda.zeebe.engine.util.EngineRule)103 BpmnElementType (io.camunda.zeebe.protocol.record.value.BpmnElementType)103 ProcessInstanceRecordValue (io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue)91 Assertions.tuple (org.assertj.core.api.Assertions.tuple)91 Collectors (java.util.stream.Collectors)87 ClassRule (org.junit.ClassRule)79 JobIntent (io.camunda.zeebe.protocol.record.intent.JobIntent)73 Map (java.util.Map)67 Duration (java.time.Duration)64 RecordingExporterTestWatcher (io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher)63 TimerIntent (io.camunda.zeebe.protocol.record.intent.TimerIntent)55