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 |
MockProducer(Cluster cluster, boolean autoComplete, Serializer<K> keySerializer, Serializer<V> valueSerializer)Create a new mock producer with invented metadata the given autoComplete setting and key\value serializers. |
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)new MockProducer(Cluster.empty(), autoComplete, new DefaultPartitioner(), keySerializer, valueSerializer)public MockProducer(Cluster cluster, boolean autoComplete, Serializer<K> keySerializer, Serializer<V> valueSerializer)
new MockProducer(cluster, autoComplete, new DefaultPartitioner(), keySerializer, valueSerializer)public MockProducer(boolean autoComplete,
Partitioner partitioner,
Serializer<K> keySerializer,
Serializer<V> valueSerializer)new MockProducer(Cluster.empty(), autoComplete, partitioner, keySerializer, valueSerializer)public MockProducer()
new MockProducer(Cluster.empty(), false, null, null, null)public void initTransactions()
ProducerinitTransactions in interface Producer<K,V>public void beginTransaction()
throws ProducerFencedExceptionProducerbeginTransaction in interface Producer<K,V>ProducerFencedException@Deprecated public void sendOffsetsToTransaction(Map<TopicPartition,OffsetAndMetadata> offsets, String consumerGroupId) throws ProducerFencedException
ProducersendOffsetsToTransaction in interface Producer<K,V>ProducerFencedExceptionpublic void sendOffsetsToTransaction(Map<TopicPartition,OffsetAndMetadata> offsets, ConsumerGroupMetadata groupMetadata) throws ProducerFencedException
ProducersendOffsetsToTransaction in interface Producer<K,V>ProducerFencedExceptionpublic void commitTransaction()
throws ProducerFencedExceptionProducercommitTransaction in interface Producer<K,V>ProducerFencedExceptionpublic void abortTransaction()
throws ProducerFencedExceptionProducerabortTransaction in interface Producer<K,V>ProducerFencedExceptionpublic 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()
Producerpublic List<PartitionInfo> partitionsFor(String topic)
ProducerpartitionsFor in interface Producer<K,V>public void disableTelemetry()
public void injectTimeoutException(int injectTimeoutExceptionCounter)
injectTimeoutExceptionCounter - use -1 for infinitepublic void setClientInstanceId(Uuid instanceId)
public Uuid clientInstanceId(Duration timeout)
ProducerclientInstanceId in interface Producer<K,V>public Map<MetricName,Metric> metrics()
Producerpublic void setMockMetrics(MetricName name, Metric metric)
public void close()
Producerpublic 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)