use of io.camunda.zeebe.client.api.response.ActivatedJob 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.response.ActivatedJob in project spring-zeebe by camunda-community-hub.
the class JobHandlerInvokingSpringBeans method createParameters.
private List<Object> createParameters(JobClient jobClient, ActivatedJob job, List<ParameterInfo> parameters) {
List<Object> args = new ArrayList<>();
for (ParameterInfo param : parameters) {
// parameter default null
Object arg = null;
Class<?> clazz = param.getParameterInfo().getType();
if (JobClient.class.isAssignableFrom(clazz)) {
arg = jobClient;
} else if (ActivatedJob.class.isAssignableFrom(clazz)) {
arg = job;
} else if (param.getParameterInfo().isAnnotationPresent(ZeebeVariable.class)) {
try {
// TODO make this work for complex types as well
arg = clazz.cast(job.getVariablesAsMap().get(param.getParameterName()));
} catch (ClassCastException ex) {
throw new RuntimeException("Cannot assign process variable '" + param.getParameterName() + "' to parameter when executing job '" + job.getType() + "', invalid type found: " + ex.getMessage());
}
} else if (param.getParameterInfo().isAnnotationPresent(ZeebeVariablesAsType.class)) {
try {
arg = job.getVariablesAsType(clazz);
} catch (RuntimeException e) {
throw new RuntimeException("Cannot assign process variables to type '" + clazz.getName() + "' when executing job '" + job.getType() + "', cause is: " + e.getMessage(), e);
}
} else if (param.getParameterInfo().isAnnotationPresent(ZeebeCustomHeaders.class)) {
try {
arg = job.getCustomHeaders();
} catch (RuntimeException e) {
throw new RuntimeException("Cannot assign headers '" + param.getParameterName() + "' to parameter when executing job '" + job.getType() + "', cause is: " + e.getMessage(), e);
}
}
args.add(arg);
}
return args;
}
use of io.camunda.zeebe.client.api.response.ActivatedJob in project micronaut-zeebe-client by camunda-community-hub.
the class ProcessTest method workerShouldProcessWork.
@Test
void workerShouldProcessWork() {
// Deploy process model
DeploymentEvent deploymentEvent = client.newDeployCommand().addResourceFromClasspath("bpmn/say_hello.bpmn").send().join();
BpmnAssert.assertThat(deploymentEvent);
// Start process instance
ProcessInstanceEvent event = client.newCreateInstanceCommand().bpmnProcessId("Process_SayHello").latestVersion().send().join();
engine.waitForIdleState();
// Verify that process has started
ProcessInstanceAssert processInstanceAssertions = BpmnAssert.assertThat(event);
processInstanceAssertions.hasPassedElement("start");
processInstanceAssertions.isWaitingAtElement("say_hello");
// Fetch job: say-hello
ActivateJobsResponse response = client.newActivateJobsCommand().jobType("say-hello").maxJobsToActivate(1).send().join();
// Complete job: say-hello
ActivatedJob activatedJob = response.getJobs().get(0);
client.newCompleteCommand(activatedJob.getKey()).send().join();
engine.waitForIdleState();
// Fetch job: say-goodbye
response = client.newActivateJobsCommand().jobType("say-goodbye").maxJobsToActivate(1).send().join();
// Complete job: say-goodbye
activatedJob = response.getJobs().get(0);
client.newCompleteCommand(activatedJob.getKey()).send().join();
engine.waitForIdleState();
// Verify completed
engine.waitForIdleState();
processInstanceAssertions.isCompleted();
}
use of io.camunda.zeebe.client.api.response.ActivatedJob 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.client.api.response.ActivatedJob in project zeebe by camunda.
the class AvailabilityTest method shouldActivateJobsRoundRobinWhenOnePartitionDown.
@Test
public void shouldActivateJobsRoundRobinWhenOnePartitionDown() {
// 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
Awaitility.await().until(() -> RecordingExporter.jobRecords(JobIntent.CREATED).limit(numInstances).count() == numInstances);
final Set<Long> activatedJobsKey = new HashSet<>();
final List<ActivatedJob> jobs = clientRule.getClient().newActivateJobsCommand().jobType(JOBTYPE).maxJobsToActivate(2 * numInstances).timeout(Duration.ofMinutes(5)).send().join().getJobs();
jobs.forEach(job -> activatedJobsKey.add(job.getKey()));
// then
assertThat(activatedJobsKey).hasSize(numInstances);
}
Aggregations