Search in sources :

Example 1 with CommandResponseWriter

use of io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter in project zeebe by zeebe-io.

the class TestStreams method buildStreamProcessor.

private StreamProcessor buildStreamProcessor(final SynchronousLogStream stream, final ZeebeDbFactory zeebeDbFactory, final TypedRecordProcessorFactory factory, final boolean awaitOpening) {
    final var storage = createRuntimeFolder(stream);
    final var snapshot = storage.getParent().resolve(SNAPSHOT_FOLDER);
    final var recoveredLatch = new CountDownLatch(1);
    final var recoveredAwaiter = new StreamProcessorLifecycleAware() {

        @Override
        public void onRecovered(final ReadonlyProcessingContext context) {
            recoveredLatch.countDown();
        }
    };
    final TypedRecordProcessorFactory wrappedFactory = (ctx) -> factory.createProcessors(ctx).withListener(recoveredAwaiter);
    final ZeebeDb<?> zeebeDb;
    if (snapshotWasTaken) {
        zeebeDb = zeebeDbFactory.createDb(snapshot.toFile());
    } else {
        zeebeDb = zeebeDbFactory.createDb(storage.toFile());
    }
    final String logName = stream.getLogName();
    final StreamProcessor streamProcessor = StreamProcessor.builder().logStream(stream.getAsyncLogStream()).zeebeDb(zeebeDb).actorSchedulingService(actorScheduler).commandResponseWriter(mockCommandResponseWriter).listener(mockStreamProcessorListener).streamProcessorFactory(wrappedFactory).eventApplierFactory(eventApplierFactory).streamProcessorMode(streamProcessorMode).build();
    final var openFuture = streamProcessor.openAsync(false);
    if (awaitOpening) {
        // and recovery
        try {
            recoveredLatch.await(15, TimeUnit.SECONDS);
        } catch (final InterruptedException e) {
            Thread.interrupted();
        }
    }
    openFuture.join(15, TimeUnit.SECONDS);
    final LogContext context = logContextMap.get(logName);
    final ProcessorContext processorContext = ProcessorContext.createStreamContext(context, streamProcessor, zeebeDb, storage, snapshot);
    streamContextMap.put(logName, processorContext);
    closeables.manage(processorContext);
    return streamProcessor;
}
Also used : StreamProcessorListener(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorListener) UnpackedObject(io.camunda.zeebe.msgpack.UnpackedObject) Protocol(io.camunda.zeebe.protocol.Protocol) RecordType(io.camunda.zeebe.protocol.record.RecordType) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) LogStreamRecordWriter(io.camunda.zeebe.logstreams.log.LogStreamRecordWriter) LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) Map(java.util.Map) Path(java.nio.file.Path) StreamProcessorMode(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorMode) TypedEventRegistry(io.camunda.zeebe.engine.processing.streamprocessor.TypedEventRegistry) LogStorage(io.camunda.zeebe.logstreams.storage.LogStorage) MutableZeebeState(io.camunda.zeebe.engine.state.mutable.MutableZeebeState) EventApplier(io.camunda.zeebe.engine.state.EventApplier) Loggers(io.camunda.zeebe.util.Loggers) TypedRecordProcessorFactory(io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessorFactory) UncheckedIOException(java.io.UncheckedIOException) CountDownLatch(java.util.concurrent.CountDownLatch) TestUtil.doRepeatedly(io.camunda.zeebe.test.util.TestUtil.doRepeatedly) Stream(java.util.stream.Stream) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) EventAppliers(io.camunda.zeebe.engine.state.appliers.EventAppliers) Optional(java.util.Optional) LOG(io.camunda.zeebe.logstreams.impl.log.LogStorageAppender.LOG) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LogStreamBatchWriter(io.camunda.zeebe.logstreams.log.LogStreamBatchWriter) ValueType(io.camunda.zeebe.protocol.record.ValueType) HashMap(java.util.HashMap) Function(java.util.function.Function) ZeebeDb(io.camunda.zeebe.db.ZeebeDb) SynchronousLogStream(io.camunda.zeebe.logstreams.util.SynchronousLogStream) StreamSupport(java.util.stream.StreamSupport) NoSuchElementException(java.util.NoSuchElementException) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) FileUtil(io.camunda.zeebe.util.FileUtil) Intent(io.camunda.zeebe.protocol.record.intent.Intent) StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) Files(java.nio.file.Files) SyncLogStream(io.camunda.zeebe.logstreams.util.SyncLogStream) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ZeebeDbFactory(io.camunda.zeebe.db.ZeebeDbFactory) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ReadonlyProcessingContext(io.camunda.zeebe.engine.processing.streamprocessor.ReadonlyProcessingContext) StreamProcessorLifecycleAware(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorLifecycleAware) TemporaryFolder(org.junit.rules.TemporaryFolder) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) StreamProcessorLifecycleAware(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorLifecycleAware) StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) ReadonlyProcessingContext(io.camunda.zeebe.engine.processing.streamprocessor.ReadonlyProcessingContext) CountDownLatch(java.util.concurrent.CountDownLatch) TypedRecordProcessorFactory(io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessorFactory)

