Search in sources :

Example 11 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldGiveTaskToSingleSubscription.

@Test
public void shouldGiveTaskToSingleSubscription() {
    // given
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler((c, t) -> c.complete(t).withoutPayload().execute());
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofHours(1)).lockOwner("test").handler(taskHandler).open();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofHours(2)).lockOwner("test").handler(taskHandler).open();
    // when
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    waitUntil(() -> taskHandler.getHandledTasks().size() == 1);
    // then
    assertThat(taskHandler.getHandledTasks()).hasSize(1);
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) Test(org.junit.Test)

Example 12 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldSubscribeToMultipleTypes.

@Test
public void shouldSubscribeToMultipleTypes() throws InterruptedException {
    // given
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    clientRule.tasks().create(clientRule.getDefaultTopic(), "bar").execute();
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("bar").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    waitUntil(() -> taskHandler.getHandledTasks().size() == 2);
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) Test(org.junit.Test)

Example 13 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldHandleMoreTasksThanPrefetchCapacity.

@Test
public void shouldHandleMoreTasksThanPrefetchCapacity() {
    // given
    final int subscriptionCapacity = 16;
    for (int i = 0; i < subscriptionCapacity + 1; i++) {
        clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").addCustomHeader("key", "value").payload("{}").execute();
    }
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler();
    // when
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    // then
    TestUtil.waitUntil(() -> taskHandler.getHandledTasks().size() > subscriptionCapacity);
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) Test(org.junit.Test)

Example 14 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class ServiceTaskTest method shouldMapPayloadIntoTask.

@Test
public void shouldMapPayloadIntoTask() {
    // given
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(Bpmn.createExecutableWorkflow("process").startEvent("start").serviceTask("task", t -> t.taskType("foo").input("$.foo", "$.bar")).endEvent("end").done(), "workflow.bpmn").execute();
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("process").payload("{\"foo\":1}").execute();
    // when
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> recordingTaskHandler.getHandledTasks().size() >= 1);
    final TaskEvent taskLockedEvent = recordingTaskHandler.getHandledTasks().get(0);
    assertThat(taskLockedEvent.getPayload()).isEqualTo("{\"bar\":1}");
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent)

Example 15 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class ServiceTaskTest method shouldLockServiceTask.

@Test
public void shouldLockServiceTask() {
    // given
    final Map<String, String> taskHeaders = new HashMap<>();
    taskHeaders.put("cust1", "a");
    taskHeaders.put("cust2", "b");
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(Bpmn.createExecutableWorkflow("process").startEvent("start").serviceTask("task", t -> t.taskType("foo").taskHeader("cust1", "a").taskHeader("cust2", "b")).endEvent("end").done(), "workflow.bpmn").execute();
    final WorkflowInstanceEvent workflowInstance = workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    // when
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> recordingTaskHandler.getHandledTasks().size() >= 1);
    assertThat(recordingTaskHandler.getHandledTasks()).hasSize(1);
    final WorkflowInstanceEvent activityInstance = eventRecorder.getSingleWorkflowInstanceEvent(e -> "ACTIVITY_ACTIVATED".equals(e.getState()));
    final TaskEvent taskLockedEvent = recordingTaskHandler.getHandledTasks().get(0);
    assertThat(taskLockedEvent.getHeaders()).containsOnly(entry("bpmnProcessId", "process"), entry("workflowDefinitionVersion", 1), entry("workflowKey", workflowInstance.getWorkflowKey()), entry("workflowInstanceKey", workflowInstance.getWorkflowInstanceKey()), entry("activityId", "task"), entry("activityInstanceKey", activityInstance.getMetadata().getKey()));
    assertThat(taskLockedEvent.getCustomHeaders()).containsOnly(entry("cust1", "a"), entry("cust2", "b"));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) HashMap(java.util.HashMap) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) TaskEvent(io.zeebe.client.event.TaskEvent)

Aggregations

RecordingTaskHandler (io.zeebe.broker.it.util.RecordingTaskHandler)27 Test (org.junit.Test)23 TaskEvent (io.zeebe.client.event.TaskEvent)19 PollableTaskSubscription (io.zeebe.client.task.PollableTaskSubscription)3 TaskSubscription (io.zeebe.client.task.TaskSubscription)3 WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)2 ClientRule (io.zeebe.broker.it.ClientRule)1 EmbeddedBrokerRule (io.zeebe.broker.it.EmbeddedBrokerRule)1 TopicEventRecorder (io.zeebe.broker.it.util.TopicEventRecorder)1 TopicEventRecorder.taskEvent (io.zeebe.broker.it.util.TopicEventRecorder.taskEvent)1 TopicEventRecorder.taskRetries (io.zeebe.broker.it.util.TopicEventRecorder.taskRetries)1 ZeebeClient (io.zeebe.client.ZeebeClient)1 CreateTaskCommandImpl (io.zeebe.client.task.impl.CreateTaskCommandImpl)1 Topic (io.zeebe.client.topic.Topic)1 Topics (io.zeebe.client.topic.Topics)1 TestUtil (io.zeebe.test.util.TestUtil)1 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)1 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1