BatchingProcessingITSupport.java

Overview

`BatchingProcessingITSupport.java` is an **abstract integration test support class** designed for testing Kafka message batching and manual offset commit scenarios within the Apache Camel Kafka component. It extends `BaseKafkaTestSupport` and provides reusable setup, utility methods, and validation logic for derived classes that implement specific integration tests involving Kafka message consumption in batch mode.

The class focuses on verifying:

This file plays a key role in ensuring that Kafka batch processing features work as expected in the Camel Kafka connector integration suite.


Classes and Methods

abstract class BatchingProcessingITSupport extends BaseKafkaTestSupport

This abstract class serves as the base for Kafka batch processing integration tests. It encapsulates Kafka producer setup, test lifecycle hooks, and common validation utilities.

Fields

Field

Type

Description

protected MockEndpoint to

org.apache.camel.component.mock.MockEndpoint

Mock endpoint "mock:result" to capture test messages.

protected MockEndpoint toBar

org.apache.camel.component.mock.MockEndpoint

Mock endpoint "mock:resultBar" (may be used by subclasses).

protected KafkaProducer producer

org.apache.kafka.clients.producer.KafkaProducer

Kafka producer used to send test messages to Kafka topics.

Methods


@BeforeEach public void createClient()

public void cleanupKafka(String topic)

public void kafkaManualCommitTest(String topic) throws Exception

private static void validateReceivedExchanges(int expectedCount, List<Exchange> exchanges)

protected void setupPostExecutionExpectations()

protected void sendRecords(int startIndex, int lastIndex, String topic)

protected void setupPreExecutionExpectations()

Important Implementation Details and Algorithms


Interaction with Other Components


Visual Diagram

classDiagram
    class BatchingProcessingITSupport {
        -Logger LOG
        -MockEndpoint to
        -MockEndpoint toBar
        -KafkaProducer<String,String> producer
        +void createClient()
        +void cleanupKafka(String topic)
        +void kafkaManualCommitTest(String topic)
        -static void validateReceivedExchanges(int expectedCount, List<Exchange> exchanges)
        +void setupPostExecutionExpectations()
        +void sendRecords(int startIndex, int lastIndex, String topic)
        +void setupPreExecutionExpectations()
    }

    BatchingProcessingITSupport --|> BaseKafkaTestSupport

Usage Example in a Concrete Test Class

public class MyBatchingIT extends BatchingProcessingITSupport {

    @Test
    public void testKafkaBatchManualCommit() throws Exception {
        String topic = "test-topic";

        // Clean topic before test
        cleanupKafka(topic);

        // Execute manual commit test scenario
        kafkaManualCommitTest(topic);
    }

    @Override
    protected void setupPreExecutionExpectations() {
        to.expectedMessageCount(1);
    }

    @Override
    protected void setupPostExecutionExpectations() {
        to.expectedMessageCount(1);
    }
}

This documentation provides a complete understanding of the `BatchingProcessingITSupport.java` file, its role in Kafka batch processing integration testing within Apache Camel, and guidelines for extending and utilizing it in test suites.