Search in sources :

Example 21 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project ksql by confluentinc.

the class KafkaTopicClientImplTest method getDeleteInternalTopicsResult.

private DeleteTopicsResult getDeleteInternalTopicsResult() {
    DeleteTopicsResult deleteTopicsResult = mock(DeleteTopicsResult.class);
    Map<String, KafkaFuture<Void>> deletedTopics = new HashMap<>();
    deletedTopics.put(internalTopic1, KafkaFuture.allOf());
    deletedTopics.put(internalTopic2, KafkaFuture.allOf());
    expect(deleteTopicsResult.values()).andReturn(deletedTopics);
    replay(deleteTopicsResult);
    return deleteTopicsResult;
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) HashMap(java.util.HashMap) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 22 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project Microservice-Benchmark by OpenHFT.

the class KafkaBenchmarkDriver method init.

@Override
public void init() {
    Driver.super.init();
    Properties commonProperties = new Properties();
    commonProperties.putAll(commonConfig);
    producerConfig.putAll(commonConfig);
    producerConfig.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    producerConfig.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
    consumerConfig.putAll(commonConfig);
    consumerConfig.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
    consumerConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
    admin = AdminClient.create(commonProperties);
    if (reset) {
        // List existing topics
        ListTopicsResult result = admin.listTopics();
        try {
            Set<String> topics = result.names().get();
            // Delete all existing topics
            DeleteTopicsResult deletes = admin.deleteTopics(topics);
            deletes.all().get();
        } catch (InterruptedException | ExecutionException e) {
            LoggerFactory.getLogger(getClass()).warn("Error on reset", e);
            throw new IORuntimeException(e);
        }
    }
}
Also used : StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) ByteArraySerializer(org.apache.kafka.common.serialization.ByteArraySerializer) IORuntimeException(net.openhft.chronicle.core.io.IORuntimeException) ListTopicsResult(org.apache.kafka.clients.admin.ListTopicsResult) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) ExecutionException(java.util.concurrent.ExecutionException) StringSerializer(org.apache.kafka.common.serialization.StringSerializer)

Example 23 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project strimzi by strimzi.

the class KafkaImplTest method mockDeleteTopics.

private void mockDeleteTopics(Admin admin, Map<String, Either<Void, Exception>> result) {
    DeleteTopicsResult deleteTopicsResult = mock(DeleteTopicsResult.class);
    when(deleteTopicsResult.topicNameValues()).thenReturn(result.entrySet().stream().collect(toMap(Map.Entry::getKey, entry -> {
        KafkaFutureImpl<Void> kafkaFuture = new KafkaFutureImpl<>();
        if (entry.getValue().isLeft()) {
            kafkaFuture.complete(null);
        } else {
            kafkaFuture.completeExceptionally(entry.getValue().right());
        }
        return kafkaFuture;
    })));
    when(admin.deleteTopics(result.keySet())).thenReturn(deleteTopicsResult);
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl)

Example 24 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project strimzi-kafka-operator by strimzi.

the class TopicOperatorBaseIT method deleteTopicInKafka.

protected void deleteTopicInKafka(String topicName, String resourceName) throws InterruptedException, ExecutionException {
    LOGGER.info("Deleting topic {} (KafkaTopic {})", topicName, resourceName);
    // Now we can delete the topic
    DeleteTopicsResult dlt = adminClient.deleteTopics(singletonList(topicName));
    dlt.all().get();
    LOGGER.info("Deleted topic {}", topicName);
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 25 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project strimzi-kafka-operator by strimzi.

the class KafkaImplTest method mockDeleteTopics.

private void mockDeleteTopics(Admin admin, Map<String, Either<Void, Exception>> result) {
    DeleteTopicsResult deleteTopicsResult = mock(DeleteTopicsResult.class);
    when(deleteTopicsResult.topicNameValues()).thenReturn(result.entrySet().stream().collect(toMap(Map.Entry::getKey, entry -> {
        KafkaFutureImpl<Void> kafkaFuture = new KafkaFutureImpl<>();
        if (entry.getValue().isLeft()) {
            kafkaFuture.complete(null);
        } else {
            kafkaFuture.completeExceptionally(entry.getValue().right());
        }
        return kafkaFuture;
    })));
    when(admin.deleteTopics(result.keySet())).thenReturn(deleteTopicsResult);
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl)

Aggregations

DeleteTopicsResult (org.apache.kafka.clients.admin.DeleteTopicsResult)33 ExecutionException (java.util.concurrent.ExecutionException)12 AdminClient (org.apache.kafka.clients.admin.AdminClient)6 KafkaFuture (org.apache.kafka.common.KafkaFuture)6 IOException (java.io.IOException)4 Map (java.util.Map)4 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)3 ListTopicsResult (org.apache.kafka.clients.admin.ListTopicsResult)3 TopicExistsException (org.apache.kafka.common.errors.TopicExistsException)3 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)3 ByteArrayDeserializer (org.apache.kafka.common.serialization.ByteArrayDeserializer)3 ByteArraySerializer (org.apache.kafka.common.serialization.ByteArraySerializer)3 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)3 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)3 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)2 StringReader (java.io.StringReader)2 ParseException (java.text.ParseException)2 OptionException (joptsimple.OptionException)2 Cleanup (lombok.Cleanup)2