Search in sources :

Example 16 with Record

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

the class NonInterruptingEventSubprocessTest method shouldTriggerEventSubprocessTwiceWithOwnLocalScopeVariable.

@Test
public void shouldTriggerEventSubprocessTwiceWithOwnLocalScopeVariable() {
    // given
    final BpmnModelInstance model = eventSubprocModelWithLocalScopeVariable(builder);
    final long processInstanceKey = createInstanceAndTriggerEvent(model);
    RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED).withElementId("event_sub_start").withElementType(BpmnElementType.START_EVENT).withProcessInstanceKey(processInstanceKey).await();
    // when
    triggerEventSubprocess.accept(processInstanceKey);
    // then
    final List<Record<ProcessInstanceRecordValue>> eventSubProcessActivatedList = RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED).withElementId("event_sub_proc").withElementType(BpmnElementType.EVENT_SUB_PROCESS).withProcessInstanceKey(processInstanceKey).limit(2).collect(Collectors.toList());
    RecordingExporter.variableRecords().withProcessInstanceKey(processInstanceKey).withName("localScope").withScopeKey(eventSubProcessActivatedList.get(0).getKey()).await();
    RecordingExporter.variableRecords().withProcessInstanceKey(processInstanceKey).withName("localScope").withScopeKey(eventSubProcessActivatedList.get(1).getKey()).await();
}
Also used : Record(io.camunda.zeebe.protocol.record.Record) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 17 with Record

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

the class CreateDeploymentMultiplePartitionsTest method assertDeploymentEventResources.

private void assertDeploymentEventResources(final int expectedPartition, final DeploymentIntent deploymentIntent, final long expectedKey, final Consumer<Record<DeploymentRecordValue>> deploymentAssert) {
    final Record deploymentCreatedEvent = RecordingExporter.deploymentRecords().withPartitionId(expectedPartition).withIntent(deploymentIntent).withRecordKey(expectedKey).getFirst();
    assertThat(deploymentCreatedEvent.getKey()).isEqualTo(expectedKey);
    assertThat(deploymentCreatedEvent.getPartitionId()).isEqualTo(expectedPartition);
    deploymentAssert.accept(deploymentCreatedEvent);
}
Also used : Record(io.camunda.zeebe.protocol.record.Record)

Example 18 with Record

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

the class CreateDeploymentMultiplePartitionsTest method shouldCreateDeploymentOnAllPartitions.

