Search in sources :

Example 1 with KafkaFutureImpl

use of org.apache.kafka.common.internals.KafkaFutureImpl in project apache-kafka-on-k8s by banzaicloud.

the class MockAdminClient method listTopics.

@Override
public ListTopicsResult listTopics(ListTopicsOptions options) {
    Map<String, TopicListing> topicListings = new HashMap<>();
    if (timeoutNextRequests > 0) {
        KafkaFutureImpl<Map<String, TopicListing>> future = new KafkaFutureImpl<>();
        future.completeExceptionally(new TimeoutException());
        --timeoutNextRequests;
        return new ListTopicsResult(future);
    }
    for (Map.Entry<String, TopicMetadata> topicDescription : allTopics.entrySet()) {
        String topicName = topicDescription.getKey();
        topicListings.put(topicName, new TopicListing(topicName, topicDescription.getValue().isInternalTopic));
    }
    KafkaFutureImpl<Map<String, TopicListing>> future = new KafkaFutureImpl<>();
    future.complete(topicListings);
    return new ListTopicsResult(future);
}
Also used : HashMap(java.util.HashMap) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) HashMap(java.util.HashMap) Map(java.util.Map) TimeoutException(org.apache.kafka.common.errors.TimeoutException)

Example 2 with KafkaFutureImpl

use of org.apache.kafka.common.internals.KafkaFutureImpl in project apache-kafka-on-k8s by banzaicloud.

the class MockAdminClient method describeConfigs.

@Override
public DescribeConfigsResult describeConfigs(Collection<ConfigResource> resources, DescribeConfigsOptions options) {
    Map<ConfigResource, KafkaFuture<Config>> configescriptions = new HashMap<>();
    for (ConfigResource resource : resources) {
        if (resource.type() == ConfigResource.Type.TOPIC) {
            Map<String, String> configs = allTopics.get(resource.name()).configs;
            List<ConfigEntry> configEntries = new ArrayList<>();
            for (Map.Entry<String, String> entry : configs.entrySet()) {
                configEntries.add(new ConfigEntry(entry.getKey(), entry.getValue()));
            }
            KafkaFutureImpl<Config> future = new KafkaFutureImpl<>();
            future.complete(new Config(configEntries));
            configescriptions.put(resource, future);
        } else {
            throw new UnsupportedOperationException("Not implemented yet");
        }
    }
    return new DescribeConfigsResult(configescriptions);
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ConfigResource(org.apache.kafka.common.config.ConfigResource) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with KafkaFutureImpl

use of org.apache.kafka.common.internals.KafkaFutureImpl in project apache-kafka-on-k8s by banzaicloud.

the class MockAdminClient method deleteTopics.

@Override
public DeleteTopicsResult deleteTopics(Collection<String> topicsToDelete, DeleteTopicsOptions options) {
    Map<String, KafkaFuture<Void>> deleteTopicsResult = new HashMap<>();
    if (timeoutNextRequests > 0) {
        for (final String topicName : topicsToDelete) {
            KafkaFutureImpl<Void> future = new KafkaFutureImpl<>();
            future.completeExceptionally(new TimeoutException());
            deleteTopicsResult.put(topicName, future);
        }
        --timeoutNextRequests;
        return new DeleteTopicsResult(deleteTopicsResult);
    }
    for (final String topicName : topicsToDelete) {
        KafkaFutureImpl<Void> future = new KafkaFutureImpl<>();
        if (allTopics.remove(topicName) == null) {
            future.completeExceptionally(new UnknownTopicOrPartitionException(String.format("Topic %s does not exist.", topicName)));
        } else {
            future.complete(null);
        }
        deleteTopicsResult.put(topicName, future);
    }
    return new DeleteTopicsResult(deleteTopicsResult);
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) HashMap(java.util.HashMap) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) TimeoutException(org.apache.kafka.common.errors.TimeoutException)

Example 4 with KafkaFutureImpl

use of org.apache.kafka.common.internals.KafkaFutureImpl in project apache-kafka-on-k8s by banzaicloud.

the class TaskManagerTest method shouldSendPurgeData.

