Skip to content

[Bug]: Latest release does not include apache/kafka KafkaContainer despite docs referencing it #8576

@filpano

Description

@filpano

Module

Kafka

Testcontainers version

1.19.7

Using the latest Testcontainers version?

Yes

Host OS

Ubuntu 22.04.3 LTS

Host Arch

6.5.0-28-generic #29~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr 4 14:39:20 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Docker version

Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:07:41 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:07:41 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.24
  GitCommit:        61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
 runc:
  Version:          1.1.9
  GitCommit:        v1.1.9-0-gccaecfc
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

I wanted to use a KafkaContainer in an integration test which uses the official apache/kafka Image. However, I was unable to find an import of the following class:

https://github.com/testcontainers/testcontainers-java/blob/main/modules/kafka/src/main/java/org/testcontainers/kafka/KafkaContainer.java

In the docs, this is referenced as being one of the supported images for the Kafka Testcontainers (the other being the confluentinc/cp-kafka image).

However, this class is not included in the 1.19.7 release: https://github.com/testcontainers/testcontainers-java/tree/1.19.7/modules/kafka/src/main/java/org/testcontainers

Either this was mistakenly not included in the release or the docs were merged prematurely.

Additionally, it would be nice to have support for e.g. bitnami/kafka images as well, since the official apache/kafka images only seem to support Kafka >=3.7.0. For legacy applications still using Kafka 2.x, there is currently no recourse besides using a custom image or using asCompatibleSubstituteFor, which is error-prone.

Relevant log output

java.lang.ExceptionInInitializerError
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
	at java.base/java.util.Optional.orElseGet(Optional.java:364)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: java.lang.IllegalStateException: Failed to verify that image 'apache/kafka:2.8.0' is a compatible substitute for 'confluentinc/cp-kafka'. This generally means that you are trying to use an image that Testcontainers has not been designed to use. If this is deliberate, and if you are confident that the image is compatible, you should declare compatibility in code using the `asCompatibleSubstituteFor` method. For example:
   DockerImageName myImage = DockerImageName.parse("apache/kafka:...").asCompatibleSubstituteFor("confluentinc/cp-kafka");
and then use `myImage` instead.

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions