use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
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.emptyList());
mockAdminClient.addTopic(false, "myTopic", Collections.singletonList(topicPartitionInfo), null);
TopicAdmin admin = new TopicAdmin(null, mockAdminClient);
assertFalse(admin.createTopic(newTopic));
assertTrue(admin.createTopics(newTopic).isEmpty());
assertTrue(admin.createOrFindTopic(newTopic));
TopicAdmin.TopicCreationResponse response = admin.createOrFindTopics(newTopic);
assertTrue(response.isCreatedOrExisting(newTopic.name()));
assertTrue(response.isExisting(newTopic.name()));
assertFalse(response.isCreated(newTopic.name()));
}
}
use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
the class TopicAdminTest method returnEmptyWithTopicAuthorizationFailureOnCreate.
@Test
public void returnEmptyWithTopicAuthorizationFailureOnCreate() {
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(createTopicResponseWithTopicAuthorizationException(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
assertFalse(admin.createTopic(newTopic));
env.kafkaClient().prepareResponse(createTopicResponseWithTopicAuthorizationException(newTopic));
assertTrue(admin.createOrFindTopics(newTopic).isEmpty());
}
}
use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
the class TopicAdminTest method describeTopicConfigShouldReturnEmptyMapWhenTopicAuthorizationFailure.
@Test
public void describeTopicConfigShouldReturnEmptyMapWhenTopicAuthorizationFailure() {
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(describeConfigsResponseWithTopicAuthorizationException(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
Map<String, Config> results = admin.describeTopicConfigs(newTopic.name());
assertTrue(results.isEmpty());
}
}
use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
the class TopicAdminTest method shouldCreateTopicWithDefaultPartitionsAndReplicationFactorWhenItDoesNotExist.
@Test
public void shouldCreateTopicWithDefaultPartitionsAndReplicationFactorWhenItDoesNotExist() {
NewTopic newTopic = TopicAdmin.defineTopic("my-topic").defaultPartitions().defaultReplicationFactor().compacted().build();
for (int numBrokers = 1; numBrokers < 10; ++numBrokers) {
int expectedReplicas = Math.min(3, numBrokers);
assertTopicCreation(numBrokers, newTopic, null, null, expectedReplicas, 1);
assertTopicCreation(numBrokers, newTopic, 30, null, expectedReplicas, 30);
}
}
use of org.apache.kafka.clients.admin.NewTopic in project kafka by apache.
the class TopicAdminTest method describeTopicConfigShouldReturnEmptyMapWhenClusterAuthorizationFailure.
@Test
public void describeTopicConfigShouldReturnEmptyMapWhenClusterAuthorizationFailure() {
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(describeConfigsResponseWithClusterAuthorizationException(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
Map<String, Config> results = admin.describeTopicConfigs(newTopic.name());
assertTrue(results.isEmpty());
}
}
Aggregations