Search in sources :

Example 6 with Topic

use of io.zeebe.client.topic.Topic in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldReceiveTasksFromMultiplePartitions.

@Test
public void shouldReceiveTasksFromMultiplePartitions() {
    // given
    final String topicName = "gyros";
    final int numPartitions = 2;
    final ZeebeClient client = clientRule.getClient();
    client.topics().create(topicName, numPartitions).execute();
    final Topics topics = client.topics().getTopics().execute();
    final Topic topic = topics.getTopics().stream().filter(t -> t.getName().equals(topicName)).findFirst().get();
    final Integer[] partitionIds = topic.getPartitions().stream().mapToInt(p -> p.getId()).boxed().toArray(Integer[]::new);
    final String taskType = "foooo";
    final RecordingTaskHandler handler = new RecordingTaskHandler();
    createTaskOnPartition(client, topicName, partitionIds[0], taskType);
    createTaskOnPartition(client, topicName, partitionIds[1], taskType);
    // when
    client.tasks().newTaskSubscription(topicName).handler(handler).lockOwner("foo").lockTime(Duration.ofSeconds(30)).taskType(taskType).open();
    // then
    waitUntil(() -> handler.getHandledTasks().size() == 2);
    final Integer[] receivedPartitionIds = handler.getHandledTasks().stream().map(t -> t.getMetadata().getPartitionId()).toArray(Integer[]::new);
    assertThat(receivedPartitionIds).containsExactlyInAnyOrder(partitionIds);
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskSubscription(io.zeebe.client.task.TaskSubscription) Test(org.junit.Test) TopicEventRecorder.taskEvent(io.zeebe.broker.it.util.TopicEventRecorder.taskEvent) Instant(java.time.Instant) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) TopicEventRecorder(io.zeebe.broker.it.util.TopicEventRecorder) ZeebeClient(io.zeebe.client.ZeebeClient) List(java.util.List) ClientRule(io.zeebe.broker.it.ClientRule) org.junit.rules(org.junit.rules) TopicEventRecorder.taskRetries(io.zeebe.broker.it.util.TopicEventRecorder.taskRetries) Rule(org.junit.Rule) Duration(java.time.Duration) CreateTaskCommandImpl(io.zeebe.client.task.impl.CreateTaskCommandImpl) Topic(io.zeebe.client.topic.Topic) EmbeddedBrokerRule(io.zeebe.broker.it.EmbeddedBrokerRule) Topics(io.zeebe.client.topic.Topics) TestUtil(io.zeebe.test.util.TestUtil) Topics(io.zeebe.client.topic.Topics) RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) ZeebeClient(io.zeebe.client.ZeebeClient) Topic(io.zeebe.client.topic.Topic) Test(org.junit.Test)

Example 7 with Topic

use of io.zeebe.client.topic.Topic 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)

Example 8 with Topic

use of io.zeebe.client.topic.Topic in project zeebe by zeebe-io.

the class DeploymentClusteredTest method shouldCreateInstancesOnRestartedBroker.

@Test
public void shouldCreateInstancesOnRestartedBroker() {
    // given
    final int workCount = PARTITION_COUNT;
    final Topic topic = clusteringRule.createTopic("test", PARTITION_COUNT);
    clusteringRule.stopBroker(ClusteringRule.BROKER_3_CLIENT_ADDRESS);
    client.workflows().deploy("test").addWorkflowModel(WORKFLOW, "workflow.bpmn").execute();
    // when
    clusteringRule.restartBroker(ClusteringRule.BROKER_3_CLIENT_ADDRESS);
    // then create wf instance on each partition
    final Integer[] partitionIds = topic.getPartitions().stream().mapToInt(p -> p.getId()).boxed().toArray(Integer[]::new);
    for (int partition : partitionIds) {
        final WorkflowInstanceEvent workflowInstanceEvent = createWorkflowInstanceOnPartition("test", partition, "process");
        assertThat(workflowInstanceEvent.getState()).isEqualTo("WORKFLOW_INSTANCE_CREATED");
    }
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) Topic(io.zeebe.client.topic.Topic) Test(org.junit.Test)

Aggregations

Topic (io.zeebe.client.topic.Topic)8 Test (org.junit.Test)8 ZeebeClient (io.zeebe.client.ZeebeClient)6 ClientRule (io.zeebe.broker.it.ClientRule)5 Topics (io.zeebe.client.topic.Topics)5 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)5 List (java.util.List)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Rule (org.junit.Rule)5 CreateTaskCommandImpl (io.zeebe.client.task.impl.CreateTaskCommandImpl)4 Before (org.junit.Before)4 RuleChain (org.junit.rules.RuleChain)4 Timeout (org.junit.rules.Timeout)4 EmbeddedBrokerRule (io.zeebe.broker.it.EmbeddedBrokerRule)3 TaskEvent (io.zeebe.client.event.TaskEvent)3 TestUtil (io.zeebe.test.util.TestUtil)3 Duration (java.time.Duration)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 ExpectedException (org.junit.rules.ExpectedException)3