Search in sources :

Example 1 with JobBatchRecordValue

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

Example 2 with JobBatchRecordValue

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);
}
Also used : JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) Duration(java.time.Duration) Test(org.junit.Test)

Example 3 with JobBatchRecordValue

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());
}
Also used : ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) Duration(java.time.Duration) RandomString(org.assertj.core.internal.bytebuddy.utility.RandomString) Test(org.junit.Test)

Example 4 with JobBatchRecordValue

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);
}
Also used : JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) Duration(java.time.Duration) RandomString(org.assertj.core.internal.bytebuddy.utility.RandomString) Test(org.junit.Test)

Example 5 with JobBatchRecordValue

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'");
}
Also used : JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) ThrowableAssert.catchThrowable(org.assertj.core.api.ThrowableAssert.catchThrowable) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Aggregations

JobBatchRecordValue (io.camunda.zeebe.protocol.record.value.JobBatchRecordValue)49 Test (org.junit.Test)43 JobRecordValue (io.camunda.zeebe.protocol.record.value.JobRecordValue)31 Duration (java.time.Duration)15 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)9 EngineRule (io.camunda.zeebe.engine.util.EngineRule)3 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)3 StartEventBuilder (io.camunda.zeebe.model.bpmn.builder.StartEventBuilder)3 Record (io.camunda.zeebe.protocol.record.Record)3 JobIntent (io.camunda.zeebe.protocol.record.intent.JobIntent)3 MessageSubscriptionIntent (io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent)3 ProcessInstanceIntent (io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent)3 TimerIntent (io.camunda.zeebe.protocol.record.intent.TimerIntent)3 BpmnElementType (io.camunda.zeebe.protocol.record.value.BpmnElementType)3 RecordingExporter (io.camunda.zeebe.test.util.record.RecordingExporter)3 RecordingExporterTestWatcher (io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher)3 ControlledActorClock (io.camunda.zeebe.util.sched.clock.ControlledActorClock)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Consumer (java.util.function.Consumer)3