use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv 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.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method endOffsetsShouldReturnOffsetsForOnePartition.
@Test
public void endOffsetsShouldReturnOffsetsForOnePartition() {
String topicName = "myTopic";
TopicPartition tp1 = new TopicPartition(topicName, 0);
Set<TopicPartition> tps = Collections.singleton(tp1);
long offset = 1000L;
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(listOffsetsResult(tp1, offset));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
Map<TopicPartition, Long> offsets = admin.endOffsets(tps);
assertEquals(1, offsets.size());
assertEquals(Long.valueOf(offset), offsets.get(tp1));
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv 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());
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method endOffsetsShouldFailWhenAnyTopicPartitionHasError.
@Test
public void endOffsetsShouldFailWhenAnyTopicPartitionHasError() {
String topicName = "myTopic";
TopicPartition tp1 = new TopicPartition(topicName, 0);
Set<TopicPartition> tps = Collections.singleton(tp1);
long offset = 1000;
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, null));
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"));
}
}
Aggregations