use of io.camunda.zeebe.protocol.impl.record.value.job.JobRecord in project zeebe by camunda-cloud.
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.protocol.impl.record.value.job.JobRecord in project zeebe by camunda-cloud.
the class FailJobTest method shouldMapRequestAndResponse.
@Test
public void shouldMapRequestAndResponse() {
// given
final FailJobStub stub = new FailJobStub();
stub.registerWith(brokerClient);
final int retries = 123;
final int retryBackOff = 100;
final FailJobRequest request = FailJobRequest.newBuilder().setJobKey(stub.getKey()).setRetries(retries).setRetryBackOff(retryBackOff).setErrorMessage("failed").build();
// when
final FailJobResponse response = client.failJob(request);
// then
assertThat(response).isNotNull();
final BrokerFailJobRequest brokerRequest = brokerClient.getSingleBrokerRequest();
assertThat(brokerRequest.getKey()).isEqualTo(stub.getKey());
assertThat(brokerRequest.getIntent()).isEqualTo(JobIntent.FAIL);
assertThat(brokerRequest.getValueType()).isEqualTo(ValueType.JOB);
final JobRecord brokerRequestValue = brokerRequest.getRequestWriter();
assertThat(brokerRequestValue.getRetries()).isEqualTo(retries);
assertThat(brokerRequestValue.getRetryBackoff()).isEqualTo(retryBackOff);
assertThat(brokerRequestValue.getErrorMessageBuffer()).isEqualTo(wrapString("failed"));
}
use of io.camunda.zeebe.protocol.impl.record.value.job.JobRecord in project zeebe by zeebe-io.
the class JobStateTest method shouldReturnCorrectJob.
@Test
public void shouldReturnCorrectJob() {
// given
final long key = 1L;
final JobRecord jobRecord = newJobRecord().setType("test");
// when
jobState.create(key, jobRecord);
jobState.create(key + 1, newJobRecord().setType("other"));
// then
final JobRecord savedJob = jobState.getJob(key);
assertJobRecordIsEqualTo(savedJob, jobRecord);
assertThat(BufferUtil.bufferAsString(savedJob.getTypeBuffer())).isEqualTo("test");
}
use of io.camunda.zeebe.protocol.impl.record.value.job.JobRecord in project zeebe by zeebe-io.
the class JobStateTest method shouldCreateJobEntry.
@Test
public void shouldCreateJobEntry() {
// given
final long key = 1L;
final JobRecord jobRecord = newJobRecord();
// when
jobState.create(key, jobRecord);
// then
assertThat(jobState.exists(key)).isTrue();
assertJobState(key, State.ACTIVATABLE);
assertJobRecordIsEqualTo(jobState.getJob(key), jobRecord);
assertListedAsActivatable(key, jobRecord.getTypeBuffer());
refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1);
refuteListedAsBackOff(key, jobRecord.getRecurringTime() + 1);
}
use of io.camunda.zeebe.protocol.impl.record.value.job.JobRecord in project zeebe by zeebe-io.
the class JobStateTest method shouldImmediatelyRetryJobAfterFailedIfRetryBackoffIsZeroAndHasRetries.
@Test
public void shouldImmediatelyRetryJobAfterFailedIfRetryBackoffIsZeroAndHasRetries() {
// given
final long jobKey = 1L;
final JobRecord jobRecord = newJobRecord().setRetries(1).setRetryBackoff(0);
// when
jobState.create(jobKey, jobRecord);
jobState.activate(jobKey, jobRecord);
jobState.fail(jobKey, jobRecord);
// then
assertThat(jobState.exists(jobKey)).isTrue();
assertJobState(jobKey, State.ACTIVATABLE);
refuteListedAsBackOff(jobKey, jobRecord.getRecurringTime());
}
Aggregations