use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class PartitionedTopicSubscriptionTest method shouldReceiveEventsFromMultiplePartitions.
@Test
public void shouldReceiveEventsFromMultiplePartitions() {
// given
final int subscriberKey1 = 456;
broker1.stubTopicSubscriptionApi(subscriberKey1);
final int subscriberKey2 = 789;
broker2.stubTopicSubscriptionApi(subscriberKey2);
final RecordingEventHandler eventHandler = new RecordingEventHandler();
client.topics().newSubscription(TOPIC).handler(eventHandler).name("hohoho").open();
final RemoteAddress clientAddressFromBroker1 = broker1.getReceivedCommandRequests().get(0).getSource();
final RemoteAddress clientAddressFromBroker2 = broker2.getReceivedCommandRequests().get(0).getSource();
// when
final long key1 = 3;
broker1.pushTopicEvent(clientAddressFromBroker1, b -> b.partitionId(PARTITION_1).subscriberKey(subscriberKey1).key(key1));
final long key2 = 4;
broker2.pushTopicEvent(clientAddressFromBroker2, b -> b.partitionId(PARTITION_2).subscriberKey(subscriberKey2).key(key2));
// then
waitUntil(() -> eventHandler.numRecordedEvents() == 2);
assertThat(eventHandler.getRecordedEvents()).extracting("metadata.key").containsExactlyInAnyOrder(key1, key2);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class PollableTopicSubscriptionTest method shouldAcknowledgeOnlyOnceWhenTriggeredMultipleTimes.
@Test
public void shouldAcknowledgeOnlyOnceWhenTriggeredMultipleTimes() throws InterruptedException {
// given
final long subscriberKey = 123L;
broker.stubTopicSubscriptionApi(subscriberKey);
final ResponseController ackResponseController = stubAcknowledgeRequest().registerControlled();
final PollableTopicSubscription subscription = clientRule.topics().newPollableSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().name(SUBSCRIPTION_NAME).open();
final int subscriptionCapacity = ((ZeebeClientImpl) client).getSubscriptionPrefetchCapacity();
final int replenishmentThreshold = (int) (subscriptionCapacity * (1.0d - Subscriber.REPLENISHMENT_THRESHOLD));
final RemoteAddress clientAddress = receivedSubscribeCommands().findFirst().get().getSource();
// push and handle as many events such that an ACK is triggered
for (int i = 0; i < replenishmentThreshold + 1; i++) {
broker.pushTopicEvent(clientAddress, subscriberKey, i, i);
}
final AtomicInteger handledEvents = new AtomicInteger(0);
doRepeatedly(() -> handledEvents.addAndGet(subscription.poll(DO_NOTHING))).until(e -> e == replenishmentThreshold + 1);
waitUntil(() -> receivedAckRequests().count() == 1);
// when consuming another event (while the ACK is not yet confirmed)
broker.pushTopicEvent(clientAddress, subscriberKey, 99, 99);
doRepeatedly(() -> subscription.poll(DO_NOTHING)).until(e -> e == 1);
// then
// give some time for another ACK request
Thread.sleep(500L);
ackResponseController.unblockNextResponse();
final List<ExecuteCommandRequest> ackRequests = receivedAckRequests().collect(Collectors.toList());
// and not two
assertThat(ackRequests).hasSize(1);
// unblock the request so tear down succeeds
stubAcknowledgeRequest().register();
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldContinueEventHandlingAfterSuccessfulRetry.
@Test
public void shouldContinueEventHandlingAfterSuccessfulRetry() {
// given
broker.stubTopicSubscriptionApi(123L);
final AtomicInteger counter = new AtomicInteger(3);
final FailingHandler handler = new FailingHandler(e -> e.getMetadata().getPosition() == 1L && counter.decrementAndGet() > 0);
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(() -> handler.getRecordedEvents().stream().anyMatch(re -> re.getMetadata().getPosition() == 2L));
final List<Long> handledEventPositions = handler.getRecordedEvents().stream().map((re) -> re.getMetadata().getPosition()).collect(Collectors.toList());
assertThat(handledEventPositions).containsExactly(1L, 1L, 1L, 2L);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldInvokeTasktHandlerForTaskEvent.
@Test
public void shouldInvokeTasktHandlerForTaskEvent() {
// given
broker.stubTopicSubscriptionApi(123L);
final RecordingTopicEventHandler eventHandler = subscribeToAllEvents();
final RemoteAddress clientAddress = broker.getReceivedCommandRequests().get(0).getSource();
// when pushing two events
broker.pushTopicEvent(clientAddress, 123L, 1L, 1L, EventType.TASK_EVENT);
broker.pushTopicEvent(clientAddress, 123L, 1L, 2L, EventType.TASK_EVENT);
// then
waitUntil(() -> eventHandler.numTaskEvents() >= 2);
final TaskEvent event1 = eventHandler.taskEvents.get(0);
final TaskEvent event2 = eventHandler.taskEvents.get(1);
assertMetadata(event1, 1L, 1L, TopicEventType.TASK);
assertMetadata(event2, 1L, 2L, TopicEventType.TASK);
assertThat(eventHandler.numTopicEvents()).isEqualTo(0);
assertThat(eventHandler.numTaskEvents()).isEqualTo(2);
assertThat(eventHandler.numWorkflowEvents()).isEqualTo(0);
assertThat(eventHandler.numWorkflowInstanceEvents()).isEqualTo(0);
assertThat(eventHandler.numIncidentEvents()).isEqualTo(0);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldInvokeIncidentEventHandlerForIncidentEvent.
@Test
public void shouldInvokeIncidentEventHandlerForIncidentEvent() {
// given
broker.stubTopicSubscriptionApi(123L);
final RecordingTopicEventHandler eventHandler = subscribeToAllEvents();
final RemoteAddress clientAddress = broker.getReceivedCommandRequests().get(0).getSource();
// when pushing two events
broker.pushTopicEvent(clientAddress, 123L, 1L, 1L, EventType.INCIDENT_EVENT);
broker.pushTopicEvent(clientAddress, 123L, 1L, 2L, EventType.INCIDENT_EVENT);
// then
waitUntil(() -> eventHandler.numIncidentEvents() >= 2);
final IncidentEvent event1 = eventHandler.incidentEvents.get(0);
final IncidentEvent event2 = eventHandler.incidentEvents.get(1);
assertMetadata(event1, 1L, 1L, TopicEventType.INCIDENT);
assertMetadata(event2, 1L, 2L, TopicEventType.INCIDENT);
assertThat(eventHandler.numTopicEvents()).isEqualTo(0);
assertThat(eventHandler.numTaskEvents()).isEqualTo(0);
assertThat(eventHandler.numWorkflowEvents()).isEqualTo(0);
assertThat(eventHandler.numWorkflowInstanceEvents()).isEqualTo(0);
assertThat(eventHandler.numIncidentEvents()).isEqualTo(2);
}
Aggregations