Search in sources :

Example 1 with Topics

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

the class CreateTopicClusteredTest method shouldRequestTopicsAfterTopicCreation.

@Test
public void shouldRequestTopicsAfterTopicCreation() {
    // given
    clusteringRule.createTopic("foo", PARTITION_COUNT);
    // when
    final Topics topicsResponse = doRepeatedly(() -> client.topics().getTopics().execute()).until((topics -> topics.getTopics().size() == 1));
    final List<Topic> topics = topicsResponse.getTopics();
    // then
    assertThat(topics.size()).isEqualTo(1);
    assertThat(topics.get(0).getName()).isEqualTo("foo");
    final List<Integer> partitions = topics.get(0).getPartitions().stream().map((partition -> partition.getId())).collect(Collectors.toList());
    assertThat(partitions.size()).isEqualTo(5);
    assertThat(partitions).containsExactlyInAnyOrder(1, 2, 3, 4, 5);
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) ZeebeClient(io.zeebe.client.ZeebeClient) RuleChain(org.junit.rules.RuleChain) ClientRule(io.zeebe.broker.it.ClientRule) List(java.util.List) SocketAddress(io.zeebe.transport.SocketAddress) Rule(org.junit.Rule) Topic(io.zeebe.client.topic.Topic) Timeout(org.junit.rules.Timeout) Topics(io.zeebe.client.topic.Topics) AutoCloseableRule(io.zeebe.test.util.AutoCloseableRule) Before(org.junit.Before) Topics(io.zeebe.client.topic.Topics) Topic(io.zeebe.client.topic.Topic) Test(org.junit.Test)

Example 2 with Topics

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

the class TaskEventClusteredTest method shouldCreateTaskWhenFollowerUnavailable.

@Test
public void shouldCreateTaskWhenFollowerUnavailable() {
    // given
    final ZeebeClient client = clientRule.getClient();
    final String topicName = "foo";
    clusteringRule.createTopic(topicName, 1);
    final Topics topics = client.topics().getTopics().execute();
    final Topic topic = topics.getTopics().stream().filter(t -> topicName.equals(t.getName())).findFirst().get();
    final TopologyBroker leader = clusteringRule.getLeaderForPartition(topic.getPartitions().get(0).getId());
    // choosing a new leader in a raft group where the previously leading broker is no longer available
    clusteringRule.stopBroker(leader.getSocketAddress());
    // when
    final TaskEvent taskEvent = client.tasks().create(topicName, "bar").execute();
    // then
    assertThat(taskEvent.getState()).isEqualTo("CREATED");
}
Also used : Topics(io.zeebe.client.topic.Topics) ZeebeClient(io.zeebe.client.ZeebeClient) TaskEvent(io.zeebe.client.event.TaskEvent) Topic(io.zeebe.client.topic.Topic) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 3 with Topics

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

the class TopicSubscriptionTest method shouldReceiveEventsFromMultiplePartitions.

@Test
public void shouldReceiveEventsFromMultiplePartitions() {
    // given
    final String topicName = "pasta al forno";
    final int numPartitions = 2;
    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);
    createTaskOnPartition(topicName, partitionIds[0]);
    createTaskOnPartition(topicName, partitionIds[1]);
    final List<Integer> receivedPartitionIds = new ArrayList<>();
    // when
    client.topics().newSubscription(topicName).handler(recordingHandler).taskEventHandler(e -> {
        if ("CREATE".equals(e.getState())) {
            receivedPartitionIds.add(e.getMetadata().getPartitionId());
        }
    }).startAtHeadOfTopic().name("foo").open();
    // then
    waitUntil(() -> receivedPartitionIds.size() == numPartitions);
    assertThat(receivedPartitionIds).containsExactlyInAnyOrder(partitionIds);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Topics(io.zeebe.client.topic.Topics) ArrayList(java.util.ArrayList) Topic(io.zeebe.client.topic.Topic) Test(org.junit.Test)

Example 4 with Topics

use of io.zeebe.client.topic.Topics 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 5 with Topics

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

the class CreateTopicTest method shouldRequestTopics.

@Test
public void shouldRequestTopics() {
    // given
    final TopicsClient topics = clientRule.topics();
    topics.create("foo", 2).execute();
    // when
    final Topics returnedTopics = clientRule.topics().getTopics().execute();
    // then
    assertThat(returnedTopics.getTopics()).hasSize(2);
    final Map<String, List<Partition>> topicsByName = returnedTopics.getTopics().stream().collect(Collectors.toMap(Topic::getName, Topic::getPartitions));
    assertThat(topicsByName.get("foo")).hasSize(2);
    assertThat(topicsByName.get(ClientRule.DEFAULT_TOPIC)).hasSize(1);
}
Also used : TopicsClient(io.zeebe.client.TopicsClient) Topics(io.zeebe.client.topic.Topics) List(java.util.List) Test(org.junit.Test)

Aggregations

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