@Test
public void shouldCreateDeploymentOnAllPartitions() {
    // when
    final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("shouldCreateDeploymentOnAllPartitions").startEvent().endEvent().done();
    final BpmnModelInstance secondNoopModel = Bpmn.createExecutableProcess("shouldCreateDeploymentOnAllPartitionsSecondNoopDeployment").startEvent().endEvent().done();
    final Record<DeploymentRecordValue> deployment = ENGINE.deployment().withXmlResource("process.bpmn", modelInstance).deploy();
    final Record<DeploymentRecordValue> secondDeployment = ENGINE.deployment().withXmlResource("secondNoopModel.bpmn", secondNoopModel).deploy();
    // then
    assertThat(deployment.getKey()).isNotNegative();
    assertThat(deployment.getPartitionId()).isEqualTo(PARTITION_ID);
    assertThat(deployment.getRecordType()).isEqualTo(RecordType.EVENT);
    assertThat(deployment.getIntent()).isEqualTo(DeploymentIntent.CREATED);
    final var deploymentRecords = RecordingExporter.records().limit(r -> r.getIntent() == DeploymentIntent.FULLY_DISTRIBUTED && r.getKey() == secondDeployment.getKey()).withRecordKey(deployment.getKey()).collect(Collectors.toList());
    final var listOfFullyDistributed = deploymentRecords.stream().filter(r -> r.getIntent() == DeploymentIntent.FULLY_DISTRIBUTED).collect(Collectors.toList());
    assertThat(listOfFullyDistributed).hasSize(1);
    final var fullyDistributedDeployment = listOfFullyDistributed.get(0);
    assertThat(fullyDistributedDeployment.getKey()).isNotNegative();
    assertThat(fullyDistributedDeployment.getPartitionId()).isEqualTo(PARTITION_ID);
    assertThat(fullyDistributedDeployment.getRecordType()).isEqualTo(RecordType.EVENT);
    assertThat(fullyDistributedDeployment.getIntent()).isEqualTo(DeploymentIntent.FULLY_DISTRIBUTED);
    assertThat(deploymentRecords.stream().filter(r -> r.getIntent() == DeploymentIntent.DISTRIBUTE).count()).isEqualTo(PARTITION_COUNT - 1);
    assertThat(deploymentRecords.stream().filter(r -> r.getIntent() == DeploymentDistributionIntent.DISTRIBUTING).count()).isEqualTo(PARTITION_COUNT - 1);
    assertThat(deploymentRecords.stream().filter(r -> r.getIntent() == DeploymentDistributionIntent.COMPLETE).count()).isEqualTo(PARTITION_COUNT - 1);
    // todo(zell): https://github.com/zeebe-io/zeebe/issues/6314 fully distributed contains
    // currently no longer any resources
    // 
    // assertDeploymentEventResources(
    // DEPLOYMENT_PARTITION,
    // DeploymentIntent.CREATED,
    // deployment.getKey(),
    // (createdDeployment) ->
    // assertDeploymentRecord(fullyDistributedDeployment, createdDeployment));
    ENGINE.getPartitionIds().forEach(partitionId -> {
        if (DEPLOYMENT_PARTITION == partitionId) {
            return;
        }
        assertDeploymentEventResources(partitionId, DeploymentIntent.DISTRIBUTED, deployment.getKey(), (createdDeployment) -> assertDeploymentRecord(deployment, createdDeployment));
    });
}
Also used : DeploymentRecordValue(io.camunda.zeebe.protocol.record.value.DeploymentRecordValue) ProcessMetadataValue(io.camunda.zeebe.protocol.record.value.deployment.ProcessMetadataValue) RecordType(io.camunda.zeebe.protocol.record.RecordType) DeploymentDistributionRecordValue(io.camunda.zeebe.protocol.record.value.DeploymentDistributionRecordValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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) Test(org.junit.Test) DeploymentRecordValue(io.camunda.zeebe.protocol.record.value.DeploymentRecordValue) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Collectors(java.util.stream.Collectors) Assertions(io.camunda.zeebe.protocol.record.Assertions) 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) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) DeploymentDistributionIntent(io.camunda.zeebe.protocol.record.intent.DeploymentDistributionIntent) DEPLOYMENT_PARTITION(io.camunda.zeebe.protocol.Protocol.DEPLOYMENT_PARTITION) ClassRule(org.junit.ClassRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 19 with Record

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

the class BoundaryEventTest method shouldApplyOutputMappingOnTriggering.

@Test
public void shouldApplyOutputMappingOnTriggering() {
    // given
    final BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_ID).startEvent().serviceTask("task", b -> b.zeebeJobType("type")).boundaryEvent("event").message(m -> m.name("message").zeebeCorrelationKeyExpression("key")).zeebeOutputExpression("foo", "bar").endEvent("endTimer").moveToActivity("task").endEvent().done();
    ENGINE.deployment().withXmlResource(process).deploy();
    final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable("key", "123").create();
    // when
    ENGINE.message().withName("message").withCorrelationKey("123").withVariables(asMsgPack("foo", 3)).publish();
    // then
    final Record<VariableRecordValue> variableEvent = RecordingExporter.variableRecords().withProcessInstanceKey(processInstanceKey).withName("bar").getFirst();
    Assertions.assertThat(variableEvent.getValue()).hasValue("3");
}
Also used : TimerIntent(io.camunda.zeebe.protocol.record.intent.TimerIntent) ErrorType(io.camunda.zeebe.protocol.record.value.ErrorType) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) RecordValue(io.camunda.zeebe.protocol.record.RecordValue) ValueType(io.camunda.zeebe.protocol.record.ValueType) Record(io.camunda.zeebe.protocol.record.Record) Duration(java.time.Duration) 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) ProcessEventIntent(io.camunda.zeebe.protocol.record.intent.ProcessEventIntent) MsgPackUtil.asMsgPack(io.camunda.zeebe.test.util.MsgPackUtil.asMsgPack) Assertions.tuple(org.assertj.core.api.Assertions.tuple) IncidentRecordValue(io.camunda.zeebe.protocol.record.value.IncidentRecordValue) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Assertions(io.camunda.zeebe.protocol.record.Assertions) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) List(java.util.List) ProcessInstances(io.camunda.zeebe.test.util.record.ProcessInstances) Rule(org.junit.Rule) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) IncidentIntent(io.camunda.zeebe.protocol.record.intent.IncidentIntent) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) VariableRecordValue(io.camunda.zeebe.protocol.record.value.VariableRecordValue) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 20 with Record

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

