use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldInvokeTaskHandlerForPollableSubscription.
@Test
public void shouldInvokeTaskHandlerForPollableSubscription() {
// given
broker.stubTaskSubscriptionApi(123L);
stubTaskCompleteRequest();
final RecordingTaskHandler handler = new RecordingTaskHandler();
final PollableTaskSubscription subscription = clientRule.tasks().newPollableTaskSubscription(clientRule.getDefaultTopicName()).lockOwner("foo").lockTime(10000L).taskType("bar").open();
final RemoteAddress clientAddress = getSubscribeRequests().findFirst().get().getSource();
broker.pushLockedTask(clientAddress, 123L, 4L, 5L, "foo", "type");
// when
final Integer handledTasks = TestUtil.doRepeatedly(() -> subscription.poll(handler)).until(numTasks -> numTasks > 0);
// then
assertThat(handledTasks).isEqualTo(1);
assertThat(handler.getHandledTasks()).hasSize(1);
final TaskEvent task = handler.getHandledTasks().get(0);
assertThat(task.getMetadata().getKey()).isEqualTo(4L);
assertThat(task.getType()).isEqualTo("type");
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class BrokerRestartTest method shouldCreateTopicAfterRestart.
@Test
public void shouldCreateTopicAfterRestart() {
// given
final ZeebeClient client = clientRule.getClient();
restartBroker();
// when
client.topics().create("foo", 2).execute();
// then
final TaskEvent taskEvent = client.tasks().create("foo", "bar").execute();
assertThat(taskEvent.getState()).isEqualTo("CREATED");
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class TaskTopicSubscriptionTest method shouldInvokeDefaultHandler.
@Test
public void shouldInvokeDefaultHandler() throws IOException {
// given
final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").addCustomHeader("key", "value").payload("{}").execute();
final RecordingEventHandler handler = new RecordingEventHandler();
// when no POJO handler is registered
clientRule.topics().newSubscription(clientRule.getDefaultTopic()).startAtHeadOfTopic().handler(handler).name("sub-2").open();
// then
TestUtil.waitUntil(() -> handler.numRecordedTaskEvents() == 2);
final long taskKey = task.getMetadata().getKey();
handler.assertTaskEvent(0, taskKey, "CREATE");
handler.assertTaskEvent(1, taskKey, "CREATED");
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldUpdateTaskRetries.
@Test
public void shouldUpdateTaskRetries() {
// given
eventRecorder.startRecordingEvents();
final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").retries(1).execute();
final RecordingTaskHandler taskHandler = new RecordingTaskHandler((c, t) -> {
throw new RuntimeException("expected failure");
}, (c, t) -> c.complete(t).withoutPayload().execute());
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
waitUntil(() -> taskHandler.getHandledTasks().size() == 1);
waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("FAILED").and(taskRetries(0))));
// when
final TaskEvent updatedTask = clientRule.tasks().updateRetries(task).retries(2).execute();
// then
assertThat(updatedTask.getMetadata().getKey()).isEqualTo(task.getMetadata().getKey());
waitUntil(() -> taskHandler.getHandledTasks().size() == 2);
waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldCompletionTaskInHandler.
@Test
public void shouldCompletionTaskInHandler() throws InterruptedException {
// given
eventRecorder.startRecordingEvents();
final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").payload("{\"a\":1}").addCustomHeader("b", "2").execute();
// when
final RecordingTaskHandler taskHandler = new RecordingTaskHandler((c, t) -> c.complete(t).payload("{\"a\":3}").execute());
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
// then
waitUntil(() -> !taskHandler.getHandledTasks().isEmpty());
assertThat(taskHandler.getHandledTasks()).hasSize(1);
final TaskEvent subscribedTask = taskHandler.getHandledTasks().get(0);
assertThat(subscribedTask.getMetadata().getKey()).isEqualTo(task.getMetadata().getKey());
assertThat(subscribedTask.getType()).isEqualTo("foo");
assertThat(subscribedTask.getLockExpirationTime()).isAfter(Instant.now());
waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
final TaskEvent taskEvent = eventRecorder.getTaskEvents(taskEvent("COMPLETED")).get(0);
assertThat(taskEvent.getPayload()).isEqualTo("{\"a\":3}");
assertThat(task.getCustomHeaders()).containsEntry("b", "2");
}
Aggregations