use of io.camunda.zeebe.engine.util.RecordStream in project zeebe by camunda.
the class TypedStreamProcessorTest method shouldSkipFailingEvent.
@Test
public void shouldSkipFailingEvent() {
// given
streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> TypedRecordProcessors.processors(keyGenerator, processingContext.getWriters()).onCommand(ValueType.DEPLOYMENT, DeploymentIntent.CREATE, new ErrorProneProcessor()));
final AtomicLong requestId = new AtomicLong(0);
final AtomicInteger requestStreamId = new AtomicInteger(0);
when(mockCommandResponseWriter.tryWriteResponse(anyInt(), anyLong())).then((invocationOnMock -> {
final int streamIdArg = invocationOnMock.getArgument(0);
final long requestIdArg = invocationOnMock.getArgument(1);
requestId.set(requestIdArg);
requestStreamId.set(streamIdArg);
return true;
}));
final long failingKey = keyGenerator.nextKey();
streams.newRecord(STREAM_NAME).event(deployment("foo")).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).requestId(255L).requestStreamId(99).key(failingKey).write();
final long secondEventPosition = streams.newRecord(STREAM_NAME).event(deployment("foo2")).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).key(keyGenerator.nextKey()).write();
// when
final LoggedEvent writtenEvent = TestUtil.doRepeatedly(() -> streams.events(STREAM_NAME).filter(e -> Records.isEvent(e, ValueType.DEPLOYMENT, DeploymentIntent.CREATED)).findFirst()).until(o -> o.isPresent()).get();
// then
assertThat(writtenEvent.getKey()).isEqualTo(1);
assertThat(writtenEvent.getSourceEventPosition()).isEqualTo(secondEventPosition);
// error response
verify(mockCommandResponseWriter).tryWriteResponse(anyInt(), anyLong());
assertThat(requestId.get()).isEqualTo(255L);
assertThat(requestStreamId.get()).isEqualTo(99);
final Record<DeploymentRecord> deploymentRejection = new RecordStream(streams.events(STREAM_NAME)).onlyDeploymentRecords().onlyRejections().withIntent(DeploymentIntent.CREATE).getFirst();
assertThat(deploymentRejection.getKey()).isEqualTo(failingKey);
assertThat(deploymentRejection.getRejectionType()).isEqualTo(RejectionType.PROCESSING_ERROR);
}
use of io.camunda.zeebe.engine.util.RecordStream in project zeebe by camunda.
the class SkipFailingEventsTest method shouldWriteErrorEvent.
@Test
public void shouldWriteErrorEvent() {
// given
final ErrorProneProcessor errorProneProcessor = new ErrorProneProcessor();
streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> {
zeebeState = processingContext.getZeebeState();
return TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), processingContext.getWriters()).onCommand(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ACTIVATE_ELEMENT, errorProneProcessor);
});
final long failingEventPosition = streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.ACTIVATE_ELEMENT).key(keyGenerator.nextKey()).write();
// when
waitForRecordWhichSatisfies(e -> Records.isEvent(e, ValueType.ERROR, ErrorIntent.CREATED));
// then
assertThat(errorProneProcessor.getProcessCount()).isEqualTo(1);
final ErrorRecord errorRecord = new RecordStream(streams.events(STREAM_NAME)).onlyErrorRecords().getFirst().getValue();
assertThat(errorRecord.getErrorEventPosition()).isEqualTo(failingEventPosition);
assertThat(BufferUtil.bufferAsString(errorRecord.getExceptionMessageBuffer())).isEqualTo("expected");
assertThat(errorRecord.getProcessInstanceKey()).isEqualTo(1);
}
use of io.camunda.zeebe.engine.util.RecordStream in project zeebe by camunda.
the class SkipFailingEventsTest method shouldWriteErrorEventWithNoMessage.
@Test
public void shouldWriteErrorEventWithNoMessage() {
// given
streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> {
zeebeState = processingContext.getZeebeState();
return TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), processingContext.getWriters()).onCommand(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ACTIVATE_ELEMENT, new TypedRecordProcessor<>() {
@Override
public void processRecord(final TypedRecord<UnifiedRecordValue> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) {
throw new NullPointerException();
}
});
});
final long failingEventPosition = streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.ACTIVATE_ELEMENT).key(keyGenerator.nextKey()).write();
// when
waitForRecordWhichSatisfies(e -> Records.isEvent(e, ValueType.ERROR, ErrorIntent.CREATED));
// then
final ErrorRecord errorRecord = new RecordStream(streams.events(STREAM_NAME)).onlyErrorRecords().getFirst().getValue();
assertThat(errorRecord.getErrorEventPosition()).isEqualTo(failingEventPosition);
assertThat(BufferUtil.bufferAsString(errorRecord.getExceptionMessageBuffer())).isEqualTo("Without exception message.");
assertThat(errorRecord.getProcessInstanceKey()).isEqualTo(1);
}
use of io.camunda.zeebe.engine.util.RecordStream in project zeebe by camunda.
the class StreamProcessorInconsistentPositionTest method shouldNotStartOnInconsistentLog.
@Test
public void shouldNotStartOnInconsistentLog() {
// given
final var position = firstStreamProcessorComposite.writeCommand(ProcessInstanceIntent.ACTIVATE_ELEMENT, PROCESS_INSTANCE_RECORD);
final var secondPosition = firstStreamProcessorComposite.writeCommand(ProcessInstanceIntent.ACTIVATE_ELEMENT, PROCESS_INSTANCE_RECORD);
waitUntil(() -> new RecordStream(testStreams.events(getLogName(1))).onlyProcessInstanceRecords().withIntent(ACTIVATE_ELEMENT).count() == 2);
final var otherPosition = secondStreamProcessorComposite.writeCommand(ProcessInstanceIntent.ACTIVATE_ELEMENT, PROCESS_INSTANCE_RECORD);
final var otherSecondPosition = secondStreamProcessorComposite.writeCommand(ProcessInstanceIntent.ACTIVATE_ELEMENT, PROCESS_INSTANCE_RECORD);
waitUntil(() -> new RecordStream(testStreams.events(getLogName(2))).onlyProcessInstanceRecords().withIntent(ACTIVATE_ELEMENT).count() == 4);
assertThat(position).isEqualTo(otherPosition);
assertThat(secondPosition).isEqualTo(otherSecondPosition);
// when
final var typedRecordProcessor = mock(TypedRecordProcessor.class);
final var streamProcessor = firstStreamProcessorComposite.startTypedStreamProcessorNotAwaitOpening((processors, context) -> processors.onCommand(ValueType.PROCESS_INSTANCE, ACTIVATE_ELEMENT, typedRecordProcessor));
// then
waitUntil(streamProcessor::isFailed);
assertThat(streamProcessor.isFailed()).isTrue();
}
use of io.camunda.zeebe.engine.util.RecordStream in project zeebe by zeebe-io.
the class SkipFailingEventsTest method shouldWriteErrorEvent.
@Test
public void shouldWriteErrorEvent() {
// given
final ErrorProneProcessor errorProneProcessor = new ErrorProneProcessor();
streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> {
zeebeState = processingContext.getZeebeState();
return TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), processingContext.getWriters()).onCommand(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ACTIVATE_ELEMENT, errorProneProcessor);
});
final long failingEventPosition = streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.ACTIVATE_ELEMENT).key(keyGenerator.nextKey()).write();
// when
waitForRecordWhichSatisfies(e -> Records.isEvent(e, ValueType.ERROR, ErrorIntent.CREATED));
// then
assertThat(errorProneProcessor.getProcessCount()).isEqualTo(1);
final ErrorRecord errorRecord = new RecordStream(streams.events(STREAM_NAME)).onlyErrorRecords().getFirst().getValue();
assertThat(errorRecord.getErrorEventPosition()).isEqualTo(failingEventPosition);
assertThat(BufferUtil.bufferAsString(errorRecord.getExceptionMessageBuffer())).isEqualTo("expected");
assertThat(errorRecord.getProcessInstanceKey()).isEqualTo(1);
}
Aggregations