use of io.zeebe.broker.it.subscription.RecordingEventHandler in project zeebe by zeebe-io.
the class SubscriptionClusteredTest method shouldOpenSubscriptionGroupForDistributedTopic.
@Test
public void shouldOpenSubscriptionGroupForDistributedTopic() {
// given
final String topicName = "pasta al forno";
final Topic topic = clusteringRule.createTopic(topicName, PARTITION_COUNT);
// when
final Integer[] partitionIds = topic.getPartitions().stream().mapToInt(p -> p.getId()).boxed().toArray(Integer[]::new);
createTaskOnPartition(topicName, partitionIds[0]);
createTaskOnPartition(topicName, partitionIds[1]);
createTaskOnPartition(topicName, partitionIds[2]);
createTaskOnPartition(topicName, partitionIds[3]);
createTaskOnPartition(topicName, partitionIds[4]);
// and
final RecordingEventHandler recordingEventHandler = new RecordingEventHandler();
final List<Integer> receivedPartitionIds = new ArrayList<>();
client.topics().newSubscription(topicName).handler(recordingEventHandler).taskEventHandler(e -> {
if ("CREATE".equals(e.getState())) {
receivedPartitionIds.add(e.getMetadata().getPartitionId());
}
}).startAtHeadOfTopic().name("SubscriptionName").open();
// then
waitUntil(() -> receivedPartitionIds.size() == PARTITION_COUNT);
assertThat(receivedPartitionIds).containsExactlyInAnyOrder(partitionIds);
}
Aggregations