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(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
Equivalent to
MockProducer(Cluster, boolean, Partitioner, Serializer, Serializer) new MockProducer(Cluster.empty(), autoComplete, partitioner, keySerializer, valueSerializer)} |
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
Equivalent to
MockProducer(Cluster, boolean, Partitioner, Serializer, Serializer) new MockProducer(Cluster.empty(), autoComplete, new DefaultPartitioner(), keySerializer, valueSerializer)} |
MockProducer(Cluster cluster,
boolean autoComplete,
Partitioner partitioner,
Serializer<K> keySerializer,
Serializer<V> valueSerializer)
Create a mock producer
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the stored history of sent records
|
void |
close()
Close this producer
|
void |
close(long timeout,
TimeUnit timeUnit)
Tries to close the producer cleanly within the specified timeout.
|
boolean |
completeNext()
Complete the earliest uncompleted call successfully.
|
boolean |
errorNext(RuntimeException e)
Complete the earliest uncompleted call with the given error.
|
void |
flush()
Flush any accumulated records from the producer.
|
List<ProducerRecord<K,V>> |
history()
Get the list of sent records since the last call to
clear() |
Map<MetricName,Metric> |
metrics()
Return a map of metrics maintained by the producer
|
List<PartitionInfo> |
partitionsFor(String topic)
Get a list of partitions for the given topic for custom partition assignment.
|
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.
|
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 @{link
java.util.concurrent.Future 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 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 close()
Producer
public void close(long timeout, TimeUnit timeUnit)
Producer
public List<ProducerRecord<K,V>> history()
clear()
public void clear()
public boolean completeNext()
public boolean errorNext(RuntimeException e)