Search in sources :

Example 1 with JobRecordValue

use of io.camunda.zeebe.protocol.record.value.JobRecordValue in project zeebe-process-test by camunda.

the class RecordStreamLogger method logJobRecordValue.

private String logJobRecordValue(final Record<?> record) {
    final JobRecordValue value = (JobRecordValue) record.getValue();
    final StringJoiner joiner = new StringJoiner(", ", "", "");
    // These fields are empty for commands
    if (record.getRecordType().equals(RecordType.EVENT)) {
        joiner.add(String.format("(Element id: %s)", value.getElementId()));
        joiner.add(String.format("(Job type: %s)", value.getType()));
        joiner.add(logVariables(value.getVariables()));
    }
    return joiner.toString();
}
Also used : JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) StringJoiner(java.util.StringJoiner)

Example 2 with JobRecordValue

use of io.camunda.zeebe.protocol.record.value.JobRecordValue in project zeebe-exporter-protobuf by camunda-community-hub.

the class RecordTransformTest method shouldTransformJob.

@Test
public void shouldTransformJob() {
    // given
    final JobRecordValue jobRecordValue = mockJobRecordValue();
    final Record<JobRecordValue> mockedRecord = mockRecord(jobRecordValue, ValueType.JOB, JobIntent.CREATED);
    // when
    final Schema.JobRecord jobRecord = (Schema.JobRecord) RecordTransformer.toProtobufMessage(mockedRecord);
    // then
    assertMetadata(jobRecord.getMetadata(), "JOB", "CREATED");
    assertJobRecord(jobRecord);
}
Also used : JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) JobRecord(io.zeebe.exporter.proto.Schema.JobRecord) JobRecord(io.zeebe.exporter.proto.Schema.JobRecord) Test(org.junit.Test)

Example 3 with JobRecordValue

use of io.camunda.zeebe.protocol.record.value.JobRecordValue 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 4 with JobRecordValue

use of io.camunda.zeebe.protocol.record.value.JobRecordValue 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 5 with JobRecordValue

use of io.camunda.zeebe.protocol.record.value.JobRecordValue 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)

Aggregations

JobRecordValue (io.camunda.zeebe.protocol.record.value.JobRecordValue)73 Test (org.junit.Test)42 JobBatchRecordValue (io.camunda.zeebe.protocol.record.value.JobBatchRecordValue)31 Test (org.junit.jupiter.api.Test)20 Duration (java.time.Duration)15 Record (io.camunda.zeebe.protocol.record.Record)13 ProcessInstanceRecordValue (io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue)13 JobBatchRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)12 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)10 JobIntent (io.camunda.zeebe.protocol.record.intent.JobIntent)10 ProcessInstanceIntent (io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent)10 List (java.util.List)10 Map (java.util.Map)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 TimerIntent (io.camunda.zeebe.protocol.record.intent.TimerIntent)7 EngineRule (io.camunda.zeebe.engine.util.EngineRule)6 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)6 RecordType (io.camunda.zeebe.protocol.record.RecordType)6 IncidentRecordValue (io.camunda.zeebe.protocol.record.value.IncidentRecordValue)6 Collectors (java.util.stream.Collectors)6