KafkaConsumerAuthInvalidWithReconnectIT.java

Overview

`KafkaConsumerAuthInvalidWithReconnectIT.java` is an integration test class designed to validate the behavior of a Kafka consumer configured with SASL/JAAS authentication when encountering invalid authentication credentials and subsequently reconnecting with valid ones. It specifically tests a Kafka container supporting JAAS+SASL authentication and verifies that the consumer initially fails to connect due to invalid credentials but successfully reconnects after the Kafka service is restarted with valid credentials.

The class is part of the Apache Camel Kafka component integration tests. It leverages the Camel Kafka component, Kafka AdminClient API, and JUnit 5 with Awaitility for asynchronous assertions. The test ensures robustness of Kafka consumer error handling and reconnect logic when using SASL/PLAIN authentication protocol.


Detailed Explanation

Package and Imports


Class: KafkaConsumerAuthInvalidWithReconnectIT

Description

This class contains integration tests that:

Annotations


Fields and Constants

Name

Type

Description

`TOPIC`

`String`

Kafka topic used in tests (`test-auth-invalid-with-reconnect`).

`LOG`

`Logger`

Logger instance for debug and trace messages.

`service`

`ContainerLocalAuthKafkaService`

Local Kafka container service with JAAS SASL config (static instance).

`contextExtension`

`CamelContextExtension`

Camel context extension for route management.

`producer`

`KafkaProducer`

Kafka producer used to send test messages.


Static Initialization Block


Lifecycle Methods

beforeClass()

before()

after()


Route Configuration

Method: createRouteBuilder()

Method: createRouteBuilder(CamelContext context)


Tests

Test: testIsDisconnected() (Order 1)

Test: testReconnect() (Order 2)


Helper Method: assertIsConnected(AdminClient adminClient)


Important Implementation Details and Algorithms


Interaction with Other System Components


Usage Example

This test class is meant to be run as part of the integration test suite for Apache Camel Kafka component. Upon execution, it validates that a Kafka consumer:


Mermaid Class Diagram

classDiagram
    class KafkaConsumerAuthInvalidWithReconnectIT {
        <<test class>>
        +String TOPIC
        -Logger LOG
        -ContainerLocalAuthKafkaService service
        -CamelContextExtension contextExtension
        -KafkaProducer<String,String> producer
        +static void beforeClass()
        +void before()
        +void after()
        +void createRouteBuilder(CamelContext context)
        +RouteBuilder createRouteBuilder()
        +void testIsDisconnected()
        +void testReconnect()
        -void assertIsConnected(AdminClient adminClient)
    }

Summary

`KafkaConsumerAuthInvalidWithReconnectIT.java` is a focused integration test that ensures robust handling of Kafka consumer authentication failures and automatic reconnection in Apache Camel Kafka component when using SASL/JAAS authentication. It programmatically manipulates the Kafka service's authentication configuration to simulate connection failures and recoveries, verifying the consumer's resilience and error recovery mechanisms.