Search in sources :

Example 21 with Record

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

the class ExclusiveGatewayTest method shouldEndScopeIfGatewayHasNoOutgoingFlows.

@Test
public void shouldEndScopeIfGatewayHasNoOutgoingFlows() {
    // given
    final String processId = Strings.newRandomValidBpmnId();
    final BpmnModelInstance processDefinition = Bpmn.createExecutableProcess(processId).startEvent().exclusiveGateway("xor").done();
    ENGINE.deployment().withXmlResource(processDefinition).deploy();
    // when
    final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(processId).withVariable("foo", 10).create();
    // then
    final List<Record<ProcessInstanceRecordValue>> completedEvents = RecordingExporter.processInstanceRecords().onlyEvents().withProcessInstanceKey(processInstanceKey).skipUntil(r -> r.getValue().getElementId().equals("xor")).limitToProcessInstanceCompleted().collect(Collectors.toList());
    assertThat(completedEvents).extracting(r -> tuple(r.getValue().getBpmnElementType(), r.getIntent())).containsExactly(tuple(BpmnElementType.EXCLUSIVE_GATEWAY, ProcessInstanceIntent.ELEMENT_ACTIVATING), tuple(BpmnElementType.EXCLUSIVE_GATEWAY, ProcessInstanceIntent.ELEMENT_ACTIVATED), tuple(BpmnElementType.EXCLUSIVE_GATEWAY, ProcessInstanceIntent.ELEMENT_COMPLETING), tuple(BpmnElementType.EXCLUSIVE_GATEWAY, ProcessInstanceIntent.ELEMENT_COMPLETED), tuple(BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETING), tuple(BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETED));
}
Also used : Arrays(java.util.Arrays) 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) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Collectors(java.util.stream.Collectors) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) Record(io.camunda.zeebe.protocol.record.Record) Strings(io.camunda.zeebe.test.util.Strings) List(java.util.List) Rule(org.junit.Rule) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) IncidentIntent(io.camunda.zeebe.protocol.record.intent.IncidentIntent) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ClassRule(org.junit.ClassRule) Record(io.camunda.zeebe.protocol.record.Record) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 22 with Record

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

the class ExclusiveGatewayTest method shouldSplitOnExclusiveGateway.

@Test
public void shouldSplitOnExclusiveGateway() {
    // given
    final String processId = Strings.newRandomValidBpmnId();
    final BpmnModelInstance processDefinition = Bpmn.createExecutableProcess(processId).startEvent().exclusiveGateway("xor").sequenceFlowId("s1").conditionExpression("foo < 5").endEvent("a").moveToLastGateway().sequenceFlowId("s2").conditionExpression("foo >= 5 and foo < 10").endEvent("b").moveToLastExclusiveGateway().defaultFlow().sequenceFlowId("s3").endEvent("c").done();
    ENGINE.deployment().withXmlResource(processDefinition).deploy();
    // when
    final long processInstance1 = ENGINE.processInstance().ofBpmnProcessId(processId).withVariable("foo", 4).create();
    final long processInstance2 = ENGINE.processInstance().ofBpmnProcessId(processId).withVariable("foo", 8).create();
    final long processInstance3 = ENGINE.processInstance().ofBpmnProcessId(processId).withVariable("foo", 12).create();
    final List<Long> processInstanceKeys = Arrays.asList(processInstance1, processInstance2, processInstance3);
    // then
    assertThat(RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).valueFilter(r -> processInstanceKeys.contains(r.getProcessInstanceKey())).withElementType(BpmnElementType.END_EVENT).limit(3)).extracting(Record::getValue).extracting(v -> tuple(v.getProcessInstanceKey(), v.getElementId())).contains(tuple(processInstance1, "a"), tuple(processInstance2, "b"), tuple(processInstance3, "c"));
}
Also used : Arrays(java.util.Arrays) 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) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) Collectors(java.util.stream.Collectors) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) Record(io.camunda.zeebe.protocol.record.Record) Strings(io.camunda.zeebe.test.util.Strings) List(java.util.List) Rule(org.junit.Rule) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) IncidentIntent(io.camunda.zeebe.protocol.record.intent.IncidentIntent) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ClassRule(org.junit.ClassRule) Record(io.camunda.zeebe.protocol.record.Record) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 23 with Record

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

the class ParallelGatewayTest method shouldPassThroughParallelGateway.

