use of io.camunda.zeebe.engine.state.KeyGenerator 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.state.KeyGenerator in project zeebe by camunda.
the class TypedStreamProcessorTest method shouldWriteSourceEventAndProducerOnBatch.
@Test
public void shouldWriteSourceEventAndProducerOnBatch() {
// given
streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> TypedRecordProcessors.processors(keyGenerator, processingContext.getWriters()).onCommand(ValueType.DEPLOYMENT, DeploymentIntent.CREATE, new BatchProcessor()));
final long firstEventPosition = streams.newRecord(STREAM_NAME).event(deployment("foo")).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).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.getSourceEventPosition()).isEqualTo(firstEventPosition);
}
use of io.camunda.zeebe.engine.state.KeyGenerator in project zeebe by camunda.
the class ProcessEventProcessors method addProcessInstanceCreationStreamProcessors.
private static void addProcessInstanceCreationStreamProcessors(final TypedRecordProcessors typedRecordProcessors, final MutableZeebeState zeebeState, final Writers writers, final VariableBehavior variableBehavior) {
final MutableElementInstanceState elementInstanceState = zeebeState.getElementInstanceState();
final KeyGenerator keyGenerator = zeebeState.getKeyGenerator();
final CreateProcessInstanceProcessor createProcessor = new CreateProcessInstanceProcessor(zeebeState.getProcessState(), keyGenerator, writers, variableBehavior);
typedRecordProcessors.onCommand(ValueType.PROCESS_INSTANCE_CREATION, ProcessInstanceCreationIntent.CREATE, createProcessor);
typedRecordProcessors.onCommand(ValueType.PROCESS_INSTANCE_CREATION, ProcessInstanceCreationIntent.CREATE_WITH_AWAITING_RESULT, new CreateProcessInstanceWithResultProcessor(createProcessor, elementInstanceState));
}
use of io.camunda.zeebe.engine.state.KeyGenerator in project zeebe by camunda.
the class ProcessStateTest method creatingProcessRecord.
public static ProcessRecord creatingProcessRecord(final MutableZeebeState zeebeState, final String processId, final int version) {
final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(processId).startEvent().serviceTask("test", task -> task.zeebeJobType("type")).endEvent().done();
final ProcessRecord processRecord = new ProcessRecord();
final String resourceName = "process.bpmn";
final var resource = wrapString(Bpmn.convertToString(modelInstance));
final var checksum = wrapString("checksum");
final KeyGenerator keyGenerator = zeebeState.getKeyGenerator();
final long key = keyGenerator.nextKey();
processRecord.setResourceName(wrapString(resourceName)).setResource(resource).setBpmnProcessId(BufferUtil.wrapString(processId)).setVersion(version).setKey(key).setResourceName(resourceName).setChecksum(checksum);
return processRecord;
}
use of io.camunda.zeebe.engine.state.KeyGenerator in project zeebe by zeebe-io.
the class ProcessStateTest method creatingDeploymentRecord.
public static DeploymentRecord creatingDeploymentRecord(final MutableZeebeState zeebeState, final String processId, final int version) {
final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(processId).startEvent().serviceTask("test", task -> {
task.zeebeJobType("type");
}).endEvent().done();
final DeploymentRecord deploymentRecord = new DeploymentRecord();
final String resourceName = "process.bpmn";
final var resource = wrapString(Bpmn.convertToString(modelInstance));
final var checksum = wrapString("checksum");
deploymentRecord.resources().add().setResourceName(wrapString(resourceName)).setResource(resource);
final KeyGenerator keyGenerator = zeebeState.getKeyGenerator();
final long key = keyGenerator.nextKey();
deploymentRecord.processesMetadata().add().setBpmnProcessId(BufferUtil.wrapString(processId)).setVersion(version).setKey(key).setResourceName(resourceName).setChecksum(checksum);
return deploymentRecord;
}
Aggregations