Example 2 with CommandResponseWriter

use of io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter in project zeebe by camunda.

the class StreamProcessorTest method shouldWriteResponseOnFailedEventProcessing.

@Test
public void shouldWriteResponseOnFailedEventProcessing() {
    // given
    streamProcessorRule.startTypedStreamProcessor((processors, context) -> processors.onCommand(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ACTIVATE_ELEMENT, new TypedRecordProcessor<>() {

        @Override
        public void processRecord(final long position, final TypedRecord<UnifiedRecordValue> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter, final Consumer<SideEffectProducer> sideEffect) {
            responseWriter.writeEventOnCommand(3, ProcessInstanceIntent.ELEMENT_ACTIVATING, record.getValue(), record);
            throw new RuntimeException("expected");
        }
    }));
    // when
    streamProcessorRule.writeCommand(ProcessInstanceIntent.ACTIVATE_ELEMENT, PROCESS_INSTANCE_RECORD);
    // then
    final CommandResponseWriter commandResponseWriter = streamProcessorRule.getCommandResponseWriter();
    final InOrder inOrder = inOrder(commandResponseWriter);
    // it doesn't send the staged command response
    inOrder.verify(commandResponseWriter, TIMEOUT.times(1)).key(3);
    inOrder.verify(commandResponseWriter, TIMEOUT.times(1)).intent(ProcessInstanceIntent.ELEMENT_ACTIVATING);
    inOrder.verify(commandResponseWriter, TIMEOUT.times(1)).recordType(RecordType.EVENT);
    inOrder.verify(commandResponseWriter, TIMEOUT.times(1)).valueType(ValueType.PROCESS_INSTANCE);
    // instead, it sends a rejection response because of the failure
    inOrder.verify(commandResponseWriter, TIMEOUT.times(1)).recordType(RecordType.COMMAND_REJECTION);
    inOrder.verify(commandResponseWriter, TIMEOUT.times(1)).rejectionType(RejectionType.PROCESSING_ERROR);
    inOrder.verify(commandResponseWriter, TIMEOUT.times(1)).tryWriteResponse(anyInt(), anyLong());
}
Also used : CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) InOrder(org.mockito.InOrder) Consumer(java.util.function.Consumer) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) Test(org.junit.Test)

Example 3 with CommandResponseWriter

use of io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter in project zeebe by camunda.

the class TestStreams method buildStreamProcessor.

