use of io.camunda.zeebe.client.api.response.ActivateJobsResponse 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.ActivateJobsResponse in project zeebe by camunda.
the class CreateProcessInstanceWithResultTest method completeJobWithVariables.
private void completeJobWithVariables(final Map<String, Object> variables) {
waitUntil(() -> RecordingExporter.jobRecords(JobIntent.CREATED).withType(jobType).exists());
final ActivateJobsResponse response = CLIENT_RULE.getClient().newActivateJobsCommand().jobType(jobType).maxJobsToActivate(1).send().join();
// when
CLIENT_RULE.getClient().newCompleteCommand(response.getJobs().iterator().next().getKey()).variables(variables).send();
}
use of io.camunda.zeebe.client.api.response.ActivateJobsResponse in project zeebe by camunda.
the class ActivateJobsTest method shouldRespondActivatedJobsWhenJobsAreAvailable.
@Test(timeout = 5000)
public void shouldRespondActivatedJobsWhenJobsAreAvailable() {
// given
CLIENT_RULE.createJobs(jobType, 2);
// when
final ZeebeFuture<ActivateJobsResponse> responseFuture = CLIENT_RULE.getClient().newActivateJobsCommand().jobType(jobType).maxJobsToActivate(2).send();
// then
final ActivateJobsResponse response = responseFuture.join();
assertThat(response.getJobs()).hasSize(2);
}
use of io.camunda.zeebe.client.api.response.ActivateJobsResponse in project zeebe by camunda.
the class ActivateJobsTest method shouldActivateJobs.
@Test
public void shouldActivateJobs() {
// given
final ActivatedJob activatedJob1 = ActivatedJob.newBuilder().setKey(12).setType("foo").setProcessInstanceKey(123).setBpmnProcessId("test1").setProcessDefinitionVersion(2).setProcessDefinitionKey(23).setElementId("foo").setElementInstanceKey(23213).setCustomHeaders("{\"version\": \"1\"}").setWorker("worker1").setRetries(34).setDeadline(1231).setVariables("{\"key\": \"val\"}").build();
final ActivatedJob activatedJob2 = ActivatedJob.newBuilder().setKey(42).setType("foo").setProcessInstanceKey(333).setBpmnProcessId("test3").setProcessDefinitionVersion(23).setProcessDefinitionKey(11).setElementId("bar").setElementInstanceKey(111).setCustomHeaders("{\"key\": \"value\"}").setWorker("worker1").setRetries(334).setDeadline(3131).setVariables("{\"bar\": 3}").build();
gatewayService.onActivateJobsRequest(activatedJob1, activatedJob2);
// when
final ActivateJobsResponse response = client.newActivateJobsCommand().jobType("foo").maxJobsToActivate(3).timeout(Duration.ofMillis(1000)).workerName("worker1").send().join();
// then
assertThat(response.getJobs()).hasSize(2);
io.camunda.zeebe.client.api.response.ActivatedJob job = response.getJobs().get(0);
assertThat(job.getKey()).isEqualTo(activatedJob1.getKey());
assertThat(job.getType()).isEqualTo(activatedJob1.getType());
assertThat(job.getBpmnProcessId()).isEqualTo(activatedJob1.getBpmnProcessId());
assertThat(job.getElementId()).isEqualTo(activatedJob1.getElementId());
assertThat(job.getElementInstanceKey()).isEqualTo(activatedJob1.getElementInstanceKey());
assertThat(job.getProcessDefinitionVersion()).isEqualTo(activatedJob1.getProcessDefinitionVersion());
assertThat(job.getProcessDefinitionKey()).isEqualTo(activatedJob1.getProcessDefinitionKey());
assertThat(job.getProcessInstanceKey()).isEqualTo(activatedJob1.getProcessInstanceKey());
assertThat(job.getCustomHeaders()).isEqualTo(fromJsonAsMap(activatedJob1.getCustomHeaders()));
assertThat(job.getWorker()).isEqualTo(activatedJob1.getWorker());
assertThat(job.getRetries()).isEqualTo(activatedJob1.getRetries());
assertThat(job.getDeadline()).isEqualTo(activatedJob1.getDeadline());
assertThat(job.getVariables()).isEqualTo(activatedJob1.getVariables());
job = response.getJobs().get(1);
assertThat(job.getKey()).isEqualTo(activatedJob2.getKey());
assertThat(job.getType()).isEqualTo(activatedJob2.getType());
assertThat(job.getBpmnProcessId()).isEqualTo(activatedJob2.getBpmnProcessId());
assertThat(job.getElementId()).isEqualTo(activatedJob2.getElementId());
assertThat(job.getElementInstanceKey()).isEqualTo(activatedJob2.getElementInstanceKey());
assertThat(job.getProcessDefinitionVersion()).isEqualTo(activatedJob2.getProcessDefinitionVersion());
assertThat(job.getProcessDefinitionKey()).isEqualTo(activatedJob2.getProcessDefinitionKey());
assertThat(job.getProcessInstanceKey()).isEqualTo(activatedJob2.getProcessInstanceKey());
assertThat(job.getCustomHeaders()).isEqualTo(fromJsonAsMap(activatedJob2.getCustomHeaders()));
assertThat(job.getWorker()).isEqualTo(activatedJob2.getWorker());
assertThat(job.getRetries()).isEqualTo(activatedJob2.getRetries());
assertThat(job.getDeadline()).isEqualTo(activatedJob2.getDeadline());
assertThat(job.getVariables()).isEqualTo(activatedJob2.getVariables());
final ActivateJobsRequest request = gatewayService.getLastRequest();
assertThat(request.getType()).isEqualTo("foo");
assertThat(request.getMaxJobsToActivate()).isEqualTo(3);
assertThat(request.getTimeout()).isEqualTo(1000);
assertThat(request.getWorker()).isEqualTo("worker1");
}
use of io.camunda.zeebe.client.api.response.ActivateJobsResponse in project zeebe by camunda.
the class UpdateTestCaseProvider method activateJob.
private long activateJob(final ContainerState state) {
awaitElementInState(state, JOB, "CREATED");
final ActivateJobsResponse jobsResponse = state.client().newActivateJobsCommand().jobType(TASK).maxJobsToActivate(1).send().join();
assertThat(jobsResponse.getJobs()).hasSize(1);
awaitElementInState(state, JOB, "ACTIVATED");
return jobsResponse.getJobs().get(0).getKey();
}
Aggregations