Search in sources :

Example 96 with Record

use of io.camunda.zeebe.protocol.record.Record in project zeebe by zeebe-io.

the class ParallelGatewayTest method shouldMergeAndSplitInOneGateway.

@Test
public void shouldMergeAndSplitInOneGateway() {
    // given
    final BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_ID).startEvent("start").parallelGateway("fork").parallelGateway("join-fork").moveToNode("fork").connectTo("join-fork").serviceTask("task1", b -> b.zeebeJobType("type1")).moveToLastGateway().serviceTask("task2", b -> b.zeebeJobType("type2")).done();
    engine.deployment().withXmlResource(process).deploy();
    // when
    engine.processInstance().ofBpmnProcessId(PROCESS_ID).create();
    // then
    final List<Record<ProcessInstanceRecordValue>> elementInstances = RecordingExporter.processInstanceRecords().filter(r -> r.getIntent() == ProcessInstanceIntent.ELEMENT_ACTIVATED && r.getValue().getBpmnElementType() == BpmnElementType.SERVICE_TASK).limit(2).collect(Collectors.toList());
    assertThat(elementInstances).extracting(e -> e.getValue().getElementId()).contains("task1", "task2");
}
Also used : 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) Collectors(java.util.stream.Collectors) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) Record(io.camunda.zeebe.protocol.record.Record) ServiceTask(io.camunda.zeebe.model.bpmn.instance.ServiceTask) List(java.util.List) Rule(org.junit.Rule) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Record(io.camunda.zeebe.protocol.record.Record) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 97 with Record

use of io.camunda.zeebe.protocol.record.Record in project zeebe by zeebe-io.

the class MultiInstanceActivityTest method shouldTriggerNonInterruptingBoundaryEvent.

@Test
public void shouldTriggerNonInterruptingBoundaryEvent() {
    // given
    final ServiceTask task = process(miBuilder).getModelElementById(ELEMENT_ID);
    final var process = task.builder().boundaryEvent("boundary-event", b -> b.cancelActivity(false).message(MESSAGE_BUILDER)).sequenceFlowId("to-notified").endEvent("notified").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 subscription 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.processInstanceRecords().withProcessInstanceKey(processInstanceKey).limit(r -> r.getValue().getBpmnElementType() == BpmnElementType.END_EVENT)).extracting(r -> tuple(r.getValue().getElementId(), r.getValue().getBpmnElementType(), r.getIntent())).containsSubsequence(tuple("to-notified", BpmnElementType.SEQUENCE_FLOW, ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("notified", BpmnElementType.END_EVENT, ProcessInstanceIntent.ACTIVATE_ELEMENT));
    // and
    completeJobs(processInstanceKey, 1);
    assertThat(RecordingExporter.messageSubscriptionRecords().withProcessInstanceKey(processInstanceKey).limit(7)).extracting(Record::getIntent).containsExactly(MessageSubscriptionIntent.CREATE, MessageSubscriptionIntent.CREATED, MessageSubscriptionIntent.CORRELATING, MessageSubscriptionIntent.CORRELATE, MessageSubscriptionIntent.CORRELATED, MessageSubscriptionIntent.DELETE, MessageSubscriptionIntent.DELETED);
    assertThat(RecordingExporter.processInstanceRecords().withProcessInstanceKey(processInstanceKey).limitToProcessInstanceCompleted()).extracting(r -> tuple(r.getValue().getElementId(), r.getValue().getBpmnElementType(), r.getIntent())).containsSubsequence(tuple("notified", BpmnElementType.END_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETED), tuple(ELEMENT_ID, BpmnElementType.SERVICE_TASK, ProcessInstanceIntent.ELEMENT_COMPLETED), tuple(ELEMENT_ID, BpmnElementType.MULTI_INSTANCE_BODY, ProcessInstanceIntent.ELEMENT_COMPLETED), tuple(PROCESS_ID, BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETED));
}
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 98 with Record

use of io.camunda.zeebe.protocol.record.Record in project zeebe by zeebe-io.

the class MultiInstanceActivityTest method shouldApplyOutputMapping.

