use of io.zeebe.client.topic.Topic in project zeebe by zeebe-io.
the class TopicSubscriptionTest method testSubscriptionsWithSameNameOnDifferentTopicShouldReceiveRespectiveEvents.
@Test
public void testSubscriptionsWithSameNameOnDifferentTopicShouldReceiveRespectiveEvents() {
// given
final String anotherTopicName = "another-topic";
final TopicEventImpl event = (TopicEventImpl) client.topics().create(anotherTopicName, 1).execute();
final int anotherPartitionId = 2;
final TopicSubscription topic0subscription = client.topics().newSubscription(clientRule.getDefaultTopic()).startAtHeadOfTopic().handler(recordingHandler).name(SUBSCRIPTION_NAME).open();
final RecordingEventHandler anotherRecordingHandler = new RecordingEventHandler();
final TopicSubscription topic1Subscription = client.topics().newSubscription(anotherTopicName).startAtHeadOfTopic().handler(anotherRecordingHandler).name(SUBSCRIPTION_NAME).open();
// when
clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
clientRule.tasks().create(anotherTopicName, "bar").execute();
// then
waitUntil(() -> recordingHandler.numRecordedTaskEvents() >= 2);
waitUntil(() -> anotherRecordingHandler.numRecordedTaskEvents() >= 2);
topic0subscription.close();
topic1Subscription.close();
Set<String> receivedTopicNamesSubscription = recordingHandler.getRecordedEvents().stream().filter((re) -> re.getMetadata().getType() == TopicEventType.TASK).map((re) -> re.getMetadata().getTopicName()).collect(Collectors.toSet());
Set<Integer> receivedPartitionIdsSubscription = recordingHandler.getRecordedEvents().stream().filter((re) -> re.getMetadata().getType() == TopicEventType.TASK).map((re) -> re.getMetadata().getPartitionId()).collect(Collectors.toSet());
assertThat(receivedTopicNamesSubscription).containsExactly(clientRule.getDefaultTopic());
assertThat(receivedPartitionIdsSubscription).containsExactly(clientRule.getDefaultPartition());
receivedTopicNamesSubscription = anotherRecordingHandler.getRecordedEvents().stream().filter((re) -> re.getMetadata().getType() == TopicEventType.TASK).map((re) -> re.getMetadata().getTopicName()).collect(Collectors.toSet());
receivedPartitionIdsSubscription = anotherRecordingHandler.getRecordedEvents().stream().filter((re) -> re.getMetadata().getType() == TopicEventType.TASK).map((re) -> re.getMetadata().getPartitionId()).collect(Collectors.toSet());
assertThat(receivedTopicNamesSubscription).containsExactly(anotherTopicName);
assertThat(receivedPartitionIdsSubscription).containsExactly(anotherPartitionId);
}
use of io.zeebe.client.topic.Topic in project zeebe by zeebe-io.
the class CreateTopicClusteredTest method shouldCreateTopic.
@Test
public void shouldCreateTopic() {
// given
// when
final Topic topic = clusteringRule.createTopic("foo", PARTITION_COUNT);
// then
assertThat(topic.getName()).isEqualTo("foo");
assertThat(topic.getPartitions().size()).isEqualTo(PARTITION_COUNT);
}
use of io.zeebe.client.topic.Topic 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.Topic 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.Topic 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);
}
Aggregations