public static JobRecordStream jobRecords(final JobIntent intent) { return jobRecords().withIntent(intent); }
public JobRecordStream receiveJobs() { return RecordingExporter.jobRecords().withPartitionId(partitionId); }
public JobRecordStream receiveJobs() { return RecordingExporter.jobRecords().withPartitionId(partitionId); }
public static JobRecordStream jobRecords(final JobIntent intent) { return jobRecords().withIntent(intent); }
@Test public void shouldCompleteActivatedJobs() { // given final int jobAmount = 5; final List<Long> jobKeys = createJobs(jobAmount); final List<Job> jobs = activateJobs(jobAmount); // when jobs.forEach(this::completeJob); // then final List<Record<JobRecordValue>> records = jobRecords(JobIntent.COMPLETED).limit(jobAmount).collect(Collectors.toList()); assertThat(records).extracting(Record::getKey).containsOnlyElementsOf(jobKeys); }
@Test public void shouldCompleteActivatedJobs() { // given final int jobAmount = 5; final List<Long> jobKeys = createJobs(jobAmount); final List<Job> jobs = activateJobs(jobAmount); // when jobs.forEach(this::completeJob); // then final List<Record<JobRecordValue>> records = jobRecords(JobIntent.COMPLETED).limit(jobAmount).collect(Collectors.toList()); assertThat(records).extracting(Record::getKey).containsOnlyElementsOf(jobKeys); }
@Test public void shouldActivateJobBatch() { // given final List<Long> expectedJobKeys = createJobs(5).subList(0, 3); // when final List<Job> jobs = activateJobs(3); // then assertThat(jobs).extracting(Job::getKey).containsOnlyElementsOf(expectedJobKeys); final List<Record<JobRecordValue>> record = jobRecords(JobIntent.ACTIVATED).limit(3).collect(Collectors.toList()); assertThat(record).extracting(Record::getKey).containsOnlyElementsOf(expectedJobKeys); }
@Test public void shouldActivateJobBatch() { // given final List<Long> expectedJobKeys = createJobs(5).subList(0, 3); // when final List<Job> jobs = activateJobs(3); // then assertThat(jobs).extracting(Job::getKey).containsOnlyElementsOf(expectedJobKeys); final List<Record<JobRecordValue>> record = jobRecords(JobIntent.ACTIVATED).limit(3).collect(Collectors.toList()); assertThat(record).extracting(Record::getKey).containsOnlyElementsOf(expectedJobKeys); }
@Test public void shouldOnlyReturnJobsOfCorrectType() { // given final List<Long> jobKeys = createJobs(JOB_TYPE, 3); createJobs("different" + JOB_TYPE, 5); jobKeys.addAll(createJobs(JOB_TYPE, 4)); // when final List<Job> jobs = activateJobs(JOB_TYPE, 7); // then assertThat(jobs).extracting(Job::getKey).containsOnlyElementsOf(jobKeys); final List<Record<JobRecordValue>> records = jobRecords(JobIntent.ACTIVATED).limit(jobKeys.size()).collect(Collectors.toList()); assertThat(records).extracting(Record::getKey).containsOnlyElementsOf(jobKeys); assertThat(records).extracting("value.type").containsOnly(JOB_TYPE); }
@Test public void shouldOnlyReturnJobsOfCorrectType() { // given final List<Long> jobKeys = createJobs(JOB_TYPE, 3); createJobs("different" + JOB_TYPE, 5); jobKeys.addAll(createJobs(JOB_TYPE, 4)); // when final List<Job> jobs = activateJobs(JOB_TYPE, 7); // then assertThat(jobs).extracting(Job::getKey).containsOnlyElementsOf(jobKeys); final List<Record<JobRecordValue>> records = jobRecords(JobIntent.ACTIVATED).limit(jobKeys.size()).collect(Collectors.toList()); assertThat(records).extracting(Record::getKey).containsOnlyElementsOf(jobKeys); assertThat(records).extracting("value.type").containsOnly(JOB_TYPE); }
public long createJob(final String type, Consumer<ServiceTaskBuilder> consumer, String payload) { deploy( Bpmn.createExecutableProcess("process") .startEvent() .serviceTask( "task", b -> { b.zeebeTaskType(type).zeebeTaskRetries(3); consumer.accept(b); }) .done()); final long workflowInstance = createWorkflowInstance("process", payload); return RecordingExporter.jobRecords(JobIntent.CREATED) .withType(type) .filter(j -> j.getValue().getHeaders().getWorkflowInstanceKey() == workflowInstance) .getFirst() .getKey(); }
public long createJob(final String type, Consumer<ServiceTaskBuilder> consumer, String payload) { deploy( Bpmn.createExecutableProcess("process") .startEvent() .serviceTask( "task", b -> { b.zeebeTaskType(type).zeebeTaskRetries(3); consumer.accept(b); }) .done()); final long workflowInstance = createWorkflowInstance("process", payload); return RecordingExporter.jobRecords(JobIntent.CREATED) .withType(type) .filter(j -> j.getValue().getHeaders().getWorkflowInstanceKey() == workflowInstance) .getFirst() .getKey(); }
@Test public void shouldFail() { // given client.createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = client.receiveFirstJobEvent(ACTIVATED); final int retries = 23; // when final ExecuteCommandResponse response = client.failJob(jobEvent.getKey(), retries); // then final JobRecordValue jobEventValue = jobEvent.getValue(); assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(FAILED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) retries), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(FAILED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }
@Test public void shouldFail() { // given client.createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = client.receiveFirstJobEvent(ACTIVATED); final int retries = 23; // when final ExecuteCommandResponse response = client.failJob(jobEvent.getKey(), retries); // then final JobRecordValue jobEventValue = jobEvent.getValue(); assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(FAILED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) retries), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(FAILED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }
@Test public void shouldCompleteJob() { // given createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = receiveSingleJobEvent(); // when final JobRecordValue jobEventValue = jobEvent.getValue(); final ExecuteCommandResponse response = testClient.completeJob(jobEvent.getKey(), jobEventValue.getPayload()); // then assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(JobIntent.COMPLETED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) jobEventValue.getRetries()), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(JobIntent.COMPLETED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }
@Test public void shouldCompleteJob() { // given createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = receiveSingleJobEvent(); // when final JobRecordValue jobEventValue = jobEvent.getValue(); final ExecuteCommandResponse response = testClient.completeJob(jobEvent.getKey(), jobEventValue.getPayload()); // then assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(JobIntent.COMPLETED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) jobEventValue.getRetries()), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(JobIntent.COMPLETED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }
@Test public void shouldActivateJobsWithLongCustomHeaders() { // given final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("processId") .startEvent() .serviceTask( "task", b -> { b.zeebeTaskType("taskType").zeebeTaskHeader("foo", LONG_CUSTOM_HEADER_VALUE); }) .endEvent() .done(); apiRule.partitionClient().deployWithResponse(Bpmn.convertToString(modelInstance).getBytes()); apiRule.partitionClient().createWorkflowInstance("processId"); // when apiRule.partitionClient().completeJobOfType("taskType"); // then final JobRecordValue jobRecord = RecordingExporter.jobRecords(JobIntent.ACTIVATED).limit(1).getFirst().getValue(); assertThat(jobRecord.getCustomHeaders().get("foo")).isEqualTo(LONG_CUSTOM_HEADER_VALUE); }
@Test public void shouldActivateJobsWithLongCustomHeaders() { // given final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("processId") .startEvent() .serviceTask( "task", b -> { b.zeebeTaskType("taskType").zeebeTaskHeader("foo", LONG_CUSTOM_HEADER_VALUE); }) .endEvent() .done(); apiRule.partitionClient().deployWithResponse(Bpmn.convertToString(modelInstance).getBytes()); apiRule.partitionClient().createWorkflowInstance("processId"); // when apiRule.partitionClient().completeJobOfType("taskType"); // then final JobRecordValue jobRecord = RecordingExporter.jobRecords(JobIntent.ACTIVATED).limit(1).getFirst().getValue(); assertThat(jobRecord.getCustomHeaders().get("foo")).isEqualTo(LONG_CUSTOM_HEADER_VALUE); }
@Test public void shouldApplyInputMappings() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask( "service", builder -> { builder.zeebeTaskType("test"); mappings.accept(builder); }) .endEvent() .done()); // when testClient.createWorkflowInstance(PROCESS_ID, initialPayload); // then final Record<JobRecordValue> jobCreated = RecordingExporter.jobRecords(JobIntent.CREATED).getFirst(); JsonUtil.assertEquality(jobCreated.getValue().getPayload(), expectedPayload); }
@Test public void shouldApplyInputMappings() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask( "service", builder -> { builder.zeebeTaskType("test"); mappings.accept(builder); }) .endEvent() .done()); // when testClient.createWorkflowInstance(PROCESS_ID, initialPayload); // then final Record<JobRecordValue> jobCreated = RecordingExporter.jobRecords(JobIntent.CREATED).getFirst(); JsonUtil.assertEquality(jobCreated.getValue().getPayload(), expectedPayload); }