|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.kafka.clients.producer.MockProducer
public class MockProducer
A mock of the producer interface you can use for testing code that uses Kafka.
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 Summary | |
---|---|
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 |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
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)
Method Detail |
---|
public java.util.concurrent.Future<RecordMetadata> send(ProducerRecord<byte[],byte[]> record)
RecordMetadata
returned will be immediately satisfied.
send
in interface Producer<byte[],byte[]>
record
- The record to send
history()
public java.util.concurrent.Future<RecordMetadata> send(ProducerRecord<byte[],byte[]> record, Callback callback)
send
in interface Producer<byte[],byte[]>
history()
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
metrics
in interface Producer<byte[],byte[]>
public void close()
Producer
close
in interface java.io.Closeable
close
in interface Producer<byte[],byte[]>
public java.util.List<ProducerRecord<byte[],byte[]>> history()
clear()
public void clear()
public boolean completeNext()
public boolean errorNext(java.lang.RuntimeException e)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |