Search in sources :

Example 16 with TaskEvent

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

the class BrokerRecoveryTest 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 17 with TaskEvent

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

the class CreateTopicTest method shouldCreateTaskOnNewTopic.

@Test
public void shouldCreateTaskOnNewTopic() {
    // given
    clientRule.topics().create("newTopic", 2).execute();
    // when
    final TaskEvent taskEvent = clientRule.tasks().create("newTopic", "foo").execute();
    // then
    assertThat(taskEvent.getState()).isEqualTo("CREATED");
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 18 with TaskEvent

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

the class TaskEventClusteredTest method shouldCreateTaskWhenFollowerUnavailable.

@Test
public void shouldCreateTaskWhenFollowerUnavailable() {
    // given
    final ZeebeClient client = clientRule.getClient();
    final String topicName = "foo";
    clusteringRule.createTopic(topicName, 1);
    final Topics topics = client.topics().getTopics().execute();
    final Topic topic = topics.getTopics().stream().filter(t -> topicName.equals(t.getName())).findFirst().get();
    final TopologyBroker leader = clusteringRule.getLeaderForPartition(topic.getPartitions().get(0).getId());
    // choosing a new leader in a raft group where the previously leading broker is no longer available
    clusteringRule.stopBroker(leader.getSocketAddress());
    // when
    final TaskEvent taskEvent = client.tasks().create(topicName, "bar").execute();
    // then
    assertThat(taskEvent.getState()).isEqualTo("CREATED");
}
Also used : Topics(io.zeebe.client.topic.Topics) ZeebeClient(io.zeebe.client.ZeebeClient) TaskEvent(io.zeebe.client.event.TaskEvent) Topic(io.zeebe.client.topic.Topic) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 19 with TaskEvent

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

the class IncidentTest method shouldCreateAndResolveTaskIncident.

@Test
public void shouldCreateAndResolveTaskIncident() {
    // given a workflow instance with an open task
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(WORKFLOW, "workflow.bpmn").execute();
    clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").payload(PAYLOAD).execute();
    // when the task fails until it has no more retries left
    final ControllableTaskHandler taskHandler = new ControllableTaskHandler();
    taskHandler.failTask = true;
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("test").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler(taskHandler).open();
    // then an incident is created
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("CREATED")));
    // when the task retries are increased
    taskHandler.failTask = false;
    final TaskEvent task = taskHandler.task;
    clientRule.tasks().updateRetries(task).retries(3).execute();
    // then the incident is deleted
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("DELETED")));
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 20 with TaskEvent

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

the class MultipleClientTest method shouldOpenTaskSubscriptionsForDifferentTypes.

@Test
public void shouldOpenTaskSubscriptionsForDifferentTypes() {
    // given
    final RecordingTaskHandler handler1 = new RecordingTaskHandler();
    final RecordingTaskHandler handler2 = new RecordingTaskHandler();
    client1.tasks().newTaskSubscription(client1.getDefaultTopic()).handler(handler1).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("client1").open();
    client2.tasks().newTaskSubscription(client2.getDefaultTopic()).handler(handler2).taskType("bar").lockTime(Duration.ofMinutes(5)).lockOwner("client2").open();
    // when
    final TaskEvent task1 = client1.tasks().create(client1.getDefaultTopic(), "foo").execute();
    final TaskEvent task2 = client1.tasks().create(client1.getDefaultTopic(), "bar").execute();
    // then
    waitUntil(() -> handler1.getHandledTasks().size() + handler2.getHandledTasks().size() >= 2);
    assertThat(handler1.getHandledTasks()).hasSize(1);
    assertThat(handler1.getHandledTasks().get(0).getMetadata().getKey()).isEqualTo(task1.getMetadata().getKey());
    assertThat(handler2.getHandledTasks()).hasSize(1);
    assertThat(handler2.getHandledTasks().get(0).getMetadata().getKey()).isEqualTo(task2.getMetadata().getKey());
}
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