Search in sources :

Example 6 with ApiError

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());
        }
    }
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) HashMap(java.util.HashMap) CreatePartitionsResponse(org.apache.kafka.common.requests.CreatePartitionsResponse) InvalidTopicException(org.apache.kafka.common.errors.InvalidTopicException) ApiError(org.apache.kafka.common.requests.ApiError) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 7 with ApiError

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();
    }
}
Also used : CreateTopicsResponse(org.apache.kafka.common.requests.CreateTopicsResponse) ApiError(org.apache.kafka.common.requests.ApiError) Test(org.junit.Test)

Aggregations

ApiError (org.apache.kafka.common.requests.ApiError)7 Test (org.junit.Test)6 KafkaFuture (org.apache.kafka.common.KafkaFuture)3 CreateTopicsResponse (org.apache.kafka.common.requests.CreateTopicsResponse)3 HashMap (java.util.HashMap)2 AclBinding (org.apache.kafka.common.acl.AclBinding)2 InvalidTopicException (org.apache.kafka.common.errors.InvalidTopicException)2 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 FilterResults (org.apache.kafka.clients.admin.DeleteAclsResult.FilterResults)1 Node (org.apache.kafka.common.Node)1 AclBindingFilter (org.apache.kafka.common.acl.AclBindingFilter)1 ApiException (org.apache.kafka.common.errors.ApiException)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)1 AbstractRequest (org.apache.kafka.common.requests.AbstractRequest)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1 CreateAclsResponse (org.apache.kafka.common.requests.CreateAclsResponse)1 AclCreationResponse (org.apache.kafka.common.requests.CreateAclsResponse.AclCreationResponse)1 CreatePartitionsResponse (org.apache.kafka.common.requests.CreatePartitionsResponse)1