public class MockProducer<K,V> extends Object implements Producer<K,V>
By default this mock will synchronously complete each send call successfully. However it can be configured to allow the user to control the completion of the call and supply an optional error for the producer to throw.
Constructor and Description |
---|
MockProducer()
Create a new mock producer with invented metadata.
|
MockProducer(boolean autoComplete,
Partitioner partitioner,
Serializer<K> keySerializer,
Serializer<V> valueSerializer)
Create a new mock producer with invented metadata the given autoComplete setting, partitioner and key\value serializers.
|
MockProducer(boolean autoComplete,
Serializer<K> keySerializer,
Serializer<V> valueSerializer)
Create a new mock producer with invented metadata the given autoComplete setting and key\value serializers.
|
MockProducer(Cluster cluster,
boolean autoComplete,
Partitioner partitioner,
Serializer<K> keySerializer,
Serializer<V> valueSerializer)
Create a mock producer
|
Modifier and Type | Method and Description |
---|---|
void |
abortTransaction()
|
void |
beginTransaction()
|
void |
clear()
Clear the stored history of sent records, consumer group offsets
|
void |
close()
|
void |
close(Duration timeout)
|
boolean |
closed() |
long |
commitCount() |
void |
commitTransaction()
|
boolean |
completeNext()
Complete the earliest uncompleted call successfully.
|
List<Map<String,Map<TopicPartition,OffsetAndMetadata>>> |
consumerGroupOffsetsHistory()
Get the list of committed consumer group offsets since the last call to
clear() |
boolean |
errorNext(RuntimeException e)
Complete the earliest uncompleted call with the given error.
|
void |
fenceProducer() |
void |
flush()
|
boolean |
flushed() |
List<ProducerRecord<K,V>> |
history()
Get the list of sent records since the last call to
clear() |
void |
initTransactions()
|
Map<MetricName,Metric> |
metrics()
|
List<PartitionInfo> |
partitionsFor(String topic)
|
Future<RecordMetadata> |
send(ProducerRecord<K,V> record)
Adds the record to the list of sent records.
|
Future<RecordMetadata> |
send(ProducerRecord<K,V> record,
Callback callback)
Adds the record to the list of sent records.
|
void |
sendOffsetsToTransaction(Map<TopicPartition,OffsetAndMetadata> offsets,
ConsumerGroupMetadata groupMetadata)
|
void |
sendOffsetsToTransaction(Map<TopicPartition,OffsetAndMetadata> offsets,
String consumerGroupId)
Deprecated.
|
boolean |
sentOffsets() |
void |
setMockMetrics(MetricName name,
Metric metric)
Set a mock metric for testing purpose
|
boolean |
transactionAborted() |
boolean |
transactionCommitted() |
boolean |
transactionInFlight() |
boolean |
transactionInitialized() |
Map<String,Map<TopicPartition,OffsetAndMetadata>> |
uncommittedOffsets() |
List<ProducerRecord<K,V>> |
uncommittedRecords() |
public RuntimeException initTransactionException
public RuntimeException beginTransactionException
public RuntimeException sendOffsetsToTransactionException
public RuntimeException commitTransactionException
public RuntimeException abortTransactionException
public RuntimeException sendException
public RuntimeException flushException
public RuntimeException partitionsForException
public RuntimeException closeException
public MockProducer(Cluster cluster, boolean autoComplete, Partitioner partitioner, Serializer<K> keySerializer, Serializer<V> valueSerializer)
cluster
- The cluster holding metadata for this producerautoComplete
- If true automatically complete all requests successfully and execute the callback. Otherwise
the user must call completeNext()
or errorNext(RuntimeException)
after
send()
to complete the call and unblock the Future<RecordMetadata>
that is returned.partitioner
- The partition strategykeySerializer
- The serializer for key that implements Serializer
.valueSerializer
- The serializer for value that implements Serializer
.public MockProducer(boolean autoComplete, Serializer<K> keySerializer, Serializer<V> valueSerializer)
MockProducer(Cluster, boolean, Partitioner, Serializer, Serializer)
new MockProducer(Cluster.empty(), autoComplete, new DefaultPartitioner(), keySerializer, valueSerializer)}public MockProducer(boolean autoComplete, Partitioner partitioner, Serializer<K> keySerializer, Serializer<V> valueSerializer)
MockProducer(Cluster, boolean, Partitioner, Serializer, Serializer)
new MockProducer(Cluster.empty(), autoComplete, partitioner, keySerializer, valueSerializer)}public MockProducer()
MockProducer(Cluster, boolean, Partitioner, Serializer, Serializer)
new MockProducer(Cluster.empty(), false, null, null, null)}public void initTransactions()
Producer
initTransactions
in interface Producer<K,V>
public void beginTransaction() throws ProducerFencedException
Producer
beginTransaction
in interface Producer<K,V>
ProducerFencedException
@Deprecated public void sendOffsetsToTransaction(Map<TopicPartition,OffsetAndMetadata> offsets, String consumerGroupId) throws ProducerFencedException
Producer
sendOffsetsToTransaction
in interface Producer<K,V>
ProducerFencedException
public void sendOffsetsToTransaction(Map<TopicPartition,OffsetAndMetadata> offsets, ConsumerGroupMetadata groupMetadata) throws ProducerFencedException
Producer
sendOffsetsToTransaction
in interface Producer<K,V>
ProducerFencedException
public void commitTransaction() throws ProducerFencedException
Producer
commitTransaction
in interface Producer<K,V>
ProducerFencedException
public void abortTransaction() throws ProducerFencedException
Producer
abortTransaction
in interface Producer<K,V>
ProducerFencedException
public Future<RecordMetadata> send(ProducerRecord<K,V> record)
RecordMetadata
returned will be immediately satisfied.public Future<RecordMetadata> send(ProducerRecord<K,V> record, Callback callback)
public void flush()
Producer
public List<PartitionInfo> partitionsFor(String topic)
Producer
partitionsFor
in interface Producer<K,V>
public Map<MetricName,Metric> metrics()
Producer
public void setMockMetrics(MetricName name, Metric metric)
public void close()
Producer
public boolean closed()
public void fenceProducer()
public boolean transactionInitialized()
public boolean transactionInFlight()
public boolean transactionCommitted()
public boolean transactionAborted()
public boolean flushed()
public boolean sentOffsets()
public long commitCount()
public List<ProducerRecord<K,V>> history()
clear()
public List<ProducerRecord<K,V>> uncommittedRecords()
public List<Map<String,Map<TopicPartition,OffsetAndMetadata>>> consumerGroupOffsetsHistory()
clear()
public Map<String,Map<TopicPartition,OffsetAndMetadata>> uncommittedOffsets()
public void clear()
public boolean completeNext()
public boolean errorNext(RuntimeException e)