use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project apache-kafka-on-k8s by banzaicloud.
the class TopicAdminTest method returnNullWithApiVersionMismatch.
/**
* 0.11.0.0 clients can talk with older brokers, but the CREATE_TOPIC API was added in 0.10.1.0. That means,
* if our TopicAdmin talks to a pre 0.10.1 broker, it should receive an UnsupportedVersionException, should
* create no topics, and return false.
*/
@Test
public void returnNullWithApiVersionMismatch() {
final NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(cluster)) {
env.kafkaClient().setNode(cluster.controller());
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareMetadataUpdate(env.cluster(), Collections.<String>emptySet());
env.kafkaClient().prepareResponse(createTopicResponseWithUnsupportedVersion(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 endOffsetsShouldFailWithTimeoutExceptionWhenTimeoutErrorOccurs.
@Test
public void endOffsetsShouldFailWithTimeoutExceptionWhenTimeoutErrorOccurs() {
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(listOffsetsResultWithTimeout(tp1, offset));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
TimeoutException e = assertThrows(TimeoutException.class, () -> admin.endOffsets(tps));
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method endOffsetsShouldFailWithNonRetriableWhenUnknownErrorOccurs.
@Test
public void endOffsetsShouldFailWithNonRetriableWhenUnknownErrorOccurs() {
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(listOffsetsResultWithUnknownError(tp1, offset));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
ConnectException e = assertThrows(ConnectException.class, () -> admin.endOffsets(tps));
assertTrue(e.getMessage().contains("Error while getting end offsets for topic"));
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method throwsWithClusterAuthorizationFailureOnDescribe.
@Test
public void throwsWithClusterAuthorizationFailureOnDescribe() {
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(describeTopicResponseWithClusterAuthorizationException(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
Exception e = assertThrows(ConnectException.class, () -> admin.describeTopics(newTopic.name()));
assertTrue(e.getCause() instanceof ClusterAuthorizationException);
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method throwsWithApiVersionMismatchOnDescribe.
/**
* 0.11.0.0 clients can talk with older brokers, but the DESCRIBE_TOPIC API was added in 0.10.0.0. That means,
* if our TopicAdmin talks to a pre 0.10.0 broker, it should receive an UnsupportedVersionException, should
* create no topics, and return false.
*/
@Test
public void throwsWithApiVersionMismatchOnDescribe() {
final NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(new MockTime(), cluster)) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareResponse(describeTopicResponseWithUnsupportedVersion(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
Exception e = assertThrows(ConnectException.class, () -> admin.describeTopics(newTopic.name()));
assertTrue(e.getCause() instanceof UnsupportedVersionException);
}
}
Aggregations