Search in sources :

Example 1 with RecordingJobHandler

use of io.camunda.zeebe.it.util.RecordingJobHandler in project zeebe by camunda.

the class JobWorkerTest method shouldActivateJobsOfDifferentTypes.

@Test
public void shouldActivateJobsOfDifferentTypes() {
    // given
    final long jobX = CLIENT_RULE.createSingleJob(jobType + "x");
    final long jobY = CLIENT_RULE.createSingleJob(jobType + "y");
    // when
    final RecordingJobHandler jobHandlerX = new RecordingJobHandler();
    final RecordingJobHandler jobHandlerY = new RecordingJobHandler();
    CLIENT_RULE.getClient().newWorker().jobType(jobType + "x").handler(jobHandlerX).open();
    CLIENT_RULE.getClient().newWorker().jobType(jobType + "y").handler(jobHandlerY).open();
    waitUntil(() -> jobHandlerX.getHandledJobs().size() >= 1);
    waitUntil(() -> jobHandlerY.getHandledJobs().size() >= 1);
    // then
    assertThat(jobHandlerX.getHandledJobs()).hasSize(1).extracting(ActivatedJob::getKey).contains(jobX);
    assertThat(jobHandlerY.getHandledJobs()).hasSize(1).extracting(ActivatedJob::getKey).contains(jobY);
}
Also used : RecordingJobHandler(io.camunda.zeebe.it.util.RecordingJobHandler) Test(org.junit.Test)

Example 2 with RecordingJobHandler

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

Example 3 with RecordingJobHandler

use of io.camunda.zeebe.it.util.RecordingJobHandler in project zeebe by camunda.

the class MultipleClientTest method shouldOpenJobWorkerForDifferentTypes.

@Test
public void shouldOpenJobWorkerForDifferentTypes() {
    // given
    final RecordingJobHandler handler1 = new RecordingJobHandler();
    final RecordingJobHandler handler2 = new RecordingJobHandler();
    client1.getClient().newWorker().jobType("foo").handler(handler1).open();
    client2.getClient().newWorker().jobType("bar").handler(handler2).open();
    // when
    final long job1Key = client1.createSingleJob("foo");
    final long job2Key = client1.createSingleJob("bar");
    // then
    waitUntil(() -> handler1.getHandledJobs().size() + handler2.getHandledJobs().size() >= 2);
    assertThat(handler1.getHandledJobs()).hasSize(1);
    assertThat(handler1.getHandledJobs().get(0).getKey()).isEqualTo(job1Key);
    assertThat(handler2.getHandledJobs()).hasSize(1);
    assertThat(handler2.getHandledJobs().get(0).getKey()).isEqualTo(job2Key);
}
Also used : RecordingJobHandler(io.camunda.zeebe.it.util.RecordingJobHandler) Test(org.junit.Test)

Example 4 with RecordingJobHandler

use of io.camunda.zeebe.it.util.RecordingJobHandler in project zeebe by zeebe-io.

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

Example 5 with RecordingJobHandler

use of io.camunda.zeebe.it.util.RecordingJobHandler in project zeebe by zeebe-io.

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)

Aggregations

RecordingJobHandler (io.camunda.zeebe.it.util.RecordingJobHandler)18 Test (org.junit.Test)15 ActivatedJob (io.camunda.zeebe.client.api.response.ActivatedJob)9 Before (org.junit.Before)6 EmbeddedBrokerRule (io.camunda.zeebe.broker.test.EmbeddedBrokerRule)3 GrpcClientRule (io.camunda.zeebe.it.util.GrpcClientRule)3 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)3 BrokerClassRuleHelper (io.camunda.zeebe.test.util.BrokerClassRuleHelper)3 TestUtil.waitUntil (io.camunda.zeebe.test.util.TestUtil.waitUntil)3 Instant (java.time.Instant)3 List (java.util.List)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.entry (org.assertj.core.api.Assertions.entry)3 ClassRule (org.junit.ClassRule)3 Rule (org.junit.Rule)3 RuleChain (org.junit.rules.RuleChain)3