Search in sources :

Example 6 with RemoteAddress

use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.

the class TopicSubscriptionTest method shouldReceiveEventsAfterChannelInterruption.

@Test
public void shouldReceiveEventsAfterChannelInterruption() {
    // given
    broker.stubTopicSubscriptionApi(123L);
    final RecordingEventHandler recordingHandler = new RecordingEventHandler();
    clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(recordingHandler).name(SUBSCRIPTION_NAME).open();
    broker.interruptAllServerChannels();
    TestUtil.waitUntil(() -> receivedSubscribeCommands().count() >= 2);
    final RemoteAddress clientAddress = receivedSubscribeCommands().skip(1).findFirst().get().getSource();
    // when
    broker.pushTopicEvent(clientAddress, 124L, 1L, 2L);
    // then
    TestUtil.waitUntil(() -> recordingHandler.getRecordedEvents().size() > 0);
    assertThat(recordingHandler.getRecordedEvents()).hasSize(1);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) Test(org.junit.Test)

Example 7 with RemoteAddress

use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.

the class TopicSubscriptionTest method shouldInvokeWorkflowHandlerForWorkflowEvent.

@Test
public void shouldInvokeWorkflowHandlerForWorkflowEvent() {
    // 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.WORKFLOW_EVENT);
    broker.pushTopicEvent(clientAddress, 123L, 1L, 2L, EventType.WORKFLOW_EVENT);
    // then
    waitUntil(() -> eventHandler.numWorkflowEvents() >= 2);
    final WorkflowEvent event1 = eventHandler.workflowEvents.get(0);
    final WorkflowEvent event2 = eventHandler.workflowEvents.get(1);
    assertMetadata(event1, 1L, 1L, TopicEventType.WORKFLOW);
    assertMetadata(event2, 1L, 2L, TopicEventType.WORKFLOW);
    assertThat(eventHandler.numTopicEvents()).isEqualTo(0);
    assertThat(eventHandler.numTaskEvents()).isEqualTo(0);
    assertThat(eventHandler.numWorkflowEvents()).isEqualTo(2);
    assertThat(eventHandler.numWorkflowInstanceEvents()).isEqualTo(0);
    assertThat(eventHandler.numIncidentEvents()).isEqualTo(0);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) Test(org.junit.Test)

Example 8 with RemoteAddress

use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.

the class TopicSubscriptionTest method shouldInvokeWorkflowInstanceHandlerForWorkflowInstanceEvent.

@Test
public void shouldInvokeWorkflowInstanceHandlerForWorkflowInstanceEvent() {
    // 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.WORKFLOW_INSTANCE_EVENT);
    broker.pushTopicEvent(clientAddress, 123L, 1L, 2L, EventType.WORKFLOW_INSTANCE_EVENT);
    // then
    waitUntil(() -> eventHandler.numWorkflowInstanceEvents() >= 2);
    final WorkflowInstanceEvent event1 = eventHandler.workflowInstanceEvents.get(0);
    final WorkflowInstanceEvent event2 = eventHandler.workflowInstanceEvents.get(1);
    assertMetadata(event1, 1L, 1L, TopicEventType.WORKFLOW_INSTANCE);
    assertMetadata(event2, 1L, 2L, TopicEventType.WORKFLOW_INSTANCE);
    assertThat(eventHandler.numTopicEvents()).isEqualTo(0);
    assertThat(eventHandler.numTaskEvents()).isEqualTo(0);
    assertThat(eventHandler.numWorkflowEvents()).isEqualTo(0);
    assertThat(eventHandler.numWorkflowInstanceEvents()).isEqualTo(2);
    assertThat(eventHandler.numIncidentEvents()).isEqualTo(0);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) Test(org.junit.Test)

Example 9 with RemoteAddress

use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.

the class TopicSubscriptionTest method shouldInvokeRaftEventHandlerForRaftEvent.

@Test
public void shouldInvokeRaftEventHandlerForRaftEvent() {
    // 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.RAFT_EVENT);
    broker.pushTopicEvent(clientAddress, 123L, 1L, 2L, EventType.RAFT_EVENT);
    // then
    waitUntil(() -> eventHandler.numRaftEvents() >= 2);
    final RaftEvent event1 = eventHandler.raftEvents.get(0);
    final RaftEvent event2 = eventHandler.raftEvents.get(1);
    assertMetadata(event1, 1L, 1L, TopicEventType.RAFT);
    assertMetadata(event2, 1L, 2L, TopicEventType.RAFT);
    assertThat(eventHandler.numTopicEvents()).isEqualTo(0);
    assertThat(eventHandler.numTaskEvents()).isEqualTo(0);
    assertThat(eventHandler.numWorkflowEvents()).isEqualTo(0);
    assertThat(eventHandler.numWorkflowInstanceEvents()).isEqualTo(0);
    assertThat(eventHandler.numIncidentEvents()).isEqualTo(0);
    assertThat(eventHandler.numRaftEvents()).isEqualTo(2);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) Test(org.junit.Test)

Example 10 with RemoteAddress

use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.

the class PartitionedTaskSubscriptionTest method shouldReceiveEventsFromMultiplePartitions.

@Test
public void shouldReceiveEventsFromMultiplePartitions() {
    // given
    final int subscriberKey1 = 456;
    broker1.stubTaskSubscriptionApi(subscriberKey1);
    final int subscriberKey2 = 789;
    broker2.stubTaskSubscriptionApi(subscriberKey2);
    final RecordingTaskHandler eventHandler = new RecordingTaskHandler();
    client.tasks().newTaskSubscription(TOPIC).handler(eventHandler).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();
    // when
    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);
    // then
    waitUntil(() -> eventHandler.numHandledTasks() == 2);
    assertThat(eventHandler.getHandledTasks()).extracting("metadata.key").containsExactlyInAnyOrder(key1, key2);
}
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