use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldGiveTaskToSingleSubscription.
@Test
public void shouldGiveTaskToSingleSubscription() {
// given
final RecordingTaskHandler taskHandler = new RecordingTaskHandler((c, t) -> c.complete(t).withoutPayload().execute());
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofHours(1)).lockOwner("test").handler(taskHandler).open();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofHours(2)).lockOwner("test").handler(taskHandler).open();
// when
clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
waitUntil(() -> taskHandler.getHandledTasks().size() == 1);
// then
assertThat(taskHandler.getHandledTasks()).hasSize(1);
}
use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldSubscribeToMultipleTypes.
@Test
public void shouldSubscribeToMultipleTypes() throws InterruptedException {
// given
clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
clientRule.tasks().create(clientRule.getDefaultTopic(), "bar").execute();
final RecordingTaskHandler taskHandler = new RecordingTaskHandler();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("bar").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
waitUntil(() -> taskHandler.getHandledTasks().size() == 2);
}
use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldHandleMoreTasksThanPrefetchCapacity.
@Test
public void shouldHandleMoreTasksThanPrefetchCapacity() {
// given
final int subscriptionCapacity = 16;
for (int i = 0; i < subscriptionCapacity + 1; i++) {
clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").addCustomHeader("key", "value").payload("{}").execute();
}
final RecordingTaskHandler taskHandler = new RecordingTaskHandler();
// when
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
// then
TestUtil.waitUntil(() -> taskHandler.getHandledTasks().size() > subscriptionCapacity);
}
use of io.zeebe.broker.it.util.RecordingTaskHandler 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.broker.it.util.RecordingTaskHandler 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"));
}
Aggregations