Package com.linkedin.venice.pubsub.mock
Class InMemoryPubSubBroker
java.lang.Object
com.linkedin.venice.pubsub.mock.InMemoryPubSubBroker
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconsume
(String topicName, int partition, InMemoryPubSubPosition position) void
createTopic
(String topicName, int partitionCount) endOffsets
(String topicName, int partition) endPosition
(String topicName, int partition) int
getPartitionCount
(String topicName) int
getPort()
produce
(String topicName, int partition, InMemoryPubSubMessage message)
-
Constructor Details
-
InMemoryPubSubBroker
-
-
Method Details
-
createTopic
-
produce
public InMemoryPubSubPosition produce(String topicName, int partition, InMemoryPubSubMessage message) - Parameters:
topicName
- The name of the topic in which to produce.partition
- The partition in which to produce a message.message
- TheInMemoryPubSubMessage
to produce into the partition.- Returns:
- the offset of the produced message
- Throws:
IllegalArgumentException
- if the topic or partition does not exist.
-
consume
public Optional<InMemoryPubSubMessage> consume(String topicName, int partition, InMemoryPubSubPosition position) throws IllegalArgumentException - Parameters:
topicName
- The name of the topic from which to consume.partition
- The partition from which to produce a message.- Returns:
- Some
InMemoryPubSubMessage
instance, or theOptional.empty()
instance if that partition is drained. - Throws:
IllegalArgumentException
- if the topic or partition does not exist.
-
getPartitionCount
-
getPubSubBrokerAddress
- Returns:
- a synthetic broker server url.
-
endOffsets
-
endPosition
-
getPort
public int getPort()
-