use of io.zeebe.client.task.impl.subscription.SubscriptionManager in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldCloseSubscriptionWhileOpeningSubscriber.
@Test
public void shouldCloseSubscriptionWhileOpeningSubscriber() {
// given
final int subscriberKey = 123;
broker.stubTopicSubscriptionApi(0L);
final ResponseController responseController = broker.onExecuteCommandRequest(EventType.SUBSCRIBER_EVENT, "SUBSCRIBE").respondWith().key(subscriberKey).event().allOf((r) -> r.getCommand()).put("state", "SUBSCRIBED").done().registerControlled();
final TopicSubscriptionBuilderImpl builder = (TopicSubscriptionBuilderImpl) client.topics().newSubscription(clientRule.getDefaultTopicName()).handler(DO_NOTHING).name("foo");
final Future<TopicSubscriberGroup> future = builder.buildSubscriberGroup();
waitUntil(() -> broker.getReceivedCommandRequests().stream().filter(r -> r.eventType() == EventType.SUBSCRIBER_EVENT && "SUBSCRIBE".equals(r.getCommand().get("state"))).count() == 1);
final Thread closingThread = new Thread(client::close);
closingThread.start();
final SubscriptionManager subscriptionManager = ((ZeebeClientImpl) client).getSubscriptionManager();
waitUntil(() -> subscriptionManager.isClosing());
// when
responseController.unblockNextResponse();
// then
waitUntil(() -> future.isDone());
assertThat(future).isDone();
final Optional<ControlMessageRequest> closeRequest = broker.getReceivedControlMessageRequests().stream().filter(c -> c.messageType() == ControlMessageType.REMOVE_TOPIC_SUBSCRIPTION).findFirst();
assertThat(closeRequest).isPresent();
final ControlMessageRequest request = closeRequest.get();
assertThat(request.getData()).containsEntry("subscriberKey", subscriberKey);
}
Aggregations