Search in sources :

Example 6 with Record

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

the class MappingIncidentTest method shouldResolveIncidentAfterPreviousResolvingFailed.

@Test
public void shouldResolveIncidentAfterPreviousResolvingFailed() {
    // given
    ENGINE.deployment().withXmlResource(PROCESS_INPUT_MAPPING).deploy();
    final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId("process").create();
    final Record failureEvent = RecordingExporter.processInstanceRecords().withElementId("failingTask").withIntent(ProcessInstanceIntent.ELEMENT_ACTIVATING).withProcessInstanceKey(processInstanceKey).getFirst();
    final Record firstIncident = RecordingExporter.incidentRecords().withProcessInstanceKey(processInstanceKey).withIntent(IncidentIntent.CREATED).getFirst();
    ENGINE.variables().ofScope(failureEvent.getKey()).withDocument(new HashMap<>()).update();
    ENGINE.incident().ofInstance(processInstanceKey).withKey(firstIncident.getKey()).resolve();
    final Record<IncidentRecordValue> secondIncident = RecordingExporter.incidentRecords().onlyEvents().withProcessInstanceKey(processInstanceKey).skipUntil(e -> e.getIntent() == RESOLVED).withIntent(IncidentIntent.CREATED).getFirst();
    // when
    ENGINE.variables().ofScope(failureEvent.getKey()).withDocument(VARIABLES).update();
    final Record<IncidentRecordValue> secondResolvedIncident = ENGINE.incident().ofInstance(processInstanceKey).withKey(secondIncident.getKey()).resolve();
    // then
    assertThat(secondResolvedIncident.getKey()).isGreaterThan(firstIncident.getKey());
    Assertions.assertThat(secondResolvedIncident.getValue()).hasErrorType(ErrorType.IO_MAPPING_ERROR).hasBpmnProcessId("process").hasProcessInstanceKey(processInstanceKey).hasElementId("failingTask").hasElementInstanceKey(failureEvent.getKey()).hasVariableScopeKey(failureEvent.getKey());
    assertThat(secondResolvedIncident.getValue().getErrorMessage()).contains("no variable found for name 'foo'");
}
Also used : HashMap(java.util.HashMap) Record(io.camunda.zeebe.protocol.record.Record) IncidentRecordValue(io.camunda.zeebe.protocol.record.value.IncidentRecordValue) Test(org.junit.Test)

Example 7 with Record

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

the class MultiInstanceIncidentTest method shouldCreateIncidentWhenInputCollectionModifiedConcurrently.

/**
 * This test is a bit more complex then shouldResolveIncidentDueToInputCollection, because it
 * tests a parallel multi-instance body that is about to activate, but while it's activating (and
 * before it's children activate) the input collection is modified. This should result in
 * incidents on each of the children's activations, which can be resolved individually.
 */
