io.kroxylicious.test.tester.KroxyliciousTester Maven / Gradle / Ivy
/*
* Copyright Kroxylicious Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.kroxylicious.test.tester;
import java.io.Closeable;
import java.util.Map;
import java.util.Set;
import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.common.serialization.Serde;
import io.kroxylicious.test.client.KafkaClient;
/**
* A convenient tester for a Kroxylicious instance. Implementations of this will
* typically create a Kroxylicious server and clean it up on {@link #close()}. It provides
* convenient methods for obtaining clients configured to talk to Kroxylicious.
* KroxyliciousTester is virtual cluster aware, so you can ask it for a client
* for a specific virtual cluster offered by the kroxylicious instance.
*/
public interface KroxyliciousTester extends Closeable {
/**
* Creates an Admin Client configured with the kroxylicious bootstrap server
* for the only virtual cluster configured.
* @param additionalConfig additional configuration for the Admin client
* @return Admin client
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
Admin admin(Map additionalConfig);
/**
* Creates an Admin Client configured with the kroxylicious bootstrap server
* for a specific virtual cluster.
* @param virtualCluster the virtual cluster we want the client to connect to
* @param additionalConfig additional configuration for the Admin client
* @return Admin client
* @throws IllegalArgumentException if the named virtual cluster is not part of the kroxylicious server
*/
Admin admin(String virtualCluster, Map additionalConfig);
/**
* Creates an Admin Client configured with the kroxylicious bootstrap server
* for the only virtual cluster configured.
* @return Admin client
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
Admin admin();
/**
* Creates an Admin Client configured with the kroxylicious bootstrap server
* for a specific virtual cluster.
* @param virtualCluster the virtual cluster we want the client to connect to
* @return Admin client
* @throws IllegalArgumentException if the named virtual cluster is not part of the kroxylicious server
*/
Admin admin(String virtualCluster);
/**
* Creates a Producer configured with the kroxylicious bootstrap server
* for the only virtual cluster configured.
* @param additionalConfig additional producer configuration
* @return Producer
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
Producer producer(Map additionalConfig);
/**
* Creates a Producer configured with the kroxylicious bootstrap server
* for a specific virtual cluster.
* @param virtualCluster the virtual cluster we want the client to connect to
* @param additionalConfig additional producer configuration
* @return Producer
* @throws IllegalArgumentException if the named virtual cluster is not part of the kroxylicious server
*/
Producer producer(String virtualCluster, Map additionalConfig);
/**
* Creates a Producer configured with the kroxylicious bootstrap server
* for the only virtual cluster configured.
* @return Producer
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
Producer producer();
/**
* Creates a Producer configured with the kroxylicious bootstrap server
* for a specific virtual cluster.
* @param virtualCluster the virtual cluster we want the client to connect to
* @return Producer
* @throws IllegalArgumentException if the named virtual cluster is not part of the kroxylicious server
*/
Producer producer(String virtualCluster);
/**
* Creates a Producer configured with the kroxylicious bootstrap server
* for the only virtual cluster configured.
* @param key type
* @param value type
* @param keySerde key serde
* @param valueSerde value serde
* @param additionalConfig additional produce config
* @return Producer
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
Producer producer(Serde keySerde, Serde valueSerde, Map additionalConfig);
/**
* Creates a Producer configured with the kroxylicious bootstrap server
* for a specific virtual cluster.
* @param key type
* @param value type
* @param keySerde key serde
* @param valueSerde value serde
* @param additionalConfig additional produce config
* @param virtualCluster the virtual cluster we want the client to connect to
* @return Producer
* @throws IllegalArgumentException if the named virtual cluster is not part of the kroxylicious server
*/
Producer producer(String virtualCluster, Serde keySerde, Serde valueSerde, Map additionalConfig);
/**
* Creates a Consumer configured with the kroxylicious bootstrap server
* for the only virtual cluster configured.
* @param additionalConfig additional consumer config
* @return Consumer
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
Consumer consumer(Map additionalConfig);
/**
* Creates a Consumer configured with the kroxylicious bootstrap server
* for a specific virtual cluster.
* @param additionalConfig additional consumer config
* @param virtualCluster the virtual cluster we want the client to connect to
* @return Consumer
* @throws IllegalArgumentException if the named virtual cluster is not part of the kroxylicious server
*/
Consumer consumer(String virtualCluster, Map additionalConfig);
/**
* Creates a Consumer configured with the kroxylicious bootstrap server
* for the only virtual cluster configured. Also sets a random group id
* and sets auto offset reset to "earliest".
* @return Consumer
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
Consumer consumer();
/**
* Creates a Consumer configured with the kroxylicious bootstrap server
* for a specific virtual cluster. Also sets a random group id
* and sets auto offset reset to "earliest".
* @param virtualCluster the virtual cluster we want the client to connect to
* @return Consumer
* @throws IllegalArgumentException if the named virtual cluster is not part of the kroxylicious server
*/
Consumer consumer(String virtualCluster);
/**
* Creates a Consumer configured with the kroxylicious bootstrap server
* for the only virtual cluster configured.
* @param key type
* @param value type
* @param keySerde key serde
* @param valueSerde value serde
* @param additionalConfig additional consumer config
* @return Admin client
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
Consumer consumer(Serde keySerde, Serde valueSerde, Map additionalConfig);
/**
* Creates a Consumer configured with the kroxylicious bootstrap server
* for a specific virtual cluster. Also sets a random group id
* and sets auto offset reset to "earliest".
* @param key type
* @param value type
* @param keySerde key serde
* @param valueSerde value serde
* @param additionalConfig additional consumer config
* @param virtualCluster the virtual cluster we want the client to connect to
* @return Consumer
* @throws IllegalArgumentException if the named virtual cluster is not part of the kroxylicious server
*/
Consumer consumer(String virtualCluster, Serde keySerde, Serde valueSerde, Map additionalConfig);
/**
* Creates a Mock Request client configured with the kroxylicious bootstrap server
* for the only virtual cluster configured. This client can be used to send multiple
* ApiMessage to kroxilicious and receive many ApiMessage responses.
* @return KafkaClient
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
KafkaClient simpleTestClient();
/**
* Creates a Mock Request client configured with the kroxylicious bootstrap server
* for a specific virtual cluster. This client can be used to send multiple
* ApiMessage to kroxilicious and receive many ApiMessage responses.
* @param virtualCluster the virtual cluster we want the client to connect to
* @return KafkaClient
* @throws IllegalArgumentException if the named virtual cluster is not part of the kroxylicious server
*/
KafkaClient simpleTestClient(String virtualCluster);
/**
* Restarts the Kroxylicious server under test without closing any other resources.
*/
void restartProxy();
/**
* Close the Kroxylicious server under test and any other resources that need cleaning.
*/
void close();
/**
* Creates a single topic on the default Kafka cluster with a fixed partition count (1) and replication factor (1).
*
* The number of partitions can be increased via {@link Admin#createPartitions(Map) Admin.createParitions}.
* The number of replicas can be increased via {@link Admin#alterPartitionReassignments(Map) Admin.alterParitionsReassignments} by altering the replica assignments.
* See the Kafka docs for details
*
* @param clusterName the name of the virtual cluster on which to create the topic
* @return the name of the created topic
*/
default String createTopic(String clusterName) {
return createTopics(clusterName, 1).stream().findFirst().orElseThrow(() -> new IllegalStateException("Failed to create topic"));
}
/**
* Creates N topics with a fixed partition count (1) and replication factor (1).
*
* The number of partitions can be increased via {@link Admin#createPartitions(Map) Admin.createParitions}.
* The number of replicas can be increased via {@link Admin#alterPartitionReassignments(Map) Admin.alterParitionsReassignments} by altering the replica assignments.
* See the Kafka docs for details
*
* @param clusterName the name of the virtual cluster on which to create the topic
* @param numberOfTopics the number of topics to create on the cluster
* @return the Set of topic names which have been created.
*/
Set createTopics(String clusterName, int numberOfTopics);
/**
* Asks the tester to delete all topics created by the tester on a specific virtual cluster.
* @param clusterName the name of the virtual cluster from which to delete the topics.
*/
void deleteTopics(String clusterName);
/**
* @return the bootstrap address of the only virtual cluster
* @throws AmbiguousVirtualClusterException if this tester is for a Kroxylicious configured with multiple virtual clusters
*/
String getBootstrapAddress();
/**
* @return the bootstrap address of the named virtual cluster
*/
String getBootstrapAddress(String clusterName);
/**
* @return the Admin Http Client
* @throws IllegalStateException admin interface not available
*/
AdminHttpClient getAdminHttpClient();
}