2

I'm using testcontainers (https://www.testcontainers.org) to perform integration tests. The test case requires an Oracle database and an Eclipse Microprofile compliant platform which, in my case, is Wildfly 20. I have the following docker-compose.yaml file:

version: '3.7'
...
services:
  oracle:
    image: oracleinanutshell/oracle-xe-11g:latest
    ....
    ports:
      - 49161:1521
      - 5500:5500
    environment:
      ...
    volumes:
      ...
  customers:
    image: customers:1.0-SNAPSHOT
    ...
    depends_on:
      - oracle
    ports:
      - 8080:8080
      - 9990:9990
    environment:
      ...

This docker-compose file is okay and works as expected when ran with the docker-compose command or with the docker-compose-maven-plugin.

In order to use the same docker-compose.yaml file for integration tests, I'm using the following code:

public class CustomersIT
{
  @ClassRule
  public static DockerComposeContainer composer = DockerCompose.newContainer()
    .withLogConsumer(DockerCompose.DATABASE, new Slf4jLogConsumer(log))
    .withLogConsumer(DockerCompose.SERVICE, new Slf4jLogConsumer(log));
  private static URI baseUri;
  private static URI finalUri;
  private static String id;
  private static Map<String, String> props = new HashMap<>();

  @BeforeAll
  public static void beforeAll()
  {
    baseUri = UriBuilder.fromPath("customers")
      .scheme("http")
      .host(composer.getServiceHost(DockerCompose.SERVICE, DockerCompose.SERVICE_PORT))
      .port(composer.getServicePort(DockerCompose.SERVICE, DockerCompose.SERVICE_PORT))
      .build();
    finalUri = UriBuilder.fromUri(baseUri).path("test").path("customers").build();
  }
....
}

The code above uses the class DockerCompose which is a wrapper around DockerComposeContainer, as shown below:

public class DockerCompose
{
  public static final String DATABASE = "oracle";
  public static final String SERVICE = "customers";
  public static final int DATABASE_PORT = 1521;
  public static final int SERVICE_PORT = 8080;
  private final DockerComposeContainer dcc =
    new DockerComposeContainer(new File("../platform/src/main/resources/docker-compose.yaml"))
    .withExposedService(DATABASE, DATABASE_PORT, Wait.forLogMessage(".*WFLYSRV0051.*", 1))
    .withExposedService(SERVICE, SERVICE_PORT);

  private DockerCompose()
  {
    super();
  }

  public static DockerComposeContainer newContainer()
  {
    return new DockerCompose().dcc;
  }
}

Trying to run the integration test raises the following exception:

[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running ...tests.CustomersIT
2021-02-16 19:16:06 DEBUG TestcontainersConfiguration:178 - Testcontainers configuration overrides will be loaded from file:/home/seymour/.testcontainers.properties
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.149 s <<< FAILURE!  - in ....tests.CustomersIT
[ERROR] ....tests.CustomersIT  Time elapsed: 0.148 s  <<< ERROR!
java.lang.ExceptionInInitializerError
        at ...tests.CustomersIT.<clinit>(CustomersIT.java:26)

No any additional information even in DEBUG mode.The line #26 referenced above is the following one:

  public static DockerComposeContainer composer = DockerCompose.newContainer()
    .withLogConsumer(DockerCompose.DATABASE, new Slf4jLogConsumer(log))
    .withLogConsumer(DockerCompose.SERVICE, new Slf4jLogConsumer(log));

so the exception is raised here:

  private final DockerComposeContainer dcc =
    new DockerComposeContainer(new File("../platform/src/main/resources/docker-compose.yaml"))
    .withExposedService(DATABASE, DATABASE_PORT, Wait.forLogMessage(".*WFLYSRV0051.*", 1))
    .withExposedService(SERVICE, SERVICE_PORT);

Could anyone please let me know what am I doing wrong here ?

Many thanks in advance.

Seymour

Seymour Glass
  • 81
  • 2
  • 15

1 Answers1

0

It appears that the docker-compose module in testcontainers doesn't support things like:

networks:
  of-network:
    ipv4_address: ...

or even:

container_name: ...

Removing these statements from the yaml file will solve the issue. But of course, if these statements are there, this is because they are required and removing them isn't probably an option.

So I will conclude by saying that, since the docker-compose module doesn't fully support the official syntax, it is not yet mature enough.

Seymour Glass
  • 81
  • 2
  • 15