Search in sources :

Example 1 with ActivateJobsRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest in project zeebe by camunda.

the class ActivateJobsTest method shouldMapRequestAndResponse.

@Test
public void shouldMapRequestAndResponse() {
    // given
    final ActivateJobsStub stub = new ActivateJobsStub();
    stub.registerWith(brokerClient);
    final String jobType = "testJob";
    final String worker = "testWorker";
    final int maxJobsToActivate = 13;
    final Duration timeout = Duration.ofMinutes(12);
    final List<String> fetchVariables = Arrays.asList("foo", "bar", "baz");
    final ActivateJobsRequest request = ActivateJobsRequest.newBuilder().setType(jobType).setWorker(worker).setMaxJobsToActivate(maxJobsToActivate).setTimeout(timeout.toMillis()).addAllFetchVariable(fetchVariables).build();
    stub.addAvailableJobs(jobType, maxJobsToActivate);
    // when
    final Iterator<ActivateJobsResponse> responses = client.activateJobs(request);
    // then
    assertThat(responses.hasNext()).isTrue();
    final ActivateJobsResponse response = responses.next();
    assertThat(response.getJobsCount()).isEqualTo(maxJobsToActivate);
    for (int i = 0; i < maxJobsToActivate; i++) {
        final ActivatedJob job = response.getJobs(i);
        assertThat(job.getKey()).isEqualTo(Protocol.encodePartitionId(Protocol.START_PARTITION_ID, i));
        assertThat(job.getType()).isEqualTo(jobType);
        assertThat(job.getWorker()).isEqualTo(worker);
        assertThat(job.getRetries()).isEqualTo(stub.getRetries());
        assertThat(job.getDeadline()).isEqualTo(stub.getDeadline());
        assertThat(job.getProcessInstanceKey()).isEqualTo(stub.getProcessInstanceKey());
        assertThat(job.getBpmnProcessId()).isEqualTo(stub.getBpmnProcessId());
        assertThat(job.getProcessDefinitionVersion()).isEqualTo(stub.getProcessDefinitionVersion());
        assertThat(job.getProcessDefinitionKey()).isEqualTo(stub.getProcessDefinitionKey());
        assertThat(job.getElementId()).isEqualTo(stub.getElementId());
        assertThat(job.getElementInstanceKey()).isEqualTo(stub.getElementInstanceKey());
        JsonUtil.assertEquality(job.getCustomHeaders(), stub.getCustomHeaders());
        JsonUtil.assertEquality(job.getVariables(), stub.getVariables());
    }
    final BrokerActivateJobsRequest brokerRequest = brokerClient.getSingleBrokerRequest();
    final JobBatchRecord brokerRequestValue = brokerRequest.getRequestWriter();
    assertThat(brokerRequestValue.getMaxJobsToActivate()).isEqualTo(maxJobsToActivate);
    assertThat(brokerRequestValue.getTypeBuffer()).isEqualTo(wrapString(jobType));
    assertThat(brokerRequestValue.getTimeout()).isEqualTo(timeout.toMillis());
    assertThat(brokerRequestValue.getWorkerBuffer()).isEqualTo(wrapString(worker));
    assertThat(brokerRequestValue.variables()).extracting(v -> BufferUtil.bufferAsString(v.getValue())).containsExactlyInAnyOrderElementsOf(fetchVariables);
}
Also used : ActivatedJob(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob) BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) Protocol(io.camunda.zeebe.protocol.Protocol) Arrays(java.util.Arrays) BrokerRejectionResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejectionResponse) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ActivatedJob(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob) Status(io.grpc.Status) BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) Parameterized(org.junit.runners.Parameterized) Intent(io.camunda.zeebe.protocol.record.intent.Intent) RequestHandler(io.camunda.zeebe.gateway.api.util.StubbedBrokerClient.RequestHandler) Iterator(java.util.Iterator) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) JsonUtil(io.camunda.zeebe.test.util.JsonUtil) Test(org.junit.Test) StatusRuntimeException(io.grpc.StatusRuntimeException) List(java.util.List) ActivateJobsResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord) BrokerRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest) BufferUtil(io.camunda.zeebe.util.buffer.BufferUtil) BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) ActivateJobsResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse) Duration(java.time.Duration) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) Test(org.junit.Test)

