Testing HTTP/2 communication requires a server and client communicating over TCP connections.

While looking for a way to implement automated tests for the HTTP/2 client h2c, I came across Arquillian Cube, which is an Arquillian extension that can be used to manage Docker containers from Arquillian.

I created some initial tests in the arquillian-tests folder in the h2c GitHub repository. The test can be run with maven:

mvn clean package

TL;DR

This blog shows how to implement automated tests of HTTP/2 communication with Arquillian Cube.

Running the tests in the arquillian-tests directory will:

Arquillian Cube provides a convenient way to test HTTP/2 services through real TCP connections without using mocks.

How to Use Docker with Arquillian

First of all, the arquillian-cube-docker dependency need to be added to pom.xml (in addition to the usual arquillian dependencies):

<dependency>
    <groupId>org.arquillian.cube</groupId>
    <artifactId>arquillian-cube-docker</artifactId>
    <version>1.0.0.Alpha7</version>
    <scope>test</scope>
</dependency>

Secondly, the maven-surefire-plugin must be configured to launch the wildfly-docker container:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.17</version>
    <configuration>
        <systemPropertyVariables>
            <!-- The wildfly-docker container is defined in src/test/resources/arquillian.xml -->
            <arquillian.launch>wildfly-docker</arquillian.launch>
        </systemPropertyVariables>
    </configuration>
</plugin>

The container itself is configured in arquillian.xml in src/test/resources:

<?xml version="1.0"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://jboss.org/schema/arquillian"
            xsi:schemaLocation="http://jboss.org/schema/arquillian
  http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

    <extension qualifier="docker">

        <!-- REMOVE THE serverUri IF RUNNING ON LINUX -->
        <property name="serverUri">https://dockerHost:2376</property>

        <property name="dockerContainers">
            wildfly-docker:
                image: fstab/wildfly-http2:9.0.1.Final
                await:
                    strategy: polling
                    sleepPollingTime: 1000
                    iterations: 120
                portBindings: ["8443", "9990"]
        </property>
    </extension>

    <!-- The container configuration uses the magic string dockerServerIp -->
    <!-- to point to the boot2docker ip (Windows, OS X) or to localhost (Linux). -->
    <container qualifier="wildfly-docker" default="true">
        <configuration>
            <property name="managementAddress">dockerServerIp</property>
            <property name="managementPort">9990</property>
            <property name="username">admin</property>
            <property name="password">admin</property>
        </configuration>
    </container>
</arquillian>
Update: The arquillian.xml in the original post contained a static wait strategy with a statically configured boot2docker host. I simplified this after Alex Soto's comment. Thanks Alex.


The configuration above assumes boot2docker listening on port 2376. In order to run it on native Linux, remove the property serverUri in arquillian.xml.