@Test
public void shouldCreateIncidentWhenInputCollectionModifiedConcurrently() {
    // given
    final var process = Bpmn.createExecutableProcess("multi-task").startEvent().serviceTask(ELEMENT_ID, t -> t.zeebeJobType(jobType)).sequenceFlowId("from-task-to-multi-instance").serviceTask("multi-instance", t -> t.zeebeJobType(jobType)).multiInstance(b -> b.parallel().zeebeInputCollectionExpression(INPUT_COLLECTION).zeebeInputElement(INPUT_ELEMENT)).endEvent().done();
    final var deployment = ENGINE.deployment().withXmlResource(process).deploy();
    final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId("multi-task").withVariable(INPUT_COLLECTION, List.of(1, 2, 3)).create();
    final var serviceTask = RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED).withProcessInstanceKey(processInstanceKey).withElementType(BpmnElementType.SERVICE_TASK).getFirst();
    final var job = findNthJob(processInstanceKey, 1);
    final var nextKey = ENGINE.getZeebeState().getKeyGenerator().nextKey();
    ENGINE.stop();
    RecordingExporter.reset();
    // when
    final ProcessInstanceRecord sequenceFlow = Records.processInstance(processInstanceKey, "multi-task").setBpmnElementType(BpmnElementType.SEQUENCE_FLOW).setElementId("from-task-to-multi-instance").setFlowScopeKey(processInstanceKey).setProcessDefinitionKey(deployment.getValue().getProcessesMetadata().get(0).getProcessDefinitionKey());
    final ProcessInstanceRecord multiInstanceBody = Records.processInstance(processInstanceKey, "multi-task").setBpmnElementType(BpmnElementType.MULTI_INSTANCE_BODY).setElementId("multi-instance").setFlowScopeKey(processInstanceKey).setProcessDefinitionKey(deployment.getValue().getProcessesMetadata().get(0).getProcessDefinitionKey());
    ENGINE.writeRecords(RecordToWrite.command().key(job.getKey()).job(JobIntent.COMPLETE, job.getValue()), RecordToWrite.event().causedBy(0).key(job.getKey()).job(JobIntent.COMPLETED, job.getValue()), RecordToWrite.command().causedBy(0).key(serviceTask.getKey()).processInstance(ProcessInstanceIntent.COMPLETE_ELEMENT, serviceTask.getValue()), RecordToWrite.event().causedBy(2).key(serviceTask.getKey()).processInstance(ProcessInstanceIntent.ELEMENT_COMPLETING, serviceTask.getValue()), RecordToWrite.event().causedBy(2).key(serviceTask.getKey()).processInstance(ProcessInstanceIntent.ELEMENT_COMPLETED, serviceTask.getValue()), RecordToWrite.event().causedBy(2).key(nextKey).processInstance(ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN, sequenceFlow), RecordToWrite.command().causedBy(2).processInstance(ProcessInstanceIntent.ACTIVATE_ELEMENT, multiInstanceBody), RecordToWrite.command().variable(VariableDocumentIntent.UPDATE, Records.variableDocument(processInstanceKey, "{\"items\":0}")));
    ENGINE.start();
    // then
    final var incidents = RecordingExporter.incidentRecords(IncidentIntent.CREATED).withProcessInstanceKey(processInstanceKey).limit(3).asList();
    assertThat(incidents).describedAs("Should create incident for each child when input element cannot be retrieved from input collection").extracting(Record::getValue).extracting(IncidentRecordValue::getElementId, IncidentRecordValue::getErrorType, IncidentRecordValue::getErrorMessage).containsOnly(tuple("multi-instance", ErrorType.EXTRACT_VALUE_ERROR, "Expected result of the expression 'items' to be 'ARRAY', but was 'NUMBER'."));
    ENGINE.variables().ofScope(processInstanceKey).withDocument(Collections.singletonMap(INPUT_COLLECTION, List.of(1, 2, 3))).update();
    incidents.forEach(i -> ENGINE.incident().ofInstance(processInstanceKey).withKey(i.getKey()).resolve());
    completeNthJob(processInstanceKey, 2);
    completeNthJob(processInstanceKey, 3);
    completeNthJob(processInstanceKey, 4);
    RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).withProcessInstanceKey(processInstanceKey).withElementType(BpmnElementType.PROCESS).await();
}
Also used : ErrorType(io.camunda.zeebe.protocol.record.value.ErrorType) Arrays(java.util.Arrays) VariableDocumentIntent(io.camunda.zeebe.protocol.record.intent.VariableDocumentIntent) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) Record(io.camunda.zeebe.protocol.record.Record) Map(java.util.Map) EngineRule(io.camunda.zeebe.engine.util.EngineRule) RecordToWrite(io.camunda.zeebe.engine.util.RecordToWrite) Records(io.camunda.zeebe.engine.util.Records) VariableRecordValue(io.camunda.zeebe.protocol.record.value.VariableRecordValue) ClassRule(org.junit.ClassRule) ResolveIncidentClient(io.camunda.zeebe.engine.util.client.IncidentClient.ResolveIncidentClient) Before(org.junit.Before) Assertions.tuple(org.assertj.core.api.Assertions.tuple) IncidentRecordValue(io.camunda.zeebe.protocol.record.value.IncidentRecordValue) Set(java.util.Set) 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) Assertions(io.camunda.zeebe.protocol.record.Assertions) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) List(java.util.List) 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) 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) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) Record(io.camunda.zeebe.protocol.record.Record) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) Test(org.junit.Test)

Example 8 with Record

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

the class ExporterDirectorTest method shouldApplyRecordFilter.

