Search in sources :

Example 31 with TaskEvent

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");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemoteAddress(io.zeebe.transport.RemoteAddress) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 32 with TaskEvent

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");
}
Also used : ZeebeClient(io.zeebe.client.ZeebeClient) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 33 with TaskEvent

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");
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 34 with TaskEvent

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")));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 35 with TaskEvent

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");
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Aggregations

TaskEvent (io.zeebe.client.event.TaskEvent)47 Test (org.junit.Test)43 RecordingTaskHandler (io.zeebe.broker.it.util.RecordingTaskHandler)20 ExpectedException (org.junit.rules.ExpectedException)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 Rule (org.junit.Rule)9 ZeebeClient (io.zeebe.client.ZeebeClient)7 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)7 TaskEventImpl (io.zeebe.client.event.impl.TaskEventImpl)7 EventType (io.zeebe.protocol.clientapi.EventType)7 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)7 RuleChain (org.junit.rules.RuleChain)7 TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)6 ClientRule (io.zeebe.client.util.ClientRule)5 Events (io.zeebe.client.util.Events)5 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)5 SocketAddress (io.zeebe.transport.SocketAddress)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Assertions.entry (org.assertj.core.api.Assertions.entry)5 WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)4