Refactor exclusive query execution in test framework
@@ -190,15 +190,15 @@ public abstract class AbstractTestQueryFramework
protected void assertAccessAllowed(Session session, @Language("SQL") String sql, TestingPrivilege... deniedPrivileges)
{
- queryRunner.getExclusiveLock().lock();
+ executeExclusively(() -> {
try {
queryRunner.getAccessControl().deny(deniedPrivileges);
queryRunner.execute(session, sql);
}
finally {
queryRunner.getAccessControl().reset();
- queryRunner.getExclusiveLock().unlock();
}
+ });
}
protected void assertAccessDenied(@Language("SQL") String sql, @Language("RegExp") String exceptionsMessageRegExp, TestingPrivilege... deniedPrivileges)
@@ -212,7 +212,7 @@ public abstract class AbstractTestQueryFramework
@Language("RegExp") String exceptionsMessageRegExp,
TestingPrivilege... deniedPrivileges)
{
- queryRunner.getExclusiveLock().lock();
+ executeExclusively(() -> {
try {
queryRunner.getAccessControl().deny(deniedPrivileges);
queryRunner.execute(session, sql);
@@ -223,8 +223,8 @@ public abstract class AbstractTestQueryFramework
}
finally {
queryRunner.getAccessControl().reset();
- queryRunner.getExclusiveLock().unlock();
}
+ });
}
protected void assertTableColumnNames(String tableName, String... columnNames)
@@ -249,6 +249,17 @@ public abstract class AbstractTestQueryFramework
return h2QueryRunner.execute(getSession(), sql, resultTypes);
}
+ protected void executeExclusively(Runnable executionBlock)
+ {
+ queryRunner.getExclusiveLock().lock();
+ try {
+ executionBlock.run();
+ }
+ finally {
+ queryRunner.getExclusiveLock().unlock();
+ }
+ }
+
protected String formatSqlText(String sql)
{
return formatSql(sqlParser.createStatement(sql), Optional.empty());
