use of io.camunda.zeebe.protocol.record.RecordType 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);
}
use of io.camunda.zeebe.protocol.record.RecordType 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.protocol.record.RecordType 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.protocol.record.RecordType in project zeebe by zeebe-io.
the class PushDeploymentRequestHandler method writeDistributeDeployment.
private boolean writeDistributeDeployment(final LogStreamRecordWriter logStreamWriter, final long key, final UnpackedObject event) {
final RecordType recordType = RecordType.COMMAND;
final ValueType valueType = ValueType.DEPLOYMENT;
final Intent intent = DeploymentIntent.DISTRIBUTE;
logStreamWriter.reset();
recordMetadata.reset().recordType(recordType).valueType(valueType).intent(intent);
final long position = logStreamWriter.key(key).metadataWriter(recordMetadata).valueWriter(event).tryWrite();
return position > 0;
}
use of io.camunda.zeebe.protocol.record.RecordType in project zeebe by zeebe-io.
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);
}
Aggregations