Skip to main content

Tests

Introduction

This page describes tests using mavin, eclipse, docker or a virtual machine.

Configuration

The services.json file

The tests project's services.json file lists the containers/services (docker) required to run the tests.

Maven will launch the containers present in the file before launching tests and will stop them afterwards.

For example, for two docker images, one for the postgres database and one for elasticsearch, the file contains:

[{
"name":"bluemind/postgres-tests"
},{
"name":"bluemind/elasticsearch-tests"
}]

The net.bluemind.pool.dockerconfig fragment

This fragment is used to overload (replace) the BmConfIni.class.

If the fragment is active (not closed) and that the tests project contains a services.json file, the fragment will contact the docker instance to find the IP addresses of the containers that correspond to the images of the services.json file and will replace/overload the parameters provided by BmConfIni (the database host, for example).

When you run tests in Eclipse and you want to use the services provided by a BlueMind virtual machine (postgres, elasticsearch, etc.), you just need to close the fragment. The standard configuration files will then take over (/etc/bm/bm.ini, /etc/bm/mcast.id, etc.)

Maven configuration

The Maven tests projects configuration lists the plugins required to launch the tests:

<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
<showEclipseLog>true</showEclipseLog>
<useUIHarness>false</useUIHarness>
<useUIThread>false</useUIThread>
<product>org.eclipse.platform.ide</product>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<dependency-resolution>
<extraRequirements>
<requirement>
<type>eclipse-feature</type>
<id>net.bluemind.tests.feature</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
</plugin>

Playing tests from Docker

Install Docker (preferably use the packages you can download from docker.com rather than the packages that come with distributions).

Set Docker to listen on a socket, e.g. on Debian/Ubuntu:

  1. edit /etc/default/docker

  2. define the following variable: DOCKER_OPTS="-H tcp://<ip hote>:10000 -H [unix:///var/run/docker.sock](unix://forge.blue-mind.net/var/run/docker.sock)"

  3. restart the Docker service

On the development machine, the one with Eclipse and BlueMind sources, you must indicate what Docker service to use by creating the file ~/.docker.io.properties with the following content:

docker.io.url=http://<ip hote docker>:10000

Later on, the Docker containers will have to be accessible from Eclipse. You may have to add a route on the Eclipse machine to access the containers' network.

Other possible methods can be found in the docker-java Git.

Docker images

As things stand, you must install the images locally (on the Docker used for the tests). The images can be found in the project bm/bm-docker-devenv:

$ git clone https://forge.blue-mind.net/stash/scm/bm/bm-docker-devenv.git
$ ./build
caution

Remember to rebuild your images regularly so that you are using the most recent versions of BlueMind binaries.

Connecting local directories as Docker volumes

This is done through a "volumes" array.

E.g. to connect the local directory "/tmp/backups/bluemind" with the directory "/var/backups/bluemind" in the docker container, the following code will be used:

[{
"name":"bluemind/postgres-tests",
"volumes":[ { "localPath":"/tmp/backups/bluemind", "containerPath":"/var/backups/bluemind" } ]
}]

In the docker images DockerFile, add the VOLUME:

VOLUME ["/var/backups/bluemind"]

Playing tests from Eclipse

Build the BlueMind project for the first time:

$ cd <sourcesBM>/open
$ mvn -Dmaven.test.skip=true clean install

Start the required Docker containers:

$ cd <plugin test directory>
$ mvn pre-integration-test

Finally, launch the tests in Eclipse.

caution

Caution: For Windows and MacOS, you must add a route on the (Windows or MacOS) VM host in order to reach the Docker containers' network. You must also enable routing on the Docker VM:

$ sysctl -w net.ipv4.ip_forward=1
$ echo 'net.ipv4.ip_forward=1' > /etc/sysctl.conf

Running tests without an OSGI container (Junit)

Classes named *Test.java (not to be confused with *Test**s**.java) are executed without an OSGI container. 

This means launching tests in Eclipse using "Run as Junit Test" (instead of "Run as Junit Plugin Test") and resolves Classpath issues with proxy based mock frameworks, such as Mockito. The tests are also faster.