we are running Junit ans Selenium test cases from CI every midnight. We are pre populating the data using the Maven-SQL plugin as following.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>create-database-tables</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>false</autocommit>
<onError>continue</onError>
<srcFiles>
<srcFile>../sql/delete_data.sql</srcFile>
<srcFile>../sql/load_data.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>
we are frequently facing the DB deadlocks due to simultaneous builds by different users. The solution we thought is to lock the database before running the DB scripts.
Can we lock the DB access before running the scripts and unlock it after running the scripts.
A shared database for testing is never a great idea, presumably you know this which is why you’re asking how to restrict access to one user at a time.
Preaching aside….. I’d like to offer a left-field solution of liquibase to manage both the database schema and data population. Has lots of useful features one of which is that it will automatically lock the database and prevent two instance of liquibase interfering with each other.
Example