private StreamProcessor buildStreamProcessor(final SynchronousLogStream stream, final ZeebeDbFactory zeebeDbFactory, final TypedRecordProcessorFactory factory, final boolean awaitOpening) {
    final var storage = createRuntimeFolder(stream);
    final var snapshot = storage.getParent().resolve(SNAPSHOT_FOLDER);
    final var recoveredLatch = new CountDownLatch(1);
    final var recoveredAwaiter = new StreamProcessorLifecycleAware() {

        @Override
        public void onRecovered(final ReadonlyProcessingContext context) {
            recoveredLatch.countDown();
        }
    };
    final TypedRecordProcessorFactory wrappedFactory = (ctx) -> factory.createProcessors(ctx).withListener(recoveredAwaiter);
    final ZeebeDb<?> zeebeDb;
    if (snapshotWasTaken) {
        zeebeDb = zeebeDbFactory.createDb(snapshot.toFile());
    } else {
        zeebeDb = zeebeDbFactory.createDb(storage.toFile());
    }
    final String logName = stream.getLogName();
    final StreamProcessor streamProcessor = StreamProcessor.builder().logStream(stream.getAsyncLogStream()).zeebeDb(zeebeDb).actorSchedulingService(actorScheduler).commandResponseWriter(mockCommandResponseWriter).listener(mockStreamProcessorListener).streamProcessorFactory(wrappedFactory).eventApplierFactory(eventApplierFactory).streamProcessorMode(streamProcessorMode).build();
    final var openFuture = streamProcessor.openAsync(false);
    if (awaitOpening) {
        // and recovery
        try {
            recoveredLatch.await(15, TimeUnit.SECONDS);
        } catch (final InterruptedException e) {
            Thread.interrupted();
        }
    }
    openFuture.join(15, TimeUnit.SECONDS);
    final LogContext context = logContextMap.get(logName);
    final ProcessorContext processorContext = ProcessorContext.createStreamContext(context, streamProcessor, zeebeDb, storage, snapshot);
    streamContextMap.put(logName, processorContext);
    closeables.manage(processorContext);
    return streamProcessor;
}
Also used : StreamProcessorListener(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorListener) UnpackedObject(io.camunda.zeebe.msgpack.UnpackedObject) Protocol(io.camunda.zeebe.protocol.Protocol) RecordType(io.camunda.zeebe.protocol.record.RecordType) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) LogStreamRecordWriter(io.camunda.zeebe.logstreams.log.LogStreamRecordWriter) LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) Map(java.util.Map) Path(java.nio.file.Path) StreamProcessorMode(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorMode) TypedEventRegistry(io.camunda.zeebe.engine.processing.streamprocessor.TypedEventRegistry) LogStorage(io.camunda.zeebe.logstreams.storage.LogStorage) MutableZeebeState(io.camunda.zeebe.engine.state.mutable.MutableZeebeState) EventApplier(io.camunda.zeebe.engine.state.EventApplier) Loggers(io.camunda.zeebe.util.Loggers) TypedRecordProcessorFactory(io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessorFactory) UncheckedIOException(java.io.UncheckedIOException) CountDownLatch(java.util.concurrent.CountDownLatch) TestUtil.doRepeatedly(io.camunda.zeebe.test.util.TestUtil.doRepeatedly) Stream(java.util.stream.Stream) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) EventAppliers(io.camunda.zeebe.engine.state.appliers.EventAppliers) Optional(java.util.Optional) LOG(io.camunda.zeebe.logstreams.impl.log.LogStorageAppender.LOG) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LogStreamBatchWriter(io.camunda.zeebe.logstreams.log.LogStreamBatchWriter) ValueType(io.camunda.zeebe.protocol.record.ValueType) HashMap(java.util.HashMap) Function(java.util.function.Function) ZeebeDb(io.camunda.zeebe.db.ZeebeDb) SynchronousLogStream(io.camunda.zeebe.logstreams.util.SynchronousLogStream) StreamSupport(java.util.stream.StreamSupport) NoSuchElementException(java.util.NoSuchElementException) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) FileUtil(io.camunda.zeebe.util.FileUtil) Intent(io.camunda.zeebe.protocol.record.intent.Intent) StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) Files(java.nio.file.Files) SyncLogStream(io.camunda.zeebe.logstreams.util.SyncLogStream) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ZeebeDbFactory(io.camunda.zeebe.db.ZeebeDbFactory) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ReadonlyProcessingContext(io.camunda.zeebe.engine.processing.streamprocessor.ReadonlyProcessingContext) StreamProcessorLifecycleAware(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorLifecycleAware) TemporaryFolder(org.junit.rules.TemporaryFolder) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) StreamProcessorLifecycleAware(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorLifecycleAware) StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) ReadonlyProcessingContext(io.camunda.zeebe.engine.processing.streamprocessor.ReadonlyProcessingContext) CountDownLatch(java.util.concurrent.CountDownLatch) TypedRecordProcessorFactory(io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessorFactory)

