use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
the class TopicAdminTest method throwsWithTopicAuthorizationFailureOnDescribe.
@Test
public void throwsWithTopicAuthorizationFailureOnDescribe() {
final NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(new MockTime(), cluster)) {
env.kafkaClient().prepareResponse(describeTopicResponseWithTopicAuthorizationException(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
Exception e = assertThrows(ConnectException.class, () -> admin.describeTopics(newTopic.name()));
assertTrue(e.getCause() instanceof TopicAuthorizationException);
}
}
use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
the class TopicAdminTest method describeTopicConfigShouldReturnMapWithNullValueWhenTopicDoesNotExist.
@Test
public void describeTopicConfigShouldReturnMapWithNullValueWhenTopicDoesNotExist() {
NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (TopicAdmin admin = new TopicAdmin(null, new MockAdminClient(cluster.nodes(), cluster.nodeById(0)))) {
Map<String, Config> results = admin.describeTopicConfigs(newTopic.name());
assertFalse(results.isEmpty());
assertEquals(1, results.size());
assertNull(results.get("myTopic"));
}
}
use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
the class TopicAdminTest method describeShouldReturnEmptyWhenTopicDoesNotExist.
@Test
public void describeShouldReturnEmptyWhenTopicDoesNotExist() {
NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (TopicAdmin admin = new TopicAdmin(null, new MockAdminClient(cluster.nodes(), cluster.nodeById(0)))) {
assertTrue(admin.describeTopics(newTopic.name()).isEmpty());
}
}
use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
the class TopicAdminTest method shouldCreateOneTopicWhenProvidedMultipleDefinitionsWithSameTopicName.
@Test
public void shouldCreateOneTopicWhenProvidedMultipleDefinitionsWithSameTopicName() {
NewTopic newTopic1 = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
NewTopic newTopic2 = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (TopicAdmin admin = new TopicAdmin(null, new MockAdminClient(cluster.nodes(), cluster.nodeById(0)))) {
Set<String> newTopicNames = admin.createTopics(newTopic1, newTopic2);
assertEquals(1, newTopicNames.size());
assertEquals(newTopic2.name(), newTopicNames.iterator().next());
}
}
use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
the class TopicAdminTest method describeTopicConfigShouldReturnEmptyMapWhenNoTopicsAreSpecified.
@Test
public void describeTopicConfigShouldReturnEmptyMapWhenNoTopicsAreSpecified() {
final NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(new MockTime(), cluster)) {
env.kafkaClient().prepareResponse(describeConfigsResponseWithUnsupportedVersion(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
Map<String, Config> results = admin.describeTopicConfigs();
assertTrue(results.isEmpty());
}
}
Aggregations