Search in sources :

Example 1 with LogStreamReader

use of io.camunda.zeebe.logstreams.log.LogStreamReader in project zeebe-process-test by camunda.

the class EngineFactory method create.

public static ZeebeTestEngine create(final int port) {
    final int partitionId = 1;
    final int partitionCount = 1;
    final ControlledActorClock clock = createActorClock();
    final ActorScheduler scheduler = createAndStartActorScheduler(clock);
    final InMemoryLogStorage logStorage = new InMemoryLogStorage();
    final LogStream logStream = createLogStream(logStorage, scheduler, partitionId);
    final SubscriptionCommandSenderFactory subscriptionCommandSenderFactory = new SubscriptionCommandSenderFactory(logStream.newLogStreamRecordWriter().join(), partitionId);
    final GrpcToLogStreamGateway gateway = new GrpcToLogStreamGateway(logStream.newLogStreamRecordWriter().join(), partitionId, partitionCount, port);
    final Server grpcServer = ServerBuilder.forPort(port).addService(gateway).build();
    final GrpcResponseWriter grpcResponseWriter = new GrpcResponseWriter(gateway);
    final ZeebeDb<ZbColumnFamilies> zeebeDb = createDatabase();
    final EngineStateMonitor engineStateMonitor = new EngineStateMonitor(logStorage, logStream.newLogStreamReader().join());
    final StreamProcessor streamProcessor = createStreamProcessor(logStream, zeebeDb, scheduler, grpcResponseWriter, engineStateMonitor, partitionCount, subscriptionCommandSenderFactory);
    final LogStreamReader reader = logStream.newLogStreamReader().join();
    final RecordStreamSourceImpl recordStream = new RecordStreamSourceImpl(reader, partitionId);
    return new InMemoryEngine(grpcServer, streamProcessor, gateway, zeebeDb, logStream, scheduler, recordStream, clock, engineStateMonitor);
}
Also used : StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) Server(io.grpc.Server) LogStream(io.camunda.zeebe.logstreams.log.LogStream) ZbColumnFamilies(io.camunda.zeebe.engine.state.ZbColumnFamilies) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader)

Example 2 with LogStreamReader

use of io.camunda.zeebe.logstreams.log.LogStreamReader in project zeebe by camunda.

the class TestStreams method events.

public Stream<LoggedEvent> events(final String logName) {
    final SynchronousLogStream logStream = getLogStream(logName);
    final LogStreamReader reader = logStream.newLogStreamReader();
    closeables.manage(reader);
    reader.seekToFirstEvent();
    final Iterable<LoggedEvent> iterable = () -> reader;
    return StreamSupport.stream(iterable.spliterator(), false);
}
Also used : LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader) SynchronousLogStream(io.camunda.zeebe.logstreams.util.SynchronousLogStream) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent)

Example 3 with LogStreamReader

use of io.camunda.zeebe.logstreams.log.LogStreamReader in project zeebe by camunda.

the class LogStreamImpl method createLogStreamReader.

private LogStreamReader createLogStreamReader() {
    final LogStreamReader newReader = new LogStreamReaderImpl(logStorage.newReader());
    readers.add(newReader);
    return newReader;
}
Also used : LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader)

Example 4 with LogStreamReader

use of io.camunda.zeebe.logstreams.log.LogStreamReader in project zeebe by camunda.

the class LogStreamReaderTest method shouldNotHaveNextIfReaderIsClosed.

@Test
public void shouldNotHaveNextIfReaderIsClosed() {
    // given
    final LogStreamReader reader = logStreamRule.getLogStreamReader();
    reader.close();
    // when - then
    assertThat(reader.hasNext()).isFalse();
}
Also used : LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader) Test(org.junit.Test)

Example 5 with LogStreamReader

use of io.camunda.zeebe.logstreams.log.LogStreamReader in project zeebe by camunda.

the class LogStreamReaderTest method shouldThrowExceptionIfReaderClosedOnNext.

@Test
public void shouldThrowExceptionIfReaderClosedOnNext() {
    // given
    final LogStreamReader reader = logStreamRule.getLogStreamReader();
    reader.close();
    // when - then
    assertThatCode(reader::next).isInstanceOf(NoSuchElementException.class);
}
Also used : LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader) Test(org.junit.Test)

Aggregations

LogStreamReader (io.camunda.zeebe.logstreams.log.LogStreamReader)29 Test (org.junit.Test)18 LogStream (io.camunda.zeebe.logstreams.log.LogStream)11 Broker (io.camunda.zeebe.broker.Broker)6 LoggedEvent (io.camunda.zeebe.logstreams.log.LoggedEvent)6 SynchronousLogStream (io.camunda.zeebe.logstreams.util.SynchronousLogStream)3 UnpackedObject (io.camunda.zeebe.msgpack.UnpackedObject)3 ValueType (io.camunda.zeebe.protocol.record.ValueType)3 EnumMap (java.util.EnumMap)3 StreamProcessor (io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor)2 ZbColumnFamilies (io.camunda.zeebe.engine.state.ZbColumnFamilies)2 ActorScheduler (io.camunda.zeebe.util.sched.ActorScheduler)2 ControlledActorClock (io.camunda.zeebe.util.sched.clock.ControlledActorClock)2 Server (io.grpc.Server)2