Search in sources :

Example 21 with RecordingTaskHandler

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

the class TaskSubscriptionTest method shouldReceiveTasksFromMultiplePartitions.

@Test
public void shouldReceiveTasksFromMultiplePartitions() {
    // given
    final String topicName = "gyros";
    final int numPartitions = 2;
    final ZeebeClient client = clientRule.getClient();
    client.topics().create(topicName, numPartitions).execute();
    final Topics topics = client.topics().getTopics().execute();
    final Topic topic = topics.getTopics().stream().filter(t -> t.getName().equals(topicName)).findFirst().get();
    final Integer[] partitionIds = topic.getPartitions().stream().mapToInt(p -> p.getId()).boxed().toArray(Integer[]::new);
    final String taskType = "foooo";
    final RecordingTaskHandler handler = new RecordingTaskHandler();
    createTaskOnPartition(client, topicName, partitionIds[0], taskType);
    createTaskOnPartition(client, topicName, partitionIds[1], taskType);
    // when
    client.tasks().newTaskSubscription(topicName).handler(handler).lockOwner("foo").lockTime(Duration.ofSeconds(30)).taskType(taskType).open();
    // then
    waitUntil(() -> handler.getHandledTasks().size() == 2);
    final Integer[] receivedPartitionIds = handler.getHandledTasks().stream().map(t -> t.getMetadata().getPartitionId()).toArray(Integer[]::new);
    assertThat(receivedPartitionIds).containsExactlyInAnyOrder(partitionIds);
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskSubscription(io.zeebe.client.task.TaskSubscription) Test(org.junit.Test) TopicEventRecorder.taskEvent(io.zeebe.broker.it.util.TopicEventRecorder.taskEvent) Instant(java.time.Instant) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) TopicEventRecorder(io.zeebe.broker.it.util.TopicEventRecorder) ZeebeClient(io.zeebe.client.ZeebeClient) List(java.util.List) ClientRule(io.zeebe.broker.it.ClientRule) org.junit.rules(org.junit.rules) TopicEventRecorder.taskRetries(io.zeebe.broker.it.util.TopicEventRecorder.taskRetries) Rule(org.junit.Rule) Duration(java.time.Duration) CreateTaskCommandImpl(io.zeebe.client.task.impl.CreateTaskCommandImpl) Topic(io.zeebe.client.topic.Topic) EmbeddedBrokerRule(io.zeebe.broker.it.EmbeddedBrokerRule) Topics(io.zeebe.client.topic.Topics) TestUtil(io.zeebe.test.util.TestUtil) Topics(io.zeebe.client.topic.Topics) RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) ZeebeClient(io.zeebe.client.ZeebeClient) Topic(io.zeebe.client.topic.Topic) Test(org.junit.Test)

Example 22 with RecordingTaskHandler

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

the class TaskSubscriptionTest method shouldExpireTaskLock.

@Test
public void shouldExpireTaskLock() {
    // given
    eventRecorder.startRecordingEvents();
    final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler((c, t) -> {
    // don't complete the task - just wait for lock expiration
    });
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    waitUntil(() -> taskHandler.getHandledTasks().size() == 1);
    // then
    doRepeatedly(() -> brokerRule.getClock().addTime(Duration.ofMinutes(5))).until((v) -> taskHandler.getHandledTasks().size() == 2);
    final long taskKey = task.getMetadata().getKey();
    assertThat(taskHandler.getHandledTasks()).hasSize(2).extracting("metadata.key").containsExactly(taskKey, taskKey);
    assertThat(eventRecorder.hasTaskEvent(taskEvent("LOCK_EXPIRED"))).isTrue();
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 23 with RecordingTaskHandler

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

the class TaskSubscriptionTest method shouldFetchAndHandleTasks.

@Test
public void shouldFetchAndHandleTasks() {
    // given
    final int numTasks = 50;
    for (int i = 0; i < numTasks; i++) {
        clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    }
    final RecordingTaskHandler handler = new RecordingTaskHandler((c, t) -> {
        c.complete(t).withoutPayload().execute();
    });
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(handler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").taskFetchSize(10).open();
    // when
    waitUntil(() -> handler.getHandledTasks().size() == numTasks);
    // then
    assertThat(handler.getHandledTasks()).hasSize(numTasks);
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) Test(org.junit.Test)

Example 24 with RecordingTaskHandler

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

the class YamlWorkflowTest method shouldGetTaskWithHeaders.

@Test
public void shouldGetTaskWithHeaders() {
    // given
    workflowClient.deploy(clientRule.getDefaultTopic()).addResourceFromClasspath("workflows/workflow-with-headers.yaml").execute();
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("workflow-headers").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.getCustomHeaders()).containsEntry("foo", "f").containsEntry("bar", "b");
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent)

Example 25 with RecordingTaskHandler

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

the class BrokerRecoveryTest method shouldCompleteStandaloneTaskAfterRestart.

@Test
public void shouldCompleteStandaloneTaskAfterRestart() {
    // given
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("test").lockTime(Duration.ofSeconds(5)).handler(recordingTaskHandler).open();
    waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
    // when
    restartBroker();
    final TaskEvent task = recordingTaskHandler.getHandledTasks().get(0);
    clientRule.tasks().complete(task).execute();
    // then
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

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