use of io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest in project zeebe by zeebe-io.
the class PartitionedTopicSubscriptionTest method shouldCloseSuccessfulSubscriptionIfAnotherSubscriptionCannotBeOpened.
@Test
public void shouldCloseSuccessfulSubscriptionIfAnotherSubscriptionCannotBeOpened() throws Exception {
// given
final int subscriberKey1 = 456;
broker1.stubTopicSubscriptionApi(subscriberKey1);
final ResponseController responseController = broker2.onExecuteCommandRequest(EventType.SUBSCRIBER_EVENT, "SUBSCRIBE").respondWithError().errorCode(ErrorCode.REQUEST_PROCESSING_FAILURE).errorData("foo").registerControlled();
// assuming that subscription to broker 1 is successful
final TopicSubscriptionBuilderImpl builder = (TopicSubscriptionBuilderImpl) client.topics().newSubscription(TOPIC).handler(new RecordingEventHandler()).name("hohoho");
final Future<TopicSubscriberGroup> groupFuture = builder.buildSubscriberGroup();
waitUntil(() -> getOpenSubscriptionRequests(broker1).size() == 1);
// when
// triggering the error response and continuing
responseController.unblockNextResponse();
// then
waitUntil(() -> groupFuture.isDone());
assertFailed(groupFuture);
final List<ControlMessageRequest> closeRequestsBroker1 = getCloseSubscriptionRequests(broker1);
assertThat(closeRequestsBroker1).hasSize(1);
assertThat(closeRequestsBroker1.get(0).getData().get("subscriberKey")).isEqualTo(subscriberKey1);
}
use of io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldNotLoseCreditsOnFailureToReportTaskFailure.
/**
* i.e. if signalling task failure itself fails
*/
@Test
public void shouldNotLoseCreditsOnFailureToReportTaskFailure() throws InterruptedException {
// given
broker.stubTaskSubscriptionApi(123L);
failTaskFailure();
final int subscriptionCapacity = 8;
final AtomicInteger failedTasks = new AtomicInteger(0);
final TaskHandler taskHandler = (c, t) -> {
failedTasks.incrementAndGet();
throw new RuntimeException("foo");
};
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(taskHandler).lockOwner("owner").lockTime(1000L).taskFetchSize(subscriptionCapacity).taskType("foo").open();
final RemoteAddress clientAddress = broker.getReceivedControlMessageRequests().get(0).getSource();
for (int i = 0; i < subscriptionCapacity; i++) {
broker.pushLockedTask(clientAddress, 123L, i, i, "owner", "foo");
}
// when
TestUtil.waitUntil(() -> failedTasks.get() == 8);
// give the client a bit of time to submit credits; this is not coupled to any defined event, so we just sleep for a bit
Thread.sleep(500L);
// then
final List<ControlMessageRequest> creditRequests = getCreditRequests().collect(Collectors.toList());
assertThat(creditRequests).isNotEmpty();
final int numSubmittedCredits = creditRequests.stream().mapToInt((r) -> (int) r.getData().get("credits")).sum();
assertThat(numSubmittedCredits).isGreaterThan(0);
}
use of io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldSendCorrectCreditsRequest.
@Test
public void shouldSendCorrectCreditsRequest() {
// given
broker.stubTaskSubscriptionApi(123L);
final TasksClientImpl taskClient = (TasksClientImpl) clientRule.tasks();
// when
taskClient.increaseSubscriptionCredits(StubBrokerRule.TEST_PARTITION_ID).credits(123).subscriberKey(456L).execute();
// then
final List<ControlMessageRequest> controlMessageRequests = broker.getReceivedControlMessageRequests().stream().filter(r -> r.messageType() == ControlMessageType.INCREASE_TASK_SUBSCRIPTION_CREDITS).collect(Collectors.toList());
assertThat(controlMessageRequests).hasSize(1);
final ControlMessageRequest request = controlMessageRequests.get(0);
assertThat(request.messageType()).isEqualTo(ControlMessageType.INCREASE_TASK_SUBSCRIPTION_CREDITS);
assertThat(request.getData()).contains(entry("credits", 123), entry("subscriberKey", 456));
}
use of io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldOpenSubscriptionWithLockTimeAsDuration.
@Test
public void shouldOpenSubscriptionWithLockTimeAsDuration() {
// given
broker.stubTaskSubscriptionApi(123L);
// when
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(DO_NOTHING).lockOwner("foo").lockTime(Duration.ofDays(10)).taskType("bar").open();
// then
final ControlMessageRequest subscriptionRequest = getSubscribeRequests().findFirst().get();
assertThat(subscriptionRequest.getData()).contains(entry("lockDuration", (int) TimeUnit.DAYS.toMillis(10L)));
}
use of io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldReopenSubscriptionAfterChannelInterruption.
@Test
public void shouldReopenSubscriptionAfterChannelInterruption() {
// given
broker.stubTaskSubscriptionApi(123L);
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(DO_NOTHING).lockOwner("foo").lockTime(10000L).taskType("bar").open();
// when
broker.interruptAllServerChannels();
// then
TestUtil.waitUntil(() -> getSubscribeRequests().count() == 2);
final ControlMessageRequest reopenRequest = getSubscribeRequests().skip(1).findFirst().get();
assertThat(reopenRequest.getData()).contains(entry("lockOwner", "foo"), entry("lockDuration", 10000), entry("taskType", "bar"));
}
Aggregations