Search in sources :

Example 1 with TopicEventImpl

use of io.zeebe.client.topic.impl.TopicEventImpl in project zeebe by zeebe-io.

the class TopicSubscriptionTest method testSubscriptionsWithSameNameOnDifferentTopicShouldReceiveRespectiveEvents.

@Test
public void testSubscriptionsWithSameNameOnDifferentTopicShouldReceiveRespectiveEvents() {
    // given
    final String anotherTopicName = "another-topic";
    final TopicEventImpl event = (TopicEventImpl) client.topics().create(anotherTopicName, 1).execute();
    final int anotherPartitionId = 2;
    final TopicSubscription topic0subscription = client.topics().newSubscription(clientRule.getDefaultTopic()).startAtHeadOfTopic().handler(recordingHandler).name(SUBSCRIPTION_NAME).open();
    final RecordingEventHandler anotherRecordingHandler = new RecordingEventHandler();
    final TopicSubscription topic1Subscription = client.topics().newSubscription(anotherTopicName).startAtHeadOfTopic().handler(anotherRecordingHandler).name(SUBSCRIPTION_NAME).open();
    // when
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    clientRule.tasks().create(anotherTopicName, "bar").execute();
    // then
    waitUntil(() -> recordingHandler.numRecordedTaskEvents() >= 2);
    waitUntil(() -> anotherRecordingHandler.numRecordedTaskEvents() >= 2);
    topic0subscription.close();
    topic1Subscription.close();
    Set<String> receivedTopicNamesSubscription = recordingHandler.getRecordedEvents().stream().filter((re) -> re.getMetadata().getType() == TopicEventType.TASK).map((re) -> re.getMetadata().getTopicName()).collect(Collectors.toSet());
    Set<Integer> receivedPartitionIdsSubscription = recordingHandler.getRecordedEvents().stream().filter((re) -> re.getMetadata().getType() == TopicEventType.TASK).map((re) -> re.getMetadata().getPartitionId()).collect(Collectors.toSet());
    assertThat(receivedTopicNamesSubscription).containsExactly(clientRule.getDefaultTopic());
    assertThat(receivedPartitionIdsSubscription).containsExactly(clientRule.getDefaultPartition());
    receivedTopicNamesSubscription = anotherRecordingHandler.getRecordedEvents().stream().filter((re) -> re.getMetadata().getType() == TopicEventType.TASK).map((re) -> re.getMetadata().getTopicName()).collect(Collectors.toSet());
    receivedPartitionIdsSubscription = anotherRecordingHandler.getRecordedEvents().stream().filter((re) -> re.getMetadata().getType() == TopicEventType.TASK).map((re) -> re.getMetadata().getPartitionId()).collect(Collectors.toSet());
    assertThat(receivedTopicNamesSubscription).containsExactly(anotherTopicName);
    assertThat(receivedPartitionIdsSubscription).containsExactly(anotherPartitionId);
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) ZeebeClient(io.zeebe.client.ZeebeClient) TopicEventImpl(io.zeebe.client.topic.impl.TopicEventImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Topic(io.zeebe.client.topic.Topic) EmbeddedBrokerRule(io.zeebe.broker.it.EmbeddedBrokerRule) Timeout(org.junit.rules.Timeout) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) Properties(java.util.Properties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) RuleChain(org.junit.rules.RuleChain) List(java.util.List) ClientRule(io.zeebe.broker.it.ClientRule) Rule(org.junit.Rule) CreateTaskCommandImpl(io.zeebe.client.task.impl.CreateTaskCommandImpl) ClientProperties(io.zeebe.client.ClientProperties) Topics(io.zeebe.client.topic.Topics) io.zeebe.client.event(io.zeebe.client.event) TestUtil(io.zeebe.test.util.TestUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TopicEventImpl(io.zeebe.client.topic.impl.TopicEventImpl) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ClientRule (io.zeebe.broker.it.ClientRule)1 EmbeddedBrokerRule (io.zeebe.broker.it.EmbeddedBrokerRule)1 ClientProperties (io.zeebe.client.ClientProperties)1 ZeebeClient (io.zeebe.client.ZeebeClient)1 io.zeebe.client.event (io.zeebe.client.event)1 CreateTaskCommandImpl (io.zeebe.client.task.impl.CreateTaskCommandImpl)1 Topic (io.zeebe.client.topic.Topic)1 Topics (io.zeebe.client.topic.Topics)1 TopicEventImpl (io.zeebe.client.topic.impl.TopicEventImpl)1 TestUtil (io.zeebe.test.util.TestUtil)1 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1