Search in sources :

Example 1 with RecordMetadata

use of io.camunda.zeebe.protocol.impl.record.RecordMetadata in project zeebe by camunda.

the class TypedEventSerializationTest method createRecordTuple.

private static Tuple<TypedRecord, CopiedRecord> createRecordTuple() {
    final RecordMetadata recordMetadata = new RecordMetadata();
    final DeploymentIntent intent = DeploymentIntent.CREATE;
    final int protocolVersion = 1;
    final ValueType valueType = ValueType.DEPLOYMENT;
    final RecordType recordType = RecordType.COMMAND;
    final String rejectionReason = "fails";
    final RejectionType rejectionType = RejectionType.INVALID_ARGUMENT;
    final int requestId = 23;
    final int requestStreamId = 1;
    recordMetadata.intent(intent).protocolVersion(protocolVersion).valueType(valueType).recordType(recordType).rejectionReason(rejectionReason).rejectionType(rejectionType).requestId(requestId).requestStreamId(requestStreamId);
    final String resourceName = "resource";
    final DirectBuffer resource = wrapString("contents");
    final String bpmnProcessId = "testProcess";
    final long processDefinitionKey = 123;
    final int processVersion = 12;
    final DeploymentRecord record = new DeploymentRecord();
    record.resources().add().setResourceName(wrapString(resourceName)).setResource(resource);
    record.processesMetadata().add().setBpmnProcessId(wrapString(bpmnProcessId)).setKey(processDefinitionKey).setResourceName(wrapString(resourceName)).setVersion(processVersion).setChecksum(wrapString("checksum"));
    final long key = 1234;
    final long position = 4321;
    final long sourcePosition = 231;
    final long timestamp = 2191L;
    final LoggedEvent loggedEvent = mock(LoggedEvent.class);
    when(loggedEvent.getPosition()).thenReturn(position);
    when(loggedEvent.getKey()).thenReturn(key);
    when(loggedEvent.getSourceEventPosition()).thenReturn(sourcePosition);
    when(loggedEvent.getTimestamp()).thenReturn(timestamp);
    final TypedEventImpl typedEvent = new TypedEventImpl(0);
    typedEvent.wrap(loggedEvent, recordMetadata, record);
    final CopiedRecord copiedRecord = new CopiedRecord<>(record, recordMetadata, key, 0, position, sourcePosition, timestamp);
    return new Tuple<>(typedEvent, copiedRecord);
}
Also used : RejectionType(io.camunda.zeebe.protocol.record.RejectionType) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) ValueType(io.camunda.zeebe.protocol.record.ValueType) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) DeploymentIntent(io.camunda.zeebe.protocol.record.intent.DeploymentIntent) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) DirectBuffer(org.agrona.DirectBuffer) RecordType(io.camunda.zeebe.protocol.record.RecordType) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) Tuple(io.camunda.zeebe.util.collection.Tuple)

Example 2 with RecordMetadata

use of io.camunda.zeebe.protocol.impl.record.RecordMetadata 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);
}
Also used : RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) Test(org.junit.Test)

Example 3 with RecordMetadata

use of io.camunda.zeebe.protocol.impl.record.RecordMetadata 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));
}
Also used : RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with RecordMetadata

use of io.camunda.zeebe.protocol.impl.record.RecordMetadata 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);
}
Also used : TimerRecord(io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) ArrayList(java.util.ArrayList) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) Test(org.junit.Test)

Example 5 with RecordMetadata

use of io.camunda.zeebe.protocol.impl.record.RecordMetadata in project zeebe by camunda.

the class BlacklistInstanceTest method shouldBlacklist.

@Test
public void shouldBlacklist() {
    // given
    final RecordMetadata metadata = new RecordMetadata();
    metadata.intent(recordIntent);
    metadata.valueType(recordValueType);
    final TypedEventImpl typedEvent = new TypedEventImpl(1);
    final LoggedEvent loggedEvent = mock(LoggedEvent.class);
    when(loggedEvent.getPosition()).thenReturn(1024L);
    typedEvent.wrap(loggedEvent, metadata, new Value());
    // when
    final MutableZeebeState zeebeState = ZEEBE_STATE_RULE.getZeebeState();
    zeebeState.getBlackListState().tryToBlacklist(typedEvent, (processInstanceKey) -> {
    });
    // then
    metadata.intent(ProcessInstanceIntent.ELEMENT_ACTIVATING);
    metadata.valueType(ValueType.PROCESS_INSTANCE);
    typedEvent.wrap(null, metadata, new Value());
    assertThat(zeebeState.getBlackListState().isOnBlacklist(typedEvent)).isEqualTo(expectedToBlacklist);
}
Also used : RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) MutableZeebeState(io.camunda.zeebe.engine.state.mutable.MutableZeebeState) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) UnifiedRecordValue(io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue) Test(org.junit.Test)

Aggregations

RecordMetadata (io.camunda.zeebe.protocol.impl.record.RecordMetadata)55 ProcessInstanceRecord (io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord)19 MockTypedRecord (io.camunda.zeebe.engine.util.MockTypedRecord)15 Test (org.junit.Test)15 LoggedEvent (io.camunda.zeebe.logstreams.log.LoggedEvent)12 JobRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)10 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)9 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 TypedEventImpl (io.camunda.zeebe.engine.processing.streamprocessor.TypedEventImpl)6 TypedResponseWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter)6 TypedStreamWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter)6 CopiedRecord (io.camunda.zeebe.protocol.impl.record.CopiedRecord)6 UnifiedRecordValue (io.camunda.zeebe.protocol.impl.record.UnifiedRecordValue)6 JobBatchRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)6 ArrayList (java.util.ArrayList)6 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)6 ProcessInstanceCreationRecord (io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceCreationRecord)5 DirectBuffer (org.agrona.DirectBuffer)5 RecordType (io.camunda.zeebe.protocol.record.RecordType)4 ValueType (io.camunda.zeebe.protocol.record.ValueType)4