use of org.apache.kafka.common.TopicPartitionInfo in project apache-kafka-on-k8s by banzaicloud.
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)).values().get(TEST_TOPIC).get());
}
use of org.apache.kafka.common.TopicPartitionInfo in project apache-kafka-on-k8s by banzaicloud.
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)).values().get(TEST_TOPIC).get());
}
use of org.apache.kafka.common.TopicPartitionInfo in project apache-kafka-on-k8s by banzaicloud.
the class TopicAdminTest method shouldNotCreateTopicWhenItAlreadyExists.
@Test
public void shouldNotCreateTopicWhenItAlreadyExists() {
NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (MockAdminClient mockAdminClient = new MockAdminClient(cluster.nodes(), cluster.nodeById(0))) {
TopicPartitionInfo topicPartitionInfo = new TopicPartitionInfo(0, cluster.nodeById(0), cluster.nodes(), Collections.<Node>emptyList());
mockAdminClient.addTopic(false, "myTopic", Collections.singletonList(topicPartitionInfo), null);
TopicAdmin admin = new TopicAdmin(null, mockAdminClient);
assertFalse(admin.createTopic(newTopic));
}
}
use of org.apache.kafka.common.TopicPartitionInfo in project apache-kafka-on-k8s by banzaicloud.
the class InternalTopicManagerTest method shouldCreateRequiredTopics.
@Test
public void shouldCreateRequiredTopics() throws Exception {
final InternalTopicConfig topicConfig = new RepartitionTopicConfig(topic, Collections.<String, String>emptyMap());
topicConfig.setNumberOfPartitions(1);
final InternalTopicConfig topicConfig2 = new UnwindowedChangelogTopicConfig(topic2, Collections.<String, String>emptyMap());
topicConfig2.setNumberOfPartitions(1);
final InternalTopicConfig topicConfig3 = new WindowedChangelogTopicConfig(topic3, Collections.<String, String>emptyMap());
topicConfig3.setNumberOfPartitions(1);
internalTopicManager.makeReady(Collections.singletonMap(topic, topicConfig));
internalTopicManager.makeReady(Collections.singletonMap(topic2, topicConfig2));
internalTopicManager.makeReady(Collections.singletonMap(topic3, topicConfig3));
assertEquals(Utils.mkSet(topic, topic2, topic3), mockAdminClient.listTopics().names().get());
assertEquals(new TopicDescription(topic, false, new ArrayList<TopicPartitionInfo>() {
{
add(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()));
}
}), mockAdminClient.describeTopics(Collections.singleton(topic)).values().get(topic).get());
assertEquals(new TopicDescription(topic2, false, new ArrayList<TopicPartitionInfo>() {
{
add(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()));
}
}), mockAdminClient.describeTopics(Collections.singleton(topic2)).values().get(topic2).get());
assertEquals(new TopicDescription(topic3, false, new ArrayList<TopicPartitionInfo>() {
{
add(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()));
}
}), mockAdminClient.describeTopics(Collections.singleton(topic3)).values().get(topic3).get());
ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, topic);
ConfigResource resource2 = new ConfigResource(ConfigResource.Type.TOPIC, topic2);
ConfigResource resource3 = new ConfigResource(ConfigResource.Type.TOPIC, topic3);
assertEquals(new ConfigEntry(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_DELETE), mockAdminClient.describeConfigs(Collections.singleton(resource)).values().get(resource).get().get(TopicConfig.CLEANUP_POLICY_CONFIG));
assertEquals(new ConfigEntry(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_COMPACT), mockAdminClient.describeConfigs(Collections.singleton(resource2)).values().get(resource2).get().get(TopicConfig.CLEANUP_POLICY_CONFIG));
assertEquals(new ConfigEntry(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_COMPACT + "," + TopicConfig.CLEANUP_POLICY_DELETE), mockAdminClient.describeConfigs(Collections.singleton(resource3)).values().get(resource3).get().get(TopicConfig.CLEANUP_POLICY_CONFIG));
}
use of org.apache.kafka.common.TopicPartitionInfo in project core-ng-project by neowu.
the class KafkaController method view.
private KafkaTopic view(String name, TopicDescription description) {
KafkaTopic view = new KafkaTopic();
view.name = name;
for (TopicPartitionInfo info : description.partitions()) {
KafkaTopic.Partition partition = new KafkaTopic.Partition();
partition.id = info.partition();
partition.leader = node(info.leader());
partition.replicas = nodes(info.replicas());
partition.inSyncReplicas = nodes(info.isr());
view.partitions.add(partition);
}
return view;
}
Aggregations