use of io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection 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.gateway.impl.broker.response.BrokerRejection in project zeebe by zeebe-io.
the class LongPollingActivateJobsTest method shouldCancelTimerOnBrokerRejectionException.
@Test
public void shouldCancelTimerOnBrokerRejectionException() {
// given
final InflightActivateJobsRequest request = getLongPollingActivateJobsRequest();
brokerClient.registerHandler(BrokerActivateJobsRequest.class, new RequestHandler<BrokerActivateJobsRequest, BrokerResponse<?>>() {
private int count = 0;
/*
* First execution of the request (count < partitionCount) -> don't activate jobs
* Second execution of the request (count >= partitionCount) -> fail immediately
*/
@Override
public BrokerResponse<?> handle(final BrokerActivateJobsRequest request) throws Exception {
if (count >= partitionsCount) {
return new BrokerRejectionResponse<>(new BrokerRejection(Intent.UNKNOWN, 1, RejectionType.INVALID_ARGUMENT, "expected"));
}
count += 1;
return activateJobsStub.handle(request);
}
});
// when
handler.activateJobs(request);
waitUntil(request::hasScheduledTimer);
brokerClient.notifyJobsAvailable(TYPE);
Awaitility.await().until(request::isAborted);
// then
final ArgumentCaptor<Throwable> throwableCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(request.getResponseObserver(), times(1)).onError(throwableCaptor.capture());
assertThat(throwableCaptor.getValue()).isInstanceOf(BrokerRejectionException.class);
assertThat(request.hasScheduledTimer()).isFalse();
}
use of io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection in project zeebe by camunda-cloud.
the class GatewayIntegrationTest method shouldReturnRejectionWithCorrectTypeAndReason.
@Test
public void shouldReturnRejectionWithCorrectTypeAndReason() throws InterruptedException {
// given
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> errorResponse = new AtomicReference<>();
// when
client.sendRequestWithRetry(new BrokerCreateProcessInstanceRequest(), (k, r) -> {
}, error -> {
errorResponse.set(error);
latch.countDown();
});
// then
latch.await();
final var error = errorResponse.get();
assertThat(error).isInstanceOf(BrokerRejectionException.class);
final BrokerRejection rejection = ((BrokerRejectionException) error).getRejection();
assertThat(rejection.getType()).isEqualTo(RejectionType.INVALID_ARGUMENT);
assertThat(rejection.getReason()).isEqualTo("Expected at least a bpmnProcessId or a key greater than -1, but none given");
}
use of io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection in project zeebe by zeebe-io.
the class GatewayIntegrationTest method shouldReturnRejectionWithCorrectTypeAndReason.
@Test
public void shouldReturnRejectionWithCorrectTypeAndReason() throws InterruptedException {
// given
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> errorResponse = new AtomicReference<>();
// when
client.sendRequestWithRetry(new BrokerCreateProcessInstanceRequest(), (k, r) -> {
}, error -> {
errorResponse.set(error);
latch.countDown();
});
// then
latch.await();
final var error = errorResponse.get();
assertThat(error).isInstanceOf(BrokerRejectionException.class);
final BrokerRejection rejection = ((BrokerRejectionException) error).getRejection();
assertThat(rejection.getType()).isEqualTo(RejectionType.INVALID_ARGUMENT);
assertThat(rejection.getReason()).isEqualTo("Expected at least a bpmnProcessId or a key greater than -1, but none given");
}
use of io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection in project zeebe by zeebe-io.
the class BrokerClientTest method shouldReturnRejectionWithCorrectTypeAndReason.
@Test
public void shouldReturnRejectionWithCorrectTypeAndReason() {
// given
broker.jobs().registerCompleteCommand(b -> b.rejection(RejectionType.INVALID_ARGUMENT, "foo"));
// when
final var responseFuture = client.sendRequestWithRetry(new BrokerCompleteJobRequest(Protocol.encodePartitionId(Protocol.DEPLOYMENT_PARTITION, 79), DocumentValue.EMPTY_DOCUMENT));
// then
assertThatThrownBy(responseFuture::join).hasCauseInstanceOf(BrokerRejectionException.class).hasCause(new BrokerRejectionException(new BrokerRejection(JobIntent.COMPLETE, Protocol.encodePartitionId(Protocol.DEPLOYMENT_PARTITION, 79), RejectionType.INVALID_ARGUMENT, "foo")));
}
Aggregations