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}");
}
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"));
}
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}");
}
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();
}
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);
}
Aggregations