use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project apache-kafka-on-k8s by banzaicloud.
the class TopicAdminTest method returnNullWithClusterAuthorizationFailure.
@Test
public void returnNullWithClusterAuthorizationFailure() {
final NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(cluster)) {
env.kafkaClient().prepareMetadataUpdate(env.cluster(), Collections.<String>emptySet());
env.kafkaClient().prepareResponse(createTopicResponseWithClusterAuthorizationException(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
boolean created = admin.createTopic(newTopic);
assertFalse(created);
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method endOffsetsShouldFailWithNonRetriableWhenAuthorizationFailureOccurs.
@Test
public void endOffsetsShouldFailWithNonRetriableWhenAuthorizationFailureOccurs() {
String topicName = "myTopic";
TopicPartition tp1 = new TopicPartition(topicName, 0);
Set<TopicPartition> tps = Collections.singleton(tp1);
// response should use error
Long offset = null;
Cluster cluster = createCluster(1, topicName, 1);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(new MockTime(), cluster)) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareResponse(prepareMetadataResponse(cluster, Errors.NONE));
env.kafkaClient().prepareResponse(listOffsetsResultWithClusterAuthorizationException(tp1, offset));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
ConnectException e = assertThrows(ConnectException.class, () -> admin.endOffsets(tps));
assertTrue(e.getMessage().contains("Not authorized to get the end offsets"));
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv 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.AdminClientUnitTestEnv 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.AdminClientUnitTestEnv 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