use of io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest in project zeebe by camunda.
the class ActivateJobsTest method shouldMapRequestAndResponse.
@Test
public void shouldMapRequestAndResponse() {
// given
final ActivateJobsStub stub = new ActivateJobsStub();
stub.registerWith(brokerClient);
final String jobType = "testJob";
final String worker = "testWorker";
final int maxJobsToActivate = 13;
final Duration timeout = Duration.ofMinutes(12);
final List<String> fetchVariables = Arrays.asList("foo", "bar", "baz");
final ActivateJobsRequest request = ActivateJobsRequest.newBuilder().setType(jobType).setWorker(worker).setMaxJobsToActivate(maxJobsToActivate).setTimeout(timeout.toMillis()).addAllFetchVariable(fetchVariables).build();
stub.addAvailableJobs(jobType, maxJobsToActivate);
// when
final Iterator<ActivateJobsResponse> responses = client.activateJobs(request);
// then
assertThat(responses.hasNext()).isTrue();
final ActivateJobsResponse response = responses.next();
assertThat(response.getJobsCount()).isEqualTo(maxJobsToActivate);
for (int i = 0; i < maxJobsToActivate; i++) {
final ActivatedJob job = response.getJobs(i);
assertThat(job.getKey()).isEqualTo(Protocol.encodePartitionId(Protocol.START_PARTITION_ID, i));
assertThat(job.getType()).isEqualTo(jobType);
assertThat(job.getWorker()).isEqualTo(worker);
assertThat(job.getRetries()).isEqualTo(stub.getRetries());
assertThat(job.getDeadline()).isEqualTo(stub.getDeadline());
assertThat(job.getProcessInstanceKey()).isEqualTo(stub.getProcessInstanceKey());
assertThat(job.getBpmnProcessId()).isEqualTo(stub.getBpmnProcessId());
assertThat(job.getProcessDefinitionVersion()).isEqualTo(stub.getProcessDefinitionVersion());
assertThat(job.getProcessDefinitionKey()).isEqualTo(stub.getProcessDefinitionKey());
assertThat(job.getElementId()).isEqualTo(stub.getElementId());
assertThat(job.getElementInstanceKey()).isEqualTo(stub.getElementInstanceKey());
JsonUtil.assertEquality(job.getCustomHeaders(), stub.getCustomHeaders());
JsonUtil.assertEquality(job.getVariables(), stub.getVariables());
}
final BrokerActivateJobsRequest brokerRequest = brokerClient.getSingleBrokerRequest();
final JobBatchRecord brokerRequestValue = brokerRequest.getRequestWriter();
assertThat(brokerRequestValue.getMaxJobsToActivate()).isEqualTo(maxJobsToActivate);
assertThat(brokerRequestValue.getTypeBuffer()).isEqualTo(wrapString(jobType));
assertThat(brokerRequestValue.getTimeout()).isEqualTo(timeout.toMillis());
assertThat(brokerRequestValue.getWorkerBuffer()).isEqualTo(wrapString(worker));
assertThat(brokerRequestValue.variables()).extracting(v -> BufferUtil.bufferAsString(v.getValue())).containsExactlyInAnyOrderElementsOf(fetchVariables);
}
use of io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest in project zeebe by zeebe-io.
the class ActivateJobsTest method shouldMapRequestAndResponse.
@Test
public void shouldMapRequestAndResponse() {
// given
final ActivateJobsStub stub = new ActivateJobsStub();
stub.registerWith(brokerClient);
final String jobType = "testJob";
final String worker = "testWorker";
final int maxJobsToActivate = 13;
final Duration timeout = Duration.ofMinutes(12);
final List<String> fetchVariables = Arrays.asList("foo", "bar", "baz");
final ActivateJobsRequest request = ActivateJobsRequest.newBuilder().setType(jobType).setWorker(worker).setMaxJobsToActivate(maxJobsToActivate).setTimeout(timeout.toMillis()).addAllFetchVariable(fetchVariables).build();
stub.addAvailableJobs(jobType, maxJobsToActivate);
// when
final Iterator<ActivateJobsResponse> responses = client.activateJobs(request);
// then
assertThat(responses.hasNext()).isTrue();
final ActivateJobsResponse response = responses.next();
assertThat(response.getJobsCount()).isEqualTo(maxJobsToActivate);
for (int i = 0; i < maxJobsToActivate; i++) {
final ActivatedJob job = response.getJobs(i);
assertThat(job.getKey()).isEqualTo(Protocol.encodePartitionId(Protocol.START_PARTITION_ID, i));
assertThat(job.getType()).isEqualTo(jobType);
assertThat(job.getWorker()).isEqualTo(worker);
assertThat(job.getRetries()).isEqualTo(stub.getRetries());
assertThat(job.getDeadline()).isEqualTo(stub.getDeadline());
assertThat(job.getProcessInstanceKey()).isEqualTo(stub.getProcessInstanceKey());
assertThat(job.getBpmnProcessId()).isEqualTo(stub.getBpmnProcessId());
assertThat(job.getProcessDefinitionVersion()).isEqualTo(stub.getProcessDefinitionVersion());
assertThat(job.getProcessDefinitionKey()).isEqualTo(stub.getProcessDefinitionKey());
assertThat(job.getElementId()).isEqualTo(stub.getElementId());
assertThat(job.getElementInstanceKey()).isEqualTo(stub.getElementInstanceKey());
JsonUtil.assertEquality(job.getCustomHeaders(), stub.getCustomHeaders());
JsonUtil.assertEquality(job.getVariables(), stub.getVariables());
}
final BrokerActivateJobsRequest brokerRequest = brokerClient.getSingleBrokerRequest();
final JobBatchRecord brokerRequestValue = brokerRequest.getRequestWriter();
assertThat(brokerRequestValue.getMaxJobsToActivate()).isEqualTo(maxJobsToActivate);
assertThat(brokerRequestValue.getTypeBuffer()).isEqualTo(wrapString(jobType));
assertThat(brokerRequestValue.getTimeout()).isEqualTo(timeout.toMillis());
assertThat(brokerRequestValue.getWorkerBuffer()).isEqualTo(wrapString(worker));
assertThat(brokerRequestValue.variables()).extracting(v -> BufferUtil.bufferAsString(v.getValue())).containsExactlyInAnyOrderElementsOf(fetchVariables);
}
use of io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest 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.request.BrokerRequest in project zeebe by camunda-cloud.
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.request.BrokerRequest in project zeebe by camunda-cloud.
the class ActivateJobsTest method shouldMapRequestAndResponse.
@Test
public void shouldMapRequestAndResponse() {
// given
final ActivateJobsStub stub = new ActivateJobsStub();
stub.registerWith(brokerClient);
final String jobType = "testJob";
final String worker = "testWorker";
final int maxJobsToActivate = 13;
final Duration timeout = Duration.ofMinutes(12);
final List<String> fetchVariables = Arrays.asList("foo", "bar", "baz");
final ActivateJobsRequest request = ActivateJobsRequest.newBuilder().setType(jobType).setWorker(worker).setMaxJobsToActivate(maxJobsToActivate).setTimeout(timeout.toMillis()).addAllFetchVariable(fetchVariables).build();
stub.addAvailableJobs(jobType, maxJobsToActivate);
// when
final Iterator<ActivateJobsResponse> responses = client.activateJobs(request);
// then
assertThat(responses.hasNext()).isTrue();
final ActivateJobsResponse response = responses.next();
assertThat(response.getJobsCount()).isEqualTo(maxJobsToActivate);
for (int i = 0; i < maxJobsToActivate; i++) {
final ActivatedJob job = response.getJobs(i);
assertThat(job.getKey()).isEqualTo(Protocol.encodePartitionId(Protocol.START_PARTITION_ID, i));
assertThat(job.getType()).isEqualTo(jobType);
assertThat(job.getWorker()).isEqualTo(worker);
assertThat(job.getRetries()).isEqualTo(stub.getRetries());
assertThat(job.getDeadline()).isEqualTo(stub.getDeadline());
assertThat(job.getProcessInstanceKey()).isEqualTo(stub.getProcessInstanceKey());
assertThat(job.getBpmnProcessId()).isEqualTo(stub.getBpmnProcessId());
assertThat(job.getProcessDefinitionVersion()).isEqualTo(stub.getProcessDefinitionVersion());
assertThat(job.getProcessDefinitionKey()).isEqualTo(stub.getProcessDefinitionKey());
assertThat(job.getElementId()).isEqualTo(stub.getElementId());
assertThat(job.getElementInstanceKey()).isEqualTo(stub.getElementInstanceKey());
JsonUtil.assertEquality(job.getCustomHeaders(), stub.getCustomHeaders());
JsonUtil.assertEquality(job.getVariables(), stub.getVariables());
}
final BrokerActivateJobsRequest brokerRequest = brokerClient.getSingleBrokerRequest();
final JobBatchRecord brokerRequestValue = brokerRequest.getRequestWriter();
assertThat(brokerRequestValue.getMaxJobsToActivate()).isEqualTo(maxJobsToActivate);
assertThat(brokerRequestValue.getTypeBuffer()).isEqualTo(wrapString(jobType));
assertThat(brokerRequestValue.getTimeout()).isEqualTo(timeout.toMillis());
assertThat(brokerRequestValue.getWorkerBuffer()).isEqualTo(wrapString(worker));
assertThat(brokerRequestValue.variables()).extracting(v -> BufferUtil.bufferAsString(v.getValue())).containsExactlyInAnyOrderElementsOf(fetchVariables);
}
Aggregations