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,
KafkaEmbedded 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.lang.Object |
getPropertyValue(java.lang.Object root,
java.lang.String propertyPath)
Uses nested
DirectFieldAccessor s 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(KafkaEmbedded 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, KafkaEmbedded embeddedKafka)
<Integer, String>
consumer.group
- the group id.autoCommit
- the auto commit.embeddedKafka
- a KafkaEmbedded
instance.public static java.util.Map<java.lang.String,java.lang.Object> producerProps(KafkaEmbedded embeddedKafka)
<Integer, String>
producer.embeddedKafka
- a KafkaEmbedded
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.org.junit.ComparisonFailure
- 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)
.org.junit.ComparisonFailure
- if exactly one record is not received.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)
.public static java.lang.Object getPropertyValue(java.lang.Object root, java.lang.String propertyPath)
DirectFieldAccessor
s 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)