Search in sources :

Example 1 with RecordStream

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);
}
Also used : ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) RecordType(io.camunda.zeebe.protocol.record.RecordType) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) DefaultZeebeDbFactory(io.camunda.zeebe.engine.state.DefaultZeebeDbFactory) DeploymentIntent(io.camunda.zeebe.protocol.record.intent.DeploymentIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ValueType(io.camunda.zeebe.protocol.record.ValueType) CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) Record(io.camunda.zeebe.protocol.record.Record) MockitoAnnotations(org.mockito.MockitoAnnotations) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SynchronousLogStream(io.camunda.zeebe.logstreams.util.SynchronousLogStream) TestUtil(io.camunda.zeebe.test.util.TestUtil) ActorSchedulerRule(io.camunda.zeebe.util.sched.testing.ActorSchedulerRule) Records(io.camunda.zeebe.engine.util.Records) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) Before(org.junit.Before) TestStreams(io.camunda.zeebe.engine.util.TestStreams) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) RuleChain(org.junit.rules.RuleChain) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) RecordStream(io.camunda.zeebe.engine.util.RecordStream) TemporaryFolder(org.junit.rules.TemporaryFolder) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordStream(io.camunda.zeebe.engine.util.RecordStream) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 2 with RecordStream

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);
}
Also used : RecordStream(io.camunda.zeebe.engine.util.RecordStream) ErrorRecord(io.camunda.zeebe.protocol.impl.record.value.error.ErrorRecord) Test(org.junit.Test)

Example 3 with RecordStream

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);
}
Also used : RecordStream(io.camunda.zeebe.engine.util.RecordStream) UnifiedRecordValue(io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) ErrorRecord(io.camunda.zeebe.protocol.impl.record.value.error.ErrorRecord) Test(org.junit.Test)

Example 4 with RecordStream

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();
}
Also used : RecordStream(io.camunda.zeebe.engine.util.RecordStream) Test(org.junit.Test)

Example 5 with RecordStream

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);
}
Also used : RecordStream(io.camunda.zeebe.engine.util.RecordStream) ErrorRecord(io.camunda.zeebe.protocol.impl.record.value.error.ErrorRecord) Test(org.junit.Test)

Aggregations

RecordStream (io.camunda.zeebe.engine.util.RecordStream)12 Test (org.junit.Test)12 TypedResponseWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter)6 TypedStreamWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter)6 ErrorRecord (io.camunda.zeebe.protocol.impl.record.value.error.ErrorRecord)6 CommandResponseWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter)3 DefaultZeebeDbFactory (io.camunda.zeebe.engine.state.DefaultZeebeDbFactory)3 KeyGenerator (io.camunda.zeebe.engine.state.KeyGenerator)3 Records (io.camunda.zeebe.engine.util.Records)3 TestStreams (io.camunda.zeebe.engine.util.TestStreams)3 LoggedEvent (io.camunda.zeebe.logstreams.log.LoggedEvent)3 SynchronousLogStream (io.camunda.zeebe.logstreams.util.SynchronousLogStream)3 UnifiedRecordValue (io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue)3 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)3 Record (io.camunda.zeebe.protocol.record.Record)3 RecordType (io.camunda.zeebe.protocol.record.RecordType)3 RejectionType (io.camunda.zeebe.protocol.record.RejectionType)3 ValueType (io.camunda.zeebe.protocol.record.ValueType)3 DeploymentIntent (io.camunda.zeebe.protocol.record.intent.DeploymentIntent)3 AutoCloseableRule (io.camunda.zeebe.test.util.AutoCloseableRule)3