Search in sources :

Example 1 with BrokerCreateProcessInstanceRequest

use of io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest in project zeebe by camunda.

the class BrokerClientTest method shouldReturnErrorOnReadResponseFailure.

@Test
public void shouldReturnErrorOnReadResponseFailure() {
    // given
    registerCreateWfCommand();
    final BrokerCreateProcessInstanceRequest request = new BrokerCreateProcessInstanceRequest() {

        @Override
        protected ProcessInstanceCreationRecord toResponseDto(final DirectBuffer buffer) {
            throw new RuntimeException("Catch Me");
        }
    };
    // then
    assertThatThrownBy(() -> client.sendRequestWithRetry(request).join()).hasCauseInstanceOf(ClientResponseException.class).hasMessageContaining("Catch Me");
}
Also used : DirectBuffer(org.agrona.DirectBuffer) ClientResponseException(io.camunda.zeebe.gateway.cmd.ClientResponseException) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) Test(org.junit.Test)

Example 2 with BrokerCreateProcessInstanceRequest

use of io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest in project zeebe by camunda.

the class BrokerClientTest method shouldReturnErrorOnRequestFailure.

@Test
public void shouldReturnErrorOnRequestFailure() {
    // given
    broker.onExecuteCommandRequest(ValueType.PROCESS_INSTANCE_CREATION, ProcessInstanceCreationIntent.CREATE).respondWithError().errorCode(ErrorCode.INTERNAL_ERROR).errorData("test").register();
    assertThatThrownBy(() -> client.sendRequestWithRetry(new BrokerCreateProcessInstanceRequest()).join()).hasCauseInstanceOf(BrokerErrorException.class).hasCause(new BrokerErrorException(new BrokerError(ErrorCode.INTERNAL_ERROR, "test")));
    // then
    final List<ExecuteCommandRequest> receivedCommandRequests = broker.getReceivedCommandRequests();
    assertThat(receivedCommandRequests).hasSize(1);
    receivedCommandRequests.forEach(request -> {
        assertThat(request.valueType()).isEqualTo(ValueType.PROCESS_INSTANCE_CREATION);
        assertThat(request.intent()).isEqualTo(ProcessInstanceCreationIntent.CREATE);
    });
}
Also used : ExecuteCommandRequest(io.camunda.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) BrokerErrorException(io.camunda.zeebe.gateway.cmd.BrokerErrorException) BrokerError(io.camunda.zeebe.gateway.impl.broker.response.BrokerError) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) Test(org.junit.Test)

Example 3 with BrokerCreateProcessInstanceRequest

use of io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest in project zeebe by camunda.

the class BrokerClientTest method shouldTimeoutIfPartitionLeaderMismatchResponse.

@Test
public void shouldTimeoutIfPartitionLeaderMismatchResponse() {
    // given
    broker.onExecuteCommandRequest(ValueType.PROCESS_INSTANCE_CREATION, ProcessInstanceCreationIntent.CREATE).respondWithError().errorCode(ErrorCode.PARTITION_LEADER_MISMATCH).errorData("").register();
    // when
    final var future = client.sendRequestWithRetry(new BrokerCreateProcessInstanceRequest());
    // then
    // when the partition is repeatedly not found, the client loops
    // over refreshing the topology and making a request that fails and so on. The timeout
    // kicks in at any point in that loop, so we cannot assert the exact error message any more
    // specifically. It is also possible that Atomix times out before hand if we calculated a very
    // small time out for the request, e.g. < 50ms, so we also cannot assert the value of the
    // timeout
    assertThatThrownBy(future::join).hasCauseInstanceOf(TimeoutException.class);
}
Also used : BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) Test(org.junit.Test)

Example 4 with BrokerCreateProcessInstanceRequest

use of io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest in project zeebe by camunda.

the class ClusteringRule method createProcessInstanceOnPartition.

public long createProcessInstanceOnPartition(final int partitionId, final String bpmnProcessId) {
    final BrokerCreateProcessInstanceRequest request = new BrokerCreateProcessInstanceRequest().setBpmnProcessId(bpmnProcessId);
    request.setPartitionId(partitionId);
    final BrokerResponse<ProcessInstanceCreationRecord> response = gateway.getBrokerClient().sendRequestWithRetry(request).join();
    if (response.isResponse()) {
        return response.getResponse().getProcessInstanceKey();
    } else {
        throw new RuntimeException("Failed to create process instance for bpmn process id " + bpmnProcessId + " on partition with id " + partitionId + ": " + response);
    }
}
Also used : ProcessInstanceCreationRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceCreationRecord) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest)

Example 5 with BrokerCreateProcessInstanceRequest

use of io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest in project zeebe by zeebe-io.

the class BrokerClientTest method shouldNotTimeoutIfPartitionLeaderMismatchResponseWhenRetryDisabled.

@Test
public void shouldNotTimeoutIfPartitionLeaderMismatchResponseWhenRetryDisabled() {
    // given
    broker.onExecuteCommandRequest(ValueType.PROCESS_INSTANCE_CREATION, ProcessInstanceCreationIntent.CREATE).respondWithError().errorCode(ErrorCode.PARTITION_LEADER_MISMATCH).errorData("").register();
    // when
    final var future = client.sendRequest(new BrokerCreateProcessInstanceRequest());
    // then
    assertThatThrownBy(future::join).hasCause(new BrokerErrorException(new BrokerError(ErrorCode.PARTITION_LEADER_MISMATCH, "")));
}
Also used : BrokerErrorException(io.camunda.zeebe.gateway.cmd.BrokerErrorException) BrokerError(io.camunda.zeebe.gateway.impl.broker.response.BrokerError) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) Test(org.junit.Test)

Aggregations

BrokerCreateProcessInstanceRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest)24 Test (org.junit.Test)18 BrokerErrorException (io.camunda.zeebe.gateway.cmd.BrokerErrorException)6 BrokerError (io.camunda.zeebe.gateway.impl.broker.response.BrokerError)6 ProcessInstanceCreationRecord (io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceCreationRecord)6 GatewayTest (io.camunda.zeebe.gateway.api.util.GatewayTest)3 BrokerRejectionException (io.camunda.zeebe.gateway.cmd.BrokerRejectionException)3 ClientResponseException (io.camunda.zeebe.gateway.cmd.ClientResponseException)3 BrokerRejection (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection)3 CreateProcessInstanceRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CreateProcessInstanceRequest)3 CreateProcessInstanceResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CreateProcessInstanceResponse)3 ExecuteCommandRequest (io.camunda.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 DirectBuffer (org.agrona.DirectBuffer)3