KafkaConsumerBadPortSupervisingHealthCheckIT.java


Overview

`KafkaConsumerBadPortSupervisingHealthCheckIT.java` is an integration test class designed to validate the health check mechanisms of a Kafka consumer within the Apache Camel framework when configured with an incorrect Kafka broker port. The test ensures that Apache Camel's Supervising Route Controller can detect and manage route failures caused by bad broker configurations, and that Camel's health check system correctly reports the liveness and readiness of the Kafka consumer routes.

The test class specifically:

This test is part of the Kafka component integration tests under the health check suite.


Class and Method Details

Class: KafkaConsumerBadPortSupervisingHealthCheckIT

Extends: `KafkaHealthCheckTestSupport` (not shown here but assumed to provide Kafka test infrastructure and Camel context support)

This class contains several JUnit 5 tests that verify the health check behavior of a Kafka consumer route managed by the Supervising Route Controller when configured with a non-existent Kafka broker port.


Fields

Name

Type

Description

`TOPIC`

`String`

Kafka topic used for testing (`"test-health"`).

`LOG`

`Logger`

SLF4J Logger for logging trace messages.


Methods

void configureContext(CamelContext context)


RouteBuilder createRouteBuilder()


void testReportUpWhenIsUp()


void testReportCorrectlyWhenDown()


static void readinessCheck(CamelContext context)


void kafkaConsumerHealthCheck()


Important Implementation Details


Interactions with Other System Parts


Usage Example (Test Execution Flow)

  1. Setup:
    Configure Camel context with the Kafka component set to an invalid broker port and supervising route controller.

  2. Route Creation:
    A Kafka consumer route is created consuming from test-health topic.

  3. Health Check - Liveness:
    Verify that the route is considered alive (liveness UP), even if Kafka broker is unreachable.

  4. Health Check - Readiness:
    Verify that the route readiness correctly reports DOWN due to connection failure.

  5. Message Consumption:
    Send messages to Kafka and assert no messages are consumed or processed.


Mermaid Class Diagram

classDiagram
    class KafkaConsumerBadPortSupervisingHealthCheckIT {
        +static final String TOPIC
        +static final Logger LOG
        +void configureContext(CamelContext context)
        +RouteBuilder createRouteBuilder()
        +void testReportUpWhenIsUp()
        +void testReportCorrectlyWhenDown()
        +static void readinessCheck(CamelContext context)
        +void kafkaConsumerHealthCheck() throws InterruptedException
    }
    KafkaConsumerBadPortSupervisingHealthCheckIT --|> KafkaHealthCheckTestSupport

Summary

`KafkaConsumerBadPortSupervisingHealthCheckIT` is a critical integration test ensuring robust health monitoring and automatic failure recovery of Kafka consumer routes within Apache Camel. By simulating broker connectivity failure through an invalid port, it validates the Supervising Route Controller's ability to manage route restarts and demonstrates how Camel's health checks accurately reflect route states under failure conditions. This test reinforces system resilience and observability in production environments where Kafka brokers may be intermittently unavailable.