use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldSendPrefetchCapacityAsDefinedInClientProperties.
@Test
public void shouldSendPrefetchCapacityAsDefinedInClientProperties() {
// given
broker.stubTopicSubscriptionApi(123L);
// when
clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(DO_NOTHING).name(SUBSCRIPTION_NAME).open();
// then
final ExecuteCommandRequest addSubscriptionRequest = broker.getReceivedCommandRequests().stream().filter((r) -> r.eventType() == EventType.SUBSCRIBER_EVENT && "SUBSCRIBE".equals(r.getCommand().get("state"))).findFirst().get();
assertThat(addSubscriptionRequest.getCommand()).containsEntry("prefetchCapacity", 32);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldOpenSubscriptionAtTailOfTopic.
@Test
public void shouldOpenSubscriptionAtTailOfTopic() {
// given
broker.stubTopicSubscriptionApi(123L);
// when
clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtTailOfTopic().handler(DO_NOTHING).name(SUBSCRIPTION_NAME).open();
// then
final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
assertThat(subscribeRequest.getCommand()).hasEntrySatisfying("startPosition", Conditions.isLowerThan(0)).containsEntry("state", "SUBSCRIBE").containsEntry("prefetchCapacity", 32).containsEntry("name", SUBSCRIPTION_NAME).doesNotContainEntry("forceStart", true);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldOpenSubscriptionAtPosition.
@Test
public void shouldOpenSubscriptionAtPosition() {
// given
broker.stubTopicSubscriptionApi(123L);
// when
clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtPosition(clientRule.getDefaultPartitionId(), 654L).handler(DO_NOTHING).name(SUBSCRIPTION_NAME).open();
// then
final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
assertThat(subscribeRequest.getCommand()).containsEntry("startPosition", 654).containsEntry("state", "SUBSCRIBE").containsEntry("prefetchCapacity", 32).containsEntry("name", SUBSCRIPTION_NAME).doesNotContainEntry("forceStart", true);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldResumeSubscriptionBeforeFailedEventAfterHandlerFailure.
@Test
public void shouldResumeSubscriptionBeforeFailedEventAfterHandlerFailure() {
// given
broker.stubTopicSubscriptionApi(123L);
final FailingHandler handler = new FailingHandler(e -> e.getMetadata().getPosition() == 2L);
final TopicSubscription subscription = clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(handler).name(SUBSCRIPTION_NAME).open();
final RemoteAddress clientAddress = broker.getReceivedCommandRequests().get(0).getSource();
broker.pushTopicEvent(clientAddress, 123L, 1L, 1L);
// when
broker.pushTopicEvent(clientAddress, 123L, 1L, 2L);
// then
TestUtil.waitUntil(() -> subscription.isClosed());
final List<ExecuteCommandRequest> commandRequests = broker.getReceivedCommandRequests();
final List<ExecuteCommandRequest> acknowledgements = commandRequests.stream().filter((c) -> c.eventType() == EventType.SUBSCRIPTION_EVENT).filter((c) -> "ACKNOWLEDGE".equals(c.getCommand().get("state"))).collect(Collectors.toList());
assertThat(acknowledgements).isNotEmpty();
final ExecuteCommandRequest lastAck = acknowledgements.get(acknowledgements.size() - 1);
assertThat(lastAck.getCommand().get("name")).isEqualTo(SUBSCRIPTION_NAME);
assertThat(lastAck.getCommand().get("ackPosition")).isEqualTo(1);
final ControlMessageRequest removeRequest = broker.getReceivedControlMessageRequests().stream().filter((c) -> c.messageType() == ControlMessageType.REMOVE_TOPIC_SUBSCRIPTION).findFirst().get();
final List<Object> requests = broker.getAllReceivedRequests();
assertThat(requests).contains(lastAck);
assertThat(requests.indexOf(lastAck)).isLessThan(requests.indexOf(removeRequest));
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class CompleteTaskTest method shouldClearPayload.
@Test
public void shouldClearPayload() {
// given
final TaskEventImpl baseEvent = Events.exampleTask();
brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
// when
clientRule.tasks().complete(baseEvent).withoutPayload().execute();
// then
final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
assertThat(request.getCommand()).doesNotContainKey("payload");
}
Aggregations