@Test
public void shouldPassThroughParallelGateway() {
    // given
    final BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_ID).startEvent("start").sequenceFlowId("flow1").parallelGateway("fork").sequenceFlowId("flow2").endEvent("end").done();
    engine.deployment().withXmlResource(process).deploy();
    // when
    engine.processInstance().ofBpmnProcessId(PROCESS_ID).create();
    // then
    final List<Record<ProcessInstanceRecordValue>> processInstanceEvents = RecordingExporter.processInstanceRecords().limitToProcessInstanceCompleted().collect(Collectors.toList());
    assertThat(processInstanceEvents).extracting(e -> e.getValue().getElementId(), Record::getIntent).containsSequence(tuple("fork", ProcessInstanceIntent.ELEMENT_ACTIVATING), tuple("fork", ProcessInstanceIntent.ELEMENT_ACTIVATED), tuple("fork", ProcessInstanceIntent.ELEMENT_COMPLETING), tuple("fork", ProcessInstanceIntent.ELEMENT_COMPLETED), tuple("flow2", ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("end", ProcessInstanceIntent.ACTIVATE_ELEMENT), tuple("end", ProcessInstanceIntent.ELEMENT_ACTIVATING), tuple("end", ProcessInstanceIntent.ELEMENT_ACTIVATED), tuple("end", ProcessInstanceIntent.ELEMENT_COMPLETING), tuple("end", ProcessInstanceIntent.ELEMENT_COMPLETED), tuple(PROCESS_ID, ProcessInstanceIntent.COMPLETE_ELEMENT), tuple(PROCESS_ID, ProcessInstanceIntent.ELEMENT_COMPLETING), tuple(PROCESS_ID, ProcessInstanceIntent.ELEMENT_COMPLETED));
}
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 24 with Record

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

the class ParallelGatewayTest method shouldOnlyTriggerGatewayWhenAllBranchesAreActivated.

@Test
public void shouldOnlyTriggerGatewayWhenAllBranchesAreActivated() {
    // given
    final BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_ID).startEvent().parallelGateway("fork").exclusiveGateway("exclusiveJoin").moveToLastGateway().connectTo("exclusiveJoin").sequenceFlowId("joinFlow1").parallelGateway("join").moveToNode("fork").serviceTask("waitState", b -> b.zeebeJobType("type")).sequenceFlowId("joinFlow2").connectTo("join").endEvent().done();
    engine.deployment().withXmlResource(process).deploy();
    final long processInstanceKey = engine.processInstance().ofBpmnProcessId(PROCESS_ID).create();
    // waiting until we have signalled the first incoming sequence flow twice
    // => this should not trigger the gateway yet
    RecordingExporter.processInstanceRecords().limit(r -> "joinFlow1".equals(r.getValue().getElementId())).limit(2).skip(1).getFirst();
    // when
    // we complete the job
    engine.job().ofInstance(processInstanceKey).withType("type").complete();
    // then
    final List<Record<ProcessInstanceRecordValue>> events = RecordingExporter.processInstanceRecords().limit(r -> "join".equals(r.getValue().getElementId()) && ProcessInstanceIntent.ELEMENT_COMPLETED == r.getIntent()).collect(Collectors.toList());
    assertThat(events).extracting(e -> e.getValue().getElementId(), Record::getIntent).containsSubsequence(tuple("joinFlow1", ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("joinFlow1", ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("joinFlow2", ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("join", ProcessInstanceIntent.ELEMENT_ACTIVATING));
}
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 25 with Record

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

the class ParallelGatewayTest method shouldCompleteScopeOnParallelGateway.

@Test
public void shouldCompleteScopeOnParallelGateway() {
    // given
    final BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_ID).startEvent("start").sequenceFlowId("flow1").parallelGateway("fork").done();
    engine.deployment().withXmlResource(process).deploy();
    // when
    engine.processInstance().ofBpmnProcessId(PROCESS_ID).create();
    // then
    final List<Record<ProcessInstanceRecordValue>> processInstanceEvents = RecordingExporter.processInstanceRecords().limitToProcessInstanceCompleted().collect(Collectors.toList());
    assertThat(processInstanceEvents).extracting(e -> e.getValue().getElementId(), Record::getIntent).containsSequence(tuple("fork", ProcessInstanceIntent.ELEMENT_COMPLETED), tuple(PROCESS_ID, ProcessInstanceIntent.COMPLETE_ELEMENT));
}
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)

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