use of io.camunda.zeebe.engine.util.MockTypedRecord in project zeebe by camunda.
the class SkipFailingEventsTest method shouldBlacklistInstance.
@Test
public void shouldBlacklistInstance() {
// given
final DumpProcessor dumpProcessor = spy(new DumpProcessor());
final ErrorProneProcessor processor = 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, processor).onCommand(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.COMPLETE_ELEMENT, dumpProcessor);
});
streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.ACTIVATE_ELEMENT).key(keyGenerator.nextKey()).write();
streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.COMPLETE_ELEMENT).key(keyGenerator.nextKey()).write();
// other instance
streams.newRecord(STREAM_NAME).event(Records.processInstance(2)).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.COMPLETE_ELEMENT).key(keyGenerator.nextKey()).write();
// when
waitForRecordWhichSatisfies(e -> Records.isEvent(e, ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_COMPLETED));
// then
assertThat(processor.getProcessCount()).isEqualTo(1);
final RecordMetadata metadata = new RecordMetadata();
metadata.valueType(ValueType.PROCESS_INSTANCE);
final MockTypedRecord<ProcessInstanceRecord> mockTypedRecord = new MockTypedRecord<>(0, metadata, PROCESS_INSTANCE_RECORD);
Assertions.assertThat(zeebeState.getBlackListState().isOnBlacklist(mockTypedRecord)).isTrue();
verify(dumpProcessor, times(1)).processRecord(any(), any(), any(), any());
assertThat(dumpProcessor.processedInstances).containsExactly(2L);
}
use of io.camunda.zeebe.engine.util.MockTypedRecord in project zeebe by camunda.
the class SkipFailingEventsTest method shouldBlacklistInstanceOnReplay.
@Test
public void shouldBlacklistInstanceOnReplay() throws Exception {
// given
when(commandResponseWriter.tryWriteResponse(anyInt(), anyLong())).thenReturn(true);
final long failedPos = streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.ACTIVATE_ELEMENT).key(keyGenerator.nextKey()).write();
streams.newRecord(STREAM_NAME).event(Records.error((int) PROCESS_INSTANCE_RECORD.getProcessInstanceKey(), failedPos)).recordType(RecordType.EVENT).sourceRecordPosition(failedPos).intent(ErrorIntent.CREATED).key(keyGenerator.nextKey()).write();
final CountDownLatch latch = new CountDownLatch(1);
streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> {
zeebeState = processingContext.getZeebeState();
return TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), processingContext.getWriters()).withListener(new StreamProcessorLifecycleAware() {
@Override
public void onRecovered(final ReadonlyProcessingContext ctx) {
latch.countDown();
}
}).onCommand(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ACTIVATE_ELEMENT, new DumpProcessor());
});
// when
latch.await(2000, TimeUnit.MILLISECONDS);
// then
final RecordMetadata metadata = new RecordMetadata();
metadata.valueType(ValueType.PROCESS_INSTANCE);
final MockTypedRecord<ProcessInstanceRecord> mockTypedRecord = new MockTypedRecord<>(0, metadata, PROCESS_INSTANCE_RECORD);
waitUntil(() -> zeebeState.getBlackListState().isOnBlacklist(mockTypedRecord));
}
use of io.camunda.zeebe.engine.util.MockTypedRecord 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);
}
use of io.camunda.zeebe.engine.util.MockTypedRecord in project zeebe by zeebe-io.
the class SkipFailingEventsTest method shouldBlacklistInstance.
@Test
public void shouldBlacklistInstance() {
// given
final DumpProcessor dumpProcessor = spy(new DumpProcessor());
final ErrorProneProcessor processor = 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, processor).onCommand(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.COMPLETE_ELEMENT, dumpProcessor);
});
streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.ACTIVATE_ELEMENT).key(keyGenerator.nextKey()).write();
streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.COMPLETE_ELEMENT).key(keyGenerator.nextKey()).write();
// other instance
streams.newRecord(STREAM_NAME).event(Records.processInstance(2)).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.COMPLETE_ELEMENT).key(keyGenerator.nextKey()).write();
// when
waitForRecordWhichSatisfies(e -> Records.isEvent(e, ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_COMPLETED));
// then
assertThat(processor.getProcessCount()).isEqualTo(1);
final RecordMetadata metadata = new RecordMetadata();
metadata.valueType(ValueType.PROCESS_INSTANCE);
final MockTypedRecord<ProcessInstanceRecord> mockTypedRecord = new MockTypedRecord<>(0, metadata, PROCESS_INSTANCE_RECORD);
Assertions.assertThat(zeebeState.getBlackListState().isOnBlacklist(mockTypedRecord)).isTrue();
verify(dumpProcessor, times(1)).processRecord(any(), any(), any(), any());
assertThat(dumpProcessor.processedInstances).containsExactly(2L);
}
use of io.camunda.zeebe.engine.util.MockTypedRecord in project zeebe by zeebe-io.
the class SkipFailingEventsTest method shouldBlacklistInstanceOnReplay.
@Test
public void shouldBlacklistInstanceOnReplay() throws Exception {
// given
when(commandResponseWriter.tryWriteResponse(anyInt(), anyLong())).thenReturn(true);
final long failedPos = streams.newRecord(STREAM_NAME).event(PROCESS_INSTANCE_RECORD).recordType(RecordType.COMMAND).intent(ProcessInstanceIntent.ACTIVATE_ELEMENT).key(keyGenerator.nextKey()).write();
streams.newRecord(STREAM_NAME).event(Records.error((int) PROCESS_INSTANCE_RECORD.getProcessInstanceKey(), failedPos)).recordType(RecordType.EVENT).sourceRecordPosition(failedPos).intent(ErrorIntent.CREATED).key(keyGenerator.nextKey()).write();
final CountDownLatch latch = new CountDownLatch(1);
streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> {
zeebeState = processingContext.getZeebeState();
return TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), processingContext.getWriters()).withListener(new StreamProcessorLifecycleAware() {
@Override
public void onRecovered(final ReadonlyProcessingContext ctx) {
latch.countDown();
}
}).onCommand(ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ACTIVATE_ELEMENT, new DumpProcessor());
});
// when
latch.await(2000, TimeUnit.MILLISECONDS);
// then
final RecordMetadata metadata = new RecordMetadata();
metadata.valueType(ValueType.PROCESS_INSTANCE);
final MockTypedRecord<ProcessInstanceRecord> mockTypedRecord = new MockTypedRecord<>(0, metadata, PROCESS_INSTANCE_RECORD);
waitUntil(() -> zeebeState.getBlackListState().isOnBlacklist(mockTypedRecord));
}
Aggregations