Example 4 with CommandResponseWriter

use of io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter in project zeebe by camunda-cloud.

the class TestStreams method buildStreamProcessor.

private StreamProcessor buildStreamProcessor(final SynchronousLogStream stream, final ZeebeDbFactory zeebeDbFactory, final TypedRecordProcessorFactory factory, final boolean awaitOpening) {
    final var storage = createRuntimeFolder(stream);
    final var snapshot = storage.getParent().resolve(SNAPSHOT_FOLDER);
    final var recoveredLatch = new CountDownLatch(1);
    final var recoveredAwaiter = new StreamProcessorLifecycleAware() {

        @Override
        public void onRecovered(final ReadonlyProcessingContext context) {
            recoveredLatch.countDown();
        }
    };
    final TypedRecordProcessorFactory wrappedFactory = (ctx) -> factory.createProcessors(ctx).withListener(recoveredAwaiter);
    final ZeebeDb<?> zeebeDb;
    if (snapshotWasTaken) {
        zeebeDb = zeebeDbFactory.createDb(snapshot.toFile());
    } else {
        zeebeDb = zeebeDbFactory.createDb(storage.toFile());
    }
    final String logName = stream.getLogName();
    final StreamProcessor streamProcessor = StreamProcessor.builder().logStream(stream.getAsyncLogStream()).zeebeDb(zeebeDb).actorSchedulingService(actorScheduler).commandResponseWriter(mockCommandResponseWriter).listener(mockStreamProcessorListener).streamProcessorFactory(wrappedFactory).eventApplierFactory(eventApplierFactory).streamProcessorMode(streamProcessorMode).build();
    final var openFuture = streamProcessor.openAsync(false);
    if (awaitOpening) {
        // and recovery
        try {
            recoveredLatch.await(15, TimeUnit.SECONDS);
        } catch (final InterruptedException e) {
            Thread.interrupted();
        }
    }
    openFuture.join(15, TimeUnit.SECONDS);
    final LogContext context = logContextMap.get(logName);
    final ProcessorContext processorContext = ProcessorContext.createStreamContext(context, streamProcessor, zeebeDb, storage, snapshot);
    streamContextMap.put(logName, processorContext);
    closeables.manage(processorContext);
    return streamProcessor;
}
Also used : StreamProcessorListener(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorListener) UnpackedObject(io.camunda.zeebe.msgpack.UnpackedObject) Protocol(io.camunda.zeebe.protocol.Protocol) RecordType(io.camunda.zeebe.protocol.record.RecordType) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) LogStreamRecordWriter(io.camunda.zeebe.logstreams.log.LogStreamRecordWriter) LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) Map(java.util.Map) Path(java.nio.file.Path) StreamProcessorMode(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorMode) TypedEventRegistry(io.camunda.zeebe.engine.processing.streamprocessor.TypedEventRegistry) LogStorage(io.camunda.zeebe.logstreams.storage.LogStorage) MutableZeebeState(io.camunda.zeebe.engine.state.mutable.MutableZeebeState) EventApplier(io.camunda.zeebe.engine.state.EventApplier) Loggers(io.camunda.zeebe.util.Loggers) TypedRecordProcessorFactory(io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessorFactory) UncheckedIOException(java.io.UncheckedIOException) CountDownLatch(java.util.concurrent.CountDownLatch) TestUtil.doRepeatedly(io.camunda.zeebe.test.util.TestUtil.doRepeatedly) Stream(java.util.stream.Stream) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) EventAppliers(io.camunda.zeebe.engine.state.appliers.EventAppliers) Optional(java.util.Optional) LOG(io.camunda.zeebe.logstreams.impl.log.LogStorageAppender.LOG) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LogStreamBatchWriter(io.camunda.zeebe.logstreams.log.LogStreamBatchWriter) ValueType(io.camunda.zeebe.protocol.record.ValueType) HashMap(java.util.HashMap) Function(java.util.function.Function) ZeebeDb(io.camunda.zeebe.db.ZeebeDb) SynchronousLogStream(io.camunda.zeebe.logstreams.util.SynchronousLogStream) StreamSupport(java.util.stream.StreamSupport) NoSuchElementException(java.util.NoSuchElementException) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) FileUtil(io.camunda.zeebe.util.FileUtil) Intent(io.camunda.zeebe.protocol.record.intent.Intent) StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) Files(java.nio.file.Files) SyncLogStream(io.camunda.zeebe.logstreams.util.SyncLogStream) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ZeebeDbFactory(io.camunda.zeebe.db.ZeebeDbFactory) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ReadonlyProcessingContext(io.camunda.zeebe.engine.processing.streamprocessor.ReadonlyProcessingContext) StreamProcessorLifecycleAware(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorLifecycleAware) TemporaryFolder(org.junit.rules.TemporaryFolder) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) StreamProcessorLifecycleAware(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorLifecycleAware) StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) ReadonlyProcessingContext(io.camunda.zeebe.engine.processing.streamprocessor.ReadonlyProcessingContext) CountDownLatch(java.util.concurrent.CountDownLatch) TypedRecordProcessorFactory(io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessorFactory)

