Package com.linkedin.venice.unit.kafka
Class InMemoryKafkaBroker
- java.lang.Object
-
- com.linkedin.venice.unit.kafka.InMemoryKafkaBroker
-
public class InMemoryKafkaBroker extends java.lang.Object
Used in unit tests in order to avoid spinning a full Kafka broker with network stack and disk IO. Instead, this Kafka broker keeps messages in memory. It can be used via the following mock classes:- See Also:
MockInMemoryConsumer
,MockInMemoryProducerAdapter
-
-
Constructor Summary
Constructors Constructor Description InMemoryKafkaBroker(java.lang.String brokerNamePrefix)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<InMemoryKafkaMessage>
consume(java.lang.String topicName, int partition, long offset)
void
createTopic(java.lang.String topicName, int partitionCount)
java.lang.Long
endOffsets(java.lang.String topicName, int partition)
java.lang.String
getKafkaBootstrapServer()
int
getPartitionCount(java.lang.String topicName)
long
produce(java.lang.String topicName, int partition, InMemoryKafkaMessage message)
-
-
-
Method Detail
-
createTopic
public void createTopic(java.lang.String topicName, int partitionCount)
-
produce
public long produce(java.lang.String topicName, int partition, InMemoryKafkaMessage message)
- Parameters:
topicName
- The name of the topic in which to produce.partition
- The partition in which to produce a message.message
- TheInMemoryKafkaMessage
to produce into the partition.- Returns:
- the offset of the produced message
- Throws:
java.lang.IllegalArgumentException
- if the topic or partition does not exist.
-
consume
public java.util.Optional<InMemoryKafkaMessage> consume(java.lang.String topicName, int partition, long offset) throws java.lang.IllegalArgumentException
- Parameters:
topicName
- The name of the topic from which to consume.partition
- The partition from which to produce a message.- Returns:
- Some
InMemoryKafkaMessage
instance, or theOptional.empty()
instance if that partition is drained. - Throws:
java.lang.IllegalArgumentException
- if the topic or partition does not exist.
-
getPartitionCount
public int getPartitionCount(java.lang.String topicName)
-
getKafkaBootstrapServer
public java.lang.String getKafkaBootstrapServer()
- Returns:
- an synthetic broker server url.
-
endOffsets
public java.lang.Long endOffsets(java.lang.String topicName, int partition)
-
-