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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations