use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldCompleteTaskWithoutPayload.
@Test
public void shouldCompleteTaskWithoutPayload() {
// given
broker.stubTaskSubscriptionApi(123L);
stubTaskCompleteRequest();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler((c, t) -> c.complete(t).withoutPayload().execute()).lockOwner("foo").lockTime(10000L).taskType("bar").open();
final RemoteAddress eventSource = getSubscribeRequests().findFirst().get().getSource();
// when
broker.pushLockedTask(eventSource, 123L, 4L, 5L, "foo", "bar");
// then
final ExecuteCommandRequest taskRequest = TestUtil.doRepeatedly(() -> broker.getReceivedCommandRequests().stream().filter(r -> r.eventType() == EventType.TASK_EVENT).findFirst()).until(r -> r.isPresent()).get();
assertThat(taskRequest.partitionId()).isEqualTo(clientRule.getDefaultPartitionId());
assertThat(taskRequest.key()).isEqualTo(4L);
assertThat(taskRequest.getCommand()).containsEntry("state", "COMPLETE").containsEntry("type", "bar").containsEntry("lockOwner", "foo").doesNotContainKey("payload");
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldNotAttemptReplenishmentForZeroCredits.
@Test
public void shouldNotAttemptReplenishmentForZeroCredits() throws InterruptedException {
// given
final int subscriptionCapacity = 16;
final int replenishmentThreshold = (int) (Math.ceil(subscriptionCapacity * Subscriber.REPLENISHMENT_THRESHOLD));
final int tasksToHandleBeforeReplenishment = subscriptionCapacity - replenishmentThreshold;
broker.stubTaskSubscriptionApi(123L);
final WaitingTaskHandler handler = new WaitingTaskHandler();
handler.shouldWait = false;
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(handler).lockOwner("owner").lockTime(10000L).taskFetchSize(subscriptionCapacity).taskType("type").open();
final RemoteAddress clientAddress = getSubscribeRequests().findFirst().get().getSource();
// handling these tasks should not yet trigger replenishment; the next handled task would
for (int i = 0; i < tasksToHandleBeforeReplenishment; i++) {
broker.pushLockedTask(clientAddress, 123L, 4L + i, 5L + i, "foo", "type");
}
waitUntil(() -> handler.numHandledEvents.get() == tasksToHandleBeforeReplenishment);
handler.shouldWait = true;
for (int i = 0; i < NUM_EXECUTION_THREADS; i++) {
broker.pushLockedTask(clientAddress, 123L, 4L + i, 5L + i, "foo", "type");
}
waitUntil(() -> handler.numWaitingThreads.get() == NUM_EXECUTION_THREADS);
// when all task handling threads trigger credit replenishment
continueTaskHandlingThreads();
// then
waitUntil(() -> getCreditRequests().count() >= 1);
// waiting for potentially more credit requests
Thread.sleep(500L);
final List<ControlMessageRequest> creditRequests = getCreditRequests().collect(Collectors.toList());
assertThat(creditRequests.size()).isGreaterThanOrEqualTo(1);
int totalReplenishedCredits = 0;
for (ControlMessageRequest request : creditRequests) {
final int replenishedCredits = (int) request.getData().get("credits");
assertThat(replenishedCredits).isGreaterThan(0);
totalReplenishedCredits += replenishedCredits;
}
assertThat(totalReplenishedCredits).isGreaterThanOrEqualTo(tasksToHandleBeforeReplenishment + 1);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldInvokeTaskHandlerWithTwoSubscriptions.
@Test
public void shouldInvokeTaskHandlerWithTwoSubscriptions() {
// given
broker.stubTaskSubscriptionApi(123L);
stubTaskCompleteRequest();
final RecordingTaskHandler handler1 = new RecordingTaskHandler();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(handler1).lockOwner("foo").lockTime(10000L).taskType("type1").open();
final RecordingTaskHandler handler2 = new RecordingTaskHandler();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(handler2).lockOwner("bar").lockTime(10000L).taskType("type2").open();
final RemoteAddress clientAddress = getSubscribeRequests().findFirst().get().getSource();
// when
broker.pushLockedTask(clientAddress, 123L, 4L, 5L, "foo", "type1");
broker.pushLockedTask(clientAddress, 124L, 5L, 6L, "bar", "type2");
// then
TestUtil.waitUntil(() -> !handler1.getHandledTasks().isEmpty());
TestUtil.waitUntil(() -> !handler2.getHandledTasks().isEmpty());
assertThat(handler1.getHandledTasks()).hasSize(1);
assertThat(handler2.getHandledTasks()).hasSize(1);
final TaskEvent task1 = handler1.getHandledTasks().get(0);
assertThat(task1.getMetadata().getKey()).isEqualTo(4L);
assertThat(task1.getType()).isEqualTo("type1");
final TaskEvent task2 = handler2.getHandledTasks().get(0);
assertThat(task2.getMetadata().getKey()).isEqualTo(5L);
assertThat(task2.getType()).isEqualTo("type2");
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldCompleteTaskWithPayload.
@Test
public void shouldCompleteTaskWithPayload() {
// given
broker.stubTaskSubscriptionApi(123L);
stubTaskCompleteRequest();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler((c, t) -> c.complete(t).payload("{\"a\": 1}").execute()).lockOwner("foo").lockTime(10000L).taskType("bar").open();
final RemoteAddress eventSource = getSubscribeRequests().findFirst().get().getSource();
// when
broker.pushLockedTask(eventSource, 123L, 4L, 5L, "foo", "bar");
// then
final ExecuteCommandRequest taskRequest = TestUtil.doRepeatedly(() -> broker.getReceivedCommandRequests().stream().filter(r -> r.eventType() == EventType.TASK_EVENT).findFirst()).until(r -> r.isPresent()).get();
assertThat(taskRequest.partitionId()).isEqualTo(clientRule.getDefaultPartitionId());
assertThat(taskRequest.key()).isEqualTo(4L);
assertThat(taskRequest.getCommand()).containsEntry("state", "COMPLETE").containsEntry("type", "bar").containsEntry("lockOwner", "foo").containsEntry("payload", msgPackConverter.convertToMsgPack("{\"a\": 1}"));
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldNotAutocompleteTask.
@Test
public void shouldNotAutocompleteTask() throws InterruptedException {
// given
broker.stubTaskSubscriptionApi(123L);
stubTaskCompleteRequest();
final RecordingTaskHandler handler = new RecordingTaskHandler();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(handler).lockOwner("foo").lockTime(10000L).taskType("bar").open();
final RemoteAddress clientAddress = getSubscribeRequests().findFirst().get().getSource();
// when
broker.pushLockedTask(clientAddress, 123L, 4L, 5L, "foo", "bar");
// then
Thread.sleep(1000L);
assertThat(broker.getReceivedCommandRequests().stream().filter(r -> r.eventType() == EventType.TASK_EVENT).count()).isEqualTo(0);
}
Aggregations