use of io.camunda.zeebe.client.api.worker.JobHandler in project zeebe-test-container by camunda-community-hub.
the class TriggerTimerCatchEventTest method shouldTriggerTimerStartEvent.
@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void shouldTriggerTimerStartEvent() {
// given
final ZeebeClock clock = ZeebeClock.newDefaultClock(zeebeContainer);
final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().intermediateCatchEvent().timerWithDate(TIMER_DATE.toString()).serviceTask("task", b -> b.zeebeJobType(JOB_TYPE)).endEvent().done();
final List<ActivatedJob> activatedJobs = new CopyOnWriteArrayList<>();
final Instant brokerTime;
// when
final JobHandler handler = (client, job) -> activatedJobs.add(job);
try (final ZeebeClient client = newZeebeClient(zeebeContainer);
final JobWorker worker = newJobWorker(handler, client)) {
client.newDeployCommand().addProcessModel(process, "process.bpmn").send().join();
client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().send().join();
brokerTime = clock.addTime(TIME_OFFSET);
Awaitility.await("until a job has been activated by the worker").untilAsserted(() -> Assertions.assertThat(activatedJobs).hasSize(1));
}
// then
Assertions.assertThat(activatedJobs).as("the timer event was triggered and a job is now available").hasSize(1);
Assertions.assertThat(brokerTime).as("the modified time is at least equal to one day from now").isAfterOrEqualTo(TIMER_DATE);
}
use of io.camunda.zeebe.client.api.worker.JobHandler in project zeebe by camunda.
the class RollingUpdateTest method shouldPerformRollingUpdate.
@Test
void shouldPerformRollingUpdate() {
// given
cluster.start();
// when
final long firstProcessInstanceKey;
ZeebeGatewayNode<?> availableGateway = cluster.getGateways().get("0");
try (final var client = newZeebeClient(availableGateway)) {
deployProcess(client);
// potentially retry in case we're faster than the deployment distribution
firstProcessInstanceKey = Awaitility.await("process instance creation").atMost(Duration.ofSeconds(5)).pollInterval(Duration.ofMillis(100)).ignoreExceptions().until(() -> createProcessInstance(client), Objects::nonNull).getProcessInstanceKey();
}
for (int i = cluster.getBrokers().size() - 1; i >= 0; i--) {
try (final ZeebeClient client = newZeebeClient(availableGateway)) {
final var brokerId = i;
final ZeebeBrokerNode<?> broker = cluster.getBrokers().get(i);
broker.stop();
Awaitility.await("broker is removed from topology").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> assertTopologyDoesNotContainerBroker(client, brokerId));
updateBroker(broker);
broker.start();
Awaitility.await("updated broker is added to topology").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> assertTopologyContainsUpdatedBroker(client, brokerId));
availableGateway = cluster.getGateways().get(String.valueOf(i));
}
}
// then
final Map<Long, List<String>> activatedJobs = new HashMap<>();
final var expectedOrderedJobs = List.of("firstTask", "secondTask");
final JobHandler jobHandler = (jobClient, job) -> {
jobClient.newCompleteCommand(job.getKey()).send().join();
activatedJobs.compute(job.getProcessInstanceKey(), (ignored, list) -> {
final var appendedList = Optional.ofNullable(list).orElse(new CopyOnWriteArrayList<>());
appendedList.add(job.getType());
return appendedList;
});
};
try (final var client = newZeebeClient(availableGateway)) {
final var secondProcessInstanceKey = createProcessInstance(client).getProcessInstanceKey();
final var expectedActivatedJobs = Map.of(firstProcessInstanceKey, expectedOrderedJobs, secondProcessInstanceKey, expectedOrderedJobs);
client.newWorker().jobType("firstTask").handler(jobHandler).open();
client.newWorker().jobType("secondTask").handler(jobHandler).open();
Awaitility.await("all jobs have been activated").atMost(Duration.ofSeconds(5)).untilAsserted(() -> assertThat(activatedJobs).as("the expected number of jobs has been activated").isEqualTo(expectedActivatedJobs));
}
}
use of io.camunda.zeebe.client.api.worker.JobHandler in project zeebe by camunda.
the class RecordingJobHandler method handle.
@Override
public void handle(final JobClient client, final ActivatedJob job) throws Exception {
final JobHandler handler = jobHandlers[nextJobHandler];
nextJobHandler = Math.min(nextJobHandler + 1, jobHandlers.length - 1);
try {
handler.handle(client, job);
} finally {
handledJobs.add(job);
}
}
use of io.camunda.zeebe.client.api.worker.JobHandler in project zeebe by zeebe-io.
the class QueryApiIT method activateJob.
private ActivatedJob activateJob() {
final List<ActivatedJob> jobs = new CopyOnWriteArrayList<>();
final JobHandler handler = (client, job) -> jobs.add(job);
try (final var client = createZeebeClient("tenantA");
final var worker = client.newWorker().jobType("type").handler(handler).open()) {
client.newCreateInstanceCommand().processDefinitionKey(processDefinitionKey).send().join();
Awaitility.await("until one job is activated").untilAsserted(() -> assertThat(jobs).isNotEmpty());
}
return jobs.get(0);
}
use of io.camunda.zeebe.client.api.worker.JobHandler in project zeebe by zeebe-io.
the class RecordingJobHandler method handle.
@Override
public void handle(final JobClient client, final ActivatedJob job) throws Exception {
final JobHandler handler = jobHandlers[nextJobHandler];
nextJobHandler = Math.min(nextJobHandler + 1, jobHandlers.length - 1);
try {
handler.handle(client, job);
} finally {
handledJobs.add(job);
}
}
Aggregations