@Test
public void shouldApplyOutputMapping() {
    // given
    final ServiceTask task = process(miBuilder).getModelElementById(ELEMENT_ID);
    final var process = task.builder().zeebeOutputExpression("loopCounter", // overrides the variable
    OUTPUT_ELEMENT_EXPRESSION).zeebeOutputExpression("loopCounter", // propagates to root scope
    "global").done();
    ENGINE.deployment().withXmlResource(process).deploy();
    // when
    final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable(INPUT_COLLECTION_EXPRESSION, INPUT_COLLECTION).create();
    completeJobs(processInstanceKey, INPUT_COLLECTION.size());
    // then
    assertThat(RecordingExporter.variableRecords().withScopeKey(processInstanceKey).withName(OUTPUT_COLLECTION_VARIABLE).getFirst().getValue()).hasValue("[1,2,3]");
    assertThat(RecordingExporter.records().limitToProcessInstance(processInstanceKey).variableRecords().withProcessInstanceKey(processInstanceKey).withName("global")).extracting(Record::getValue).extracting(v -> tuple(v.getScopeKey(), v.getValue())).containsExactly(tuple(processInstanceKey, "1"), tuple(processInstanceKey, "2"), tuple(processInstanceKey, "3"));
}
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) Record(io.camunda.zeebe.protocol.record.Record) Test(org.junit.Test)

Example 99 with Record

use of io.camunda.zeebe.protocol.record.Record in project zeebe by zeebe-io.

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 100 with Record

use of io.camunda.zeebe.protocol.record.Record in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldRejectDeploymentWithDuplicateResources.

@Test
public void shouldRejectDeploymentWithDuplicateResources() {
    // given
    final BpmnModelInstance definition1 = Bpmn.createExecutableProcess("process1").startEvent().done();
    final BpmnModelInstance definition2 = Bpmn.createExecutableProcess("process2").startEvent().done();
    final BpmnModelInstance definition3 = Bpmn.createExecutableProcess("process2").startEvent().serviceTask("task", (t) -> t.zeebeJobType("j").zeebeTaskHeader("k", "v")).done();
    // when
    final Record<DeploymentRecordValue> deploymentRejection = ENGINE.deployment().withXmlResource("p1.bpmn", definition1).withXmlResource("p2.bpmn", definition2).withXmlResource("p3.bpmn", definition3).expectRejection().deploy();
    // then
    Assertions.assertThat(deploymentRejection).hasRejectionType(RejectionType.INVALID_ARGUMENT).hasRejectionReason("Expected to deploy new resources, but encountered the following errors:\n" + "Duplicated process id in resources 'p2.bpmn' and 'p3.bpmn'");
}
Also used : RecordType(io.camunda.zeebe.protocol.record.RecordType) DeploymentIntent(io.camunda.zeebe.protocol.record.intent.DeploymentIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DeploymentResource(io.camunda.zeebe.protocol.record.value.deployment.DeploymentResource) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) DeploymentRecordValue(io.camunda.zeebe.protocol.record.value.DeploymentRecordValue) Record(io.camunda.zeebe.protocol.record.Record) Strings(io.camunda.zeebe.test.util.Strings) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ProcessBuilder(io.camunda.zeebe.model.bpmn.builder.ProcessBuilder) DEPLOYMENT_PARTITION(io.camunda.zeebe.protocol.Protocol.DEPLOYMENT_PARTITION) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Before(org.junit.Before) ProcessMetadataValue(io.camunda.zeebe.protocol.record.value.deployment.ProcessMetadataValue) ExecuteCommandResponseDecoder(io.camunda.zeebe.protocol.record.ExecuteCommandResponseDecoder) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Test(org.junit.Test) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Collectors(java.util.stream.Collectors) Assertions(io.camunda.zeebe.protocol.record.Assertions) ProcessIntent(io.camunda.zeebe.protocol.record.intent.ProcessIntent) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) List(java.util.List) Rule(org.junit.Rule) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) Paths(java.nio.file.Paths) Message(io.camunda.zeebe.model.bpmn.instance.Message) InputStream(java.io.InputStream) DeploymentRecordValue(io.camunda.zeebe.protocol.record.value.DeploymentRecordValue) 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