Search in sources :

Example 1 with CopiedRecord

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

the class TypedEventSerializationTest method createRecordTuple.

private static Tuple<TypedRecord, CopiedRecord> createRecordTuple() {
    final RecordMetadata recordMetadata = new RecordMetadata();
    final DeploymentIntent intent = DeploymentIntent.CREATE;
    final int protocolVersion = 1;
    final ValueType valueType = ValueType.DEPLOYMENT;
    final RecordType recordType = RecordType.COMMAND;
    final String rejectionReason = "fails";
    final RejectionType rejectionType = RejectionType.INVALID_ARGUMENT;
    final int requestId = 23;
    final int requestStreamId = 1;
    recordMetadata.intent(intent).protocolVersion(protocolVersion).valueType(valueType).recordType(recordType).rejectionReason(rejectionReason).rejectionType(rejectionType).requestId(requestId).requestStreamId(requestStreamId);
    final String resourceName = "resource";
    final DirectBuffer resource = wrapString("contents");
    final String bpmnProcessId = "testProcess";
    final long processDefinitionKey = 123;
    final int processVersion = 12;
    final DeploymentRecord record = new DeploymentRecord();
    record.resources().add().setResourceName(wrapString(resourceName)).setResource(resource);
    record.processesMetadata().add().setBpmnProcessId(wrapString(bpmnProcessId)).setKey(processDefinitionKey).setResourceName(wrapString(resourceName)).setVersion(processVersion).setChecksum(wrapString("checksum"));
    final long key = 1234;
    final long position = 4321;
    final long sourcePosition = 231;
    final long timestamp = 2191L;
    final LoggedEvent loggedEvent = mock(LoggedEvent.class);
    when(loggedEvent.getPosition()).thenReturn(position);
    when(loggedEvent.getKey()).thenReturn(key);
    when(loggedEvent.getSourceEventPosition()).thenReturn(sourcePosition);
    when(loggedEvent.getTimestamp()).thenReturn(timestamp);
    final TypedEventImpl typedEvent = new TypedEventImpl(0);
    typedEvent.wrap(loggedEvent, recordMetadata, record);
    final CopiedRecord copiedRecord = new CopiedRecord<>(record, recordMetadata, key, 0, position, sourcePosition, timestamp);
    return new Tuple<>(typedEvent, copiedRecord);
}
Also used : RejectionType(io.camunda.zeebe.protocol.record.RejectionType) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) ValueType(io.camunda.zeebe.protocol.record.ValueType) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) DeploymentIntent(io.camunda.zeebe.protocol.record.intent.DeploymentIntent) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) DirectBuffer(org.agrona.DirectBuffer) RecordType(io.camunda.zeebe.protocol.record.RecordType) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) Tuple(io.camunda.zeebe.util.collection.Tuple)

Example 2 with CopiedRecord

use of io.camunda.zeebe.protocol.impl.record.CopiedRecord 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 3 with CopiedRecord

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

the class RecordStreamSourceImpl method mapToRecord.

private CopiedRecord<UnifiedRecordValue> mapToRecord(final LoggedEvent event) {
    final RecordMetadata metadata = new RecordMetadata();
    event.readMetadata(metadata);
    final UnifiedRecordValue value;
    try {
        value = TypedEventRegistry.EVENT_REGISTRY.get(metadata.getValueType()).getDeclaredConstructor().newInstance();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
    event.readValue(value);
    return new CopiedRecord<>(value, metadata, event.getKey(), partitionId, event.getPosition(), event.getSourceEventPosition(), event.getTimestamp());
}
Also used : RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) UnifiedRecordValue(io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue)

Example 4 with CopiedRecord

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

the class TypedEventSerializationTest method shouldCreateSameJson.

@Test
public void shouldCreateSameJson() {
    // given
    final Tuple<TypedRecord, CopiedRecord> records = createRecordTuple();
    final String expectedJson = records.getRight().toJson();
    // when
    final String actualJson = records.getLeft().toJson();
    // then
    JsonUtil.assertEquality(actualJson, expectedJson);
}
Also used : CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) Test(org.junit.Test)

