Search in sources :

Example 11 with KeyGenerator

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;
}
Also used : BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) ProcessRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator)

Example 12 with KeyGenerator

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));
}
Also used : MutableElementInstanceState(io.camunda.zeebe.engine.state.mutable.MutableElementInstanceState) CreateProcessInstanceProcessor(io.camunda.zeebe.engine.processing.processinstance.CreateProcessInstanceProcessor) CreateProcessInstanceWithResultProcessor(io.camunda.zeebe.engine.processing.processinstance.CreateProcessInstanceWithResultProcessor) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator)

Example 13 with KeyGenerator

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);
}
Also used : ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) RecordType(io.camunda.zeebe.protocol.record.RecordType) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) DefaultZeebeDbFactory(io.camunda.zeebe.engine.state.DefaultZeebeDbFactory) DeploymentIntent(io.camunda.zeebe.protocol.record.intent.DeploymentIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ValueType(io.camunda.zeebe.protocol.record.ValueType) CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) Record(io.camunda.zeebe.protocol.record.Record) MockitoAnnotations(org.mockito.MockitoAnnotations) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SynchronousLogStream(io.camunda.zeebe.logstreams.util.SynchronousLogStream) TestUtil(io.camunda.zeebe.test.util.TestUtil) ActorSchedulerRule(io.camunda.zeebe.util.sched.testing.ActorSchedulerRule) Records(io.camunda.zeebe.engine.util.Records) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) Before(org.junit.Before) TestStreams(io.camunda.zeebe.engine.util.TestStreams) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) RuleChain(org.junit.rules.RuleChain) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) RecordStream(io.camunda.zeebe.engine.util.RecordStream) TemporaryFolder(org.junit.rules.TemporaryFolder) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordStream(io.camunda.zeebe.engine.util.RecordStream) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 14 with KeyGenerator

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;
}
Also used : BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) ProcessRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator)

Example 15 with KeyGenerator

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));
}
Also used : MutableEventScopeInstanceState(io.camunda.zeebe.engine.state.mutable.MutableEventScopeInstanceState) MutableMessageSubscriptionState(io.camunda.zeebe.engine.state.mutable.MutableMessageSubscriptionState) MutableMessageState(io.camunda.zeebe.engine.state.mutable.MutableMessageState) MutableMessageStartEventSubscriptionState(io.camunda.zeebe.engine.state.mutable.MutableMessageStartEventSubscriptionState) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator)

Aggregations

KeyGenerator (io.camunda.zeebe.engine.state.KeyGenerator)18 BufferUtil.wrapString (io.camunda.zeebe.util.buffer.BufferUtil.wrapString)12 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)9 CommandResponseWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter)6 TypedResponseWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter)6 TypedStreamWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter)6 DefaultZeebeDbFactory (io.camunda.zeebe.engine.state.DefaultZeebeDbFactory)6 RecordStream (io.camunda.zeebe.engine.util.RecordStream)6 Records (io.camunda.zeebe.engine.util.Records)6 TestStreams (io.camunda.zeebe.engine.util.TestStreams)6 LoggedEvent (io.camunda.zeebe.logstreams.log.LoggedEvent)6 SynchronousLogStream (io.camunda.zeebe.logstreams.util.SynchronousLogStream)6 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)6 Record (io.camunda.zeebe.protocol.record.Record)6 RecordType (io.camunda.zeebe.protocol.record.RecordType)6 RejectionType (io.camunda.zeebe.protocol.record.RejectionType)6 ValueType (io.camunda.zeebe.protocol.record.ValueType)6 DeploymentIntent (io.camunda.zeebe.protocol.record.intent.DeploymentIntent)6 AutoCloseableRule (io.camunda.zeebe.test.util.AutoCloseableRule)6 TestUtil (io.camunda.zeebe.test.util.TestUtil)6