use of io.camunda.zeebe.client.api.response.ActivatedJob in project zeebe-process-test by camunda-cloud.
the class EngineClientTest method shouldUpdateRetiresOnJob.
@Test
void shouldUpdateRetiresOnJob() {
// given
zeebeClient.newDeployCommand().addProcessModel(Bpmn.createExecutableProcess("simpleProcess").startEvent().serviceTask("task", (task) -> task.zeebeJobType("jobType")).endEvent().done(), "simpleProcess.bpmn").send().join();
zeebeClient.newCreateInstanceCommand().bpmnProcessId("simpleProcess").latestVersion().variables(Map.of("test", 1)).send().join();
Awaitility.await().untilAsserted(() -> {
final ActivateJobsResponse activateJobsResponse = zeebeClient.newActivateJobsCommand().jobType("jobType").maxJobsToActivate(32).timeout(Duration.ofMinutes(1)).workerName("yolo").fetchVariables(List.of("test")).send().join();
final List<ActivatedJob> jobs = activateJobsResponse.getJobs();
assertThat(jobs).isNotEmpty();
final ActivatedJob job = jobs.get(0);
// when - then
zeebeClient.newUpdateRetriesCommand(job.getKey()).retries(3).send().join();
Awaitility.await().untilAsserted(() -> {
final Optional<Record<JobRecordValue>> retriesUpdated = StreamSupport.stream(RecordStream.of(zeebeEngine.getRecordStreamSource()).jobRecords().spliterator(), false).filter(r -> r.getKey() == job.getKey()).filter(r -> r.getIntent() == JobIntent.RETRIES_UPDATED).findFirst();
assertThat(retriesUpdated).isNotEmpty();
});
});
}
use of io.camunda.zeebe.client.api.response.ActivatedJob in project zeebe by camunda-cloud.
the class AvailabilityTest method shouldActivateJobsWhenOnePartitionDown.
@Test
public void shouldActivateJobsWhenOnePartitionDown() {
// given
final int numInstances = 2 * partitionCount;
final BrokerInfo leaderForPartition = clusteringRule.getLeaderForPartition(partitionCount);
clusteringRule.stopBroker(leaderForPartition.getNodeId());
for (int i = 0; i < numInstances; i++) {
clientRule.createProcessInstance(processDefinitionKey);
}
// when
final Set<Long> activatedJobsKey = new HashSet<>();
for (int i = 0; i < numInstances; i++) {
final List<ActivatedJob> jobs = clientRule.getClient().newActivateJobsCommand().jobType(JOBTYPE).maxJobsToActivate(1).timeout(Duration.ofMinutes(5)).requestTimeout(Duration.ofSeconds(// put a lower timeout than gateway timeout to ensure that the test fails
5)).send().join().getJobs();
jobs.forEach(job -> activatedJobsKey.add(job.getKey()));
}
// then
assertThat(activatedJobsKey).hasSize(numInstances);
}
use of io.camunda.zeebe.client.api.response.ActivatedJob in project zeebe by camunda-cloud.
the class JobWorkerTest method shouldFetchOnlySpecifiedVariables.
@Test
public void shouldFetchOnlySpecifiedVariables() {
// given
CLIENT_RULE.createSingleJob(jobType, b -> {
}, "{\"a\":1, \"b\":2, \"c\":3,\"d\":4}");
// when
final List<String> fetchVariables = List.of("a", "b");
final RecordingJobHandler jobHandler = new RecordingJobHandler();
CLIENT_RULE.getClient().newWorker().jobType(jobType).handler(jobHandler).fetchVariables(fetchVariables).open();
waitUntil(() -> jobHandler.getHandledJobs().size() >= 1);
// then
final ActivatedJob job = jobHandler.getHandledJobs().get(0);
assertThat(job.getVariablesAsMap().keySet()).containsOnlyElementsOf(fetchVariables);
}
use of io.camunda.zeebe.client.api.response.ActivatedJob in project zeebe by camunda-cloud.
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));
}
use of io.camunda.zeebe.client.api.response.ActivatedJob in project zeebe by camunda-cloud.
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);
}
Aggregations