Search in sources :

Example 11 with DeleteTopicsResult

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

the class KafkaAuthorizationTestBase method testDeleteTopicSuccess.

@Test(timeOut = 20000)
public void testDeleteTopicSuccess() throws PulsarAdminException, InterruptedException {
    String newTopic = "testDeleteTopicSuccess";
    String fullNewTopicName = "persistent://" + TENANT + "/" + NAMESPACE + "/" + newTopic;
    admin.topics().createPartitionedTopic(fullNewTopicName, 1);
    AdminClient adminClient = createAdminClient(TENANT + "/" + NAMESPACE, adminToken);
    DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(Collections.singletonList(newTopic));
    try {
        deleteTopicsResult.all().get();
    } catch (ExecutionException ex) {
        fail("Should success but have : " + ex.getMessage());
    }
    List<String> topicList = admin.topics().getList(TENANT + "/" + NAMESPACE);
    topicList.forEach(topic -> {
        if (topic.startsWith(fullNewTopicName)) {
            fail("Delete topic failed!");
        }
    });
    adminClient.close();
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) ExecutionException(java.util.concurrent.ExecutionException) AdminClient(org.apache.kafka.clients.admin.AdminClient) Test(org.testng.annotations.Test)

Example 12 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project strimzi 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 13 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project flink-mirror by flink-ci.

the class KafkaSinkITCase method deleteTestTopic.

private void deleteTestTopic(String topic) throws ExecutionException, InterruptedException, TimeoutException {
    final DeleteTopicsResult result = admin.deleteTopics(Collections.singletonList(topic));
    result.all().get(1, TimeUnit.MINUTES);
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 14 with DeleteTopicsResult

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

the class KafkaAdminClient method deleteStream.

@Override
public void deleteStream(String streamName) throws Exception {
    DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(ImmutableList.of(streamName));
    deleteTopicsResult.values().get(streamName).get();
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 15 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project kafka-benchmark by AzulSystems.

the class KafkaE2EBenchmark method deleteTopic.

public void deleteTopic(boolean wait) {
    log("Deleting topic '" + config.topic + "'...");
    try {
        DeleteTopicsResult result = adminClient.deleteTopics(Arrays.asList(config.topic));
        result.all().get();
        if (wait && config.waitAfterDeleteTopic > 0) {
            sleep(config.waitAfterDeleteTopic, "waiting after topic deletion");
        }
        log("Topic deleted '" + config.topic + "'");
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        if (e instanceof UnknownTopicOrPartitionException) {
            log("Cannot delete topic '" + config.topic + "' " + e);
            return;
        }
        if (e.getCause() instanceof UnknownTopicOrPartitionException) {
            log("Cannot delete topic '" + config.topic + "' " + e.getCause());
            return;
        }
        throw new KafkaRuntimeException("Failed to delete topic '" + config.topic + "'", e);
    }
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException)

Aggregations

DeleteTopicsResult (org.apache.kafka.clients.admin.DeleteTopicsResult)26 ExecutionException (java.util.concurrent.ExecutionException)8 AdminClient (org.apache.kafka.clients.admin.AdminClient)6 KafkaFuture (org.apache.kafka.common.KafkaFuture)6 Map (java.util.Map)4 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)3 TopicExistsException (org.apache.kafka.common.errors.TopicExistsException)3 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)3 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)2 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 OptionException (joptsimple.OptionException)2 Cleanup (lombok.Cleanup)2 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)2 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)2 KafkaDeleteTopicsException (io.confluent.ksql.exception.KafkaDeleteTopicsException)1 KafkaTopicException (io.confluent.ksql.exception.KafkaTopicException)1 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)1 KsqlException (io.confluent.ksql.util.KsqlException)1