use of io.zeebe.client.event.impl.TopicSubscriberGroup in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldOnlyAcknowledgeEventAndCloseSubscriptionAfterLastEventHasBeenHandled.
@Test
public void shouldOnlyAcknowledgeEventAndCloseSubscriptionAfterLastEventHasBeenHandled() throws InterruptedException, ExecutionException, TimeoutException {
// given
broker.stubTopicSubscriptionApi(123L);
final ControllableHandler handler = new ControllableHandler();
final TopicSubscriberGroup subscription = (TopicSubscriberGroup) 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);
TestUtil.waitUntil(() -> handler.isWaiting());
// when
final ActorFuture<?> closeFuture = subscription.closeAsync();
// then
Thread.sleep(1000L);
assertThat(closeFuture).isNotDone();
boolean hasSentAck = broker.getReceivedCommandRequests().stream().filter((r) -> r.eventType() == EventType.SUBSCRIPTION_EVENT).findAny().isPresent();
assertThat(hasSentAck).isFalse();
// and when
handler.signal();
// then
closeFuture.get(1L, TimeUnit.SECONDS);
// and
hasSentAck = broker.getReceivedCommandRequests().stream().filter((r) -> r.eventType() == EventType.SUBSCRIPTION_EVENT).findAny().isPresent();
assertThat(hasSentAck).isTrue();
}
Aggregations