public class MockProducer extends java.lang.Object implements Producer<byte[],byte[]>
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 auto completing mock producer
Equivalent to
new MockProducer(true) |
MockProducer(boolean autoComplete)
Create a new mock producer with invented metadata the given autoComplete setting.
|
MockProducer(Cluster cluster,
boolean autoComplete)
Create a mock producer
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the stored history of sent records
|
void |
close()
Close this producer
|
boolean |
completeNext()
Complete the earliest uncompleted call successfully.
|
boolean |
errorNext(java.lang.RuntimeException e)
Complete the earliest uncompleted call with the given error.
|
java.util.List<ProducerRecord<byte[],byte[]>> |
history()
Get the list of sent records since the last call to
clear() |
java.util.Map<MetricName,Metric> |
metrics()
Return a map of metrics maintained by the producer
|
java.util.List<PartitionInfo> |
partitionsFor(java.lang.String topic)
Get a list of partitions for the given topic for custom partition assignment.
|
java.util.concurrent.Future<RecordMetadata> |
send(ProducerRecord<byte[],byte[]> record)
Adds the record to the list of sent records.
|
java.util.concurrent.Future<RecordMetadata> |
send(ProducerRecord<byte[],byte[]> record,
Callback callback)
Adds the record to the list of sent records.
|
public MockProducer(Cluster cluster, boolean autoComplete)
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.public MockProducer(boolean autoComplete)
new MockProducer(null, autoComplete)
public MockProducer()
new MockProducer(true)
public java.util.concurrent.Future<RecordMetadata> send(ProducerRecord<byte[],byte[]> record)
RecordMetadata
returned will be immediately satisfied.public java.util.concurrent.Future<RecordMetadata> send(ProducerRecord<byte[],byte[]> record, Callback callback)
public java.util.List<PartitionInfo> partitionsFor(java.lang.String topic)
Producer
partitionsFor
in interface Producer<byte[],byte[]>
public java.util.Map<MetricName,Metric> metrics()
Producer
public void close()
Producer
public java.util.List<ProducerRecord<byte[],byte[]>> history()
clear()
public void clear()
public boolean completeNext()
public boolean errorNext(java.lang.RuntimeException e)