use of io.camunda.zeebe.protocol.record.Record in project zeebe-process-test by camunda.
the class ContainerizedEngine method getRecords.
/**
* Gets a list of all records that have occurred on the test engine.
*
* @return a list of records
*/
public List<Record<?>> getRecords() {
final ManagedChannel channel = getChannel();
final EngineControlBlockingStub stub = getStub(channel);
final ObjectMapper mapper = new ObjectMapper();
final List<Record<?>> mappedRecords = new ArrayList<>();
final GetRecordsRequest request = GetRecordsRequest.newBuilder().build();
final Iterator<RecordResponse> response = stub.getRecords(request);
while (response.hasNext()) {
final RecordResponse recordResponse = response.next();
try {
final Record<?> record = mapper.readValue(recordResponse.getRecordJson(), AbstractRecord.class);
mappedRecords.add(record);
} catch (final JsonProcessingException e) {
throw new RuntimeException(e);
}
}
closeChannel(channel);
return mappedRecords;
}
use of io.camunda.zeebe.protocol.record.Record in project zeebe-exporter-protobuf by camunda-community-hub.
the class RecordTransformTest method mockRecord.
private <V extends RecordValue> Record<V> mockRecord(final V recordValue, final ValueType valueType, final Intent intent) {
final Record record = mock(Record.class);
when(record.getKey()).thenReturn(KEY);
when(record.getPosition()).thenReturn(POSITION);
when(record.getSourceRecordPosition()).thenReturn(SOURCE_POSITION);
when(record.getTimestamp()).thenReturn(TIMESTAMP);
when(record.getPartitionId()).thenReturn(PARTITION_ID);
when(record.getRejectionReason()).thenReturn("failed");
when(record.getRejectionType()).thenReturn(RejectionType.INVALID_ARGUMENT);
when(record.getRecordType()).thenReturn(RecordType.COMMAND);
when(record.getValueType()).thenReturn(valueType);
when(record.getIntent()).thenReturn(intent);
when(record.getValue()).thenReturn(recordValue);
return record;
}
use of io.camunda.zeebe.protocol.record.Record in project zeebe by camunda.
the class TypedStreamProcessorTest method shouldSkipFailingEvent.
@Test
public void shouldSkipFailingEvent() {
// given
streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> TypedRecordProcessors.processors(keyGenerator, processingContext.getWriters()).onCommand(ValueType.DEPLOYMENT, DeploymentIntent.CREATE, new ErrorProneProcessor()));
final AtomicLong requestId = new AtomicLong(0);
final AtomicInteger requestStreamId = new AtomicInteger(0);
when(mockCommandResponseWriter.tryWriteResponse(anyInt(), anyLong())).then((invocationOnMock -> {
final int streamIdArg = invocationOnMock.getArgument(0);
final long requestIdArg = invocationOnMock.getArgument(1);
requestId.set(requestIdArg);
requestStreamId.set(streamIdArg);
return true;
}));
final long failingKey = keyGenerator.nextKey();
streams.newRecord(STREAM_NAME).event(deployment("foo")).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).requestId(255L).requestStreamId(99).key(failingKey).write();
final long secondEventPosition = streams.newRecord(STREAM_NAME).event(deployment("foo2")).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).key(keyGenerator.nextKey()).write();
// when
final LoggedEvent writtenEvent = TestUtil.doRepeatedly(() -> streams.events(STREAM_NAME).filter(e -> Records.isEvent(e, ValueType.DEPLOYMENT, DeploymentIntent.CREATED)).findFirst()).until(o -> o.isPresent()).get();
// then
assertThat(writtenEvent.getKey()).isEqualTo(1);
assertThat(writtenEvent.getSourceEventPosition()).isEqualTo(secondEventPosition);
// error response
verify(mockCommandResponseWriter).tryWriteResponse(anyInt(), anyLong());
assertThat(requestId.get()).isEqualTo(255L);
assertThat(requestStreamId.get()).isEqualTo(99);
final Record<DeploymentRecord> deploymentRejection = new RecordStream(streams.events(STREAM_NAME)).onlyDeploymentRecords().onlyRejections().withIntent(DeploymentIntent.CREATE).getFirst();
assertThat(deploymentRejection.getKey()).isEqualTo(failingKey);
assertThat(deploymentRejection.getRejectionType()).isEqualTo(RejectionType.PROCESSING_ERROR);
}
use of io.camunda.zeebe.protocol.record.Record in project zeebe by camunda.
the class MappingIncidentTest method shouldResolveIncidentForInputMappingFailure.
@Test
public void shouldResolveIncidentForInputMappingFailure() {
// given
ENGINE.deployment().withXmlResource(PROCESS_INPUT_MAPPING).deploy();
final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId("process").create();
final Record<ProcessInstanceRecordValue> failureEvent = RecordingExporter.processInstanceRecords().withElementId("failingTask").withIntent(ProcessInstanceIntent.ELEMENT_ACTIVATING).withProcessInstanceKey(processInstanceKey).getFirst();
final Record<IncidentRecordValue> incidentEvent = RecordingExporter.incidentRecords().withIntent(IncidentIntent.CREATED).withProcessInstanceKey(processInstanceKey).getFirst();
// when
ENGINE.variables().ofScope(failureEvent.getValue().getFlowScopeKey()).withDocument(VARIABLES).update();
final Record<IncidentRecordValue> incidentResolvedEvent = ENGINE.incident().ofInstance(processInstanceKey).withKey(incidentEvent.getKey()).resolve();
// then
final Record<ProcessInstanceRecordValue> followUpEvent = RecordingExporter.processInstanceRecords().withElementId("failingTask").withIntent(ProcessInstanceIntent.ELEMENT_ACTIVATED).withProcessInstanceKey(processInstanceKey).getFirst();
final Record incidentResolveCommand = RecordingExporter.incidentRecords().withIntent(RESOLVE).withRecordKey(incidentEvent.getKey()).getFirst();
assertThat(incidentResolvedEvent.getKey()).isEqualTo(incidentEvent.getKey());
assertThat(incidentResolveCommand.getPosition()).isEqualTo(followUpEvent.getSourceRecordPosition());
assertThat(incidentResolveCommand.getPosition()).isEqualTo(incidentResolvedEvent.getSourceRecordPosition());
Assertions.assertThat(incidentResolvedEvent.getValue()).hasErrorType(ErrorType.IO_MAPPING_ERROR).hasBpmnProcessId("process").hasProcessInstanceKey(processInstanceKey).hasElementId("failingTask").hasElementInstanceKey(failureEvent.getKey()).hasVariableScopeKey(failureEvent.getKey());
assertThat(incidentEvent.getValue().getErrorMessage()).contains("no variable found for name 'foo'");
}
use of io.camunda.zeebe.protocol.record.Record in project zeebe by camunda.
the class MappingIncidentTest method shouldCreateNewIncidentAfterResolvedFirstOne.
@Test
public void shouldCreateNewIncidentAfterResolvedFirstOne() {
// given
final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process").startEvent().serviceTask("failingTask", t -> t.zeebeJobType("external").zeebeInputExpression("foo", "foo").zeebeInputExpression("bar", "bar")).done();
ENGINE.deployment().withXmlResource(modelInstance).deploy();
final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId("process").create();
final Record failureEvent = RecordingExporter.processInstanceRecords().withProcessInstanceKey(processInstanceKey).withElementId("failingTask").withIntent(ProcessInstanceIntent.ELEMENT_ACTIVATING).getFirst();
final Record<IncidentRecordValue> incidentEvent = RecordingExporter.incidentRecords().withProcessInstanceKey(processInstanceKey).withIntent(IncidentIntent.CREATED).getFirst();
assertThat(incidentEvent.getValue().getErrorMessage()).contains("no variable found for name 'foo'");
// when
ENGINE.variables().ofScope(failureEvent.getKey()).withDocument(VARIABLES).update();
final Record<IncidentRecordValue> resolvedEvent = ENGINE.incident().ofInstance(processInstanceKey).withKey(incidentEvent.getKey()).resolve();
// then
assertThat(resolvedEvent.getKey()).isEqualTo(incidentEvent.getKey());
final Record<IncidentRecordValue> secondIncidentEvent = RecordingExporter.incidentRecords().onlyEvents().withProcessInstanceKey(processInstanceKey).skipUntil(e -> e.getIntent() == RESOLVED).withIntent(IncidentIntent.CREATED).getFirst();
Assertions.assertThat(secondIncidentEvent.getValue()).hasErrorType(ErrorType.IO_MAPPING_ERROR).hasBpmnProcessId("process").hasProcessInstanceKey(processInstanceKey).hasElementId("failingTask").hasElementInstanceKey(failureEvent.getKey()).hasVariableScopeKey(failureEvent.getKey());
assertThat(secondIncidentEvent.getValue().getErrorMessage()).contains("no variable found for name 'bar'");
}
Aggregations