Search in sources :

Example 26 with ActivatedJob

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();
        });
    });
}
Also used : PartitionBrokerRole(io.camunda.zeebe.client.api.response.PartitionBrokerRole) TimerIntent(io.camunda.zeebe.protocol.record.intent.TimerIntent) BeforeEach(org.junit.jupiter.api.BeforeEach) RecordType(io.camunda.zeebe.protocol.record.RecordType) ClientException(io.camunda.zeebe.client.api.command.ClientException) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) TimerRecordValue(io.camunda.zeebe.protocol.record.value.TimerRecordValue) ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) Record(io.camunda.zeebe.protocol.record.Record) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PartitionInfo(io.camunda.zeebe.client.api.response.PartitionInfo) Duration(java.time.Duration) Map(java.util.Map) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) Process(io.camunda.zeebe.client.api.response.Process) ProcessInstanceResult(io.camunda.zeebe.client.api.response.ProcessInstanceResult) StreamSupport(java.util.stream.StreamSupport) PartitionBrokerHealth(io.camunda.zeebe.client.api.response.PartitionBrokerHealth) VersionUtil(io.camunda.zeebe.util.VersionUtil) Topology(io.camunda.zeebe.client.api.response.Topology) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) ZeebeFuture(io.camunda.zeebe.client.api.ZeebeFuture) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) Optional(java.util.Optional) ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse) Awaitility(org.awaitility.Awaitility) RecordStream(io.camunda.zeebe.process.test.filters.RecordStream) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse) Record(io.camunda.zeebe.protocol.record.Record) Test(org.junit.jupiter.api.Test)

Example 27 with ActivatedJob

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

Example 28 with ActivatedJob

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

Example 29 with ActivatedJob

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));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) Test(org.junit.Test) BrokerClassRuleHelper(io.camunda.zeebe.test.util.BrokerClassRuleHelper) Instant(java.time.Instant) Assertions.entry(org.assertj.core.api.Assertions.entry) RuleChain(org.junit.rules.RuleChain) List(java.util.List) Rule(org.junit.Rule) GrpcClientRule(io.camunda.zeebe.it.util.GrpcClientRule) RecordingJobHandler(io.camunda.zeebe.it.util.RecordingJobHandler) TestUtil.waitUntil(io.camunda.zeebe.test.util.TestUtil.waitUntil) EmbeddedBrokerRule(io.camunda.zeebe.broker.test.EmbeddedBrokerRule) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) ClassRule(org.junit.ClassRule) Before(org.junit.Before) RecordingJobHandler(io.camunda.zeebe.it.util.RecordingJobHandler) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) Test(org.junit.Test)

Example 30 with ActivatedJob

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);
}
Also used : ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) TestAuthorizationClientInterceptor(io.camunda.zeebe.it.queryapi.util.TestAuthorizationClientInterceptor) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ByteBuddy(net.bytebuddy.ByteBuddy) ZeebeContainer(io.zeebe.containers.ZeebeContainer) LoggerFactory(org.slf4j.LoggerFactory) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) CompleteJobResponse(io.camunda.zeebe.client.api.response.CompleteJobResponse) Future(java.util.concurrent.Future) TestAuthorizationServerInterceptor(io.camunda.zeebe.it.queryapi.util.TestAuthorizationServerInterceptor) BeforeAll(org.junit.jupiter.api.BeforeAll) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Duration(java.time.Duration) Map(java.util.Map) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Container(org.testcontainers.junit.jupiter.Container) Logger(org.slf4j.Logger) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) Files(java.nio.file.Files) TestAuthorizationListener(io.camunda.zeebe.it.queryapi.util.TestAuthorizationListener) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) CloseAwareListener(io.camunda.zeebe.test.util.grpc.CloseAwareListener) IOException(java.io.IOException) ContainerLogsDumper(io.camunda.zeebe.test.util.testcontainers.ContainerLogsDumper) File(java.io.File) StatusRuntimeException(io.grpc.StatusRuntimeException) UncheckedIOException(java.io.UncheckedIOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) List(java.util.List) ZeebeTestContainerDefaults(io.camunda.zeebe.test.util.testcontainers.ZeebeTestContainerDefaults) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) MountableFile(org.testcontainers.utility.MountableFile) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) Awaitility(org.awaitility.Awaitility) CancelProcessInstanceResponse(io.camunda.zeebe.client.api.response.CancelProcessInstanceResponse) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

ActivatedJob (io.camunda.zeebe.client.api.response.ActivatedJob)46 Test (org.junit.Test)27 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)16 List (java.util.List)16 Test (org.junit.jupiter.api.Test)16 BrokerInfo (io.camunda.zeebe.client.api.response.BrokerInfo)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 ZeebeClient (io.camunda.zeebe.client.ZeebeClient)13 Duration (java.time.Duration)13 Awaitility (org.awaitility.Awaitility)13 ProcessInstanceEvent (io.camunda.zeebe.client.api.response.ProcessInstanceEvent)12 Map (java.util.Map)11 ActivateJobsResponse (io.camunda.zeebe.client.api.response.ActivateJobsResponse)9 DeploymentEvent (io.camunda.zeebe.client.api.response.DeploymentEvent)9 ZeebeFuture (io.camunda.zeebe.client.api.ZeebeFuture)8 ClientException (io.camunda.zeebe.client.api.command.ClientException)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