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