use of io.camunda.zeebe.it.util.RecordingJobHandler in project zeebe by camunda.
the class JobWorkerTest method shouldActivateJobsOfDifferentTypes.
@Test
public void shouldActivateJobsOfDifferentTypes() {
// given
final long jobX = CLIENT_RULE.createSingleJob(jobType + "x");
final long jobY = CLIENT_RULE.createSingleJob(jobType + "y");
// when
final RecordingJobHandler jobHandlerX = new RecordingJobHandler();
final RecordingJobHandler jobHandlerY = new RecordingJobHandler();
CLIENT_RULE.getClient().newWorker().jobType(jobType + "x").handler(jobHandlerX).open();
CLIENT_RULE.getClient().newWorker().jobType(jobType + "y").handler(jobHandlerY).open();
waitUntil(() -> jobHandlerX.getHandledJobs().size() >= 1);
waitUntil(() -> jobHandlerY.getHandledJobs().size() >= 1);
// then
assertThat(jobHandlerX.getHandledJobs()).hasSize(1).extracting(ActivatedJob::getKey).contains(jobX);
assertThat(jobHandlerY.getHandledJobs()).hasSize(1).extracting(ActivatedJob::getKey).contains(jobY);
}
use of io.camunda.zeebe.it.util.RecordingJobHandler in project zeebe by camunda.
the class JobWorkerWithMultiplePartitionsTest method shouldReceiveJobsFromMultiplePartitions.
@Test
public void shouldReceiveJobsFromMultiplePartitions() {
// given
final String jobType = helper.getJobType();
final RecordingJobHandler handler = new RecordingJobHandler();
IntStream.range(0, PARTITION_COUNT).forEach(p -> CLIENT_RULE.createSingleJob(jobType));
// when
CLIENT_RULE.getClient().newWorker().jobType(jobType).handler(handler).name("test").open();
// then
waitUntil(() -> handler.getHandledJobs().size() >= PARTITION_COUNT);
final List<Integer> receivedPartitionIds = handler.getHandledJobs().stream().map(ActivatedJob::getKey).map(Protocol::decodePartitionId).collect(Collectors.toList());
assertThat(receivedPartitionIds).containsExactlyInAnyOrderElementsOf(CLIENT_RULE.getPartitions());
}
use of io.camunda.zeebe.it.util.RecordingJobHandler in project zeebe by camunda.
the class MultipleClientTest method shouldOpenJobWorkerForDifferentTypes.
@Test
public void shouldOpenJobWorkerForDifferentTypes() {
// given
final RecordingJobHandler handler1 = new RecordingJobHandler();
final RecordingJobHandler handler2 = new RecordingJobHandler();
client1.getClient().newWorker().jobType("foo").handler(handler1).open();
client2.getClient().newWorker().jobType("bar").handler(handler2).open();
// when
final long job1Key = client1.createSingleJob("foo");
final long job2Key = client1.createSingleJob("bar");
// then
waitUntil(() -> handler1.getHandledJobs().size() + handler2.getHandledJobs().size() >= 2);
assertThat(handler1.getHandledJobs()).hasSize(1);
assertThat(handler1.getHandledJobs().get(0).getKey()).isEqualTo(job1Key);
assertThat(handler2.getHandledJobs()).hasSize(1);
assertThat(handler2.getHandledJobs().get(0).getKey()).isEqualTo(job2Key);
}
use of io.camunda.zeebe.it.util.RecordingJobHandler in project zeebe by zeebe-io.
the class JobWorkerWithMultiplePartitionsTest method shouldReceiveJobsFromMultiplePartitions.
@Test
public void shouldReceiveJobsFromMultiplePartitions() {
// given
final String jobType = helper.getJobType();
final RecordingJobHandler handler = new RecordingJobHandler();
IntStream.range(0, PARTITION_COUNT).forEach(p -> CLIENT_RULE.createSingleJob(jobType));
// when
CLIENT_RULE.getClient().newWorker().jobType(jobType).handler(handler).name("test").open();
// then
waitUntil(() -> handler.getHandledJobs().size() >= PARTITION_COUNT);
final List<Integer> receivedPartitionIds = handler.getHandledJobs().stream().map(ActivatedJob::getKey).map(Protocol::decodePartitionId).collect(Collectors.toList());
assertThat(receivedPartitionIds).containsExactlyInAnyOrderElementsOf(CLIENT_RULE.getPartitions());
}
use of io.camunda.zeebe.it.util.RecordingJobHandler in project zeebe by zeebe-io.
the class JobWorkerTest method shouldActivateJob.
@Test
public void shouldActivateJob() {
// given
final var process = Bpmn.createExecutableProcess("process").startEvent().serviceTask("task", t -> t.zeebeJobType(jobType).zeebeJobRetries("5").zeebeTaskHeader("x", "1").zeebeTaskHeader("y", "2")).done();
final var processDefinitionKey = CLIENT_RULE.deployProcess(process);
final var processInstanceKey = CLIENT_RULE.createProcessInstance(processDefinitionKey, "{\"a\":1, \"b\":2}");
// when
final RecordingJobHandler jobHandler = new RecordingJobHandler();
CLIENT_RULE.getClient().newWorker().jobType(jobType).handler(jobHandler).name("test").open();
waitUntil(() -> jobHandler.getHandledJobs().size() >= 1);
// then
final ActivatedJob job = jobHandler.getHandledJobs().get(0);
assertThat(job.getType()).isEqualTo(jobType);
assertThat(job.getRetries()).isEqualTo(5);
assertThat(job.getDeadline()).isGreaterThan(Instant.now().toEpochMilli());
assertThat(job.getWorker()).isEqualTo("test");
assertThat(job.getProcessDefinitionKey()).isEqualTo(processDefinitionKey);
assertThat(job.getBpmnProcessId()).isEqualTo("process");
assertThat(job.getProcessInstanceKey()).isEqualTo(processInstanceKey);
assertThat(job.getElementId()).isEqualTo("task");
assertThat(job.getCustomHeaders()).containsExactly(entry("x", "1"), entry("y", "2"));
assertThat(job.getVariablesAsMap()).containsExactly(entry("a", 1), entry("b", 2));
}
Aggregations