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);
}
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());
}
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());
}
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);
}
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);
}
Aggregations