testcontainers / testcontainers/testcontainers-java
Some errors cause a NoClassDefFoundError and the real error is hidden
Nadie ha tomado este issue todavía.
- 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
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- 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