<?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>

    <parent>
        <groupId>com.github.mstream-trader</groupId>
        <artifactId>simulation-parent</artifactId>
        <version>1.13</version>
    </parent>

    <artifactId>simulation-performance-tests</artifactId>

    <properties>
        <service.port>8080</service.port>
        <service.debug.port>5005</service.debug.port>
        <mock.server.port>80</mock.server.port>
        <mock.proxy.port>90</mock.proxy.port>
        <zookeeper.port>2181</zookeeper.port>
        <docker.server.host>${docker.host.address}</docker.server.host>
        <service.url>http://${docker.server.host}:${service.port}</service.url>
        <throughput>1</throughput>
        <durationInSeconds>10</durationInSeconds>
        <gatling.version>2.2.2</gatling.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.github.mstream-trader</groupId>
            <artifactId>commons-test</artifactId>
            <version>1.13</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcpkix-jdk15on</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.javassist</groupId>
                    <artifactId>javassist</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.21</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-reflect</artifactId>
            <version>2.11.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang.modules</groupId>
            <artifactId>scala-java8-compat_2.11</artifactId>
            <version>0.8.0-RC1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-handler</artifactId>
            <version>${nettyVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-codec</artifactId>
            <version>${nettyVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-codec-http</artifactId>
            <version>${nettyVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-transport</artifactId>
            <version>${nettyVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-transport-native-epoll</artifactId>
            <version>${nettyVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-common</artifactId>
            <version>${nettyVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_2.11</artifactId>
            <version>2.4.7</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.scala-lang.modules</groupId>
                    <artifactId>scala-java8-compat_2.11</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-http</artifactId>
            <version>${gatling.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.scala-lang</groupId>
                    <artifactId>scala-library</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.scala-lang</groupId>
                    <artifactId>scala-reflect</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.scala-lang.modules</groupId>
                    <artifactId>scala-java8-compat_2.11</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-handler</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-codec</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-codec-http</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-common</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-transport</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-transport-native-epoll</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-app</artifactId>
            <version>${gatling.version}</version>
            <scope>runtime</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.scala-lang</groupId>
                    <artifactId>scala-library</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.scala-lang</groupId>
                    <artifactId>scala-reflect</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.typesafe.akka</groupId>
                    <artifactId>akka-actor_2.11</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.gatling.highcharts</groupId>
            <artifactId>gatling-charts-highcharts</artifactId>
            <version>${gatling.version}</version>
            <scope>runtime</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.scala-lang</groupId>
                    <artifactId>scala-library</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-codec-http</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-maven-plugin</artifactId>
                <version>2.2.0</version>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <bodiesFolder>
                        ${project.basedir}/src/test/resources/templates
                    </bodiesFolder>
                    <jvmArgs>
                        <jvmArg>
                            -DserviceUrl=${service.url}
                        </jvmArg>
                        <jvmArg>-Dthroughput=${throughput}</jvmArg>
                        <jvmArg>-DdurationInSeconds=${durationInSeconds}
                        </jvmArg>
                    </jvmArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.15.7</version>
                <configuration>
                    <images>
                        <image>
                            <alias>service</alias>
                            <name>
                                mstream/trader-${serviceName}:${project.version}
                            </name>
                            <run>
                                <links>
                                    <link>mock:data-feed</link>
                                    <link>zookeeper:zookeeper</link>
                                </links>
                                <env>
                                </env>
                                <labels>
                                    <version>${project.version}</version>
                                </labels>
                                <ports>
                                    <port>${service.port}:${service.port}</port>
                                    <port>
                                        ${service.debug.port}:${service.debug.port}
                                    </port>
                                </ports>
                                <cmd>
                                    java
                                    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${service.debug.port}
                                    -DZK_CONNECTION_STRING=zookeeper:${zookeeper.port}
                                    -jar /opt/simulation.jar
                                    --port ${service.port}
                                </cmd>
                                <wait>
                                    <http>
                                        <url>
                                            http://${docker.server.host}:${service.port}/monitoring/version
                                        </url>
                                        <method>GET</method>
                                        <status>200</status>
                                    </http>
                                    <time>10000</time>
                                </wait>
                                <log>
                                </log>
                            </run>
                        </image>
                        <image>
                            <alias>mock</alias>
                            <name>jamesdbloom/mockserver</name>
                            <run>
                                <ports>
                                    <port>
                                        ${mock.server.port}:${mock.server.port}
                                    </port>
                                    <port>
                                        ${mock.proxy.port}:${mock.proxy.port}
                                    </port>
                                </ports>
                                <cmd>/opt/mockserver/run_mockserver.sh -logLevel
                                    INFO -serverPort ${mock.server.port}
                                    -proxyPort ${mock.proxy.port}
                                </cmd>
                            </run>
                        </image>
                        <image>
                            <alias>zookeeper</alias>
                            <name>zookeeper:3.4.9</name>
                            <run>
                                <ports>
                                    <port>
                                        ${zookeeper.port}:${zookeeper.port}
                                    </port>
                                </ports>
                                <wait>
                                    <tcp>
                                        <ports>
                                            <port>${zookeeper.port}</port>
                                        </ports>
                                    </tcp>
                                    <time>10000</time>
                                </wait>
                            </run>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                            <goal>remove</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <includes>
                        <include>**/PerformanceTestBeforeHook.java</include>
                    </includes>
                    <systemPropertyVariables>
                        <SERVICE_ADDRESS>${docker.server.host}</SERVICE_ADDRESS>
                        <SERVICE_PORT>${mock.server.port}</SERVICE_PORT>
                        <MOCK_ADDRESS>${docker.server.host}</MOCK_ADDRESS>
                        <MOCK_SERVER_PORT>${mock.server.port}</MOCK_SERVER_PORT>
                        <MOCK_PROXY_PORT>${mock.proxy.port}</MOCK_PROXY_PORT>
                        <ZK_CONNECTION_STRING>
                            ${docker.server.host}:${zookeeper.port}
                        </ZK_CONNECTION_STRING>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
