Search in sources :

Example 21 with TaskEvent

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

the class ServiceTaskTest method shouldMapPayloadIntoTask.

@Test
public void shouldMapPayloadIntoTask() {
    // given
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(Bpmn.createExecutableWorkflow("process").startEvent("start").serviceTask("task", t -> t.taskType("foo").input("$.foo", "$.bar")).endEvent("end").done(), "workflow.bpmn").execute();
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("process").payload("{\"foo\":1}").execute();
    // when
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> recordingTaskHandler.getHandledTasks().size() >= 1);
    final TaskEvent taskLockedEvent = recordingTaskHandler.getHandledTasks().get(0);
    assertThat(taskLockedEvent.getPayload()).isEqualTo("{\"bar\":1}");
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent)

Example 22 with TaskEvent

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

the class ServiceTaskTest method shouldLockServiceTask.

@Test
public void shouldLockServiceTask() {
    // given
    final Map<String, String> taskHeaders = new HashMap<>();
    taskHeaders.put("cust1", "a");
    taskHeaders.put("cust2", "b");
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(Bpmn.createExecutableWorkflow("process").startEvent("start").serviceTask("task", t -> t.taskType("foo").taskHeader("cust1", "a").taskHeader("cust2", "b")).endEvent("end").done(), "workflow.bpmn").execute();
    final WorkflowInstanceEvent workflowInstance = workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    // when
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> recordingTaskHandler.getHandledTasks().size() >= 1);
    assertThat(recordingTaskHandler.getHandledTasks()).hasSize(1);
    final WorkflowInstanceEvent activityInstance = eventRecorder.getSingleWorkflowInstanceEvent(e -> "ACTIVITY_ACTIVATED".equals(e.getState()));
    final TaskEvent taskLockedEvent = recordingTaskHandler.getHandledTasks().get(0);
    assertThat(taskLockedEvent.getHeaders()).containsOnly(entry("bpmnProcessId", "process"), entry("workflowDefinitionVersion", 1), entry("workflowKey", workflowInstance.getWorkflowKey()), entry("workflowInstanceKey", workflowInstance.getWorkflowInstanceKey()), entry("activityId", "task"), entry("activityInstanceKey", activityInstance.getMetadata().getKey()));
    assertThat(taskLockedEvent.getCustomHeaders()).containsOnly(entry("cust1", "a"), entry("cust2", "b"));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) HashMap(java.util.HashMap) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) TaskEvent(io.zeebe.client.event.TaskEvent)

Example 23 with TaskEvent

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

the class YamlWorkflowTest method shouldCompleteTaskWithPayload.

@Test
public void shouldCompleteTaskWithPayload() {
    // given
    workflowClient.deploy(clientRule.getDefaultTopic()).addResourceFromClasspath("workflows/workflow-with-mappings.yaml").execute();
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("workflow-mappings").payload("{\"foo\":1}").execute();
    // when
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler((c, task) -> c.complete(task).payload("{\"result\":3}").execute());
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> recordingTaskHandler.getHandledTasks().size() >= 1);
    final TaskEvent taskLockedEvent = recordingTaskHandler.getHandledTasks().get(0);
    assertThat(taskLockedEvent.getPayload()).isEqualTo("{\"bar\":1}");
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("ACTIVITY_COMPLETED")));
    final WorkflowInstanceEvent workflowEvent = eventRecorder.getSingleWorkflowInstanceEvent(wfInstanceEvent("ACTIVITY_COMPLETED"));
    assertThat(workflowEvent.getPayload()).isEqualTo("{\"result\":3}");
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent)

Example 24 with TaskEvent

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

the class BrokerLeaderChangeTest method shouldChangeLeaderAfterLeaderDies.

@Test
public void shouldChangeLeaderAfterLeaderDies() {
    // given
    clusteringRule.createTopic(clientRule.getDefaultTopic(), 2);
    final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(1);
    final SocketAddress leaderAddress = leaderForPartition.getSocketAddress();
    final TaskEvent taskEvent = taskClient.create(clientRule.getDefaultTopic(), TASK_TYPE).execute();
    // when
    clusteringRule.stopBroker(leaderAddress);
    final TaskCompleter taskCompleter = new TaskCompleter(taskEvent);
    // then
    taskCompleter.waitForTaskCompletion();
    taskCompleter.close();
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) SocketAddress(io.zeebe.transport.SocketAddress) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 25 with TaskEvent

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

the class ZeebeClientTest method shouldThrottleTopologyRefreshRequestsWhenPartitionLeaderCannotBeDetermined.

@Test
public void shouldThrottleTopologyRefreshRequestsWhenPartitionLeaderCannotBeDetermined() {
    // when
    final int nonExistingPartition = 999;
    final TaskEventImpl taskEvent = new TaskEventImpl("CREATED", new MsgPackConverter());
    taskEvent.setPartitionId(nonExistingPartition);
    assertThatThrownBy(() -> {
        client.tasks().complete(taskEvent).execute();
    });
    // +2 (one for the extra request when client is started)
    final long requestTimeout = Long.parseLong(client.getInitializationProperties().getProperty(ClientProperties.CLIENT_REQUEST_TIMEOUT_SEC));
    final long requestTimeoutMs = TimeUnit.SECONDS.toMillis(requestTimeout);
    final long expectedMaximumTopologyRequests = (requestTimeoutMs / ClientTopologyManager.MIN_REFRESH_INTERVAL_MILLIS.toMillis()) + 2;
    final long actualTopologyRequests = broker.getReceivedControlMessageRequests().stream().filter(r -> r.messageType() == ControlMessageType.REQUEST_TOPOLOGY).count();
    assertThat(actualTopologyRequests).isLessThanOrEqualTo(expectedMaximumTopologyRequests);
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) java.util(java.util) Events(io.zeebe.client.util.Events) TransportListener(io.zeebe.transport.TransportListener) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) ClientTopologyManager(io.zeebe.client.clustering.impl.ClientTopologyManager) Protocol(io.zeebe.protocol.Protocol) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) TopicSubscription(io.zeebe.client.event.TopicSubscription) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RemoteAddress(io.zeebe.transport.RemoteAddress) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TestName(org.junit.rules.TestName) After(org.junit.After) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) java.util.concurrent(java.util.concurrent) ServerTransport(io.zeebe.transport.ServerTransport) Test(org.junit.Test) ClientTransport(io.zeebe.transport.ClientTransport) Assertions.fail(org.assertj.core.api.Assertions.fail) Rule(org.junit.Rule) ClientException(io.zeebe.client.cmd.ClientException) EventType(io.zeebe.protocol.clientapi.EventType) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) ClientApiRule(io.zeebe.test.broker.protocol.clientapi.ClientApiRule) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) 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