@Test
public void shouldSendPurgeData() {
    final KafkaFutureImpl<DeletedRecords> futureDeletedRecords = new KafkaFutureImpl<>();
    final Map<TopicPartition, RecordsToDelete> recordsToDelete = Collections.singletonMap(t1p1, RecordsToDelete.beforeOffset(5L));
    final DeleteRecordsResult deleteRecordsResult = new DeleteRecordsResult(Collections.singletonMap(t1p1, (KafkaFuture<DeletedRecords>) futureDeletedRecords));
    futureDeletedRecords.complete(null);
    EasyMock.expect(active.recordsToDelete()).andReturn(Collections.singletonMap(t1p1, 5L)).times(2);
    EasyMock.expect(adminClient.deleteRecords(recordsToDelete)).andReturn(deleteRecordsResult).times(2);
    replay();
    taskManager.maybePurgeCommitedRecords();
    taskManager.maybePurgeCommitedRecords();
    verify(active, adminClient);
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) TopicPartition(org.apache.kafka.common.TopicPartition) DeletedRecords(org.apache.kafka.clients.admin.DeletedRecords) RecordsToDelete(org.apache.kafka.clients.admin.RecordsToDelete) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) DeleteRecordsResult(org.apache.kafka.clients.admin.DeleteRecordsResult) Test(org.junit.Test)

Example 5 with KafkaFutureImpl

use of org.apache.kafka.common.internals.KafkaFutureImpl in project apache-kafka-on-k8s by banzaicloud.

the class TaskManagerTest method shouldIgnorePurgeDataErrors.

@Test
public void shouldIgnorePurgeDataErrors() {
    final KafkaFutureImpl<DeletedRecords> futureDeletedRecords = new KafkaFutureImpl<>();
    final Map<TopicPartition, RecordsToDelete> recordsToDelete = Collections.singletonMap(t1p1, RecordsToDelete.beforeOffset(5L));
    final DeleteRecordsResult deleteRecordsResult = new DeleteRecordsResult(Collections.singletonMap(t1p1, (KafkaFuture<DeletedRecords>) futureDeletedRecords));
    futureDeletedRecords.completeExceptionally(new Exception("KABOOM!"));
    EasyMock.expect(active.recordsToDelete()).andReturn(Collections.singletonMap(t1p1, 5L)).times(2);
    EasyMock.expect(adminClient.deleteRecords(recordsToDelete)).andReturn(deleteRecordsResult).times(2);
    replay();
    taskManager.maybePurgeCommitedRecords();
    taskManager.maybePurgeCommitedRecords();
    verify(active, adminClient);
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) TopicPartition(org.apache.kafka.common.TopicPartition) DeletedRecords(org.apache.kafka.clients.admin.DeletedRecords) RecordsToDelete(org.apache.kafka.clients.admin.RecordsToDelete) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) DeleteRecordsResult(org.apache.kafka.clients.admin.DeleteRecordsResult) StreamsException(org.apache.kafka.streams.errors.StreamsException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)22 KafkaFuture (org.apache.kafka.common.KafkaFuture)18 HashMap (java.util.HashMap)17 Map (java.util.Map)11 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)11 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)10 ArrayList (java.util.ArrayList)9 TopicPartition (org.apache.kafka.common.TopicPartition)6 TimeoutException (org.apache.kafka.common.errors.TimeoutException)5 ConfigResource (org.apache.kafka.common.config.ConfigResource)4 AbstractRequest (org.apache.kafka.common.requests.AbstractRequest)4 LinkedList (java.util.LinkedList)3 List (java.util.List)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 DeleteRecordsResult (org.apache.kafka.clients.admin.DeleteRecordsResult)3 DeletedRecords (org.apache.kafka.clients.admin.DeletedRecords)3 RecordsToDelete (org.apache.kafka.clients.admin.RecordsToDelete)3 Node (org.apache.kafka.common.Node)3 ApiException (org.apache.kafka.common.errors.ApiException)3 InvalidTopicException (org.apache.kafka.common.errors.InvalidTopicException)3