Search in sources :

Example 1 with Events

use of io.zeebe.broker.topic.Events 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)

Aggregations

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 LoggedEvent (io.zeebe.logstreams.log.LoggedEvent)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 Test (org.junit.Test)1 RuleChain (org.junit.rules.RuleChain)1 TemporaryFolder (org.junit.rules.TemporaryFolder)1 Mock (org.mockito.Mock)1