Class InMemoryKafkaBroker

java.lang.Object
com.linkedin.venice.unit.kafka.InMemoryKafkaBroker

public class InMemoryKafkaBroker extends 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:
  • Constructor Details

    • InMemoryKafkaBroker

      public InMemoryKafkaBroker(String brokerNamePrefix)
  • Method Details

    • createTopic

      public void createTopic(String topicName, int partitionCount)
    • produce

      public long produce(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 - The InMemoryKafkaMessage 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<InMemoryKafkaMessage> consume(String topicName, int partition, long offset) throws 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 the Optional.empty() instance if that partition is drained.
      Throws:
      IllegalArgumentException - if the topic or partition does not exist.
    • getPartitionCount

      public int getPartitionCount(String topicName)
    • getKafkaBootstrapServer

      public String getKafkaBootstrapServer()
      Returns:
      an synthetic broker server url.
    • endOffsets

      public Long endOffsets(String topicName, int partition)