use of org.apache.kafka.common.TopicPartitionInfo in project kafka by apache.
the class WorkerUtilsTest method testCreatesNotExistingTopics.
@Test
public void testCreatesNotExistingTopics() throws Throwable {
// should be no topics before the call
assertEquals(0, adminClient.listTopics().names().get().size());
WorkerUtils.createTopics(log, adminClient, Collections.singletonMap(TEST_TOPIC, NEW_TEST_TOPIC), false);
assertEquals(Collections.singleton(TEST_TOPIC), adminClient.listTopics().names().get());
assertEquals(new TopicDescription(TEST_TOPIC, false, Collections.singletonList(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()))), adminClient.describeTopics(Collections.singleton(TEST_TOPIC)).topicNameValues().get(TEST_TOPIC).get());
}
use of org.apache.kafka.common.TopicPartitionInfo in project kafka by apache.
the class WorkerUtilsTest method testCreateOneTopic.
@Test
public void testCreateOneTopic() throws Throwable {
Map<String, NewTopic> newTopics = Collections.singletonMap(TEST_TOPIC, NEW_TEST_TOPIC);
WorkerUtils.createTopics(log, adminClient, newTopics, true);
assertEquals(Collections.singleton(TEST_TOPIC), adminClient.listTopics().names().get());
assertEquals(new TopicDescription(TEST_TOPIC, false, Collections.singletonList(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()))), adminClient.describeTopics(Collections.singleton(TEST_TOPIC)).topicNameValues().get(TEST_TOPIC).get());
}
use of org.apache.kafka.common.TopicPartitionInfo in project kafka by apache.
the class WorkerUtilsTest method testCreatesOneTopicVerifiesOneTopic.
@Test
public void testCreatesOneTopicVerifiesOneTopic() throws Throwable {
final String existingTopic = "existing-topic";
List<TopicPartitionInfo> tpInfo = new ArrayList<>();
tpInfo.add(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()));
tpInfo.add(new TopicPartitionInfo(1, broker2, singleReplica, Collections.<Node>emptyList()));
adminClient.addTopic(false, existingTopic, tpInfo, null);
Map<String, NewTopic> topics = new HashMap<>();
topics.put(existingTopic, new NewTopic(existingTopic, tpInfo.size(), TEST_REPLICATION_FACTOR));
topics.put(TEST_TOPIC, NEW_TEST_TOPIC);
WorkerUtils.createTopics(log, adminClient, topics, false);
assertEquals(Utils.mkSet(existingTopic, TEST_TOPIC), adminClient.listTopics().names().get());
}
use of org.apache.kafka.common.TopicPartitionInfo in project kafka by apache.
the class TransactionsCommandTest method testFindHangingLookupTopicPartitionsForTopic.
@Test
public void testFindHangingLookupTopicPartitionsForTopic() throws Exception {
String topic = "foo";
String[] args = new String[] { "--bootstrap-server", "localhost:9092", "find-hanging", "--topic", topic };
Node node0 = new Node(0, "localhost", 9092);
Node node1 = new Node(1, "localhost", 9093);
Node node5 = new Node(5, "localhost", 9097);
TopicPartitionInfo partition0 = new TopicPartitionInfo(0, node0, Arrays.asList(node0, node1), Arrays.asList(node0, node1));
TopicPartitionInfo partition1 = new TopicPartitionInfo(1, node1, Arrays.asList(node1, node5), Arrays.asList(node1, node5));
TopicDescription description = new TopicDescription(topic, false, Arrays.asList(partition0, partition1));
expectDescribeTopics(singletonMap(topic, description));
DescribeProducersResult result = Mockito.mock(DescribeProducersResult.class);
Mockito.when(result.all()).thenReturn(completedFuture(emptyMap()));
Mockito.when(admin.describeProducers(Arrays.asList(new TopicPartition(topic, 0), new TopicPartition(topic, 1)), new DescribeProducersOptions())).thenReturn(result);
execute(args);
assertNormalExit();
assertNoHangingTransactions();
}
use of org.apache.kafka.common.TopicPartitionInfo in project flink by apache.
the class TopicPatternSubscriber method getSubscribedTopicPartitions.
@Override
public Set<TopicPartition> getSubscribedTopicPartitions(AdminClient adminClient) {
LOG.debug("Fetching descriptions for all topics on Kafka cluster");
final Map<String, TopicDescription> allTopicMetadata = getAllTopicMetadata(adminClient);
Set<TopicPartition> subscribedTopicPartitions = new HashSet<>();
allTopicMetadata.forEach((topicName, topicDescription) -> {
if (topicPattern.matcher(topicName).matches()) {
for (TopicPartitionInfo partition : topicDescription.partitions()) {
subscribedTopicPartitions.add(new TopicPartition(topicDescription.name(), partition.partition()));
}
}
});
return subscribedTopicPartitions;
}
Aggregations