Search in sources :

Example 1 with LoggedEvent

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);
}
Also used : LoggedEvent(io.zeebe.logstreams.log.LoggedEvent) TopicEvent(io.zeebe.broker.system.log.TopicEvent) ActorSchedulerRule(io.zeebe.util.sched.testing.ActorSchedulerRule) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerOutput(io.zeebe.transport.ServerOutput) Test(org.junit.Test) LogStream(io.zeebe.logstreams.log.LogStream) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) TestStreams(io.zeebe.broker.util.TestStreams) RuleChain(org.junit.rules.RuleChain) TopicState(io.zeebe.broker.system.log.TopicState) MockitoAnnotations(org.mockito.MockitoAnnotations) Rule(org.junit.Rule) BufferUtil(io.zeebe.util.buffer.BufferUtil) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) EventType(io.zeebe.protocol.clientapi.EventType) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) Events(io.zeebe.broker.topic.Events) AutoCloseableRule(io.zeebe.test.util.AutoCloseableRule) LoggedEvent(io.zeebe.logstreams.log.LoggedEvent) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) Test(org.junit.Test)

Example 2 with LoggedEvent

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;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) LoggedEvent(io.zeebe.logstreams.log.LoggedEvent) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) Workflow(io.zeebe.model.bpmn.instance.Workflow)

Example 3 with LoggedEvent

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;
}
Also used : LoggedEvent(io.zeebe.logstreams.log.LoggedEvent) UnpackedObject(io.zeebe.msgpack.UnpackedObject)

Example 4 with LoggedEvent

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;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) LoggedEvent(io.zeebe.logstreams.log.LoggedEvent)

Aggregations

LoggedEvent (io.zeebe.logstreams.log.LoggedEvent)4 DirectBuffer (org.agrona.DirectBuffer)2 TopicEvent (io.zeebe.broker.system.log.TopicEvent)1 TopicState (io.zeebe.broker.system.log.TopicState)1 Events (io.zeebe.broker.topic.Events)1 StreamProcessorControl (io.zeebe.broker.topic.StreamProcessorControl)1 TestStreams (io.zeebe.broker.util.TestStreams)1 LogStream (io.zeebe.logstreams.log.LogStream)1 Workflow (io.zeebe.model.bpmn.instance.Workflow)1 WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)1 UnpackedObject (io.zeebe.msgpack.UnpackedObject)1 EventType (io.zeebe.protocol.clientapi.EventType)1 AutoCloseableRule (io.zeebe.test.util.AutoCloseableRule)1 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)1 ServerOutput (io.zeebe.transport.ServerOutput)1 BufferUtil (io.zeebe.util.buffer.BufferUtil)1 ActorSchedulerRule (io.zeebe.util.sched.testing.ActorSchedulerRule)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1