Search in sources :

Example 6 with TestUtil.waitUntil

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));
}
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) ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) RemoteAddress(io.zeebe.transport.RemoteAddress) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Aggregations

ZeebeClient (io.zeebe.client.ZeebeClient)6 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)6 ClientRule (io.zeebe.client.util.ClientRule)6 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)6 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)6 EventType (io.zeebe.protocol.clientapi.EventType)6 ControlMessageRequest (io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest)6 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)6 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)6 TestUtil (io.zeebe.test.util.TestUtil)6 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)6 RemoteAddress (io.zeebe.transport.RemoteAddress)6 Duration (java.time.Duration)6 List (java.util.List)6 TimeUnit (java.util.concurrent.TimeUnit)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 JsonParseException (com.fasterxml.jackson.core.JsonParseException)3