Example 5 with CommandResponseWriter

use of io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter in project zeebe by zeebe-io.

the class TestStreams method buildStreamProcessor.

public StreamProcessor buildStreamProcessor(final SynchronousLogStream stream, final ZeebeDbFactory zeebeDbFactory, final TypedRecordProcessorFactory factory, final Function<LogStreamBatchWriter, TypedStreamWriter> streamWriterFactory, final boolean awaitOpening) {
    final var storage = createRuntimeFolder(stream);
    final var snapshot = storage.getParent().resolve(SNAPSHOT_FOLDER);
    final var recoveredLatch = new CountDownLatch(1);
    final var recoveredAwaiter = new StreamProcessorLifecycleAware() {

        @Override
        public void onRecovered(final ReadonlyProcessingContext context) {
            recoveredLatch.countDown();
        }
    };
    final TypedRecordProcessorFactory wrappedFactory = (ctx) -> factory.createProcessors(ctx).withListener(recoveredAwaiter);
    final ZeebeDb<?> zeebeDb;
    if (snapshotWasTaken) {
        zeebeDb = zeebeDbFactory.createDb(snapshot.toFile());
    } else {
        zeebeDb = zeebeDbFactory.createDb(storage.toFile());
    }
    final String logName = stream.getLogName();
    final var builder = StreamProcessor.builder().logStream(stream.getAsyncLogStream()).zeebeDb(zeebeDb).actorSchedulingService(actorScheduler).commandResponseWriter(mockCommandResponseWriter).listener(mockStreamProcessorListener).streamProcessorFactory(wrappedFactory).eventApplierFactory(eventApplierFactory).streamProcessorMode(streamProcessorMode);
    if (streamWriterFactory != null) {
        builder.typedStreamWriterFactory(streamWriterFactory);
    }
    final StreamProcessor streamProcessor = builder.build();
    final var openFuture = streamProcessor.openAsync(false);
    if (awaitOpening) {
        // and recovery
        try {
            recoveredLatch.await(15, TimeUnit.SECONDS);
        } catch (final InterruptedException e) {
            Thread.interrupted();
        }
    }
    openFuture.join(15, TimeUnit.SECONDS);
    final LogContext context = logContextMap.get(logName);
    final ProcessorContext processorContext = ProcessorContext.createStreamContext(context, streamProcessor, zeebeDb, storage, snapshot);
    streamContextMap.put(logName, processorContext);
    closeables.manage(processorContext);
    return streamProcessor;
}
Also used : StreamProcessorListener(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorListener) UnpackedObject(io.camunda.zeebe.msgpack.UnpackedObject) Protocol(io.camunda.zeebe.protocol.Protocol) RecordType(io.camunda.zeebe.protocol.record.RecordType) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) LogStreamRecordWriter(io.camunda.zeebe.logstreams.log.LogStreamRecordWriter) LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) Loggers(io.camunda.zeebe.engine.Loggers) Map(java.util.Map) Path(java.nio.file.Path) StreamProcessorMode(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorMode) ListLogStorage(io.camunda.zeebe.logstreams.util.ListLogStorage) TypedEventRegistry(io.camunda.zeebe.engine.processing.streamprocessor.TypedEventRegistry) LogStorage(io.camunda.zeebe.logstreams.storage.LogStorage) MutableZeebeState(io.camunda.zeebe.engine.state.mutable.MutableZeebeState) EventApplier(io.camunda.zeebe.engine.state.EventApplier) TypedRecordProcessorFactory(io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessorFactory) UncheckedIOException(java.io.UncheckedIOException) CountDownLatch(java.util.concurrent.CountDownLatch) TestUtil.doRepeatedly(io.camunda.zeebe.test.util.TestUtil.doRepeatedly) Stream(java.util.stream.Stream) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) EventAppliers(io.camunda.zeebe.engine.state.appliers.EventAppliers) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LogStreamBatchWriter(io.camunda.zeebe.logstreams.log.LogStreamBatchWriter) ValueType(io.camunda.zeebe.protocol.record.ValueType) HashMap(java.util.HashMap) Function(java.util.function.Function) ZeebeDb(io.camunda.zeebe.db.ZeebeDb) SynchronousLogStream(io.camunda.zeebe.logstreams.util.SynchronousLogStream) StreamSupport(java.util.stream.StreamSupport) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) NoSuchElementException(java.util.NoSuchElementException) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) FileUtil(io.camunda.zeebe.util.FileUtil) Intent(io.camunda.zeebe.protocol.record.intent.Intent) StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) Logger(org.slf4j.Logger) Files(java.nio.file.Files) SyncLogStream(io.camunda.zeebe.logstreams.util.SyncLogStream) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ZeebeDbFactory(io.camunda.zeebe.db.ZeebeDbFactory) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ReadonlyProcessingContext(io.camunda.zeebe.engine.processing.streamprocessor.ReadonlyProcessingContext) StreamProcessorLifecycleAware(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorLifecycleAware) TemporaryFolder(org.junit.rules.TemporaryFolder) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) StreamProcessorLifecycleAware(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorLifecycleAware) StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) ReadonlyProcessingContext(io.camunda.zeebe.engine.processing.streamprocessor.ReadonlyProcessingContext) CountDownLatch(java.util.concurrent.CountDownLatch) TypedRecordProcessorFactory(io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessorFactory)

