use of io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldUseDefaultTaskFetchSize.
@Test
public void shouldUseDefaultTaskFetchSize() {
// given
broker.stubTaskSubscriptionApi(123L);
// when
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(DO_NOTHING).lockOwner("foo").lockTime(10000L).taskType("bar").open();
// then
final ControlMessageRequest subscriptionRequest = getSubscribeRequests().findFirst().get();
assertThat(subscriptionRequest.messageType()).isEqualByComparingTo(ControlMessageType.ADD_TASK_SUBSCRIPTION);
assertThat(subscriptionRequest.getData()).containsEntry("credits", 32);
}
use of io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldCloseSubscription.
@Test
public void shouldCloseSubscription() {
// given
broker.stubTaskSubscriptionApi(123L);
final TaskSubscription subscription = clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(DO_NOTHING).lockOwner("foo").lockTime(10000L).taskType("bar").open();
// when
subscription.close();
// then
assertThat(subscription.isClosed()).isTrue();
assertThat(subscription.isOpen()).isFalse();
final ControlMessageRequest subscriptionRequest = getUnsubscribeRequests().findFirst().get();
assertThat(subscriptionRequest.messageType()).isEqualByComparingTo(ControlMessageType.REMOVE_TASK_SUBSCRIPTION);
assertThat(subscriptionRequest.partitionId()).isEqualTo(clientRule.getDefaultPartitionId());
assertThat(subscriptionRequest.getData()).contains(entry("subscriberKey", 123));
}
use of io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldOpenPollableSubscription.
@Test
public void shouldOpenPollableSubscription() {
// given
broker.stubTaskSubscriptionApi(123L);
// when
final PollableTaskSubscription subscription = clientRule.tasks().newPollableTaskSubscription(clientRule.getDefaultTopicName()).lockOwner("foo").lockTime(10000L).taskType("bar").taskFetchSize(456).open();
// then
assertThat(subscription.isOpen()).isTrue();
final ControlMessageRequest subscriptionRequest = getSubscribeRequests().findFirst().get();
assertThat(subscriptionRequest.messageType()).isEqualByComparingTo(ControlMessageType.ADD_TASK_SUBSCRIPTION);
assertThat(subscriptionRequest.getData()).contains(entry("lockOwner", "foo"), entry("lockDuration", 10000), entry("taskType", "bar"), entry("credits", 456));
}
use of io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest 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.test.broker.protocol.brokerapi.ControlMessageRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldOpenSubscription.
@Test
public void shouldOpenSubscription() {
// given
broker.stubTaskSubscriptionApi(123L);
// when
final TaskSubscription subscription = clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(DO_NOTHING).lockOwner("foo").lockTime(10000L).taskType("bar").taskFetchSize(456).open();
// then
assertThat(subscription.isOpen()).isTrue();
assertThat(subscription.isClosed()).isFalse();
final ControlMessageRequest subscriptionRequest = getSubscribeRequests().findFirst().get();
assertThat(subscriptionRequest.messageType()).isEqualByComparingTo(ControlMessageType.ADD_TASK_SUBSCRIPTION);
assertThat(subscriptionRequest.partitionId()).isEqualTo(clientRule.getDefaultPartitionId());
assertThat(subscriptionRequest.getData()).contains(entry("lockOwner", "foo"), entry("lockDuration", 10000), entry("taskType", "bar"), entry("credits", 456));
}
Aggregations