KafkaProducerUseIteratorFalseIT.java

Overview

`KafkaProducerUseIteratorFalseIT` is an integration test class for the Apache Camel Kafka component. It verifies the behavior of the Kafka producer when configured with the `useIterator=false` option. This option controls how Camel sends a collection of messages to Kafka — whether as individual messages (iterator=true) or as a single message (iterator=false).

Specifically, the test ensures that when `useIterator=false`, the entire collection is sent as one Kafka message rather than multiple messages. The test sends a list of strings as a single message to a Kafka topic and verifies that only one Kafka record is produced and consumed.

This class is part of the Kafka integration tests and extends `BaseKafkaTestSupport`, which provides Kafka environment setup and teardown capabilities for testing.


Class Summary

KafkaProducerUseIteratorFalseIT

Visibility

Type

Description

public

class

Integration test for Kafka producer with `useIterator=false` configuration.


Detailed Description of Members

Constants

Name

Type

Description

`TOPIC`

String

Kafka topic name used for testing (`"use-iterator-false"`).

`FROM_URI`

String

Kafka consumer endpoint URI with specific consumer options and interceptor configured for testing.


Lifecycle Methods

@BeforeEach void init()

@AfterEach void after()


Test Methods

@Test void testUseIteratorFalse() throws Exception


Overridden Methods

protected RouteBuilder createRouteBuilder()


Important Implementation Details


Interaction with Other Components


Visual Diagram

classDiagram
    class KafkaProducerUseIteratorFalseIT {
        - static final String TOPIC
        - static final String FROM_URI
        + void init()
        + void after()
        + void testUseIteratorFalse()
        + RouteBuilder createRouteBuilder()
    }

    class BaseKafkaTestSupport
    KafkaProducerUseIteratorFalseIT --|> BaseKafkaTestSupport

    class RouteBuilder {
        +void configure()
    }

    KafkaProducerUseIteratorFalseIT o-- RouteBuilder : creates

    class MockConsumerInterceptor {
        +static List recordsCaptured
    }

    KafkaProducerUseIteratorFalseIT ..> MockConsumerInterceptor : uses for record capture

    class MockEndpoint {
        +void expectedBodiesReceived(Object)
        +void assertIsSatisfied(long)
    }

    KafkaProducerUseIteratorFalseIT ..> MockEndpoint : asserts results

Summary

`KafkaProducerUseIteratorFalseIT` is an integration test validating that when Apache Camel's Kafka producer is configured with `useIterator=false`, a collection of messages is sent as a single Kafka message. It leverages Camel routes, a mock Kafka consumer interceptor, and JUnit 5 lifecycle methods to ensure reliable and isolated testing of this behavior within the Kafka component integration suite.