use of io.zeebe.transport.RemoteAddress 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();
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldRetryThreeTimesOnHandlerFailure.
@Test
public void shouldRetryThreeTimesOnHandlerFailure() throws InterruptedException {
// given
broker.stubTopicSubscriptionApi(123L);
final FailingHandler handler = new FailingHandler();
final TopicSubscription subscription = clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(handler).name(SUBSCRIPTION_NAME).open();
final RemoteAddress clientAddress = broker.getReceivedCommandRequests().get(0).getSource();
// when pushing two events
broker.pushTopicEvent(clientAddress, 123L, 1L, 1L);
broker.pushTopicEvent(clientAddress, 123L, 1L, 2L);
// then
waitUntil(() -> !subscription.isOpen());
// wait an extra second as we might receive more events if this feature is broken
Thread.sleep(1000L);
assertThat(handler.getRecordedEvents()).hasSize(3);
final Set<Long> eventPositions = handler.getRecordedEvents().stream().map((re) -> re.getMetadata().getPosition()).collect(Collectors.toSet());
assertThat(eventPositions).containsExactly(1L);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldCloseSubscriptionWhenAckFails.
@Test
public void shouldCloseSubscriptionWhenAckFails() {
// given
final long subscriberKey = 123L;
broker.stubTopicSubscriptionApi(subscriberKey);
broker.onExecuteCommandRequest(EventType.SUBSCRIPTION_EVENT, "ACKNOWLEDGE").respondWithError().errorCode(ErrorCode.REQUEST_PROCESSING_FAILURE).errorData("foo").register();
final TopicSubscription subscription = clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(DO_NOTHING).name(SUBSCRIPTION_NAME).open();
final RemoteAddress clientAddress = receivedSubscribeCommands().findFirst().get().getSource();
final int subscriptionCapacity = ((ZeebeClientImpl) client).getSubscriptionPrefetchCapacity();
// when
for (int i = 0; i < subscriptionCapacity; i++) {
broker.pushTopicEvent(clientAddress, subscriberKey, i, i);
}
// then
waitUntil(() -> subscription.isClosed());
assertThat(subscription.isClosed()).isTrue();
}
use of io.zeebe.transport.RemoteAddress 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));
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class PartitionedTaskSubscriptionTest method shouldSumWorkCountOfPollableSubscription.
@Test
public void shouldSumWorkCountOfPollableSubscription() {
// given
final int subscriberKey1 = 456;
broker1.stubTaskSubscriptionApi(subscriberKey1);
final int subscriberKey2 = 789;
broker2.stubTaskSubscriptionApi(subscriberKey2);
final RecordingTaskHandler eventHandler = new RecordingTaskHandler();
final PollableTaskSubscription subscription = client.tasks().newPollableTaskSubscription(TOPIC).taskType(TASK_TYPE).lockOwner("bumbum").lockTime(Duration.ofSeconds(6)).open();
final RemoteAddress clientAddressFromBroker1 = broker1.getReceivedControlMessageRequests().get(0).getSource();
final RemoteAddress clientAddressFromBroker2 = broker2.getReceivedControlMessageRequests().get(0).getSource();
final long key1 = 3;
broker1.newSubscribedEvent().eventType(EventType.TASK_EVENT).partitionId(PARTITION_1).subscriberKey(subscriberKey1).key(key1).subscriptionType(SubscriptionType.TASK_SUBSCRIPTION).event().done().push(clientAddressFromBroker1);
final long key2 = 4;
broker2.newSubscribedEvent().eventType(EventType.TASK_EVENT).partitionId(PARTITION_1).subscriberKey(subscriberKey1).key(key2).subscriptionType(SubscriptionType.TASK_SUBSCRIPTION).event().done().push(clientAddressFromBroker2);
waitUntil(() -> ((SubscriberGroup<?>) subscription).size() == 2);
// when
final int polledEvents = subscription.poll(eventHandler);
// then
assertThat(polledEvents).isEqualTo(2);
}
Aggregations