Search in sources :

Example 1 with ActivateJobsResponse

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();
}
Also used : ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) ProcessInstanceAssert(io.camunda.zeebe.process.test.assertions.ProcessInstanceAssert) ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) Test(org.junit.jupiter.api.Test) ZeebeProcessTest(io.camunda.zeebe.process.test.extensions.ZeebeProcessTest)

Example 2 with ActivateJobsResponse

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();
}
Also used : ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse)

Example 3 with ActivateJobsResponse

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);
}
Also used : ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse) Test(org.junit.Test)

Example 4 with ActivateJobsResponse

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");
}
Also used : ActivatedJob(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob) ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 5 with ActivateJobsResponse

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();
}
Also used : ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse)

Aggregations

ActivateJobsResponse (io.camunda.zeebe.client.api.response.ActivateJobsResponse)39 Test (org.junit.Test)18 ActivatedJob (io.camunda.zeebe.client.api.response.ActivatedJob)9 DeploymentEvent (io.camunda.zeebe.client.api.response.DeploymentEvent)9 ProcessInstanceEvent (io.camunda.zeebe.client.api.response.ProcessInstanceEvent)9 ZeebeClient (io.camunda.zeebe.client.ZeebeClient)8 ZeebeFuture (io.camunda.zeebe.client.api.ZeebeFuture)8 ClientException (io.camunda.zeebe.client.api.command.ClientException)8 BrokerInfo (io.camunda.zeebe.client.api.response.BrokerInfo)8 PartitionBrokerHealth (io.camunda.zeebe.client.api.response.PartitionBrokerHealth)8 PartitionBrokerRole (io.camunda.zeebe.client.api.response.PartitionBrokerRole)8 PartitionInfo (io.camunda.zeebe.client.api.response.PartitionInfo)8 Process (io.camunda.zeebe.client.api.response.Process)8 ProcessInstanceResult (io.camunda.zeebe.client.api.response.ProcessInstanceResult)8 SetVariablesResponse (io.camunda.zeebe.client.api.response.SetVariablesResponse)8 Topology (io.camunda.zeebe.client.api.response.Topology)8 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)8 ZeebeTestEngine (io.camunda.zeebe.process.test.api.ZeebeTestEngine)8 RecordStream (io.camunda.zeebe.process.test.filters.RecordStream)8 Record (io.camunda.zeebe.protocol.record.Record)8