use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method verifyingTopicCleanupPolicyShouldReturnFalseWhenBrokerVersionIsUnsupported.
@Test
public void verifyingTopicCleanupPolicyShouldReturnFalseWhenBrokerVersionIsUnsupported() {
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());
boolean result = admin.verifyTopicCleanupPolicyOnlyCompact("myTopic", "worker.topic", "purpose");
assertFalse(result);
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method verifyingTopicCleanupPolicyShouldReturnFalseWhenClusterAuthorizationError.
@Test
public void verifyingTopicCleanupPolicyShouldReturnFalseWhenClusterAuthorizationError() {
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());
boolean result = admin.verifyTopicCleanupPolicyOnlyCompact("myTopic", "worker.topic", "purpose");
assertFalse(result);
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method endOffsetsShouldFailWithUnsupportedVersionWhenVersionUnsupportedErrorOccurs.
@Test
public void endOffsetsShouldFailWithUnsupportedVersionWhenVersionUnsupportedErrorOccurs() {
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(listOffsetsResultWithUnsupportedVersion(tp1, offset));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
UnsupportedVersionException e = assertThrows(UnsupportedVersionException.class, () -> admin.endOffsets(tps));
}
}
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"));
}
}
Aggregations