use of io.camunda.zeebe.protocol.record.RejectionType in project zeebe by camunda.
the class JobBatchActivateProcessor method rejectCommand.
private void rejectCommand(final TypedRecord<JobBatchRecord> record) {
final RejectionType rejectionType;
final String rejectionReason;
final JobBatchRecord value = record.getValue();
final var format = "Expected to activate job batch with %s to be %s, but it was %s";
if (value.getMaxJobsToActivate() < 1) {
rejectionType = RejectionType.INVALID_ARGUMENT;
rejectionReason = String.format(format, "max jobs to activate", "greater than zero", String.format("'%d'", value.getMaxJobsToActivate()));
} else if (value.getTimeout() < 1) {
rejectionType = RejectionType.INVALID_ARGUMENT;
rejectionReason = String.format(format, "timeout", "greater than zero", String.format("'%d'", value.getTimeout()));
} else if (value.getTypeBuffer().capacity() < 1) {
rejectionType = RejectionType.INVALID_ARGUMENT;
rejectionReason = String.format(format, "type", "present", "blank");
} else {
throw new IllegalStateException("Expected to reject an invalid activate job batch command, but it appears to be valid");
}
rejectionWriter.appendRejection(record, rejectionType, rejectionReason);
responseWriter.writeRejectionOnCommand(record, rejectionType, rejectionReason);
}
use of io.camunda.zeebe.protocol.record.RejectionType 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.RejectionType in project zeebe by zeebe-io.
the class JobBatchActivateProcessor method rejectCommand.
private void rejectCommand(final TypedRecord<JobBatchRecord> record) {
final RejectionType rejectionType;
final String rejectionReason;
final JobBatchRecord value = record.getValue();
final var format = "Expected to activate job batch with %s to be %s, but it was %s";
if (value.getMaxJobsToActivate() < 1) {
rejectionType = RejectionType.INVALID_ARGUMENT;
rejectionReason = String.format(format, "max jobs to activate", "greater than zero", String.format("'%d'", value.getMaxJobsToActivate()));
} else if (value.getTimeout() < 1) {
rejectionType = RejectionType.INVALID_ARGUMENT;
rejectionReason = String.format(format, "timeout", "greater than zero", String.format("'%d'", value.getTimeout()));
} else if (value.getTypeBuffer().capacity() < 1) {
rejectionType = RejectionType.INVALID_ARGUMENT;
rejectionReason = String.format(format, "type", "present", "blank");
} else {
throw new IllegalStateException("Expected to reject an invalid activate job batch command, but it appears to be valid");
}
rejectionWriter.appendRejection(record, rejectionType, rejectionReason);
responseWriter.writeRejectionOnCommand(record, rejectionType, rejectionReason);
}
use of io.camunda.zeebe.protocol.record.RejectionType in project zeebe by zeebe-io.
the class ActivateJobsTest method shouldSendRejectionWithoutRetrying.
@Test
public void shouldSendRejectionWithoutRetrying() {
// given
final RejectionType rejectionType = RejectionType.INVALID_ARGUMENT;
final AtomicInteger callCounter = new AtomicInteger();
brokerClient.registerHandler(BrokerActivateJobsRequest.class, (RequestHandler<BrokerRequest<?>, BrokerResponse<?>>) request -> {
callCounter.incrementAndGet();
return new BrokerRejectionResponse<>(new BrokerRejection(Intent.UNKNOWN, 1, rejectionType, "expected"));
});
final ActivateJobsRequest request = ActivateJobsRequest.newBuilder().setType("").setMaxJobsToActivate(1).build();
// when/then
assertThatThrownBy(() -> {
final Iterator<ActivateJobsResponse> responseIterator = client.activateJobs(request);
responseIterator.hasNext();
}).isInstanceOf(StatusRuntimeException.class).extracting(t -> ((StatusRuntimeException) t).getStatus().getCode()).isEqualTo(Status.INVALID_ARGUMENT.getCode());
assertThat(callCounter).hasValue(1);
}
use of io.camunda.zeebe.protocol.record.RejectionType 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