Example 2 with ActivateJobsRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest in project zeebe by camunda.

the class ActivateJobsTest method shouldActivateJobsRoundRobin.

@Test
public void shouldActivateJobsRoundRobin() {
    // given
    final ActivateJobsStub stub = new ActivateJobsStub();
    stub.registerWith(brokerClient);
    final String type = "test";
    final int maxJobsToActivate = 2;
    final ActivateJobsRequest request = ActivateJobsRequest.newBuilder().setType(type).setMaxJobsToActivate(maxJobsToActivate).build();
    for (int partitionOffset = 0; partitionOffset < 3; partitionOffset++) {
        stub.addAvailableJobs(type, maxJobsToActivate);
        // when
        final Iterator<ActivateJobsResponse> responses = client.activateJobs(request);
        // then
        assertThat(responses.hasNext()).isTrue();
        final ActivateJobsResponse response = responses.next();
        for (final ActivatedJob activatedJob : response.getJobsList()) {
            assertThat(Protocol.decodePartitionId(activatedJob.getKey())).isEqualTo(Protocol.START_PARTITION_ID + partitionOffset);
        }
    }
}
Also used : ActivatedJob(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob) BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) ActivateJobsResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) Test(org.junit.Test)

Example 3 with ActivateJobsRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest in project zeebe by camunda.

the class ActivateJobsTest method shouldSetFetchVariablesAsVargs.

@Test
public void shouldSetFetchVariablesAsVargs() {
    // given
    final String[] fetchVariables = new String[] { "foo", "bar", "baz" };
    // when
    client.newActivateJobsCommand().jobType("foo").maxJobsToActivate(3).fetchVariables(fetchVariables).send().join();
    // then
    final ActivateJobsRequest request = gatewayService.getLastRequest();
    assertThat(request.getFetchVariableList()).containsExactlyInAnyOrder(fetchVariables);
}
Also used : ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 4 with ActivateJobsRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest in project zeebe by camunda.

the class ActivateJobsTest method shouldSetDefaultValues.

@Test
public void shouldSetDefaultValues() {
    // when
    client.newActivateJobsCommand().jobType("foo").maxJobsToActivate(3).send().join();
    // then
    final ActivateJobsRequest request = gatewayService.getLastRequest();
    assertThat(request.getTimeout()).isEqualTo(client.getConfiguration().getDefaultJobTimeout().toMillis());
    assertThat(request.getWorker()).isEqualTo(client.getConfiguration().getDefaultJobWorkerName());
    assertThat(request.getRequestTimeout()).isEqualTo(client.getConfiguration().getDefaultRequestTimeout().toMillis());
}
Also used : ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 5 with ActivateJobsRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest 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)

Aggregations

ActivateJobsRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest)36 Test (org.junit.Test)33 ClientTest (io.camunda.zeebe.client.util.ClientTest)18 ActivateJobsResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse)15 Duration (java.time.Duration)15 GatewayTest (io.camunda.zeebe.gateway.api.util.GatewayTest)12 BrokerActivateJobsRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest)12 ActivatedJob (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob)12 BufferUtil.wrapString (io.camunda.zeebe.util.buffer.BufferUtil.wrapString)9 ActivateJobsResponse (io.camunda.zeebe.client.api.response.ActivateJobsResponse)6 RequestHandler (io.camunda.zeebe.gateway.api.util.StubbedBrokerClient.RequestHandler)6 BrokerRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest)6 BrokerRejection (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection)6 BrokerRejectionResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejectionResponse)6 BrokerResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse)6 GatewayCfg (io.camunda.zeebe.gateway.impl.configuration.GatewayCfg)6 Protocol (io.camunda.zeebe.protocol.Protocol)6 JobBatchRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)6 RejectionType (io.camunda.zeebe.protocol.record.RejectionType)6 Intent (io.camunda.zeebe.protocol.record.intent.Intent)6