Search in sources :

Example 1 with RemoteAddress

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));
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) TopicSubscriberGroup(io.zeebe.client.event.impl.TopicSubscriberGroup) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 2 with RemoteAddress

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);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) Test(org.junit.Test)

Example 3 with RemoteAddress

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);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) Test(org.junit.Test)

Example 4 with RemoteAddress

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);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) Test(org.junit.Test)

Example 5 with RemoteAddress

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);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) Test(org.junit.Test)

Aggregations

RemoteAddress (io.zeebe.transport.RemoteAddress)35 Test (org.junit.Test)34 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 ControlMessageRequest (io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest)12 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)12 ZeebeClient (io.zeebe.client.ZeebeClient)11 ClientRule (io.zeebe.client.util.ClientRule)11 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)11 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)11 EventType (io.zeebe.protocol.clientapi.EventType)11 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)11 TestUtil (io.zeebe.test.util.TestUtil)11 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)11 Duration (java.time.Duration)11 List (java.util.List)11 TimeUnit (java.util.concurrent.TimeUnit)11 Collectors (java.util.stream.Collectors)11 Stream (java.util.stream.Stream)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11