public class MockProducer<K,V> extends java.lang.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.
Modifier and Type | Field and Description |
---|---|
java.lang.RuntimeException |
abortTransactionException |
java.lang.RuntimeException |
beginTransactionException |
java.lang.RuntimeException |
closeException |
java.lang.RuntimeException |
commitTransactionException |
java.lang.RuntimeException |
flushException |
java.lang.RuntimeException |
initTransactionException |
java.lang.RuntimeException |
partitionsForException |
java.lang.RuntimeException |
sendException |
java.lang.RuntimeException |
sendOffsetsToTransactionException |
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(java.time.Duration timeout)
|
boolean |
closed() |
long |
commitCount() |
void |
commitTransaction()
|
boolean |
completeNext()
Complete the earliest uncompleted call successfully.
|
java.util.List<java.util.Map<java.lang.String,java.util.Map<TopicPartition,OffsetAndMetadata>>> |
consumerGroupOffsetsHistory()
Get the list of committed consumer group offsets since the last call to
clear() |
boolean |
errorNext(java.lang.RuntimeException e)
Complete the earliest uncompleted call with the given error.
|
void |
fenceProducer() |
void |
flush()
|
boolean |
flushed() |
java.util.List<ProducerRecord<K,V>> |
history()
Get the list of sent records since the last call to
clear() |
void |
initTransactions()
|
java.util.Map<MetricName,Metric> |
metrics()
|
java.util.List<PartitionInfo> |
partitionsFor(java.lang.String topic)
|
java.util.concurrent.Future<RecordMetadata> |
send(ProducerRecord<K,V> record)
Adds the record to the list of sent records.
|
java.util.concurrent.Future<RecordMetadata> |
send(ProducerRecord<K,V> record,
Callback callback)
Adds the record to the list of sent records.
|
void |
sendOffsetsToTransaction(java.util.Map<TopicPartition,OffsetAndMetadata> offsets,
ConsumerGroupMetadata groupMetadata)
|
void |
sendOffsetsToTransaction(java.util.Map<TopicPartition,OffsetAndMetadata> offsets,
java.lang.String consumerGroupId)
|
boolean |
sentOffsets() |
void |
setMockMetrics(MetricName name,
Metric metric)
Set a mock metric for testing purpose
|
boolean |
transactionAborted() |
boolean |
transactionCommitted() |
boolean |
transactionInFlight() |
boolean |
transactionInitialized() |
java.util.Map<java.lang.String,java.util.Map<TopicPartition,OffsetAndMetadata>> |
uncommittedOffsets() |
java.util.List<ProducerRecord<K,V>> |
uncommittedRecords() |
public java.lang.RuntimeException initTransactionException
public java.lang.RuntimeException beginTransactionException
public java.lang.RuntimeException sendOffsetsToTransactionException
public java.lang.RuntimeException commitTransactionException
public java.lang.RuntimeException abortTransactionException
public java.lang.RuntimeException sendException
public java.lang.RuntimeException flushException
public java.lang.RuntimeException partitionsForException
public java.lang.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
public void sendOffsetsToTransaction(java.util.Map<TopicPartition,OffsetAndMetadata> offsets, java.lang.String consumerGroupId) throws ProducerFencedException
Producer
sendOffsetsToTransaction
in interface Producer<K,V>
ProducerFencedException
public void sendOffsetsToTransaction(java.util.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 java.util.concurrent.Future<RecordMetadata> send(ProducerRecord<K,V> record)
RecordMetadata
returned will be immediately satisfied.public java.util.concurrent.Future<RecordMetadata> send(ProducerRecord<K,V> record, Callback callback)
public void flush()
Producer
public java.util.List<PartitionInfo> partitionsFor(java.lang.String topic)
Producer
partitionsFor
in interface Producer<K,V>
public java.util.Map<MetricName,Metric> metrics()
Producer
public void setMockMetrics(MetricName name, Metric metric)
public void close()
Producer
public void close(java.time.Duration timeout)
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 java.util.List<ProducerRecord<K,V>> history()
clear()
public java.util.List<ProducerRecord<K,V>> uncommittedRecords()
public java.util.List<java.util.Map<java.lang.String,java.util.Map<TopicPartition,OffsetAndMetadata>>> consumerGroupOffsetsHistory()
clear()
public java.util.Map<java.lang.String,java.util.Map<TopicPartition,OffsetAndMetadata>> uncommittedOffsets()
public void clear()
public boolean completeNext()
public boolean errorNext(java.lang.RuntimeException e)