public IncidentRecord createWorkflowInstanceIncident() { final IncidentRecord expectedRecord = new IncidentRecord(); expectedRecord.setElementInstanceKey(1234); expectedRecord.setBpmnProcessId(wrapString("process")); expectedRecord.setElementId(wrapString("process")); expectedRecord.setWorkflowInstanceKey(4321); expectedRecord.setErrorMessage("Error because of error"); expectedRecord.setErrorType(ErrorType.EXTRACT_VALUE_ERROR); return expectedRecord; }
private IncidentRecordValue ofIncidentRecord(final LoggedEvent event) { final IncidentRecord record = new IncidentRecord(); event.readValue(record); return new IncidentRecordValueImpl( objectMapper, record.getErrorType().name(), asString(record.getErrorMessage()), asString(record.getBpmnProcessId()), asString(record.getElementId()), record.getWorkflowInstanceKey(), record.getElementInstanceKey(), record.getJobKey()); }
@Override protected IncidentRecord toResponseDto(DirectBuffer buffer) { final IncidentRecord responseDto = new IncidentRecord(); responseDto.wrap(buffer); return responseDto; } }
public IncidentRecord initFromWorkflowInstanceFailure( long key, WorkflowInstanceRecord workflowInstanceEvent) { setElementInstanceKey(key); setBpmnProcessId(workflowInstanceEvent.getBpmnProcessId()); setWorkflowInstanceKey(workflowInstanceEvent.getWorkflowInstanceKey()); setElementId(workflowInstanceEvent.getElementId()); return this; } }
public void assertIncident( final IncidentRecord expectedRecord, final IncidentRecord storedRecord) { assertThat(expectedRecord.getJobKey()).isEqualTo(storedRecord.getJobKey()); assertThat(expectedRecord.getElementInstanceKey()) .isEqualTo(storedRecord.getElementInstanceKey()); assertThat(expectedRecord.getBpmnProcessId()).isEqualTo(storedRecord.getBpmnProcessId()); assertThat(expectedRecord.getElementId()).isEqualTo(storedRecord.getElementId()); assertThat(expectedRecord.getErrorMessage()).isEqualTo(storedRecord.getErrorMessage()); assertThat(expectedRecord.getErrorType()).isEqualTo(storedRecord.getErrorType()); } }
@Test public void shouldRemoveIncidentFromStateOnResolved() { // given final IncidentState incidentState = streamProcessorRule.getZeebeState().getIncidentState(); final IncidentRecord incidentRecord = new IncidentRecord(); incidentRecord.setElementInstanceKey(2); incidentState.createIncident(1, incidentRecord); // when envRule.writeCommand(1, IncidentIntent.RESOLVE, incidentRecord); // then streamProcessorRule.awaitIncidentInState(IncidentIntent.RESOLVED); final IncidentRecord persistedIncident = incidentState.getIncidentRecord(1); assertThat(persistedIncident).isNull(); } }
public IncidentRecord createJobIncident() { final IncidentRecord expectedRecord = new IncidentRecord(); expectedRecord.setJobKey(1234); expectedRecord.setErrorMessage("Error because of error"); expectedRecord.setErrorType(ErrorType.EXTRACT_VALUE_ERROR); return expectedRecord; }
public boolean rejectIncidentCreation( IncidentRecord incidentEvent, CommandControl<IncidentRecord> commandControl) { final IncidentState incidentState = zeebeState.getIncidentState(); final boolean isJobIncident = incidentState.isJobIncident(incidentEvent); if (isJobIncident) { return rejectJobIncident(incidentEvent.getJobKey(), commandControl); } else { return rejectWorkflowInstanceIncident(incidentEvent.getElementInstanceKey(), commandControl); } }
@Test public void shouldNotCreateIncidentIfNoFailedJob() { // given final IncidentRecord incidentRecord = new IncidentRecord(); incidentRecord.setJobKey(1); // when envRule.writeCommand(IncidentIntent.CREATE, incidentRecord); // trigger incident creation // then streamProcessorRule.awaitIncidentRejection(IncidentIntent.CREATE); final List<TypedRecord<IncidentRecord>> incidentEvents = envRule.events().onlyIncidentRecords().collect(Collectors.toList()); assertThat(incidentEvents) .extracting(r -> r.getMetadata()) .extracting(m -> m.getRecordType(), m -> m.getIntent()) .containsExactly( tuple(RecordType.COMMAND, IncidentIntent.CREATE), tuple(RecordType.COMMAND_REJECTION, IncidentIntent.CREATE)); }
private void initEventTypeMap() { recordsByType.put(ValueType.DEPLOYMENT, new DeploymentRecord()); recordsByType.put(ValueType.JOB, new JobRecord()); recordsByType.put(ValueType.WORKFLOW_INSTANCE, new WorkflowInstanceRecord()); recordsByType.put(ValueType.MESSAGE, new MessageRecord()); recordsByType.put(ValueType.JOB_BATCH, new JobBatchRecord()); recordsByType.put(ValueType.INCIDENT, new IncidentRecord()); }
private void attemptToContinueWorkflowProcessing( TypedResponseWriter responseWriter, TypedStreamWriter streamWriter, Consumer<SideEffectProducer> sideEffect, IncidentRecord incidentRecord) { final long elementInstanceKey = incidentRecord.getElementInstanceKey(); final IndexedRecord failedRecord = zeebeState.getWorkflowState().getElementInstanceState().getFailedRecord(elementInstanceKey); if (failedRecord != null) { typedRecord.wrap(failedRecord); queue.clear(); queue.add(responseWriter::flush); stepProcessor.processRecord(typedRecord, responseWriter, streamWriter, queue::add); sideEffect.accept(queue); } }
public void assertIncident( final IncidentRecord expectedRecord, final IncidentRecord storedRecord) { assertThat(expectedRecord.getJobKey()).isEqualTo(storedRecord.getJobKey()); assertThat(expectedRecord.getElementInstanceKey()) .isEqualTo(storedRecord.getElementInstanceKey()); assertThat(expectedRecord.getBpmnProcessId()).isEqualTo(storedRecord.getBpmnProcessId()); assertThat(expectedRecord.getElementId()).isEqualTo(storedRecord.getElementId()); assertThat(expectedRecord.getErrorMessage()).isEqualTo(storedRecord.getErrorMessage()); assertThat(expectedRecord.getErrorType()).isEqualTo(storedRecord.getErrorType()); } }
@Test public void shouldRemoveIncidentFromStateOnResolved() { // given final IncidentState incidentState = streamProcessorRule.getZeebeState().getIncidentState(); final IncidentRecord incidentRecord = new IncidentRecord(); incidentRecord.setElementInstanceKey(2); incidentState.createIncident(1, incidentRecord); // when envRule.writeCommand(1, IncidentIntent.RESOLVE, incidentRecord); // then streamProcessorRule.awaitIncidentInState(IncidentIntent.RESOLVED); final IncidentRecord persistedIncident = incidentState.getIncidentRecord(1); assertThat(persistedIncident).isNull(); } }
public IncidentRecord createJobIncident() { final IncidentRecord expectedRecord = new IncidentRecord(); expectedRecord.setJobKey(1234); expectedRecord.setErrorMessage("Error because of error"); expectedRecord.setErrorType(ErrorType.EXTRACT_VALUE_ERROR); return expectedRecord; }
public boolean rejectIncidentCreation( IncidentRecord incidentEvent, CommandControl<IncidentRecord> commandControl) { final IncidentState incidentState = zeebeState.getIncidentState(); final boolean isJobIncident = incidentState.isJobIncident(incidentEvent); if (isJobIncident) { return rejectJobIncident(incidentEvent.getJobKey(), commandControl); } else { return rejectWorkflowInstanceIncident(incidentEvent.getElementInstanceKey(), commandControl); } }
@Test public void shouldNotCreateIncidentIfNoFailedJob() { // given final IncidentRecord incidentRecord = new IncidentRecord(); incidentRecord.setJobKey(1); // when envRule.writeCommand(IncidentIntent.CREATE, incidentRecord); // trigger incident creation // then streamProcessorRule.awaitIncidentRejection(IncidentIntent.CREATE); final List<TypedRecord<IncidentRecord>> incidentEvents = envRule.events().onlyIncidentRecords().collect(Collectors.toList()); assertThat(incidentEvents) .extracting(r -> r.getMetadata()) .extracting(m -> m.getRecordType(), m -> m.getIntent()) .containsExactly( tuple(RecordType.COMMAND, IncidentIntent.CREATE), tuple(RecordType.COMMAND_REJECTION, IncidentIntent.CREATE)); }
private void initEventTypeMap() { recordsByType.put(ValueType.DEPLOYMENT, new DeploymentRecord()); recordsByType.put(ValueType.JOB, new JobRecord()); recordsByType.put(ValueType.WORKFLOW_INSTANCE, new WorkflowInstanceRecord()); recordsByType.put(ValueType.MESSAGE, new MessageRecord()); recordsByType.put(ValueType.JOB_BATCH, new JobBatchRecord()); recordsByType.put(ValueType.INCIDENT, new IncidentRecord()); }
private void attemptToContinueWorkflowProcessing( TypedResponseWriter responseWriter, TypedStreamWriter streamWriter, Consumer<SideEffectProducer> sideEffect, IncidentRecord incidentRecord) { final long elementInstanceKey = incidentRecord.getElementInstanceKey(); final IndexedRecord failedRecord = zeebeState.getWorkflowState().getElementInstanceState().getFailedRecord(elementInstanceKey); if (failedRecord != null) { typedRecord.wrap(failedRecord); queue.clear(); queue.add(responseWriter::flush); stepProcessor.processRecord(typedRecord, responseWriter, streamWriter, queue::add); sideEffect.accept(queue); } }
public IncidentRecord createWorkflowInstanceIncident() { final IncidentRecord expectedRecord = new IncidentRecord(); expectedRecord.setElementInstanceKey(1234); expectedRecord.setBpmnProcessId(wrapString("process")); expectedRecord.setElementId(wrapString("process")); expectedRecord.setWorkflowInstanceKey(4321); expectedRecord.setErrorMessage("Error because of error"); expectedRecord.setErrorType(ErrorType.EXTRACT_VALUE_ERROR); return expectedRecord; }
private IncidentRecordValue ofIncidentRecord(final LoggedEvent event) { final IncidentRecord record = new IncidentRecord(); event.readValue(record); return new IncidentRecordValueImpl( objectMapper, record.getErrorType().name(), asString(record.getErrorMessage()), asString(record.getBpmnProcessId()), asString(record.getElementId()), record.getWorkflowInstanceKey(), record.getElementInstanceKey(), record.getJobKey(), record.getVariableScopeKey()); }