use of io.zeebe.test.util.TestUtil.waitUntil 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));
}
Aggregations