2

I am having a netty application server need to be started at the pre-integration-test phase and stop it during the post-integration-test phase for the testing purpose of IntegrationTests. I had used maven-failsafe-plugin. But i don't know to execute the main class during the pre-integration-test phase and how to stop the server after the execution. Also my main class reside in the sub module of the project. I had created a profile for running the IntegrationTest in the parent pom.

     <profile>
        <id>integration-tests</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <modules>
            <module>application_module1</module>
        </modules>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.14.1</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.9.1</version>
                    <executions>
                        <execution>
                            <id>add-source</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>add-test-source</goal>
                            </goals>
                            <configuration>
                                <sources>
                                    <source>src/it/java</source>
                                </sources>
                            </configuration>
                        </execution>
                        <execution>
                            <id>add-resource</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>add-test-resource</goal>
                            </goals>
                            <configuration>
                                <resources>
                                    <resource>
                                             <directory>src/it/resources</directory>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <includes>
                            <include>**/*IT.java</include>
                        </includes>
                    </configuration>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
Boris Schegolev
  • 3,601
  • 5
  • 21
  • 34
Kgn
  • 231
  • 3
  • 14

1 Answers1

0

Interesting question, because it is similar to my recent question about doing the same thing with an embedded postgres instance.

As per @Tunaki suggestion to me, and from my research, I do not believe there is an easy way for you to have the maven-failsafe-plugin initiate a server start process without customizing/forking the failsafe plugin code itself (which I would not recommend).

Perhaps a better option is doing something like I am doing for the my postgres-embedded service need: creating a new, fairly simple plugin for initializing the netty service. Refer to @Tunaki's selected response.

Based on @Tunaki advice and following this fairly easy-to-follow maven-plugin guide I have created a small Java (Maven-plugin) project that consists of:

  • the plugin pom (using the maven-plugin-plugin 3.4 build plugin)
  • My java service class that contains the code to initiate, maintain the state of the server process and Stop the server process.
  • Two Mojo (Java classes) on for my Start Process and one for my stop process that notably are annotated like this:

    @Mojo(name = "startpostgres", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST) public class StartPostgresMojo extends AbstractMojo

My plugin pom starts like this:

<groupId>my.group.id</groupId>
<artifactId>postgres-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
  <plugin>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.4</version>
  </plugin>
</plugins>
</build> 

It sounds like doing something like this with your netty app server can work for you.

The other thing you might be able to do is fork the maven cargo plugin and try to add your own support for netty app server, since that is not of the current supported containers for cargo

Community
  • 1
  • 1
aramcodez
  • 102
  • 1
  • 8