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(long)
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(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()
public ConsumerRecords<K,V> poll(long timeout)
poll
in interface Consumer<K,V>
KafkaConsumer.poll(long)
public void addRecord(ConsumerRecord<K,V> record)
public void setException(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 seek(TopicPartition partition, long offset)
seek
in interface Consumer<K,V>
KafkaConsumer.seek(TopicPartition, long)
public OffsetAndMetadata committed(TopicPartition partition)
committed
in interface Consumer<K,V>
KafkaConsumer.committed(TopicPartition)
public long position(TopicPartition partition)
position
in interface Consumer<K,V>
KafkaConsumer.position(TopicPartition)
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 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 void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Consumer<K,V>
KafkaConsumer.close()
public boolean closed()
public void wakeup()
wakeup
in interface Consumer<K,V>
KafkaConsumer.wakeup()
public void schedulePollTask(Runnable task)
poll(long)
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()