Example 5 with CopiedRecord

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

the class TypedEventSerializationTest method createRecordTuple.

private static Tuple<TypedRecord, CopiedRecord> createRecordTuple() {
    final RecordMetadata recordMetadata = new RecordMetadata();
    final DeploymentIntent intent = DeploymentIntent.CREATE;
    final int protocolVersion = 1;
    final ValueType valueType = ValueType.DEPLOYMENT;
    final RecordType recordType = RecordType.COMMAND;
    final String rejectionReason = "fails";
    final RejectionType rejectionType = RejectionType.INVALID_ARGUMENT;
    final int requestId = 23;
    final int requestStreamId = 1;
    recordMetadata.intent(intent).protocolVersion(protocolVersion).valueType(valueType).recordType(recordType).rejectionReason(rejectionReason).rejectionType(rejectionType).requestId(requestId).requestStreamId(requestStreamId);
    final String resourceName = "resource";
    final DirectBuffer resource = wrapString("contents");
    final String bpmnProcessId = "testProcess";
    final long processDefinitionKey = 123;
    final int processVersion = 12;
    final DeploymentRecord record = new DeploymentRecord();
    record.resources().add().setResourceName(wrapString(resourceName)).setResource(resource);
    record.processesMetadata().add().setBpmnProcessId(wrapString(bpmnProcessId)).setKey(processDefinitionKey).setResourceName(wrapString(resourceName)).setVersion(processVersion).setChecksum(wrapString("checksum"));
    final long key = 1234;
    final long position = 4321;
    final long sourcePosition = 231;
    final long timestamp = 2191L;
    final LoggedEvent loggedEvent = mock(LoggedEvent.class);
    when(loggedEvent.getPosition()).thenReturn(position);
    when(loggedEvent.getKey()).thenReturn(key);
    when(loggedEvent.getSourceEventPosition()).thenReturn(sourcePosition);
    when(loggedEvent.getTimestamp()).thenReturn(timestamp);
    final TypedEventImpl typedEvent = new TypedEventImpl(0);
    typedEvent.wrap(loggedEvent, recordMetadata, record);
    final CopiedRecord copiedRecord = new CopiedRecord<>(record, recordMetadata, key, 0, position, sourcePosition, timestamp);
    return new Tuple<>(typedEvent, copiedRecord);
}
Also used : RejectionType(io.camunda.zeebe.protocol.record.RejectionType) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) ValueType(io.camunda.zeebe.protocol.record.ValueType) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) DeploymentIntent(io.camunda.zeebe.protocol.record.intent.DeploymentIntent) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) DirectBuffer(org.agrona.DirectBuffer) RecordType(io.camunda.zeebe.protocol.record.RecordType) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) Tuple(io.camunda.zeebe.util.collection.Tuple)

Aggregations

CopiedRecord (io.camunda.zeebe.protocol.impl.record.CopiedRecord)11 RecordMetadata (io.camunda.zeebe.protocol.impl.record.RecordMetadata)8 BufferUtil.wrapString (io.camunda.zeebe.util.buffer.BufferUtil.wrapString)6 DirectBuffer (org.agrona.DirectBuffer)6 UnifiedRecordValue (io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue)5 LoggedEvent (io.camunda.zeebe.logstreams.log.LoggedEvent)3 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)3 RecordType (io.camunda.zeebe.protocol.record.RecordType)3 RejectionType (io.camunda.zeebe.protocol.record.RejectionType)3 ValueType (io.camunda.zeebe.protocol.record.ValueType)3 DeploymentIntent (io.camunda.zeebe.protocol.record.intent.DeploymentIntent)3 Tuple (io.camunda.zeebe.util.collection.Tuple)3 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)3 Test (org.junit.Test)3