Search in sources :

Example 1 with UnifiedRecordValue

use of io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue in project zeebe-process-test by camunda.

the class RecordStreamSourceImpl method updateWithNewRecords.

private void updateWithNewRecords() {
    synchronized (logStreamReader) {
        if (lastPosition < 0) {
            logStreamReader.seekToFirstEvent();
        } else {
            logStreamReader.seekToNextEvent(lastPosition);
        }
        while (logStreamReader.hasNext()) {
            final LoggedEvent event = logStreamReader.next();
            final CopiedRecord<UnifiedRecordValue> record = mapToRecord(event);
            records.add(record);
            lastPosition = event.getPosition();
        }
    }
}
Also used : LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) UnifiedRecordValue(io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue)

Example 2 with UnifiedRecordValue

use of io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue in project zeebe by camunda.

the class SkipFailingEventsTest method shouldWriteErrorEventWithNoMessage.

@Test
public void shouldWriteErrorEventWithNoMessage() {
    // given
    streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> {
        zeebeState = processingContext.getZeebeState();
        return TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), processingContext.getWriters()).onCommand(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ACTIVATE_ELEMENT, new TypedRecordProcessor<>() {

            @Override
            public void processRecord(final TypedRecord<UnifiedRecordValue> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) {
                throw new NullPointerException();
            }
        });
    });
    final long failingEventPosition = streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.ACTIVATE_ELEMENT).key(keyGenerator.nextKey()).write();
    // when
    waitForRecordWhichSatisfies(e -> Records.isEvent(e, ValueType.ERROR, ErrorIntent.CREATED));
    // then
    final ErrorRecord errorRecord = new RecordStream(streams.events(STREAM_NAME)).onlyErrorRecords().getFirst().getValue();
    assertThat(errorRecord.getErrorEventPosition()).isEqualTo(failingEventPosition);
    assertThat(BufferUtil.bufferAsString(errorRecord.getExceptionMessageBuffer())).isEqualTo("Without exception message.");
    assertThat(errorRecord.getProcessInstanceKey()).isEqualTo(1);
}
Also used : RecordStream(io.camunda.zeebe.engine.util.RecordStream) UnifiedRecordValue(io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) ErrorRecord(io.camunda.zeebe.protocol.impl.record.value.error.ErrorRecord) Test(org.junit.Test)

Example 3 with UnifiedRecordValue

use of io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue in project zeebe by camunda.

the class CopiedRecords method createCopiedRecord.

public static CopiedRecord createCopiedRecord(final int partitionId, final LoggedEvent rawEvent) {
    // we have to access the underlying buffer and copy the metadata and value bytes
    // otherwise next event will overwrite the event before, since UnpackedObject
    // and RecordMetadata has properties (buffers, StringProperty etc.) which only wraps the given
    // buffer instead of copying it
    final DirectBuffer contentBuffer = rawEvent.getValueBuffer();
    final byte[] metadataBytes = new byte[rawEvent.getMetadataLength()];
    contentBuffer.getBytes(rawEvent.getMetadataOffset(), metadataBytes);
    final DirectBuffer metadataBuffer = new UnsafeBuffer(metadataBytes);
    final RecordMetadata metadata = new RecordMetadata();
    metadata.wrap(metadataBuffer, 0, metadataBuffer.capacity());
    final byte[] valueBytes = new byte[rawEvent.getValueLength()];
    contentBuffer.getBytes(rawEvent.getValueOffset(), valueBytes);
    final DirectBuffer valueBuffer = new UnsafeBuffer(valueBytes);
    final UnifiedRecordValue recordValue = ReflectUtil.newInstance(EVENT_REGISTRY.get(metadata.getValueType()));
    recordValue.wrap(valueBuffer);
    return new CopiedRecord<>(recordValue, metadata, rawEvent.getKey(), partitionId, rawEvent.getPosition(), rawEvent.getSourceEventPosition(), rawEvent.getTimestamp());
}
Also used : DirectBuffer(org.agrona.DirectBuffer) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) UnifiedRecordValue(io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 4 with UnifiedRecordValue

use of io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue in project zeebe by camunda.

the class RecordValues method readRecordValue.

public UnifiedRecordValue readRecordValue(final LoggedEvent event, final ValueType valueType) {
    final UnifiedRecordValue value = eventCache.get(valueType);
    if (value != null) {
        value.reset();
        event.readValue(value);
    }
    return value;
}
Also used : UnifiedRecordValue(io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue)

Example 5 with UnifiedRecordValue

use of io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue in project zeebe by camunda.

the class ReplayStateMachine method readRecordValue.

private TypedRecord<?> readRecordValue(final LoggedEvent currentEvent) {
    final UnifiedRecordValue value = recordValues.readRecordValue(currentEvent, metadata.getValueType());
    typedEvent.wrap(currentEvent, metadata, value);
    return typedEvent;
}
Also used : UnifiedRecordValue(io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue)

Aggregations

UnifiedRecordValue (io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue)22 TypedResponseWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter)9 TypedStreamWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter)9 Test (org.junit.Test)9 SideEffectProducer (io.camunda.zeebe.engine.processing.streamprocessor.sideeffect.SideEffectProducer)6 MutableZeebeState (io.camunda.zeebe.engine.state.mutable.MutableZeebeState)6 CopiedRecord (io.camunda.zeebe.protocol.impl.record.CopiedRecord)5 RecordMetadata (io.camunda.zeebe.protocol.impl.record.RecordMetadata)5 RecordStream (io.camunda.zeebe.engine.util.RecordStream)3 ErrorRecord (io.camunda.zeebe.protocol.impl.record.value.error.ErrorRecord)3 DirectBuffer (org.agrona.DirectBuffer)3 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)3 LoggedEvent (io.camunda.zeebe.logstreams.log.LoggedEvent)2