use of org.apache.kafka.common.requests.ApiError in project apache-kafka-on-k8s by banzaicloud.
the class KafkaAdminClientTest method testCreatePartitions.
@Test
public void testCreatePartitions() throws Exception {
try (AdminClientUnitTestEnv env = mockClientEnv()) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareMetadataUpdate(env.cluster(), Collections.<String>emptySet());
env.kafkaClient().setNode(env.cluster().controller());
Map<String, ApiError> m = new HashMap<>();
m.put("my_topic", ApiError.NONE);
m.put("other_topic", ApiError.fromThrowable(new InvalidTopicException("some detailed reason")));
// Test a call where one filter has an error.
env.kafkaClient().prepareResponse(new CreatePartitionsResponse(0, m));
Map<String, NewPartitions> counts = new HashMap<>();
counts.put("my_topic", NewPartitions.increaseTo(3));
counts.put("other_topic", NewPartitions.increaseTo(3, asList(asList(2), asList(3))));
CreatePartitionsResult results = env.adminClient().createPartitions(counts);
Map<String, KafkaFuture<Void>> values = results.values();
KafkaFuture<Void> myTopicResult = values.get("my_topic");
myTopicResult.get();
KafkaFuture<Void> otherTopicResult = values.get("other_topic");
try {
otherTopicResult.get();
fail("get() should throw ExecutionException");
} catch (ExecutionException e0) {
assertTrue(e0.getCause() instanceof InvalidTopicException);
InvalidTopicException e = (InvalidTopicException) e0.getCause();
assertEquals("some detailed reason", e.getMessage());
}
}
}
use of org.apache.kafka.common.requests.ApiError in project apache-kafka-on-k8s by banzaicloud.
the class KafkaAdminClientTest method testCreateTopics.
@Test
public void testCreateTopics() throws Exception {
try (AdminClientUnitTestEnv env = mockClientEnv()) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareMetadataUpdate(env.cluster(), Collections.<String>emptySet());
env.kafkaClient().setNode(env.cluster().controller());
env.kafkaClient().prepareResponse(new CreateTopicsResponse(Collections.singletonMap("myTopic", new ApiError(Errors.NONE, ""))));
KafkaFuture<Void> future = env.adminClient().createTopics(Collections.singleton(new NewTopic("myTopic", Collections.singletonMap(Integer.valueOf(0), asList(new Integer[] { 0, 1, 2 })))), new CreateTopicsOptions().timeoutMs(10000)).all();
future.get();
}
}
Aggregations