I'm trying to come up with a parallel maven test execution for integration tests.
Using sql-maven-plugin to create a test database before test execution starts, in conjunction with maven surefire plugin parameters and parallel execution, seems like a good approach to start with.
What I'm failing to understand is how to use the system properties that the surefire plugin sets, with sql-maven-plugin (or any other plugins for that matter). I have a setup that fails on this.
surefire plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>2</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<systemPropertyVariables>
<databaseSchema>test_schema_${surefire.forkNumber}</databaseSchema>
</systemPropertyVariables>
</configuration>
</plugin>
sql-maven-plugin configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<username>user_with_create_privs</username>
<password>password</password>
<url>jdbc:mysql://localhost/dummy_schema</url>
</configuration>
<executions>
<execution>
<id>create-db</id>
<phase>process-test-classes</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>jdbc:mysql://localhost/dummy_schema</url>
<autocommit>true</autocommit>
<sqlCommand>create database ${databaseSchema}</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>
shell execution:
mvn test
result output:
[DEBUG] SQL: drop database ${databaseSchema}
[ERROR] Failed to execute: drop database ${databaseSchema}
[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute
(create-db) on project billing-core: You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near '{databaseSchema}' at line 1 -> [Help 1]
So, looks like ${databaseSchema} is not populated, or a syntax problem. I've fiddled, but cannot get this working although it looks like it's easy and should.