Search in sources :

Example 1 with TimerRecord

use of io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord in project zeebe by camunda.

the class SkipFailingEventsTest method shouldNotBlacklistInstanceAndIgnoreTimerStartEvents.

@Test
public void shouldNotBlacklistInstanceAndIgnoreTimerStartEvents() {
    // given
    when(commandResponseWriter.tryWriteResponse(anyInt(), anyLong())).thenReturn(true);
    final List<Long> processedInstances = new ArrayList<>();
    final TypedRecordProcessor<DeploymentRecord> errorProneProcessor = new TypedRecordProcessor<>() {

        @Override
        public void processRecord(final TypedRecord<DeploymentRecord> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) {
            if (record.getKey() == 0) {
                throw new RuntimeException("expected");
            }
            processedInstances.add(TimerInstance.NO_ELEMENT_INSTANCE);
            streamWriter.appendFollowUpEvent(record.getKey(), TimerIntent.CREATED, Records.timer(TimerInstance.NO_ELEMENT_INSTANCE));
        }
    };
    final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().timerWithDuration("PT1S").endEvent().done();
    final DeploymentRecord deploymentRecord = new DeploymentRecord();
    deploymentRecord.resources().add().setResourceName("process.bpmn").setResource(Bpmn.convertToString(process).getBytes());
    streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> {
        zeebeState = processingContext.getZeebeState();
        return TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), processingContext.getWriters()).onCommand(ValueType.DEPLOYMENT, DeploymentIntent.CREATE, errorProneProcessor);
    });
    streams.newRecord(STREAM_NAME).event(deploymentRecord).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).key(0).write();
    streams.newRecord(STREAM_NAME).event(deploymentRecord).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).key(1).write();
    // when
    waitForRecordWhichSatisfies(e -> Records.isEvent(e, ValueType.TIMER, TimerIntent.CREATED));
    // then
    final RecordMetadata metadata = new RecordMetadata();
    metadata.valueType(ValueType.TIMER);
    final MockTypedRecord<TimerRecord> mockTypedRecord = new MockTypedRecord<>(0, metadata, Records.timer(TimerInstance.NO_ELEMENT_INSTANCE));
    Assertions.assertThat(zeebeState.getBlackListState().isOnBlacklist(mockTypedRecord)).isFalse();
    assertThat(processedInstances).containsExactly(TimerInstance.NO_ELEMENT_INSTANCE);
}
Also used : TimerRecord(io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) ArrayList(java.util.ArrayList) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) Test(org.junit.Test)

Example 2 with TimerRecord

use of io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord in project zeebe by camunda.

the class CancelTimerProcessor method processRecord.

@Override
public void processRecord(final TypedRecord<TimerRecord> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) {
    final TimerRecord timer = record.getValue();
    final TimerInstance timerInstance = timerInstanceState.get(timer.getElementInstanceKey(), record.getKey());
    if (timerInstance == null) {
        rejectionWriter.appendRejection(record, RejectionType.NOT_FOUND, String.format(NO_TIMER_FOUND_MESSAGE, record.getKey()));
    } else {
        stateWriter.appendFollowUpEvent(record.getKey(), TimerIntent.CANCELED, timer);
    }
}
Also used : TimerRecord(io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord) TimerInstance(io.camunda.zeebe.engine.state.instance.TimerInstance)

Example 3 with TimerRecord

use of io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord in project zeebe by camunda-cloud.

the class CancelTimerProcessor method processRecord.

@Override
public void processRecord(final TypedRecord<TimerRecord> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) {
    final TimerRecord timer = record.getValue();
    final TimerInstance timerInstance = timerInstanceState.get(timer.getElementInstanceKey(), record.getKey());
    if (timerInstance == null) {
        rejectionWriter.appendRejection(record, RejectionType.NOT_FOUND, String.format(NO_TIMER_FOUND_MESSAGE, record.getKey()));
    } else {
        stateWriter.appendFollowUpEvent(record.getKey(), TimerIntent.CANCELED, timer);
    }
}
Also used : TimerRecord(io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord) TimerInstance(io.camunda.zeebe.engine.state.instance.TimerInstance)

