K - the type of the record keyV - the type of the record valuepublic class TestOutputTopic<K,V> extends Object
TestOutputTopic is used to read records from a topic in TopologyTestDriver.
To use TestOutputTopic create a new instance via
TopologyTestDriver.createOutputTopic(String, Deserializer, Deserializer).
In actual test code, you can read record values, keys, KeyValue or TestRecord
If you have multiple source topics, you need to create a TestOutputTopic for each.
If you need to test key, value and headers, use readRecord() methods.
Using readKeyValue() you get a KeyValue pair, and thus, don't get access to the record's
timestamp or headers.
Similarly using readValue() you only get the value of a record.
private TestOutputTopic<String, Long> outputTopic;
...
outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, stringDeserializer, longDeserializer);
...
assertThat(outputTopic.readValue()).isEqual(1);
TopologyTestDriver| Modifier and Type | Method and Description |
|---|---|
long |
getQueueSize()
Get size of unread record in the topic queue.
|
boolean |
isEmpty()
Verify if the topic queue is empty.
|
KeyValue<K,V> |
readKeyValue()
Read one record from the output topic and return its key and value as pair.
|
List<KeyValue<K,V>> |
readKeyValuesToList()
Read all KeyValues from topic to List.
|
Map<K,V> |
readKeyValuesToMap()
Read output to map.
|
TestRecord<K,V> |
readRecord()
Read one Record from output topic.
|
List<TestRecord<K,V>> |
readRecordsToList()
Read output to List.
|
V |
readValue()
Read one record from the output topic and return record's value.
|
List<V> |
readValuesToList()
Read all values from topic to List.
|
String |
toString() |
public V readValue()
public KeyValue<K,V> readKeyValue()
KeyValue.public TestRecord<K,V> readRecord()
TestRecord.public List<TestRecord<K,V>> readRecordsToList()
readKeyValuesToMap() instead.public Map<K,V> readKeyValuesToMap()
readRecordsToList() instead.
The list will contain all updated, ie, a key might be contained multiple times.
If the last update to a key is a delete/tombstone, the key will still be in the map (with null-value).public List<KeyValue<K,V>> readKeyValuesToList()
public List<V> readValuesToList()
public final long getQueueSize()
public final boolean isEmpty()
true if no more record in the topic queue.