use of io.zeebe.logstreams.log.LoggedEvent in project zeebe by zeebe-io.
the class TypedStreamProcessorTest method shouldWriteSourceEventAndProducerOnBatch.
@Test
public void shouldWriteSourceEventAndProducerOnBatch() {
// given
final TypedStreamEnvironment env = new TypedStreamEnvironment(streams.getLogStream(STREAM_NAME), output);
final TypedStreamProcessor streamProcessor = env.newStreamProcessor().onEvent(EventType.TOPIC_EVENT, TopicState.CREATE, new BatchProcessor()).build();
final StreamProcessorControl streamProcessorControl = streams.initStreamProcessor(STREAM_NAME, STREAM_PROCESSOR_ID, () -> streamProcessor);
streamProcessorControl.start();
final long firstEventPosition = streams.newEvent(STREAM_NAME).event(createTopic("foo", 1)).write();
// when
streamProcessorControl.unblock();
final LoggedEvent writtenEvent = doRepeatedly(() -> streams.events(STREAM_NAME).filter(Events::isTopicEvent).filter(e -> Events.asTopicEvent(e).getState() == TopicState.CREATE_REJECTED).findFirst()).until(o -> o.isPresent()).get();
// then
assertThat(writtenEvent.getProducerId()).isEqualTo(STREAM_PROCESSOR_ID);
assertThat(writtenEvent.getSourceEventLogStreamPartitionId()).isEqualTo(stream.getPartitionId());
assertThat(writtenEvent.getSourceEventPosition()).isEqualTo(firstEventPosition);
}
use of io.zeebe.logstreams.log.LoggedEvent in project zeebe by zeebe-io.
the class WorkflowDeploymentCache method lookupWorkflow.
private DeployedWorkflow lookupWorkflow(long key) {
DeployedWorkflow deployedWorkflow = null;
final DirectBuffer positionWorkflowBuffer = keyToPositionWorkflowMap.get(key);
if (positionWorkflowBuffer != null) {
final long eventPosition = positionWorkflowBuffer.getLong(POSITION_OFFSET, BYTE_ORDER);
final int workflowIndex = positionWorkflowBuffer.getInt(WORKFLOW_INDEX_OFFSET, BYTE_ORDER);
final boolean found = logStreamReader.seek(eventPosition);
if (found && logStreamReader.hasNext()) {
final LoggedEvent event = logStreamReader.next();
workflowEvent.reset();
event.readValue(workflowEvent);
final WorkflowDefinition workflowDefinition = bpmn.readFromXmlBuffer(workflowEvent.getBpmnXml());
final Workflow workflow = getWorkflowAt(workflowDefinition, workflowIndex);
deployedWorkflow = new DeployedWorkflow(workflow, workflowEvent.getVersion());
}
}
return deployedWorkflow;
}
use of io.zeebe.logstreams.log.LoggedEvent in project zeebe by zeebe-io.
the class TypedStreamReaderImpl method readValue.
@Override
@SuppressWarnings({ "unchecked" })
public <T extends UnpackedObject> TypedEvent<T> readValue(long position, Class<T> eventClass) {
final boolean success = reader.seek(position);
if (!success) {
throw new RuntimeException("Could not find an event at position " + position);
}
final LoggedEvent rawEvent = reader.next();
metadata.reset();
rawEvent.readMetadata(metadata);
final UnpackedObject value = eventCache.get(eventClass);
value.reset();
rawEvent.readValue(value);
event.wrap(rawEvent, metadata, value);
return event;
}
use of io.zeebe.logstreams.log.LoggedEvent in project zeebe by zeebe-io.
the class PayloadCache method lookupPayload.
private DirectBuffer lookupPayload(long position) {
DirectBuffer payload = null;
final boolean found = logStreamReader.seek(position);
if (found && logStreamReader.hasNext()) {
final LoggedEvent event = logStreamReader.next();
workflowInstanceEvent.reset();
event.readValue(workflowInstanceEvent);
payload = workflowInstanceEvent.getPayload();
}
return payload;
}
Aggregations