Example 4 with TimerRecord

use of io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord in project zeebe by zeebe-io.

the class SkipFailingEventsTest method shouldNotBlacklistInstanceAndIgnoreTimerStartEvents.

@Test
public void shouldNotBlacklistInstanceAndIgnoreTimerStartEvents() {
    // given
    when(commandResponseWriter.tryWriteResponse(anyInt(), anyLong())).thenReturn(true);
    final List<Long> processedInstances = new ArrayList<>();
    final TypedRecordProcessor<DeploymentRecord> errorProneProcessor = new TypedRecordProcessor<>() {

        @Override
        public void processRecord(final TypedRecord<DeploymentRecord> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) {
            if (record.getKey() == 0) {
                throw new RuntimeException("expected");
            }
            processedInstances.add(TimerInstance.NO_ELEMENT_INSTANCE);
            streamWriter.appendFollowUpEvent(record.getKey(), TimerIntent.CREATED, Records.timer(TimerInstance.NO_ELEMENT_INSTANCE));
        }
    };
    final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().timerWithDuration("PT1S").endEvent().done();
    final DeploymentRecord deploymentRecord = new DeploymentRecord();
    deploymentRecord.resources().add().setResourceName("process.bpmn").setResource(Bpmn.convertToString(process).getBytes());
    streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> {
        zeebeState = processingContext.getZeebeState();
        return TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), processingContext.getWriters()).onCommand(ValueType.DEPLOYMENT, DeploymentIntent.CREATE, errorProneProcessor);
    });
    streams.newRecord(STREAM_NAME).event(deploymentRecord).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).key(0).write();
    streams.newRecord(STREAM_NAME).event(deploymentRecord).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).key(1).write();
    // when
    waitForRecordWhichSatisfies(e -> Records.isEvent(e, ValueType.TIMER, TimerIntent.CREATED));
    // then
    final RecordMetadata metadata = new RecordMetadata();
    metadata.valueType(ValueType.TIMER);
    final MockTypedRecord<TimerRecord> mockTypedRecord = new MockTypedRecord<>(0, metadata, Records.timer(TimerInstance.NO_ELEMENT_INSTANCE));
    Assertions.assertThat(zeebeState.getBlackListState().isOnBlacklist(mockTypedRecord)).isFalse();
    assertThat(processedInstances).containsExactly(TimerInstance.NO_ELEMENT_INSTANCE);
}
Also used : TimerRecord(io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) ArrayList(java.util.ArrayList) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) Test(org.junit.Test)

Example 5 with TimerRecord

use of io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord in project zeebe by zeebe-io.

the class CancelTimerProcessor method processRecord.

@Override
public void processRecord(final TypedRecord<TimerRecord> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) {
    final TimerRecord timer = record.getValue();
    final TimerInstance timerInstance = timerInstanceState.get(timer.getElementInstanceKey(), record.getKey());
    if (timerInstance == null) {
        rejectionWriter.appendRejection(record, RejectionType.NOT_FOUND, String.format(NO_TIMER_FOUND_MESSAGE, record.getKey()));
    } else {
        stateWriter.appendFollowUpEvent(record.getKey(), TimerIntent.CANCELED, timer);
    }
}
Also used : TimerRecord(io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord) TimerInstance(io.camunda.zeebe.engine.state.instance.TimerInstance)

Aggregations

TimerRecord (io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord)9 TypedResponseWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter)3 TypedStreamWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter)3 TimerInstance (io.camunda.zeebe.engine.state.instance.TimerInstance)3 MockTypedRecord (io.camunda.zeebe.engine.util.MockTypedRecord)3 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)3 RecordMetadata (io.camunda.zeebe.protocol.impl.record.RecordMetadata)3 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)3 ArrayList (java.util.ArrayList)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Test (org.junit.Test)3 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)3