BaseManualCommitTestSupport.java


Overview

`BaseManualCommitTestSupport.java` is an **abstract base test class** designed for integration testing of Apache Camel Kafka components focusing on **manual offset commit behavior**. It extends `BaseKafkaTestSupport` and provides reusable utility methods and test logic to verify correct manual commit functionality when consuming Kafka messages in a Camel route.

This class facilitates testing scenarios such as:

It is primarily used as a superclass for concrete test classes targeting manual commit behaviors in Kafka consumer routes within the Apache Camel Kafka component integration tests.


Detailed Class Explanation

BaseManualCommitTestSupport

An abstract test support class for Kafka manual commit integration tests in Apache Camel.

Fields

Field Name

Type

Description

`to`

`MockEndpoint`

Mock endpoint for verifying messages consumed from Kafka topic "foo". Injected via Camel's `@EndpointInject`.

`toBar`

`MockEndpoint`

Mock endpoint for verifying messages consumed from Kafka topic "bar". Injected via Camel's `@EndpointInject`. *(Not used in provided code but available for extension)*

`producer`

KafkaProducer

Kafka producer client used to send test messages to Kafka topics. Initialized before each test.

Methods


void createClient()


void cleanupKafka(String topic)


void kafkaManualCommitTest(String topic) throws Exception


void kafkaManualCommitTestWithStateRepository(String topic, StateRepository<String, String> stateRepository) throws Exception


void setupPostExecutionExpectations()


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


void setupPreExecutionExpectations()


Important Implementation Details


Interaction with Other Components


Usage Example (Pseudo)

public class ManualCommitTest extends BaseManualCommitTestSupport {

    @Test
    public void testManualCommitScenario() throws Exception {
        String topic = "foo";
        kafkaManualCommitTest(topic);
    }

    @Test
    public void testManualCommitWithStateRepo() throws Exception {
        String topic = "foo";
        StateRepository<String, String> stateRepo = new InMemoryStateRepository<>();
        kafkaManualCommitTestWithStateRepository(topic, stateRepo);
    }
}

Mermaid Class Diagram

classDiagram
    class BaseManualCommitTestSupport {
        <<abstract>>
        -MockEndpoint to
        -MockEndpoint toBar
        -KafkaProducer<String,String> producer
        +void createClient()
        +void cleanupKafka(String topic)
        +void kafkaManualCommitTest(String topic)
        +void kafkaManualCommitTestWithStateRepository(String topic, StateRepository<String,String> stateRepository)
        +void setupPostExecutionExpectations()
        +void sendRecords(int startIndex, int lastIndex, String topic)
        +void setupPreExecutionExpectations()
    }
    BaseManualCommitTestSupport --|> BaseKafkaTestSupport

Summary

`BaseManualCommitTestSupport.java` serves as a foundational test class that simplifies and standardizes manual offset commit testing for Kafka consumers in Apache Camel. It encapsulates essential test workflows — sending messages, asserting consumption, stopping/starting routes, and verifying offsets with or without external state repositories — enabling robust validation of Kafka manual commit functionality across multiple test scenarios.