Thorntail не запускается для интеграционного тестирования, но у меня есть тот же pom.xml рабочего проекта - PullRequest
0 голосов
/ 21 мая 2019

Весь этот день я пытался решить загадочную проблему с ошибкой:

[ERROR] Tests run: 3, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 9.783 s <<< FAILURE! - in api.rest.AdRestServiceTest
[ERROR] testGet  Time elapsed: 4.351 s  <<< ERROR!
java.net.ConnectException: Connection refused: connect
        at api.rest.AdRestServiceTest.testGet(AdRestServiceTest.java:32)

[ERROR] testCount  Time elapsed: 2.013 s  <<< ERROR!
java.net.ConnectException: Connection refused: connect
        at api.rest.AdRestServiceTest.testCount(AdRestServiceTest.java:27)

[ERROR] testGetAll  Time elapsed: 2.022 s  <<< ERROR!
java.net.ConnectException: Connection refused: connect
        at api.rest.AdRestServiceTest.testGetAll(AdRestServiceTest.java:21)

Я могу успешно запустить рабочий проект (https://github.com/hostettler/microservices/tree/integration_tests) с mvn clean install.

У меня есть несколько хороших Thorntail is ready для рабочего примера.

2019-05-21 16:29:26,235 INFO  [org.wildfly.swarm] (main) THORN99999: Thorntail is Ready
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.2:prepare-agent (integration-tests-preaparation) @ counterparty-service ---
[INFO] argLineForIntegration set to -javaagent:C:\\Users\\Admin\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.2\\org.jacoco.agent-0.8.2-runtime.jar=destfile=C:\\Users\\Admin\\Desktop\\ProjetINFO\\microservices\\counterparty-service\\target\\jacoco-it.exec
[INFO]
[INFO] --- maven-failsafe-plugin:2.22.1:integration-test (default) @ counterparty-service ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running api.CounterpartyRestServiceIT
2019-05-21 16:29:34,220 INFO  [stdout] (default task-1) Hibernate: ...

Я только что скопировал эти pom.xml (pom родительского и pom-сервиса контрагента), но он все равно не работает ..

Вот родительский pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ch.unige</groupId>
    <artifactId>PInfo2</artifactId>
    <version>0.2.0-SNAPSHOT</version>
    <name>Parent Pom of the PInfo2</name>

    <packaging>pom</packaging>

    <!--<scm>
        <url>https://github.com/hostettler/microservices</url>
        <connection>scm:git:git@github.com/hostettler/microservices.git</connection>
        <developerConnection>scm:git:git@github.com/hostettler/microservices</developerConnection>
    </scm> -->

    <properties>
        <version.thorntail>2.3.0.Final</version.thorntail>
        <version.h2>1.4.197</version.h2>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <skip-docker-build>true</skip-docker-build>
        <skip-docker-compose>false</skip-docker-compose>
        <dockerHost>tcp://localhost:2375</dockerHost>
    </properties>


    <modules>
        <module>image-service</module>
        <module>stats-service</module>
        <module>chat-service</module>
        <module>ad-service</module>
        <module>category-service</module>
        <module>user-service</module>
        <module>search-service</module>
        <module>api-gateway</module>
    </modules>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.thorntail</groupId>
                <artifactId>bom</artifactId>
                <version>${version.thorntail}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <!--<dependency>
                <groupId>org.aerogear.kafka</groupId>
                <artifactId>kafka-cdi-extension</artifactId>
                <version>0.1.0</version>
            </dependency> -->
            <dependency>
                <groupId>com.github.dadrus.jpa-unit</groupId>
                <artifactId>jpa-unit-bom</artifactId>
                <version>0.5.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.4</version>
            </dependency>
            <dependency>
                <groupId>javax.enterprise</groupId>
                <artifactId>cdi-api</artifactId>
                <version>1.2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.spec.javax.ws.rs</groupId>
                <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
                <version>1.0.0.Final</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <version>${version.h2}</version>
            </dependency>
            <dependency>
                <groupId>org.aerogear.kafka</groupId>
                <artifactId>kafka-cdi-extension</artifactId>
                <version>0.1.0</version>
            </dependency>
            <dependency>
                <groupId>io.thorntail</groupId>
                <artifactId>swagger</artifactId>
                <version>2.2.1.Final</version>
            </dependency>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.3.2</version>
                <scope>test</scope>
                <type>pom</type>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>5.3.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>5.3.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-launcher</artifactId>
                <version>1.3.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>2.23.4</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-junit-jupiter</artifactId>
                <version>2.23.4</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>2.3.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.3</version>
                    <configuration>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                        <tagNameFormat>@{project.version}</tagNameFormat>
                        <releaseProfiles>release</releaseProfiles>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <configuration>
                            <source>${maven.compiler.source}</source>
                            <target>${maven.compiler.target}</target>
                        </configuration>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M3</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>3.0.0-M6</version>
                </plugin>

                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.2</version>
                </plugin>
                <plugin>
                    <groupId>io.thorntail</groupId>
                    <artifactId>thorntail-maven-plugin</artifactId>
                    <version>${version.thorntail}</version>
                </plugin>
                <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>fabric8-maven-plugin</artifactId>
                    <version>4.0.0-M2</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>io.thorntail</groupId>
                <artifactId>thorntail-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unit-tests</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>integration-tests-preaparation</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <propertyName>argLineForIntegration</propertyName>                      
                            <destFile>${project.build.directory}/jacoco-it.exec</destFile>
                        </configuration>                        
                    </execution>                    
                    <execution>
                        <id>merge</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>merge</goal>
                        </goals>
                        <configuration>
                            <fileSets>
                                <fileSet>
                                    <directory>${project.build.directory}</directory>
                                    <includes>
                                        <include>*.exec</include>
                                    </includes>
                                </fileSet>
                            </fileSets>
                            <destFile>${project.build.directory}/jacoco-merged.exec</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                        <dataFile>${project.build.directory}/jacoco-merged.exec</dataFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


    <profiles>
        <profile>
            <id>activate_windows</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <dockerHost>tcp://localhost:2375</dockerHost>
            </properties>
        </profile>
        <profile>
            <id>activation_unix</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <dockerHost>unix:///var/run/docker.sock</dockerHost>
            </properties>
        </profile>
        <profile>
            <id>package-docker-image</id>
            <activation>
                <property>
                    <name>docker-build</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>fabric8-maven-plugin</artifactId>
                        <configuration>
                            <skip>${skip-docker-build}</skip>
                            <useColor>true</useColor>
                            <dockerHost>${dockerHost}</dockerHost>
                            <images>
                                <image>
                                    <name>%g/%a:%l</name>
                                    <run>
                                        <ports>
                                            <port>8080:8080</port>
                                        </ports>
                                    </run>
                                    <build>
                                        <from>java:openjdk-8-jdk</from>
                                        <ports>
                                            <port>8080</port>
                                        </ports>
                                        <assembly>
                                            <basedir>/</basedir>
                                            <inline>
                                                <files>
                                                    <file>
                                                        <source>${project.build.directory}/${project.build.finalName}-thorntail.jar</source>
                                                        <outputDirectory>/opt</outputDirectory>
                                                    </file>
                                                </files>
                                            </inline>
                                        </assembly>
                                        <entryPoint>
                                            <shell>java -Djava.net.preferIPv4Stack=true -jar \
                                                /opt/${project.build.finalName}-thorntail.jar</shell>
                                        </entryPoint>
                                    </build>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

А вот pom.xml, расположенный в рекламном сервисе (микросервис нашего проекта):

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>ch.unige</groupId>
        <artifactId>PInfo2</artifactId>
        <version>0.2.0-SNAPSHOT</version>
    </parent>

    <artifactId>ad-service</artifactId>
    <name>Ad Service</name>
    <packaging>war</packaging>

    <properties>
        <skip-docker-build>false</skip-docker-build>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>jaxrs</artifactId>
        </dependency>

        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>swagger</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>cdi</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>transactions</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.ws.rs</groupId>
            <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>datasources</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>logging</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.5</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.10.Final</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.aerogear.kafka</groupId>
            <artifactId>kafka-cdi-extension</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.dadrus.jpa-unit</groupId>
            <artifactId>jpa-unit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.dadrus.jpa-unit</groupId>
            <artifactId>jpa-unit-rdbms</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>3.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>

    </dependencies>



    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.22.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unit-tests-1</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                        <destFile>jacoco.exec</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unit-tests-2</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <append>false</append>
                        </configuration>
                    </execution>                    
                    <execution>
                        <id>report</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>io.thorntail</groupId>
                <artifactId>thorntail-maven-plugin</artifactId>
                <configuration>
                    <!--PLACEHOLDER:configuration -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                        <jvmArguments>${}</jvmArguments>
                            <properties>
                                <thorntail.port.offset>20000</thorntail.port.offset>
                            </properties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Они почти одинаковы с рабочим репо (только что добавлены зависимости кафки и изменено имя). Я не знаю, почему он не запускает сервер в фоновом режиме для интеграционного тестирования, но работает для репозитория ..

РЕПО, НА КОТОРОМ Я РАБОТАЮ, ЭТО: https://github.com/bigotromain/PInfo2/tree/integration_tests

Вот мой "тупой" тестовый файл:

package api.rest;

import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.containsString;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import io.restassured.RestAssured;

public class AdRestServiceTest {

    @BeforeAll
    public static void setup() {
        RestAssured.baseURI = "http://localhost:28080/ad";
        RestAssured.port = 8080;
    }

    @Test
    public void testGetAll() {
        when().get("/").then().body(containsString("984500C2EEUEB4A0C629"));

    }

    @Test
    public void testCount() {
        when().get("/count").then().body(containsString("5"));
    }

    @Test
    public void testGet() {
        when().get("/984500C2EEUEB4A0C629").then().body(containsString("984500C2EEUEB4A0C629"));
    }

}

Я не понимаю, почему Thorntail не запустится для тестирования интеграции ... какая-нибудь помощь? Спасибо

1 Ответ

0 голосов
/ 30 мая 2019

По умолчанию плагин Maven Surefire (отвечающий за выполнение модульных тестов в фазе test) распознает классы, называемые *Test. Плагин Maven Failsafe (отвечает за запуск интеграционных тестов в фазе integration-test) распознает классы, называемые *IT.

Ваш тестовый класс называется AdRestServiceTest, который будет выполняться в фазе test. Вы хотите, чтобы он выполнялся в фазе integration-test, потому что это фаза integration-test, которая окружена фазами pre-integration-test и post-integration-test.

Так что вам нужно переименовать AdRestServiceTest в AdRestServiceIT. (Другой вариант - перенастроить плагины Surefire и Failsafe.)

...