当 运行 测试反对 Arquillian 自由管理时,OpenLiberty 启动冻结

OpenLiberty startup frozen when ran tests agaist Arquillian liberty-managed

示例项目是here

Openliberty 20.0.0.1 AdaptOpenJDK 8

arquillian liberty 管理配置文件的配置。

 <profile>
            <!-- Run with: mvn clean test -Parq-liberty-managed -->
            <id>arq-liberty-managed</id>
            <properties>
                <skipTests>false</skipTests>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>io.openliberty.arquillian</groupId>
                    <artifactId>arquillian-liberty-managed</artifactId>
                    <version>${arquillian-liberty.version}</version>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>${maven-dependency-plugin.version}</version>
                        <executions>
                            <execution>
                                <id>unpack</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>io.openliberty</groupId>
                                            <artifactId>openliberty-runtime</artifactId>
                                            <version>${liberty.runtime.version}</version>
                                            <type>zip</type>
                                            <overWrite>false</overWrite>
                                            <outputDirectory>${project.build.directory}</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${maven-failsafe-plugin.version}</version>
                        <configuration>
                            <!--<environmentVariables>
                                <WLP_HOME>${project.build.directory}/wlp</WLP_HOME>
                            </environmentVariables>-->
                            <systemProperties>
                                <arquillian.launch>liberty-managed</arquillian.launch>
                            </systemProperties>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

arquillian.xml文件内容:

    <container qualifier="liberty-managed">
        <configuration>
            <property name="wlpHome">target/wlp/</property>
            <property name="serverName">defaultServer</property>
            <property name="httpPort">9080</property>
            <property name="serverStartTimeout">300</property>
        </configuration>
    </container>

当运行通过以下命令进行测试:

mvn clean verify -Parq-liberty-managed

并从控制台获取信息。 Github 操作构建日志可以在 here.

中找到
087 seconds.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 311.064 s <<< FAILURE! - in com.example.it.GreetingResourceTest
[ERROR] com.example.it.GreetingResourceTest  Time elapsed: 311.05 s  <<< ERROR!
org.jboss.arquillian.container.spi.client.container.LifecycleException: Could not start container
Caused by: org.jboss.arquillian.container.spi.client.container.LifecycleException: Unable to retrieve connector address for localConnector of started VM

[INFO] Running com.example.it.GreetingServiceTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.03 s <<< FAILURE! - in com.example.it.GreetingServiceTest
[ERROR] com.example.it.GreetingServiceTest  Time elapsed: 0.018 s  <<< ERROR!
java.lang.RuntimeException: Arquillian initialization has already been attempted, but failed. See previous exceptions for cause
Caused by: org.jboss.arquillian.container.spi.client.container.LifecycleException: Could not start container
Caused by: org.jboss.arquillian.container.spi.client.container.LifecycleException: Unable to retrieve connector address for localConnector of started VM

[AUDIT   ] CWWKE0055I: Server shutdown requested on Friday, February 7, 2020 at 4:44 PM. The server defaultServer is shutting down.
[AUDIT   ] CWWKE1100I: Waiting for up to 30 seconds for the server to quiesce.
[INFO    ] CWWKE1101I: Server quiesce complete.
[AUDIT   ] CWWKE0036I: The server defaultServer stopped after 5 minutes, 12.017 seconds.
Picked up JAVA_TOOL_OPTIONS: -Dcom.ibm.ws.logging.console.log.level=INFO
OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0

看了liberty-managed的代码,找到了原因。 liberty-managed 不会从 src/main/liberty/config(就像 liberty maven 插件所做的那样)或测试中读取 server.xml类路径。它只从服务器配置文件夹又名 /usr/servers/ 读取 server.xml 文件。

但是在 liberty arquillian 项目中没有文档和示例来解释这个

/src/test/下创建一个自由管理的特定文件夹,命名为arq-liberty-managed,移动server.xml,arquillian.xml(复制一份)进去.

在我的 arq-liberty-managed 配置文件中,添加测试资源配置。

<build>
    <testResources>
        <testResource>
            <directory>src/test/arq-liberty-managed</directory>
            <includes>
                <include>*</include>
            </includes>
            <excludes>
                <exclude>server.xml</exclude>
            </excludes>
        </testResource>
        <testResource>
            <directory>src/test/arq-liberty-managed</directory>
            <includes>
                <include>server.xml</include>
            </includes>
            <targetPath>
                ${project.build.directory}/wlp/usr/servers/defaultServer
            </targetPath>
        </testResource>
    </testResources>
...