<?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">
    <parent>
        <groupId>com.mulesoft.mule.tests</groupId>
        <artifactId>mule-ee-integration-tests</artifactId>
        <version>4.11.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mule-ee-integration-performance-tests</artifactId>
    <packaging>jar</packaging>
    <name>Mule EE Integration Performance Tests</name>

    <properties>
        <surefire.args>
            -XX:+IgnoreUnrecognizedVMOptions
            --add-opens=java.base/java.lang=ALL-UNNAMED
            ${surefire.slf4j.module.args}
        </surefire.args>

        <javaModuleName>com.mulesoft.mule.test.integration.performance</javaModuleName>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.openjdk.jmh</groupId>
                            <artifactId>jmh-generator-annprocess</artifactId>
                            <version>${jmh.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>${surefire.args}</argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- Target modules -->
        <dependency>
            <groupId>com.mulesoft.mule.runtime.modules</groupId>
            <artifactId>mule-module-kryo-serializer-ee</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.esotericsoftware</groupId>
            <artifactId>kryo-shaded</artifactId>
        </dependency>

        <!-- AbstractBenchmark class -->
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-performance</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>micro-benchmark</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>${surefire.args}</argLine>
                            <systemPropertyVariables>
                                <mule.test.timeoutSecs>300</mule.test.timeoutSecs>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>run-benchmarks</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <classpathScope>test</classpathScope>
                                    <executable>java</executable>
                                    <workingDirectory>${basedir}/target</workingDirectory>
                                    <arguments>
                                        <argument>-classpath</argument>
                                        <classpath/>
                                        <mainClass>org.openjdk.jmh.Main</mainClass>
                                        <!--Run only a certain class-->
                                        <argument>${jmh.benchmark}</argument>
                                        <!--Create json report-->
                                        <argument>-rf</argument>
                                        <argument>json</argument>
                                        <!--Enable gc profiler-->
                                        <argument>-prof</argument>
                                        <argument>gc</argument>
                                        <!--Number of Iterations-->
                                        <argument>-i</argument>
                                        <argument>15</argument>
                                        <!--Number of Warmup Iterations-->
                                        <argument>-wi</argument>
                                        <argument>5</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>benchmark-jar</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <archive>
                                        <manifest>
                                            <mainClass>org.openjdk.jmh.Main</mainClass>
                                        </manifest>
                                    </archive>
                                    <descriptorRefs>
                                        <descriptorRef>jar-with-dependencies</descriptorRef>
                                    </descriptorRefs>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
