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);
}
Aggregations