testcontainers / testcontainers/testcontainers-java

Some errors cause a NoClassDefFoundError and the real error is hidden

Abierto
#1,872 4 comentarios 11 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

resolution/acknowledged
Lenguaje dominante
Java
Estrellas
8.7k
Forks
1.9k
Merge medio
2 d 17 h
PR fusionados (30 d)
9

Descripción

In certain cases a test may fail with a NoClassDefFoundError, and it's a nightmare to find the real error.

For example:

static final PostgreSQLContainer = PostgreSQLContainer("postgresxxx:11.5") 
    .withDatabaseName("netonomy")
    .withUsername("postgres")
    .withPassword("password");

Then running gradle test results in:

com.example.SomeIntegrationTest > testPostgres() FAILED
    java.lang.NoClassDefFoundError: Could not initialize class com.example.SomeIntegrationTest

To find out the actual error, it was necessary to run Gradle with --info. I only used a bad image name here as an example to reproduce - the real error was "Docker environment should have more than 2GB free disk space", and it happened only on the CI build agent - so this was a real nightmare to diagnose!

What makes this even more difficult to pin down is the fact that even removing the @Testcontainers and @Container still results in the exact same behaviour!

The reason for all of this, is the fact that GenericContainer's constructor calls this.setDockerImageName() which in turn calls getDockerImageName() which actually attempts to get the image: https://github.com/testcontainers/testcontainers-java/blob/master/core/src/main/java/org/testcontainers/containers/GenericContainer.java#L1057

IMO this is an action that should not take place in a constructor - this should happen only later during start(). Either way there ought to be some better solution, because diagnosing errors this way is a nightmare.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en core/src/main/java/org/testcontainers/containers/GenericContainer.java, cerca de la llamada referenciada a getDockerImageName(), y sigue cómo la construcción activa la resolución de la imagen. Reproduce el ejemplo con gradle test y compara la salida predeterminada con --info. Se considera terminado cuando el error subyacente del contenedor o de Docker se puede diagnosticar sin quedar oculto tras NoClassDefFoundError.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
docker, java
Área
devops, testing
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.