@Test
public void shouldApplyRecordFilter() {
    // given
    exporters.get(0).onConfigure(withFilter(Arrays.asList(RecordType.COMMAND, RecordType.EVENT), Collections.singletonList(ValueType.DEPLOYMENT)));
    exporters.get(1).onConfigure(withFilter(Collections.singletonList(RecordType.EVENT), Arrays.asList(ValueType.DEPLOYMENT, ValueType.JOB)));
    startExporterDirector(exporterDescriptors);
    // when
    final long deploymentCommand = rule.writeCommand(DeploymentIntent.CREATE, new DeploymentRecord());
    final long deploymentEvent = rule.writeEvent(DeploymentIntent.CREATED, new DeploymentRecord());
    rule.writeEvent(IncidentIntent.CREATED, new IncidentRecord());
    final long jobEvent = rule.writeEvent(JobIntent.CREATED, new JobRecord());
    // then
    waitUntil(() -> exporters.get(1).getExportedRecords().size() == 2);
    assertThat(exporters.get(0).getExportedRecords()).extracting(Record::getPosition).hasSize(2).contains(deploymentCommand, deploymentEvent);
    assertThat(exporters.get(1).getExportedRecords()).extracting(Record::getPosition).hasSize(2).contains(deploymentEvent, jobEvent);
}
Also used : DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord) IncidentRecord(io.camunda.zeebe.protocol.impl.record.value.incident.IncidentRecord) JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord) Record(io.camunda.zeebe.protocol.record.Record) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) IncidentRecord(io.camunda.zeebe.protocol.impl.record.value.incident.IncidentRecord) Test(org.junit.Test)

Example 9 with Record

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

the class AvailabilityTest method shouldCreateProcessWhenOnePartitionDown.

@Test
public void shouldCreateProcessWhenOnePartitionDown() {
    final BrokerInfo leaderForPartition = clusteringRule.getLeaderForPartition(partitionCount);
    // when
    clusteringRule.stopBroker(leaderForPartition.getNodeId());
    for (int i = 0; i < 2 * partitionCount; i++) {
        clientRule.createProcessInstance(processDefinitionKey);
    }
    // then
    final List<Integer> partitionIds = RecordingExporter.processInstanceCreationRecords().withIntent(ProcessInstanceCreationIntent.CREATED).map(Record::getPartitionId).limit(2 * partitionCount).collect(Collectors.toList());
    assertThat(partitionIds).hasSize(2 * partitionCount);
    assertThat(partitionIds).containsExactlyInAnyOrder(1, 1, 1, 2, 2, 2);
}
Also used : Record(io.camunda.zeebe.protocol.record.Record) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Test(org.junit.Test)

Example 10 with Record

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

the class MultiInstanceActivityTest method shouldApplyInputMapping.

@Test
public void shouldApplyInputMapping() {
    // given
    final ServiceTask task = process(miBuilder).getModelElementById(ELEMENT_ID);
    final var process = task.builder().zeebeInputExpression(INPUT_ELEMENT_VARIABLE, "x").zeebeInputExpression("loopCounter", "y").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
    final var elementInstanceKeys = RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED).withProcessInstanceKey(processInstanceKey).withElementId(ELEMENT_ID).withElementType(BpmnElementType.SERVICE_TASK).limit(3).map(Record::getKey).collect(Collectors.toList());
    assertThat(RecordingExporter.records().limitToProcessInstance(processInstanceKey).variableRecords().withProcessInstanceKey(processInstanceKey)).extracting(Record::getValue).extracting(v -> tuple(v.getScopeKey(), v.getName(), v.getValue())).contains(tuple(elementInstanceKeys.get(0), "x", JsonUtil.toJson(INPUT_COLLECTION.get(0))), tuple(elementInstanceKeys.get(0), "y", "1"), tuple(elementInstanceKeys.get(1), "x", JsonUtil.toJson(INPUT_COLLECTION.get(1))), tuple(elementInstanceKeys.get(1), "y", "2"), tuple(elementInstanceKeys.get(2), "x", JsonUtil.toJson(INPUT_COLLECTION.get(2))), tuple(elementInstanceKeys.get(2), "y", "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)

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