Skip to content

Conversation

@janeklb
Copy link

@janeklb janeklb commented Jun 22, 2025

Motivation

The official ClickHouse java client (https://github.com/ClickHouse/clickhouse-java) offers both JDBC and HTTP interfaces; however, testcontainers-java only offers an option for JDBC clients.

Modifications

  • Add ClickHouseHttpContainer
  • Add ClickHouseHttpContainerTest

Generated by Claude Code based on the following prompt (typo and all!):

Please add an http-based container for ClickHouse. It should live alongside the existing jdbc-based ClickHouse conatiner; however, it should follow the same kind of patterns that other http-based containers apply.

Click to see Claude Code's generated work summary

Summary

I have successfully implemented an HTTP-based ClickHouse container for Testcontainers alongside the existing JDBC-based container. Here's what was created:

Files Created:

  1. ClickHouseHttpContainer.java - The main HTTP-based container class that:
    • Extends GenericContainer instead of JdbcDatabaseContainer
    • Provides HTTP-specific methods like getHttpUrl(), getHttpHostAddress(), etc.
    • Uses the same Docker image and wait strategy as the JDBC version
    • Supports custom credentials and database configuration
    • Exposes both HTTP (8123) and Native (9000) ports for flexibility
  2. ClickHouseHttpContainerTest.java - Comprehensive test suite that includes:
    • Basic HTTP query execution
    • Custom credentials testing
    • URL method validation
    • Table creation and data insertion
    • Health check verification
    • Support for multiple ClickHouse versions

Key Features:

  • HTTP API Access: Provides direct access to ClickHouse's HTTP interface for REST API calls
  • Consistent Interface: Follows the same patterns as other HTTP-based containers in the codebase
  • Full Compatibility: Uses the same Docker images and configuration as the JDBC version
  • Comprehensive Testing: All 6 test scenarios pass, covering various use cases
  • Proper Error Handling: Includes authentication and error response handling
  • Documentation: Well-documented with Javadoc comments

Integration:

The HTTP-based container lives in the same package (org.testcontainers.clickhouse) as the existing JDBC container, allowing users to choose the appropriate approach for their use
case:

  • JDBC Container - For traditional database connections with SQL drivers
  • HTTP Container - For REST API access and direct HTTP query execution

Both containers can coexist and complement each other, providing flexibility for different testing scenarios and development patterns.

@janeklb janeklb requested a review from a team June 22, 2025 22:17
@eddumelendez
Copy link
Member

Thanks for your contribution, @janeklb. IMO, #10526 covers this need already by having the JDBC driver as a runtime dependency.

Please, next time consider discussing your idea before raising a PR.

@janeklb janeklb deleted the jlb/ClickHouseHttpContainer branch August 11, 2025 17:56
@janeklb
Copy link
Author

janeklb commented Aug 11, 2025

Thanks @eddumelendez! Will do so next time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants