use of io.camunda.zeebe.protocol.record.value.JobBatchRecordValue in project zeebe by camunda.
the class ActivatableJobsNotificationTests method shouldNotifyWhenFailedJobsResolved.
@Test
public void shouldNotifyWhenFailedJobsResolved() {
// given
createProcessInstanceAndJobs(1);
final Record<JobBatchRecordValue> jobs = activateJobs(1);
final JobRecordValue job = jobs.getValue().getJobs().get(0);
ENGINE.job().withType(taskType).ofInstance(job.getProcessInstanceKey()).fail();
// when
ENGINE.job().ofInstance(job.getProcessInstanceKey()).withType(taskType).withRetries(1).updateRetries();
ENGINE.incident().ofInstance(job.getProcessInstanceKey()).resolve();
// then
Mockito.verify(JOB_AVAILABLE_CALLBACK, times(2)).accept(taskType);
}
use of io.camunda.zeebe.protocol.record.value.JobBatchRecordValue in project zeebe by camunda.
the class ActivateJobsTest method shouldAcceptEmptyWorker.
@Test
public void shouldAcceptEmptyWorker() {
// given
ENGINE.deployment().withXmlResource(PROCESS_ID + ".bpmn", MODEL_SUPPLIER.apply(taskType)).deploy();
final Duration timeout = Duration.ofMinutes(12);
// when
final Record<JobBatchRecordValue> batchRecord = ENGINE.jobs().withType(taskType).withTimeout(timeout.toMillis()).withMaxJobsToActivate(1).activate();
// then
assertThat(batchRecord.getIntent()).isEqualTo(JobBatchIntent.ACTIVATED);
}
use of io.camunda.zeebe.protocol.record.value.JobBatchRecordValue in project zeebe by camunda.
the class ActivateJobsTest method shouldFetchFullJobRecordFromProcess.
@Test
public void shouldFetchFullJobRecordFromProcess() {
// given
final ControlledActorClock clock = ENGINE.getClock();
clock.pinCurrentTime();
final String worker = "testWorker";
final Duration timeout = Duration.ofMinutes(4);
ENGINE.deployment().withXmlResource(PROCESS_ID + ".bpmn", MODEL_SUPPLIER.apply(taskType)).deploy();
createProcessInstances(1, "{'foo':'bar'}");
final Record<JobRecordValue> jobRecord = jobRecords(JobIntent.CREATED).withType(taskType).getFirst();
// when
final Record<JobBatchRecordValue> jobActivatedRecord = ENGINE.jobs().withType(taskType).byWorker(worker).withTimeout(timeout.toMillis()).withMaxJobsToActivate(1).activate();
final JobRecordValue jobActivated = jobActivatedRecord.getValue().getJobs().get(0);
final Record<JobBatchRecordValue> jobActivate = RecordingExporter.jobBatchRecords().withType(taskType).withIntent(JobBatchIntent.ACTIVATE).getFirst();
// then
assertThat(jobActivated).hasType(taskType).hasWorker(worker).hasRetries(3).hasDeadline(jobActivate.getTimestamp() + timeout.toMillis());
assertThat(jobActivated.getVariables()).containsExactly(entry("foo", "bar"));
final JobRecordValue jobRecordValue = jobRecord.getValue();
assertThat(jobActivated.getProcessInstanceKey()).isEqualTo(jobRecordValue.getProcessInstanceKey());
assertThat(jobActivated).hasBpmnProcessId(jobRecordValue.getBpmnProcessId()).hasProcessDefinitionVersion(jobRecordValue.getProcessDefinitionVersion()).hasProcessDefinitionKey(jobRecordValue.getProcessDefinitionKey()).hasElementId(jobRecordValue.getElementId()).hasElementInstanceKey(jobRecordValue.getElementInstanceKey());
assertThat(jobActivated.getCustomHeaders()).isEqualTo(jobRecordValue.getCustomHeaders());
}
use of io.camunda.zeebe.protocol.record.value.JobBatchRecordValue in project zeebe by camunda.
the class ActivateJobsTest method shouldActivateSingleJob.
@Test
public void shouldActivateSingleJob() {
// given
ENGINE.deployment().withXmlResource(PROCESS_ID + ".bpmn", MODEL_SUPPLIER.apply(taskType)).deploy();
final long firstInstanceKey = createProcessInstances(3, "{'foo':'bar'}").get(0);
final long expectedJobKey = jobRecords(JobIntent.CREATED).withType(taskType).filter(r -> r.getValue().getProcessInstanceKey() == firstInstanceKey).getFirst().getKey();
final String worker = "myTestWorker";
final Duration timeout = Duration.ofMinutes(12);
// when
final Record<JobBatchRecordValue> batchRecord = ENGINE.jobs().withType(taskType).byWorker(worker).withTimeout(timeout.toMillis()).withMaxJobsToActivate(1).activate();
final List<JobRecordValue> jobs = batchRecord.getValue().getJobs();
final List<Long> jobKeys = batchRecord.getValue().getJobKeys();
// then
assertThat(batchRecord.getIntent()).isEqualTo(JobBatchIntent.ACTIVATED);
assertThat(jobKeys).hasSize(1);
assertThat(jobs).hasSize(1);
assertThat(jobKeys.get(0)).isEqualTo(expectedJobKey);
assertThat(jobs.get(0)).hasRetries(3).hasWorker(worker).hasType(taskType);
assertThat(jobs.get(0).getVariables()).containsExactly(entry("foo", "bar"));
final var activatedJobBatch = getActivatedJobBatch();
final var jobRecordValue = activatedJobBatch.getJobs().get(0);
final var jobKey = activatedJobBatch.getJobKeys().get(0);
assertThat(jobKey).isEqualTo(expectedJobKey);
assertThat(jobRecordValue).hasRetries(3).hasWorker(worker);
}
use of io.camunda.zeebe.protocol.record.value.JobBatchRecordValue in project zeebe by camunda.
the class CompleteJobTest method shouldThrowExceptionOnCompletionIfVariablesAreInvalid.
@Test
public void shouldThrowExceptionOnCompletionIfVariablesAreInvalid() {
// given
ENGINE.createJob(jobType, PROCESS_ID);
final Record<JobBatchRecordValue> batchRecord = ENGINE.jobs().withType(jobType).activate();
// positive fixnum, i.e. no object
final byte[] invalidVariables = new byte[] { 1 };
// when
final Throwable throwable = catchThrowable(() -> ENGINE.job().withKey(batchRecord.getValue().getJobKeys().get(0)).withVariables(new UnsafeBuffer(invalidVariables)).expectRejection().complete());
// then
assertThat(throwable).isInstanceOf(RuntimeException.class);
assertThat(throwable.getMessage()).contains("Property 'variables' is invalid");
assertThat(throwable.getMessage()).contains("Expected document to be a root level object, but was 'INTEGER'");
}
Aggregations