Skip to content

Build and test

Kevin Phipps edited this page May 20, 2022 · 4 revisions

Purpose

This page is aimed at developers. It does not tell you how to install or use ids.r2dfoo but how to test any modifications you may make. The build and test relies upon maven - so there is a pom.xml in the top directory. You may choose to develop with an IDE; both Eclipse and NetBeans work with maven however no artifacts from these IDEs are stored in GitHub.

WARNING

The IDS Integration tests create and delete a Facility in the ICAT called "Integration_Test_Facility" so this is fairly safe given that you are unlikely to have a real ICAT containing a facility with this name. However, it is strongly recommended that you set up a new ICAT specifically for the IDS testing and do not re-use one containing any data that you wouldn't want to lose.

The unit and integration tests also clear out the contents of a number of directories that are used by the IDS. These directories are specified in the various run.properties files in the src/test/resources directory. Before running the tests you should check that the directories specified in these files exist and do not contain anything which you wouldn't want to lose. If the specified directories do not exist then the IDS tests will normally fail with an error message notifying you about this.

What to do

Install an icat.server configured as described at https://github.com/icatproject/icat.server/wiki

Following the ICAT Server tutorial, you will need to complete the steps up to and including installing the ICAT server component. You will need a Linux machine (possibly Vagrant as in the tutorial), a JDK, MariaDB and Payara installed, the authn.db authenticator, the icat.lucene and icat.server components. If you are using authn.simple as per the ICAT tutorial then you will need to modify the login details in the properties files in src/test/resources. The tests need some user accounts to be setup in the authenticator. For your convenience, a SQL script creating the required entries in the authn.db database is provided in the file src/test/resources/add-test-accounts.sql.

When you run maven it will attempt to deploy to Payara. For this to work you must have asadmin in your path and have one domain configured to run on port 4848. It is deployed with --force=true so that it should overwrite anything currently deployed.

Rather than running mvn install you may prefer to run mvn install -DskipTests and then run the tests from your IDE in which case you should ensure that serverUrl, javax.net.ssl.trustStore, luceneUrl and containerHome are set as system properties. When running from maven, the properties are taken from the ~/.m2/settings.xml as environment variables and passed into the tests as system properties.

Vagrant build and test instructions

These instructions follow on from the Vagrant installation tutorial and from the ICAT server build and test instructions

Overview

Assuming ICAT server and authenticator are installed as per the instructions above, it is now possible to do a mvn install on the ids.r2dfoo code to compile, deploy and test it.

Note that there are two ICAT user accounts required for the IDS server tests to run. These are configured in the src/test/resources/test.properties file (of the IDS server component) and by default have the username/passwords root/password and guest/guess. So if you haven't already set up any users in authenicator that you installed, you need to do that now.

Also, before going any further, ensure that any previous versions of ids.r2dfoo (or ids.server) are not deployed by using the undeploy command e.g.

asadmin undeploy ids.server-1.9.0

Maven settings

If you followed the ICAT server compilation instructions, then your Maven settings will already have most of the configuration needed, except for the new <testHome> property which specifies where the tests will expect the data they use during testing to be stored.

If you didn't follow the ICAT server instructions, create ~/.m2/settings.xml and put following in it, making sure that the urls are correct and that the paths are mapped correctly for your install. The example below should work if you have followed the tutorial instructions.

<settings>
   <profiles>
      <profile>
         <activation>
             <activeByDefault>true</activeByDefault>
         </activation>
         <properties>
             <serverUrl>https://localhost.localdomain:8181</serverUrl>
             <luceneUrl>https://localhost.localdomain:8181</luceneUrl>
             <javax.net.ssl.trustStore>/home/glassfish/payara5/glassfish/domains/domain1/config/cacerts.jks</javax.net.ssl.trustStore>
             <containerHome>/home/glassfish/payara5</containerHome>
             <testHome>/home/glassfish/test</testHome>
         </properties>
      </profile>
   </profiles>
</settings>

Setting up the test folder structure

The integration tests need a few folders to exist in the testHome directory for the tests to run correctly, the rest of the files and folders will be generated by the tests themselves.

mkdir -p /home/glassfish/test/data/ids/main
mkdir -p /home/glassfish/test/data/ids/cache

Build and run the tests

Everything should now be set up to be able to build ids.r2dfoo and run the associated tests.

If you don't already have a copy of the ids.r2dfoo code that you are ready to build and test then the following commands will get the latest copy:

cd ~/code
git clone https://github.com/ral-facilities/ids.r2dfoo.git
cd ids.r2dfoo

Using the command below will build, deploy and test the source code.

mvn install

As well as the unit tests, the component has a set of integration tests which are run twice. The integration tests are called IntegrationTest and ParallelRestoresIntegrationTest where the only difference is that ParallelRestoresIntegrationTest specifies a low value for the maxRestoresPerThread property in integration.parallel.run.properties. This causes multiple restore threads to be created for each restore request that run in parallel and restore the data quicker.

You may want to just deploy IDS server and not want to run the tests every time, this can be done by supplying the -DskipTests flag when running mvn install.

mvn install -DskipTests