use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.
the class FailJobStub method handle.
@Override
public BrokerResponse<JobRecord> handle(final BrokerFailJobRequest request) throws Exception {
final JobRecord responseValue = buildDefaultValue();
responseValue.setRetries(request.getRequestWriter().getRetries());
return new BrokerResponse<>(responseValue, 0, request.getKey());
}
use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.
the class DeployProcessStub method handle.
@Override
public BrokerResponse<DeploymentRecord> handle(final BrokerDeployResourceRequest request) throws Exception {
final DeploymentRecord deploymentRecord = request.getRequestWriter();
deploymentRecord.resources().iterator().forEachRemaining(r -> {
deploymentRecord.processesMetadata().add().setBpmnProcessId(r.getResourceNameBuffer()).setResourceName(r.getResourceNameBuffer()).setVersion(PROCESS_VERSION).setKey(PROCESS_KEY).setChecksum(CHECKSUM);
});
return new BrokerResponse<>(deploymentRecord, 0, KEY);
}
use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.
the class DeployResourceStub method handle.
@Override
public BrokerResponse<DeploymentRecord> handle(final BrokerDeployResourceRequest request) throws Exception {
final DeploymentRecord deploymentRecord = request.getRequestWriter();
deploymentRecord.resources().iterator().forEachRemaining(r -> {
if (r.getResourceName().endsWith(".bpmn")) {
deploymentRecord.processesMetadata().add().setBpmnProcessId(r.getResourceNameBuffer()).setResourceName(r.getResourceNameBuffer()).setVersion(PROCESS_VERSION).setKey(PROCESS_KEY).setChecksum(CHECKSUM);
} else if (r.getResourceName().endsWith(".dmn")) {
deploymentRecord.decisionsMetadata().add().setDecisionId(r.getResourceName()).setDecisionName(r.getResourceName()).setVersion(456).setDecisionKey(567).setDecisionRequirementsId(r.getResourceName()).setDecisionRequirementsKey(678);
deploymentRecord.decisionRequirementsMetadata().add().setDecisionRequirementsId(r.getResourceName()).setDecisionRequirementsName(r.getResourceName()).setDecisionRequirementsVersion(456).setDecisionRequirementsKey(678).setNamespace(r.getResourceName()).setResourceName(r.getResourceName()).setChecksum(BufferUtil.wrapString("checksum"));
}
});
return new BrokerResponse<>(deploymentRecord, 0, KEY);
}
use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.
the class ActivateJobsStub method handle.
@Override
public BrokerResponse<JobBatchRecord> handle(final BrokerActivateJobsRequest request) throws Exception {
final int partitionId = request.getPartitionId();
final JobBatchRecord requestDto = request.getRequestWriter();
final JobBatchRecord response = new JobBatchRecord();
response.setMaxJobsToActivate(requestDto.getMaxJobsToActivate());
response.setWorker(requestDto.getWorkerBuffer());
response.setType(requestDto.getTypeBuffer());
response.setTimeout(requestDto.getTimeout());
addJobs(response, partitionId, requestDto.getMaxJobsToActivate(), requestDto.getTypeBuffer(), requestDto.getWorkerBuffer());
return new BrokerResponse<>(response, partitionId, Protocol.encodePartitionId(partitionId, JOB_BATCH_KEY));
}
use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.
the class LongPollingActivateJobsTest method shouldReturnJobsIfSomeBrokersHaveJobsWhileOthersReturnResourceExhaustionResponse.
@Test
public void shouldReturnJobsIfSomeBrokersHaveJobsWhileOthersReturnResourceExhaustionResponse() {
// given
final InflightActivateJobsRequest request = new InflightActivateJobsRequest(getNextRequestId(), ActivateJobsRequest.newBuilder().setType(TYPE).setMaxJobsToActivate(15).setRequestTimeout(500).build(), spy(ServerStreamObserver.class));
brokerClient.registerHandler(BrokerActivateJobsRequest.class, new RequestHandler<BrokerActivateJobsRequest, BrokerResponse<?>>() {
private final ActivateJobsStub jobsAvailableStub = new ActivateJobsStub();
{
jobsAvailableStub.addAvailableJobs(TYPE, 10);
}
@Override
public BrokerResponse<?> handle(final BrokerActivateJobsRequest request) throws Exception {
final int partitionId = request.getPartitionId();
if (partitionId == 4) {
return new BrokerErrorResponse<>(new BrokerError(ErrorCode.RESOURCE_EXHAUSTED, "backpressure"));
} else {
return jobsAvailableStub.handle(request);
}
}
});
// when
handler.activateJobs(request);
waitUntil(request::isCompleted);
// then
assertThat(request.isTimedOut()).isFalse();
final ArgumentCaptor<ActivateJobsResponse> responseArgumentCaptor = ArgumentCaptor.forClass(ActivateJobsResponse.class);
verify(request.getResponseObserver()).onNext(responseArgumentCaptor.capture());
final ActivateJobsResponse response = responseArgumentCaptor.getValue();
assertThat(response.getJobsList()).hasSize(10);
}
Aggregations