the class BoundaryEventTest method shouldTerminateSubProcessBeforeTriggeringBoundaryEvent.

@Test
public void shouldTerminateSubProcessBeforeTriggeringBoundaryEvent() {
    // given
    final BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_ID).startEvent().subProcess("sub").embeddedSubProcess().startEvent().serviceTask("task", t -> t.zeebeJobType("type")).endEvent().subProcessDone().boundaryEvent("timer").cancelActivity(true).timerWithDuration("PT1S").endEvent("endTimer").moveToActivity("sub").endEvent().done();
    ENGINE.deployment().withXmlResource(process).deploy();
    ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).create();
    // when
    RecordingExporter.jobRecords().withIntent(JobIntent.CREATED).getFirst();
    ENGINE.increaseTime(Duration.ofMinutes(1));
    final List<Record<RecordValue>> records = RecordingExporter.records().limit(r -> r.getValue() instanceof ProcessInstanceRecord && ((ProcessInstanceRecord) r.getValue()).getElementId().equals("timer") && r.getIntent() == ProcessInstanceIntent.ELEMENT_COMPLETED).asList();
    assertThat(records).extracting(Record::getValueType, Record::getIntent).endsWith(tuple(ValueType.TIMER, TimerIntent.TRIGGERED), tuple(ValueType.PROCESS_EVENT, ProcessEventIntent.TRIGGERING), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.TERMINATE_ELEMENT), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_TERMINATING), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.TERMINATE_ELEMENT), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_TERMINATING), tuple(ValueType.JOB, JobIntent.CANCEL), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_TERMINATED), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_TERMINATED), tuple(ValueType.PROCESS_EVENT, ProcessEventIntent.TRIGGERED), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_ACTIVATING), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_ACTIVATED), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.COMPLETE_ELEMENT), tuple(ValueType.JOB, JobIntent.CANCELED), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_COMPLETING), tuple(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_COMPLETED));
}
Also used : TimerIntent(io.camunda.zeebe.protocol.record.intent.TimerIntent) ErrorType(io.camunda.zeebe.protocol.record.value.ErrorType) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) RecordValue(io.camunda.zeebe.protocol.record.RecordValue) ValueType(io.camunda.zeebe.protocol.record.ValueType) Record(io.camunda.zeebe.protocol.record.Record) Duration(java.time.Duration) 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) ProcessEventIntent(io.camunda.zeebe.protocol.record.intent.ProcessEventIntent) MsgPackUtil.asMsgPack(io.camunda.zeebe.test.util.MsgPackUtil.asMsgPack) Assertions.tuple(org.assertj.core.api.Assertions.tuple) IncidentRecordValue(io.camunda.zeebe.protocol.record.value.IncidentRecordValue) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Assertions(io.camunda.zeebe.protocol.record.Assertions) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) List(java.util.List) ProcessInstances(io.camunda.zeebe.test.util.record.ProcessInstances) Rule(org.junit.Rule) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) IncidentIntent(io.camunda.zeebe.protocol.record.intent.IncidentIntent) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) Record(io.camunda.zeebe.protocol.record.Record) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) 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