use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class PollableTopicSubscriptionTest method shouldPollEventsWhileModifyingSubscribers.
@Test
public void shouldPollEventsWhileModifyingSubscribers() throws InterruptedException {
// given
final int subscriberKey = 456;
broker.stubTopicSubscriptionApi(subscriberKey);
final ControllableHandler handler = new ControllableHandler();
final TopicSubscriberGroup subscription = (TopicSubscriberGroup) client.topics().newPollableSubscription(clientRule.getDefaultTopicName()).name("hohoho").open();
final RemoteAddress clientAddress = broker.getReceivedCommandRequests().get(0).getSource();
broker.pushTopicEvent(clientAddress, subscriberKey, 1, 1);
// event is received
waitUntil(() -> subscription.size() == 1);
final AtomicReference<Throwable> failure = new AtomicReference<>();
final Thread poller = new Thread(() -> subscription.poll(handler));
poller.setUncaughtExceptionHandler((thread, throwable) -> failure.set(throwable));
poller.start();
waitUntil(() -> handler.isWaiting());
// closing the subscriber, triggering reopen request
broker.closeTransport();
waitUntil(() -> subscription.numActiveSubscribers() == 0);
// when continuing event handling
handler.disableWait();
handler.signal();
// then the concurrent modification of subscribers did not affect the poller
poller.join(Duration.ofSeconds(10).toMillis());
assertThat(failure.get()).isNull();
// make the reopen request time out immediately so
// that the client can close without waiting for the timeout
clientRule.getClock().addTime(Duration.ofSeconds(60));
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class PollableTopicSubscriptionTest method shouldNotRetryOnHandlerFailure.
/**
* Exception handling should be left to the client for pollable subscriptions
*/
@Test
public void shouldNotRetryOnHandlerFailure() throws InterruptedException {
// given
broker.stubTopicSubscriptionApi(123L);
final FailingHandler handler = new FailingHandler();
final PollableTopicSubscription subscription = clientRule.topics().newPollableSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().name(SUBSCRIPTION_NAME).open();
final RemoteAddress clientAddress = broker.getReceivedCommandRequests().get(0).getSource();
broker.pushTopicEvent(clientAddress, 123L, 1L, 1L);
broker.pushTopicEvent(clientAddress, 123L, 1L, 2L);
// when
try {
TestUtil.doRepeatedly(() -> subscription.poll(handler)).until((i) -> false, (e) -> e != null);
fail("Exception expected");
} catch (Exception e) {
// then
assertThat(e.getCause()).isInstanceOf(RuntimeException.class);
assertThat(e.getCause()).hasMessageContaining("Exception during handling of event");
}
assertThat(subscription.isOpen()).isTrue();
assertThat(handler.numRecordedEvents()).isEqualTo(1);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldDiscardEventsReceivedBeforeReopening.
@Test
public void shouldDiscardEventsReceivedBeforeReopening() throws InterruptedException {
// given
broker.stubTopicSubscriptionApi(123L);
final ControllableHandler handler = new ControllableHandler();
clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(handler).name(SUBSCRIPTION_NAME).open();
final RemoteAddress clientAddress = receivedSubscribeCommands().findFirst().get().getSource();
broker.pushTopicEvent(clientAddress, 123L, 1L, 2L);
broker.pushTopicEvent(clientAddress, 123L, 1L, 3L);
TestUtil.waitUntil(() -> handler.isWaiting());
// when
broker.interruptAllServerChannels();
TestUtil.waitUntil(() -> receivedSubscribeCommands().count() >= 2);
handler.disableWait();
handler.signal();
// then
// give client some time to invoke handler with second event
Thread.sleep(1000L);
assertThat(handler.getNumHandledEvents()).isEqualTo(1);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldInvokeDefaultHandlerIfNoHandlerIsRegistered.
@Test
public void shouldInvokeDefaultHandlerIfNoHandlerIsRegistered() {
// given
broker.stubTopicSubscriptionApi(123L);
final RecordingTopicEventHandler defaultEventHandler = new RecordingTopicEventHandler();
clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(defaultEventHandler).name(SUBSCRIPTION_NAME).open();
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.WORKFLOW_INSTANCE_EVENT);
broker.pushTopicEvent(clientAddress, 123L, 1L, 3L, EventType.INCIDENT_EVENT);
// then
waitUntil(() -> defaultEventHandler.numTopicEvents() == 3);
assertThat(defaultEventHandler.numTopicEvents()).isEqualTo(3);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldInvokeDefaultHandlerForTopicEvent.
@Test
public void shouldInvokeDefaultHandlerForTopicEvent() {
// given
broker.stubTopicSubscriptionApi(123L);
final RecordingTopicEventHandler eventHandler = new RecordingTopicEventHandler();
clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(eventHandler).name(SUBSCRIPTION_NAME).open();
final RemoteAddress clientAddress = broker.getReceivedCommandRequests().get(0).getSource();
// when pushing two events
broker.pushTopicEvent(clientAddress, 123L, 1L, 1L, EventType.RAFT_EVENT);
broker.pushTopicEvent(clientAddress, 123L, 1L, 2L, EventType.RAFT_EVENT);
// then
waitUntil(() -> eventHandler.numTopicEvents() == 2);
final GeneralEvent event1 = eventHandler.topicEvents.get(0);
final GeneralEvent event2 = eventHandler.topicEvents.get(1);
assertMetadata(event1, 1L, 1L, TopicEventType.RAFT);
assertMetadata(event2, 1L, 2L, TopicEventType.RAFT);
assertThat(eventHandler.numTopicEvents()).isEqualTo(2);
assertThat(eventHandler.numTaskEvents()).isEqualTo(0);
assertThat(eventHandler.numWorkflowEvents()).isEqualTo(0);
assertThat(eventHandler.numWorkflowInstanceEvents()).isEqualTo(0);
assertThat(eventHandler.numIncidentEvents()).isEqualTo(0);
}
Aggregations