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.
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, and transactional state
|
void |
close()
|
void |
close(long timeout,
java.util.concurrent.TimeUnit timeUnit)
|
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 |
fenceProducerOnClose() |
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,
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() |
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 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(long timeout, java.util.concurrent.TimeUnit timeUnit)
Producer
public boolean closed()
public void fenceProducer()
public void fenceProducerOnClose()
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<java.util.Map<java.lang.String,java.util.Map<TopicPartition,OffsetAndMetadata>>> consumerGroupOffsetsHistory()
clear()
public void clear()
public boolean completeNext()
public boolean errorNext(java.lang.RuntimeException e)