Search in sources :

Example 1 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class BrokerRestartTest method shouldContinueWorkflowInstanceWithLockedTaskAfterRestart.

@Test
public void shouldContinueWorkflowInstanceWithLockedTaskAfterRestart() {
    // given
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(WORKFLOW, "workflow.bpmn").execute();
    clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").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")));
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_COMPLETED")));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 2 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class BrokerRestartTest 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)

Example 3 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class BrokerRestartTest method shouldReceiveLockExpiredTasksAfterRestart.

@Test
public void shouldReceiveLockExpiredTasksAfterRestart() {
    // given
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
    final TaskSubscription subscription = clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofSeconds(5)).lockOwner("test").handler(recordingTaskHandler).open();
    waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
    subscription.close();
    // when
    restartBroker();
    doRepeatedly(() -> {
        // retriggers lock expiration check in broker
        brokerRule.getClock().addTime(Duration.ofSeconds(60));
        return null;
    }).until(t -> eventRecorder.hasTaskEvent(taskEvent("LOCK_EXPIRED")));
    recordingTaskHandler.clear();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofMinutes(10L)).lockOwner("test").handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
    final TaskEvent task = recordingTaskHandler.getHandledTasks().get(0);
    clientRule.tasks().complete(task).execute();
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskSubscription(io.zeebe.client.task.TaskSubscription) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 4 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class TaskTopicSubscriptionTest method shouldReceiveTaskPOJOEvents.

@Test
public void shouldReceiveTaskPOJOEvents() {
    // given
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").addCustomHeader("key", "value").payload("{}").retries(2).execute();
    final RecordingTaskPOJOEventHandler handler = new RecordingTaskPOJOEventHandler();
    // when
    clientRule.topics().newSubscription(clientRule.getDefaultTopic()).startAtHeadOfTopic().taskEventHandler(handler).name("sub-1").open();
    // then
    TestUtil.waitUntil(() -> handler.numRecordedEvents() == 2);
    final TaskEvent event1 = handler.getEvent(0);
    assertThat(event1.getState()).isEqualTo("CREATE");
    assertThat(event1.getHeaders()).isEmpty();
    assertThat(event1.getCustomHeaders()).containsExactly(entry("key", "value"));
    assertThat(event1.getLockExpirationTime()).isNull();
    assertThat(event1.getLockOwner()).isNull();
    assertThat(event1.getRetries()).isEqualTo(2);
    assertThat(event1.getType()).isEqualTo("foo");
    assertThat(event1.getPayload()).isEqualTo("{}");
    final TaskEvent event2 = handler.getEvent(1);
    assertThat(event2.getState()).isEqualTo("CREATED");
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 5 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldCompleteTask.

@Test
public void shouldCompleteTask() throws InterruptedException {
    // given
    eventRecorder.startRecordingEvents();
    final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").payload("{ \"a\" : 1 }").addCustomHeader("b", "2").execute();
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    waitUntil(() -> !taskHandler.getHandledTasks().isEmpty());
    final TaskEvent lockedTask = taskHandler.getHandledTasks().get(0);
    // when
    final TaskEvent result = clientRule.tasks().complete(lockedTask).payload("{ \"a\" : 2 }").execute();
    // then
    assertThat(result.getMetadata().getKey()).isEqualTo(task.getMetadata().getKey());
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
    TaskEvent taskEvent = eventRecorder.getTaskEvents(taskEvent("CREATE")).get(0);
    assertThat(taskEvent.getLockExpirationTime()).isNull();
    assertThat(taskEvent.getLockOwner()).isNull();
    taskEvent = eventRecorder.getTaskEvents(taskEvent("CREATED")).get(0);
    assertThat(taskEvent.getLockExpirationTime()).isNull();
    taskEvent = eventRecorder.getTaskEvents(taskEvent("LOCKED")).get(0);
    assertThat(taskEvent.getLockExpirationTime()).isNotNull();
    assertThat(taskEvent.getLockOwner()).isEqualTo("test");
}
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