Class 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 Detail

      • InMemoryKafkaBroker

        public InMemoryKafkaBroker​(java.lang.String brokerNamePrefix)
    • 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 - The InMemoryKafkaMessage 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 the Optional.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)