Class EmbeddedKafkaRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class EmbeddedKafkaRule
    extends org.junit.rules.ExternalResource
    A TestRule wrapper around an EmbeddedKafkaBroker.
    Since:
    2.2
    Author:
    Artem Bilan
    See Also:
    EmbeddedKafkaBroker
    • Constructor Detail

      • EmbeddedKafkaRule

        public EmbeddedKafkaRule​(int count)
      • EmbeddedKafkaRule

        public EmbeddedKafkaRule​(int count,
                                 boolean controlledShutdown,
                                 java.lang.String... topics)
        Create embedded Kafka brokers.
        Parameters:
        count - the number of brokers.
        controlledShutdown - passed into TestUtils.createBrokerConfig.
        topics - the topics to create (2 partitions per).
      • EmbeddedKafkaRule

        public EmbeddedKafkaRule​(int count,
                                 boolean controlledShutdown,
                                 int partitions,
                                 java.lang.String... topics)
        Create embedded Kafka brokers listening on random ports.
        Parameters:
        count - the number of brokers.
        controlledShutdown - passed into TestUtils.createBrokerConfig.
        partitions - partitions per topic.
        topics - the topics to create.
    • Method Detail

      • brokerProperties

        public EmbeddedKafkaRule brokerProperties​(java.util.Map<java.lang.String,​java.lang.String> brokerProperties)
        Specify the properties to configure Kafka Broker before start, e.g. auto.create.topics.enable, transaction.state.log.replication.factor etc.
        Parameters:
        brokerProperties - the properties to use for configuring Kafka Broker(s).
        Returns:
        this for chaining configuration
        See Also:
        KafkaConfig
      • brokerProperty

        public EmbeddedKafkaRule brokerProperty​(java.lang.String property,
                                                java.lang.Object value)
        Specify a broker property.
        Parameters:
        property - the property name.
        value - the value.
        Returns:
        the EmbeddedKafkaRule.
        Since:
        2.1.4
      • kafkaPorts

        public EmbeddedKafkaRule kafkaPorts​(int... kafkaPorts)
        Set explicit ports on which the kafka brokers will listen. Useful when running an embedded broker that you want to access from other processes.
        Parameters:
        kafkaPorts - the ports.
        Returns:
        the rule.
      • before

        public void before()
        Overrides:
        before in class org.junit.rules.ExternalResource
      • after

        public void after()
        Overrides:
        after in class org.junit.rules.ExternalResource