Aggregations

CommandResponseWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter)11 Consumer (java.util.function.Consumer)11 ZeebeDb (io.camunda.zeebe.db.ZeebeDb)5 ZeebeDbFactory (io.camunda.zeebe.db.ZeebeDbFactory)5 ReadonlyProcessingContext (io.camunda.zeebe.engine.processing.streamprocessor.ReadonlyProcessingContext)5 StreamProcessor (io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor)5 StreamProcessorLifecycleAware (io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorLifecycleAware)5 StreamProcessorListener (io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorListener)5 StreamProcessorMode (io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessorMode)5 TypedEventRegistry (io.camunda.zeebe.engine.processing.streamprocessor.TypedEventRegistry)5 TypedRecordProcessorFactory (io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessorFactory)5 EventApplier (io.camunda.zeebe.engine.state.EventApplier)5 EventAppliers (io.camunda.zeebe.engine.state.appliers.EventAppliers)5 MutableZeebeState (io.camunda.zeebe.engine.state.mutable.MutableZeebeState)5 LogStreamBatchWriter (io.camunda.zeebe.logstreams.log.LogStreamBatchWriter)5 LogStreamReader (io.camunda.zeebe.logstreams.log.LogStreamReader)5 LogStreamRecordWriter (io.camunda.zeebe.logstreams.log.LogStreamRecordWriter)5 LoggedEvent (io.camunda.zeebe.logstreams.log.LoggedEvent)5 LogStorage (io.camunda.zeebe.logstreams.storage.LogStorage)5 SyncLogStream (io.camunda.zeebe.logstreams.util.SyncLogStream)5