arquillian / arquillian-cube

Control (docker, kubernetes, openshift) containers in your tests with ease!
http://arquillian.org/arquillian-cube/
121 stars 98 forks source link

When using autoStartContainers with COMPOSE format exception is thrown #212

Closed kubamarchwicki closed 8 years ago

kubamarchwicki commented 8 years ago

An exception is thrown when containers are defined in docker-compose file and autoStartContainers is used. I'm working with the latest SNAPSHOT (but with previous releases problem was the same)

I'm getting nasty exception

com.example.TranslationTest: java.util.HashSet cannot be cast to java.util.List
    at org.arquillian.cube.docker.impl.util.AutoStartOrderUtil.addAll(AutoStartOrderUtil.java:103)
    at org.arquillian.cube.docker.impl.util.AutoStartOrderUtil.from(AutoStartOrderUtil.java:70)

with a following config

    <extension qualifier="docker">
        <property name="autoStartContainers">app, mysql</property>
        <property name="serverVersion">1.12</property>
        <property name="serverUri">http://localhost:2375</property>
        <property name="definitionFormat">COMPOSE</property>
        <property name="dockerContainersFile">src/test/resources/docker-compose.yml</property>
     </extension>

The compose is dead simple (and works with the docker-compose)

app:
  image: kubamarchwicki/spring-boot-example
  ports:
    - "18080:8080"
  links:
    - mysql
mysql:
  image: tutum/mysql
  ports:  
    - "13306:3306"
  environment:
    - MYSQL_USER=admin
    - MYSQL_PASS=admin
    - ON_CREATE_DB=test

Switching to the CUBE format solves the problem

    <extension qualifier="docker">
        <property name="autoStartContainers">app, mysql</property>
        <property name="serverVersion">1.12</property>
        <property name="serverUri">http://localhost:2375</property>
        <property name="dockerContainers">
            app:
                image: kubamarchwicki/spring-boot-example
                portBindings: [18080->8080/tcp]
                await:
                    strategy: sleeping
                    sleepTime: 20s
                links:
                    - mysql:mysql
            mysql:
                image: tutum/mysql
                portBindings: [13306->3306/tcp]
                await:
                    strategy: polling
                    sleepPollingTime: 2s
                env: [MYSQL_USER=admin, MYSQL_PASS=admin, ON_CREATE_DB=test]
        </property>
    </extension>

I my (inexperienced) view the problem is within this line https://github.com/arquillian/arquillian-cube/blob/master/docker/docker/src/main/java/org/arquillian/cube/docker/impl/docker/compose/ContainerBuilder.java#L294 which returns HashSet while everything else expects a List

This fixes (worksaround?) the issue:

-            configuration.put(DockerClientExecutor.LINKS, new HashSet<>(listOfLinks));
+            configuration.put(DockerClientExecutor.LINKS, listOfLinks);

I'm happy to do a proper pull request, but I need some support and guidance. Still can't get my head around the code base.

lordofthejars commented 8 years ago

Hi @kubamarchwicki thanks for your feedback, in fact I was aware of this problem, I am going to push the code today, since I have the fix implemented locally.