Search in sources :

Example 1 with Record

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;
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) ManagedChannel(io.grpc.ManagedChannel) AbstractRecord(io.camunda.zeebe.protocol.jackson.record.AbstractRecord) Record(io.camunda.zeebe.protocol.record.Record) RecordResponse(io.camunda.zeebe.process.test.engine.protocol.EngineControlOuterClass.RecordResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EngineControlBlockingStub(io.camunda.zeebe.process.test.engine.protocol.EngineControlGrpc.EngineControlBlockingStub) GetRecordsRequest(io.camunda.zeebe.process.test.engine.protocol.EngineControlOuterClass.GetRecordsRequest)

Example 2 with Record

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;
}
Also used : JobRecord(io.zeebe.exporter.proto.Schema.JobRecord) Record(io.camunda.zeebe.protocol.record.Record)

Example 3 with 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);
}
Also used : ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) RecordType(io.camunda.zeebe.protocol.record.RecordType) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) DefaultZeebeDbFactory(io.camunda.zeebe.engine.state.DefaultZeebeDbFactory) DeploymentIntent(io.camunda.zeebe.protocol.record.intent.DeploymentIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ValueType(io.camunda.zeebe.protocol.record.ValueType) CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) Record(io.camunda.zeebe.protocol.record.Record) MockitoAnnotations(org.mockito.MockitoAnnotations) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SynchronousLogStream(io.camunda.zeebe.logstreams.util.SynchronousLogStream) TestUtil(io.camunda.zeebe.test.util.TestUtil) ActorSchedulerRule(io.camunda.zeebe.util.sched.testing.ActorSchedulerRule) Records(io.camunda.zeebe.engine.util.Records) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) Before(org.junit.Before) TestStreams(io.camunda.zeebe.engine.util.TestStreams) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) RuleChain(org.junit.rules.RuleChain) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) RecordStream(io.camunda.zeebe.engine.util.RecordStream) TemporaryFolder(org.junit.rules.TemporaryFolder) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordStream(io.camunda.zeebe.engine.util.RecordStream) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 4 with Record

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'");
}
Also used : ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) IncidentRecordValue(io.camunda.zeebe.protocol.record.value.IncidentRecordValue) Record(io.camunda.zeebe.protocol.record.Record) Test(org.junit.Test)

Example 5 with Record

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'");
}
Also used : 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) HashMap(java.util.HashMap) Record(io.camunda.zeebe.protocol.record.Record) Map(java.util.Map) EngineRule(io.camunda.zeebe.engine.util.EngineRule) RESOLVED(io.camunda.zeebe.protocol.record.intent.IncidentIntent.RESOLVED) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) CREATED(io.camunda.zeebe.protocol.record.intent.IncidentIntent.CREATED) ClassRule(org.junit.ClassRule) ELEMENT_COMPLETED(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent.ELEMENT_COMPLETED) 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) RESOLVE(io.camunda.zeebe.protocol.record.intent.IncidentIntent.RESOLVE) 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) Maps(io.camunda.zeebe.test.util.collection.Maps) Record(io.camunda.zeebe.protocol.record.Record) IncidentRecordValue(io.camunda.zeebe.protocol.record.value.IncidentRecordValue) 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