Search in sources :

Example 96 with JobRecord

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());
}
Also used : BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)

Example 97 with JobRecord

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"));
}
Also used : BrokerFailJobRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerFailJobRequest) FailJobRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.FailJobRequest) BrokerFailJobRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerFailJobRequest) JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord) FailJobResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.FailJobResponse) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) Test(org.junit.Test)

Example 98 with JobRecord

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");
}
Also used : JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord) Test(org.junit.Test)

Example 99 with JobRecord

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);
}
Also used : JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord) Test(org.junit.Test)

Example 100 with JobRecord

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());
}
Also used : JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord) Test(org.junit.Test)

Aggregations

JobRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)183 Test (org.junit.Test)96 GatewayTest (io.camunda.zeebe.gateway.api.util.GatewayTest)15 BrokerResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse)9 LongValue (io.camunda.zeebe.msgpack.value.LongValue)9 CompleteJobResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CompleteJobResponse)8 IncidentRecord (io.camunda.zeebe.protocol.impl.record.value.incident.IncidentRecord)8 DirectBuffer (org.agrona.DirectBuffer)8 RecordMetadata (io.camunda.zeebe.protocol.impl.record.RecordMetadata)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 BrokerCompleteJobRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerCompleteJobRequest)6 CompleteJobRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CompleteJobRequest)6 JobState (io.camunda.zeebe.engine.state.immutable.JobState)5 State (io.camunda.zeebe.engine.state.immutable.JobState.State)5 ActivateJobsResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse)5 ActivatedJob (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob)5 FailJobResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.FailJobResponse)5 UpdateJobRetriesResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.UpdateJobRetriesResponse)5 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)5 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)5