Search in sources :

Example 6 with TopicSubscriberGroup

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();
}
Also used : SubscriptionManager(io.zeebe.client.task.impl.subscription.SubscriptionManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) TimeoutException(java.util.concurrent.TimeoutException) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) ZeebeClient(io.zeebe.client.ZeebeClient) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) Future(java.util.concurrent.Future) ErrorCode(io.zeebe.protocol.clientapi.ErrorCode) RemoteAddress(io.zeebe.transport.RemoteAddress) ClientRule(io.zeebe.client.util.ClientRule) TopicSubscriberGroup(io.zeebe.client.event.impl.TopicSubscriberGroup) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) TopicSubscriptionBuilderImpl(io.zeebe.client.event.impl.TopicSubscriptionBuilderImpl) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ResponseController(io.zeebe.test.broker.protocol.brokerapi.ResponseController) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) RuleChain(org.junit.rules.RuleChain) ActorFuture(io.zeebe.util.sched.future.ActorFuture) List(java.util.List) Stream(java.util.stream.Stream) Rule(org.junit.Rule) EventType(io.zeebe.protocol.clientapi.EventType) Conditions(io.zeebe.test.util.Conditions) Optional(java.util.Optional) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TestUtil(io.zeebe.test.util.TestUtil) RemoteAddress(io.zeebe.transport.RemoteAddress) TopicSubscriberGroup(io.zeebe.client.event.impl.TopicSubscriberGroup) Test(org.junit.Test)

Aggregations

TopicSubscriberGroup (io.zeebe.client.event.impl.TopicSubscriberGroup)6 Test (org.junit.Test)5 TopicSubscriptionBuilderImpl (io.zeebe.client.event.impl.TopicSubscriptionBuilderImpl)4 ControlMessageRequest (io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest)4 ResponseController (io.zeebe.test.broker.protocol.brokerapi.ResponseController)4 RemoteAddress (io.zeebe.transport.RemoteAddress)4 ZeebeClient (io.zeebe.client.ZeebeClient)3 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)3 SubscriptionManager (io.zeebe.client.task.impl.subscription.SubscriptionManager)3 ClientRule (io.zeebe.client.util.ClientRule)3 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)3 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)3 EventType (io.zeebe.protocol.clientapi.EventType)3 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)3 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)3 Conditions (io.zeebe.test.util.Conditions)3 TestUtil (io.zeebe.test.util.TestUtil)3 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)3 ActorFuture (io.zeebe.util.sched.future.ActorFuture)3 Duration (java.time.Duration)3