Tests
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
Configuring Docker
Install Docker (preferably use the packages you can download from docker.com rather than the packages that come with distributions).
For Ubuntu, prefer installation via the repository
Set Docker to listen on a socket, e.g. on Debian/Ubuntu:
- Edit the docker.service by running
systemctl edit docker.service
- Define the following variable:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://127.0.0.1:10000 -H unix:///var/run/docker.sock --insecure-registry=repository.blue-mind.loc:5001
- 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://127.0.0.1:10000
remote=repository.blue-mind.loc:5001
- Edit (or create if it does not exist) the
/etc/docker/daemon.json
as defined below:
{
"insecure-registries" : [ "repository.blue-mind.loc:5001" ]
}
- Restart the daemon and the Docker service with
systemctl daemon-reload
, thensystemctl restart docker
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.
Connecting local directories as Docker volumes
This is done through a "volumes" array.
For example, 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 <repertoire plugin test>
$ mvn -D tycho.mode=maven net.bluemind:bm-docker-maven-plugin:start
Finally, launch the tests in Eclipse.
For Windows and macOS, you need to add a route on the VM host (windows or macOS) to reach the Docker container 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.