Search in sources :

Example 1 with BrokerRejection

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);
}
Also used : BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) Protocol(io.camunda.zeebe.protocol.Protocol) Arrays(java.util.Arrays) BrokerRejectionResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejectionResponse) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ActivatedJob(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob) Status(io.grpc.Status) BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) Parameterized(org.junit.runners.Parameterized) Intent(io.camunda.zeebe.protocol.record.intent.Intent) RequestHandler(io.camunda.zeebe.gateway.api.util.StubbedBrokerClient.RequestHandler) Iterator(java.util.Iterator) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) JsonUtil(io.camunda.zeebe.test.util.JsonUtil) Test(org.junit.Test) StatusRuntimeException(io.grpc.StatusRuntimeException) List(java.util.List) ActivateJobsResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord) BrokerRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest) BufferUtil(io.camunda.zeebe.util.buffer.BufferUtil) BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) Iterator(java.util.Iterator) BrokerRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) Test(org.junit.Test)

Example 2 with BrokerRejection

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();
}
Also used : BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) InflightActivateJobsRequest(io.camunda.zeebe.gateway.impl.job.InflightActivateJobsRequest) BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) StatusException(io.grpc.StatusException) Test(org.junit.Test)

Example 3 with BrokerRejection

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");
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) Test(org.junit.Test)

Example 4 with BrokerRejection

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");
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) Test(org.junit.Test)

Example 5 with BrokerRejection

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")));
}
Also used : BrokerCompleteJobRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCompleteJobRequest) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) Test(org.junit.Test)

Aggregations

BrokerRejection (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection)12 Test (org.junit.Test)12 BrokerRejectionException (io.camunda.zeebe.gateway.cmd.BrokerRejectionException)9 BrokerActivateJobsRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest)6 BrokerResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse)6 GatewayTest (io.camunda.zeebe.gateway.api.util.GatewayTest)3 RequestHandler (io.camunda.zeebe.gateway.api.util.StubbedBrokerClient.RequestHandler)3 BrokerCompleteJobRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerCompleteJobRequest)3 BrokerCreateProcessInstanceRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest)3 BrokerRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest)3 BrokerRejectionResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejectionResponse)3 GatewayCfg (io.camunda.zeebe.gateway.impl.configuration.GatewayCfg)3 InflightActivateJobsRequest (io.camunda.zeebe.gateway.impl.job.InflightActivateJobsRequest)3 ActivateJobsRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest)3 ActivateJobsResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse)3 ActivatedJob (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob)3 Protocol (io.camunda.zeebe.protocol.Protocol)3 JobBatchRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)3 RejectionType (io.camunda.zeebe.protocol.record.RejectionType)3 Intent (io.camunda.zeebe.protocol.record.intent.Intent)3