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);
}
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();
}
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);
}
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");
}
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")));
}
Aggregations