public class MockConsumer<K,V> extends Object implements Consumer<K,V>
Consumer
interface you can use for testing code that uses Kafka. This class is not
threadsafe . However, you can use the schedulePollTask(Runnable)
method to write multithreaded tests
where a driver thread waits for poll(Duration)
to be called by a background thread and then can safely perform
operations during a callback.Constructor and Description |
---|
MockConsumer(OffsetResetStrategy offsetResetStrategy) |
public MockConsumer(OffsetResetStrategy offsetResetStrategy)
public Set<TopicPartition> assignment()
assignment
in interface Consumer<K,V>
KafkaConsumer.assignment()
public void rebalance(Collection<TopicPartition> newAssignment)
public Set<String> subscription()
subscription
in interface Consumer<K,V>
KafkaConsumer.subscription()
public void subscribe(Collection<String> topics)
subscribe
in interface Consumer<K,V>
KafkaConsumer.subscribe(Collection)
public void subscribe(Pattern pattern, ConsumerRebalanceListener listener)
subscribe
in interface Consumer<K,V>
KafkaConsumer.subscribe(Pattern, ConsumerRebalanceListener)
public void subscribe(Pattern pattern)
subscribe
in interface Consumer<K,V>
KafkaConsumer.subscribe(Pattern)
public void subscribe(Collection<String> topics, ConsumerRebalanceListener listener)
subscribe
in interface Consumer<K,V>
KafkaConsumer.subscribe(Collection, ConsumerRebalanceListener)
public void assign(Collection<TopicPartition> partitions)
assign
in interface Consumer<K,V>
KafkaConsumer.assign(Collection)
public void unsubscribe()
unsubscribe
in interface Consumer<K,V>
KafkaConsumer.unsubscribe()
@Deprecated public ConsumerRecords<K,V> poll(long timeout)
poll
in interface Consumer<K,V>
KafkaConsumer.poll(long)
public ConsumerRecords<K,V> poll(Duration timeout)
poll
in interface Consumer<K,V>
KafkaConsumer.poll(Duration)
public void addRecord(ConsumerRecord<K,V> record)
@Deprecated public void setException(KafkaException exception)
setPollException(KafkaException)
insteadpublic void setPollException(KafkaException exception)
public void setOffsetsException(KafkaException exception)
public void commitAsync(Map<TopicPartition,OffsetAndMetadata> offsets, OffsetCommitCallback callback)
commitAsync
in interface Consumer<K,V>
KafkaConsumer.commitAsync(Map, OffsetCommitCallback)
public void commitSync(Map<TopicPartition,OffsetAndMetadata> offsets)
commitSync
in interface Consumer<K,V>
KafkaConsumer.commitSync(Map)
public void commitAsync()
commitAsync
in interface Consumer<K,V>
KafkaConsumer.commitAsync()
public void commitAsync(OffsetCommitCallback callback)
commitAsync
in interface Consumer<K,V>
KafkaConsumer.commitAsync(OffsetCommitCallback)
public void commitSync()
commitSync
in interface Consumer<K,V>
KafkaConsumer.commitSync()
public void commitSync(Duration timeout)
commitSync
in interface Consumer<K,V>
KafkaConsumer.commitSync(Duration)
public void commitSync(Map<TopicPartition,OffsetAndMetadata> offsets, Duration timeout)
commitSync
in interface Consumer<K,V>
KafkaConsumer.commitSync(Map, Duration)
public void seek(TopicPartition partition, long offset)
seek
in interface Consumer<K,V>
KafkaConsumer.seek(TopicPartition, long)
public void seek(TopicPartition partition, OffsetAndMetadata offsetAndMetadata)
seek
in interface Consumer<K,V>
KafkaConsumer.seek(TopicPartition, OffsetAndMetadata)
@Deprecated public OffsetAndMetadata committed(TopicPartition partition)
committed
in interface Consumer<K,V>
KafkaConsumer.committed(TopicPartition)
@Deprecated public OffsetAndMetadata committed(TopicPartition partition, Duration timeout)
committed
in interface Consumer<K,V>
KafkaConsumer.committed(TopicPartition, Duration)
public Map<TopicPartition,OffsetAndMetadata> committed(Set<TopicPartition> partitions)
committed
in interface Consumer<K,V>
KafkaConsumer.committed(Set)
public Map<TopicPartition,OffsetAndMetadata> committed(Set<TopicPartition> partitions, Duration timeout)
committed
in interface Consumer<K,V>
KafkaConsumer.committed(Set, Duration)
public long position(TopicPartition partition)
position
in interface Consumer<K,V>
KafkaConsumer.position(TopicPartition)
public long position(TopicPartition partition, Duration timeout)
position
in interface Consumer<K,V>
KafkaConsumer.position(TopicPartition, Duration)
public void seekToBeginning(Collection<TopicPartition> partitions)
seekToBeginning
in interface Consumer<K,V>
KafkaConsumer.seekToBeginning(Collection)
public void updateBeginningOffsets(Map<TopicPartition,Long> newOffsets)
public void seekToEnd(Collection<TopicPartition> partitions)
seekToEnd
in interface Consumer<K,V>
KafkaConsumer.seekToEnd(Collection)
public void addEndOffsets(Map<TopicPartition,Long> newOffsets)
public void updateEndOffsets(Map<TopicPartition,Long> newOffsets)
public Map<MetricName,? extends Metric> metrics()
metrics
in interface Consumer<K,V>
KafkaConsumer.metrics()
public List<PartitionInfo> partitionsFor(String topic)
partitionsFor
in interface Consumer<K,V>
KafkaConsumer.partitionsFor(String)
public Map<String,List<PartitionInfo>> listTopics()
listTopics
in interface Consumer<K,V>
KafkaConsumer.listTopics()
public void updatePartitions(String topic, List<PartitionInfo> partitions)
public void pause(Collection<TopicPartition> partitions)
pause
in interface Consumer<K,V>
KafkaConsumer.pause(Collection)
public void resume(Collection<TopicPartition> partitions)
resume
in interface Consumer<K,V>
KafkaConsumer.resume(Collection)
public Map<TopicPartition,OffsetAndTimestamp> offsetsForTimes(Map<TopicPartition,Long> timestampsToSearch)
offsetsForTimes
in interface Consumer<K,V>
KafkaConsumer.offsetsForTimes(Map)
public Map<TopicPartition,Long> beginningOffsets(Collection<TopicPartition> partitions)
beginningOffsets
in interface Consumer<K,V>
KafkaConsumer.beginningOffsets(Collection)
public Map<TopicPartition,Long> endOffsets(Collection<TopicPartition> partitions)
endOffsets
in interface Consumer<K,V>
KafkaConsumer.endOffsets(Collection)
public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Consumer<K,V>
KafkaConsumer.close()
public void close(long timeout, TimeUnit unit)
close
in interface Consumer<K,V>
KafkaConsumer.close(long, TimeUnit)
public boolean closed()
public void wakeup()
wakeup
in interface Consumer<K,V>
KafkaConsumer.wakeup()
public void schedulePollTask(Runnable task)
poll(Duration)
invocation. You can use this repeatedly to mock out multiple responses to poll invocations.task
- the task to be executedpublic void scheduleNopPollTask()
public Set<TopicPartition> paused()
paused
in interface Consumer<K,V>
KafkaConsumer.paused()
public List<PartitionInfo> partitionsFor(String topic, Duration timeout)
partitionsFor
in interface Consumer<K,V>
KafkaConsumer.partitionsFor(String, Duration)
public Map<String,List<PartitionInfo>> listTopics(Duration timeout)
listTopics
in interface Consumer<K,V>
KafkaConsumer.listTopics(Duration)
public Map<TopicPartition,OffsetAndTimestamp> offsetsForTimes(Map<TopicPartition,Long> timestampsToSearch, Duration timeout)
offsetsForTimes
in interface Consumer<K,V>
KafkaConsumer.offsetsForTimes(Map, Duration)
public Map<TopicPartition,Long> beginningOffsets(Collection<TopicPartition> partitions, Duration timeout)
beginningOffsets
in interface Consumer<K,V>
KafkaConsumer.beginningOffsets(Collection, Duration)
public Map<TopicPartition,Long> endOffsets(Collection<TopicPartition> partitions, Duration timeout)
endOffsets
in interface Consumer<K,V>
KafkaConsumer.endOffsets(Collection, Duration)
public ConsumerGroupMetadata groupMetadata()
groupMetadata
in interface Consumer<K,V>
KafkaConsumer.groupMetadata()