use of io.camunda.zeebe.engine.state.KeyGenerator in project zeebe by camunda-cloud.
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 camunda-cloud.
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 zeebe-io.
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 zeebe-io.
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 MessageEventProcessors method addMessageProcessors.
public static void addMessageProcessors(final EventTriggerBehavior eventTriggerBehavior, final TypedRecordProcessors typedRecordProcessors, final MutableZeebeState zeebeState, final SubscriptionCommandSender subscriptionCommandSender, final Writers writers) {
final MutableMessageState messageState = zeebeState.getMessageState();
final MutableMessageSubscriptionState subscriptionState = zeebeState.getMessageSubscriptionState();
final MutableMessageStartEventSubscriptionState startEventSubscriptionState = zeebeState.getMessageStartEventSubscriptionState();
final MutableEventScopeInstanceState eventScopeInstanceState = zeebeState.getEventScopeInstanceState();
final KeyGenerator keyGenerator = zeebeState.getKeyGenerator();
final var processState = zeebeState.getProcessState();
typedRecordProcessors.onCommand(ValueType.MESSAGE, MessageIntent.PUBLISH, new MessagePublishProcessor(messageState, subscriptionState, startEventSubscriptionState, eventScopeInstanceState, subscriptionCommandSender, keyGenerator, writers, processState, eventTriggerBehavior)).onCommand(ValueType.MESSAGE, MessageIntent.EXPIRE, new MessageExpireProcessor(writers.state())).onCommand(ValueType.MESSAGE_SUBSCRIPTION, MessageSubscriptionIntent.CREATE, new MessageSubscriptionCreateProcessor(messageState, subscriptionState, subscriptionCommandSender, writers, keyGenerator)).onCommand(ValueType.MESSAGE_SUBSCRIPTION, MessageSubscriptionIntent.CORRELATE, new MessageSubscriptionCorrelateProcessor(messageState, subscriptionState, subscriptionCommandSender, writers)).onCommand(ValueType.MESSAGE_SUBSCRIPTION, MessageSubscriptionIntent.DELETE, new MessageSubscriptionDeleteProcessor(subscriptionState, subscriptionCommandSender, writers)).onCommand(ValueType.MESSAGE_SUBSCRIPTION, MessageSubscriptionIntent.REJECT, new MessageSubscriptionRejectProcessor(messageState, subscriptionState, subscriptionCommandSender, writers)).withListener(new MessageObserver(messageState, zeebeState.getPendingMessageSubscriptionState(), subscriptionCommandSender));
}
Aggregations