Search in sources :

Example 1 with RecordingEventHandler

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);
}
Also used : TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) RecordingEventHandler(io.zeebe.broker.it.subscription.RecordingEventHandler) ZeebeClient(io.zeebe.client.ZeebeClient) ArrayList(java.util.ArrayList) RuleChain(org.junit.rules.RuleChain) ClientRule(io.zeebe.broker.it.ClientRule) List(java.util.List) Rule(org.junit.Rule) CreateTaskCommandImpl(io.zeebe.client.task.impl.CreateTaskCommandImpl) Topic(io.zeebe.client.topic.Topic) Timeout(org.junit.rules.Timeout) ExpectedException(org.junit.rules.ExpectedException) AutoCloseableRule(io.zeebe.test.util.AutoCloseableRule) Before(org.junit.Before) ArrayList(java.util.ArrayList) RecordingEventHandler(io.zeebe.broker.it.subscription.RecordingEventHandler) Topic(io.zeebe.client.topic.Topic) Test(org.junit.Test)

Aggregations

ClientRule (io.zeebe.broker.it.ClientRule)1 RecordingEventHandler (io.zeebe.broker.it.subscription.RecordingEventHandler)1 ZeebeClient (io.zeebe.client.ZeebeClient)1 CreateTaskCommandImpl (io.zeebe.client.task.impl.CreateTaskCommandImpl)1 Topic (io.zeebe.client.topic.Topic)1 AutoCloseableRule (io.zeebe.test.util.AutoCloseableRule)1 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 RuleChain (org.junit.rules.RuleChain)1 Timeout (org.junit.rules.Timeout)1