OpenLiberty / liberty-arquillian

Arquillian Liberty Managed and Remote containers
Apache License 2.0
11 stars 29 forks source link

It should be possible to specify WLP_USER_DIR as property or environment variable #28

Closed cbue closed 6 years ago

cbue commented 6 years ago
Issue Overview

For our Java EE application tests, we would like to have the untouched WLP / OpenLiberty distribution centrally located (e.g. in USER_HOME directory) and WLP_USER_DIR within build system's working directory ("target/" for Maven or "build/" for Gradle).

This way we can avoid to download and copy the distribution again and again for each test.

WLP allows to set the WLP_USER_DIR environment variable to decouple the installation (WLP_HOME_DIR) from the user directory.

Since this commit, WLP_USER_DIR as process environment variable is no longer evaluated to determine user directory. I am not sure if this was intended but at least the comments are not consistent:

WLP_USER_DIR can be specified only as a process environment variable or ${wlp.install.dir}/etc/server.env file

WLP_USER_DIR can be specified only in the ${wlp.install.dir}/etc/server.env file

if (!key.equals(WLP_USER_DIR)) { // WLP_USER_DIR can be specified only as a process environment variable
// or ${wlp.install.dir}/etc/server.env file
try {
fisServerEnv = new FileInputStream(new File(getServerEnvFilename()));
....
} catch (...)
}
}
// Liberty system wide not used for things that would collide across >1 server like LOG_DIR
if (value == null && !key.equals(LOG_DIR)) {
try {
fisSystemServerEnv = new FileInputStream(new File(getSystemServerEnvFilename()));
...
} catch (...
}
// Process environment variables
if (value == null && !key.equals(WLP_USER_DIR)) { // WLP_USER_DIR can be specified only in the
// ${wlp.install.dir}/etc/server.env file
value = getEnv(key);
}
}

From my point of view, there should be a way to externally specify WLP_USER_DIR. We cannot set it in ${wlp.install.dir}/etc/server.env, since the value could change for each test setup.

Simplest approach would be to remove the condition !key.equals(WLP_USER_DIR) from the last if-clause that prevents the process environment variable to be evaluated.

Expected Behaviour

WLP_USER_DIR is customizable via test process environment variable

Current Behaviour

WLP_USER_DIR is expected to be WLP_HOME_DIR/usr if not specified in the installation's server.env file.

Steps To Reproduce
  1. Set test process environment variable WLP_HOME_DIR to the WLP user directory to be used (that contains a created server (e.g. named testing))
  2. Arquillian test will fail since server.xml is accessed at WLP_HOME_DIR:
org.jboss.arquillian.container.spi.client.container.LifecycleException: Could not start container
...
Caused by: org.jboss.arquillian.container.spi.client.container.DeploymentException: Exception while reading server.xml file.
    at io.openliberty.arquillian.managed.WLPManagedContainer.readServerXML(WLPManagedContainer.java:789)
    at io.openliberty.arquillian.managed.WLPManagedContainer.start(WLPManagedContainer.java:192)
    ... 100 more
Caused by: java.io.FileNotFoundException: /home/test-user/.liberty/libertyDist/wlp-javaee7-18.0.0.2/usr/servers/testing/server.xml (No such file or directory)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at io.openliberty.arquillian.managed.WLPManagedContainer.readServerXML(WLPManagedContainer.java:786)
    ... 101 more
Additional Information

I will prepare a pull request for that change. Could you please review my PR and check if it would be possible to merge?

Thank you very much! Christian

cbue commented 6 years ago

Has been fixed with pull request #29 .