Search in sources :

Example 11 with TaskEvent

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

the class CreateTopicClusteredTest method shouldCreateTaskAfterTopicCreation.

@Test
public void shouldCreateTaskAfterTopicCreation() {
    // given
    clusteringRule.createTopic("foo", PARTITION_COUNT);
    // then
    final TaskEvent taskEvent = client.tasks().create("foo", "bar").execute();
    assertThat(taskEvent).isNotNull();
    assertThat(taskEvent.getState()).isEqualTo("CREATED");
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 12 with TaskEvent

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

the class CreateTopicClusteredTest method shouldCompleteTaskAfterNewLeaderWasChosen.

@Test
public void shouldCompleteTaskAfterNewLeaderWasChosen() throws Exception {
    // given
    final int partitionsCount = 1;
    clusteringRule.createTopic("foo", partitionsCount);
    final TaskEvent taskEvent = client.tasks().create("foo", "bar").execute();
    final int partitionId = taskEvent.getMetadata().getPartitionId();
    final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(partitionId);
    final SocketAddress currentLeaderAddress = leaderForPartition.getSocketAddress();
    // when
    clusteringRule.stopBroker(currentLeaderAddress);
    // then
    final TopologyBroker newLeader = clusteringRule.getLeaderForPartition(partitionId);
    assertThat(newLeader.getSocketAddress()).isNotEqualTo(leaderForPartition.getSocketAddress());
    final CompletableFuture<TaskEvent> taskCompleted = new CompletableFuture<>();
    client.tasks().newTaskSubscription("foo").handler((taskClient, lockedEvent) -> {
        final TaskEvent completedTask = taskClient.complete(lockedEvent).execute();
        taskCompleted.complete(completedTask);
    }).taskType("bar").lockOwner("owner").lockTime(5000).open();
    waitUntil(() -> taskCompleted.isDone());
    assertThat(taskCompleted).isCompleted();
    final TaskEvent completedTask = taskCompleted.get();
    assertThat(completedTask.getState()).isEqualTo("COMPLETED");
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TaskEvent(io.zeebe.client.event.TaskEvent) SocketAddress(io.zeebe.transport.SocketAddress) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 13 with TaskEvent

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

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

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

the class BrokerRecoveryTest method shouldResolveIncidentAfterRestart.

@Test
public void shouldResolveIncidentAfterRestart() {
    // given
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(WORKFLOW_INCIDENT, "incident.bpmn").execute();
    clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("CREATED")));
    final WorkflowInstanceEvent activityInstance = eventRecorder.getSingleWorkflowInstanceEvent(TopicEventRecorder.wfInstanceEvent("ACTIVITY_READY"));
    // when
    restartBroker();
    clientRule.workflows().updatePayload(activityInstance).payload("{\"foo\":\"bar\"}").execute();
    // then
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("RESOLVED")));
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("CREATED")));
    assertThat(eventRecorder.getIncidentEvents(i -> true)).extracting("state").containsExactly("CREATE", "CREATED", "RESOLVE", "RESOLVED");
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TestFileUtil(io.zeebe.test.util.TestFileUtil) TopologyResponse(io.zeebe.client.clustering.impl.TopologyResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.zeebe.model.bpmn.Bpmn) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) TopicEventRecorder(io.zeebe.broker.it.util.TopicEventRecorder) ZeebeClient(io.zeebe.client.ZeebeClient) SocketAddress(io.zeebe.transport.SocketAddress) Duration(java.time.Duration) ClusterServiceNames(io.zeebe.broker.clustering.ClusterServiceNames) EmbeddedBrokerRule(io.zeebe.broker.it.EmbeddedBrokerRule) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) ServiceName(io.zeebe.servicecontainer.ServiceName) ExpectedException(org.junit.rules.ExpectedException) Raft(io.zeebe.raft.Raft) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test) RaftState(io.zeebe.raft.state.RaftState) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BrokerPartitionState(io.zeebe.client.clustering.impl.BrokerPartitionState) RuleChain(org.junit.rules.RuleChain) List(java.util.List) ClientRule(io.zeebe.broker.it.ClientRule) Rule(org.junit.Rule) Pattern(java.util.regex.Pattern) Files(org.assertj.core.util.Files) DeploymentEvent(io.zeebe.client.event.DeploymentEvent) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) TestUtil(io.zeebe.test.util.TestUtil) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) Test(org.junit.Test)

Example 15 with TaskEvent

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

the class BrokerRecoveryTest method shouldResolveFailedIncidentAfterRestart.

@Test
public void shouldResolveFailedIncidentAfterRestart() {
    // given
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(WORKFLOW_INCIDENT, "incident.bpmn").execute();
    clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("CREATED")));
    final WorkflowInstanceEvent activityInstance = eventRecorder.getSingleWorkflowInstanceEvent(TopicEventRecorder.wfInstanceEvent("ACTIVITY_READY"));
    clientRule.workflows().updatePayload(activityInstance).payload("{\"x\":\"y\"}").execute();
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("RESOLVE_FAILED")));
    // when
    restartBroker();
    clientRule.workflows().updatePayload(activityInstance).payload("{\"foo\":\"bar\"}").execute();
    // then
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("RESOLVED")));
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("CREATED")));
    assertThat(eventRecorder.getIncidentEvents(i -> true)).extracting("state").containsExactly("CREATE", "CREATED", "RESOLVE", "RESOLVE_FAILED", "RESOLVE", "RESOLVED");
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TestFileUtil(io.zeebe.test.util.TestFileUtil) TopologyResponse(io.zeebe.client.clustering.impl.TopologyResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.zeebe.model.bpmn.Bpmn) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) TopicEventRecorder(io.zeebe.broker.it.util.TopicEventRecorder) ZeebeClient(io.zeebe.client.ZeebeClient) SocketAddress(io.zeebe.transport.SocketAddress) Duration(java.time.Duration) ClusterServiceNames(io.zeebe.broker.clustering.ClusterServiceNames) EmbeddedBrokerRule(io.zeebe.broker.it.EmbeddedBrokerRule) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) ServiceName(io.zeebe.servicecontainer.ServiceName) ExpectedException(org.junit.rules.ExpectedException) Raft(io.zeebe.raft.Raft) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test) RaftState(io.zeebe.raft.state.RaftState) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BrokerPartitionState(io.zeebe.client.clustering.impl.BrokerPartitionState) RuleChain(org.junit.rules.RuleChain) List(java.util.List) ClientRule(io.zeebe.broker.it.ClientRule) Rule(org.junit.Rule) Pattern(java.util.regex.Pattern) Files(org.assertj.core.util.Files) DeploymentEvent(io.zeebe.client.event.DeploymentEvent) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) TestUtil(io.zeebe.test.util.TestUtil) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) 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