public final class KafkaTestUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.util.Map<java.lang.String,java.lang.Object> |
consumerProps(java.lang.String group,
java.lang.String autoCommit,
EmbeddedKafkaBroker embeddedKafka)
Set up test properties for an
<Integer, String> consumer. |
static java.util.Map<java.lang.String,java.lang.Object> |
consumerProps(java.lang.String brokers,
java.lang.String group,
java.lang.String autoCommit)
Set up test properties for an
<Integer, String> consumer. |
static java.util.Properties |
defaultPropertyOverrides()
Return a
Properties object equal to the default consumer property overrides. |
static org.apache.kafka.clients.consumer.OffsetAndMetadata |
getCurrentOffset(java.lang.String brokerAddresses,
java.lang.String group,
java.lang.String topic,
int partition)
Get the current offset and metadata for the provided group/topic/partition.
|
static org.apache.kafka.clients.consumer.ConsumerRecord<?,?> |
getOneRecord(java.lang.String brokerAddresses,
java.lang.String group,
java.lang.String topic,
int partition,
boolean seekToLast,
boolean commit,
long timeout)
Get a single record for the group from the topic/partition.
|
static java.lang.Object |
getPropertyValue(java.lang.Object root,
java.lang.String propertyPath)
Uses nested
DirectFieldAccessors to obtain a property using dotted notation to traverse fields; e.g. |
static <T> T |
getPropertyValue(java.lang.Object root,
java.lang.String propertyPath,
java.lang.Class<T> type)
A typed version of
getPropertyValue(Object, String). |
static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> |
getRecords(org.apache.kafka.clients.consumer.Consumer<K,V> consumer)
Poll the consumer for records.
|
static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> |
getRecords(org.apache.kafka.clients.consumer.Consumer<K,V> consumer,
long timeout)
Poll the consumer for records.
|
static <K,V> org.apache.kafka.clients.consumer.ConsumerRecord<K,V> |
getSingleRecord(org.apache.kafka.clients.consumer.Consumer<K,V> consumer,
java.lang.String topic)
Poll the consumer, expecting a single record for the specified topic.
|
static <K,V> org.apache.kafka.clients.consumer.ConsumerRecord<K,V> |
getSingleRecord(org.apache.kafka.clients.consumer.Consumer<K,V> consumer,
java.lang.String topic,
long timeout)
Poll the consumer, expecting a single record for the specified topic.
|
static java.util.Map<java.lang.String,java.lang.Object> |
producerProps(EmbeddedKafkaBroker embeddedKafka)
Set up test properties for an
<Integer, String> producer. |
static java.util.Map<java.lang.String,java.lang.Object> |
senderProps(java.lang.String brokers)
Set up test properties for an
<Integer, String> producer. |
public static java.util.Map<java.lang.String,java.lang.Object> consumerProps(java.lang.String group,
java.lang.String autoCommit,
EmbeddedKafkaBroker embeddedKafka)
<Integer, String> consumer.group - the group id.autoCommit - the auto commit.embeddedKafka - a EmbeddedKafkaBroker instance.public static java.util.Map<java.lang.String,java.lang.Object> producerProps(EmbeddedKafkaBroker embeddedKafka)
<Integer, String> producer.embeddedKafka - a EmbeddedKafkaBroker instance.public static java.util.Map<java.lang.String,java.lang.Object> consumerProps(java.lang.String brokers,
java.lang.String group,
java.lang.String autoCommit)
<Integer, String> consumer.brokers - the bootstrapServers property.group - the group id.autoCommit - the auto commit.public static java.util.Map<java.lang.String,java.lang.Object> senderProps(java.lang.String brokers)
<Integer, String> producer.brokers - the bootstrapServers property.public static <K,V> org.apache.kafka.clients.consumer.ConsumerRecord<K,V> getSingleRecord(org.apache.kafka.clients.consumer.Consumer<K,V> consumer,
java.lang.String topic)
K - the key type.V - the value type.consumer - the consumer.topic - the topic.java.lang.IllegalStateException - if exactly one record is not received.getSingleRecord(Consumer, String, long)public static <K,V> org.apache.kafka.clients.consumer.ConsumerRecord<K,V> getSingleRecord(org.apache.kafka.clients.consumer.Consumer<K,V> consumer,
java.lang.String topic,
long timeout)
K - the key type.V - the value type.consumer - the consumer.topic - the topic.timeout - max time in milliseconds to wait for records; forwarded to Consumer.poll(long).java.lang.IllegalStateException - if exactly one record is not received.@Nullable
public static org.apache.kafka.clients.consumer.ConsumerRecord<?,?> getOneRecord(java.lang.String brokerAddresses,
java.lang.String group,
java.lang.String topic,
int partition,
boolean seekToLast,
boolean commit,
long timeout)
brokerAddresses - the broker address(es).group - the group.topic - the topic.partition - the partition.seekToLast - true to fetch an existing last record, if present.commit - commit offset after polling or not.timeout - the timeout.public static org.apache.kafka.clients.consumer.OffsetAndMetadata getCurrentOffset(java.lang.String brokerAddresses,
java.lang.String group,
java.lang.String topic,
int partition)
throws java.lang.Exception
brokerAddresses - the broker address(es).group - the group.topic - the topic.partition - the partition.java.lang.Exception - if an exception occurs.public static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> getRecords(org.apache.kafka.clients.consumer.Consumer<K,V> consumer)
K - the key type.V - the value type.consumer - the consumer.getRecords(Consumer, long)public static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> getRecords(org.apache.kafka.clients.consumer.Consumer<K,V> consumer,
long timeout)
K - the key type.V - the value type.consumer - the consumer.timeout - max time in milliseconds to wait for records; forwarded to Consumer.poll(long).java.lang.IllegalStateException - if the poll returns null (since 2.3.4).public static java.lang.Object getPropertyValue(java.lang.Object root,
java.lang.String propertyPath)
DirectFieldAccessors to obtain a property using dotted notation to traverse fields; e.g.
"foo.bar.baz" will obtain a reference to the baz field of the bar field of foo. Adopted from Spring Integration.root - The object.propertyPath - The path.public static <T> T getPropertyValue(java.lang.Object root,
java.lang.String propertyPath,
java.lang.Class<T> type)
getPropertyValue(Object, String).T - the type.root - the object.propertyPath - the path.type - the type to cast the object to.getPropertyValue(Object, String)public static java.util.Properties defaultPropertyOverrides()
Properties object equal to the default consumer property overrides.
Useful when matching arguments in Mockito tests.