HHH-13373 Remove FailureExpected annotation from tests and assure tearDownDBs method is executed even if an error occurs in the setUpDBs method
This commit is contained in:
parent
bc2aa159a1
commit
d04a1fe3fd
|
@ -1,12 +1,20 @@
|
|||
package org.hibernate.test.dialect.functional;
|
||||
|
||||
import java.sql.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.MariaDB103Dialect;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.testing.*;
|
||||
|
||||
import org.hibernate.testing.BeforeClassOnce;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -14,7 +22,6 @@ import org.junit.Test;
|
|||
* @author Nathan Xu
|
||||
*/
|
||||
@RequiresDialect(MariaDB103Dialect.class)
|
||||
@FailureExpected(jiraKey = "HHH-13373", message = "currently db user has no privilege to create secondary db and sequence within it")
|
||||
public class MariaDBExtractSequenceMatadataTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private static String primaryDbName;
|
||||
|
@ -31,9 +38,9 @@ public class MariaDBExtractSequenceMatadataTest extends BaseCoreFunctionalTestCa
|
|||
assert resultSet.next();
|
||||
primaryDbName = resultSet.getString( 1 );
|
||||
}
|
||||
stmt.execute( "CREATE DATABASE " + secondaryDbName );
|
||||
stmt.execute( "CREATE DATABASE IF NOT EXISTS " + secondaryDbName );
|
||||
stmt.execute( "USE " + secondaryDbName );
|
||||
stmt.execute( "CREATE SEQUENCE " + secondarySequenceName );
|
||||
stmt.execute( "CREATE SEQUENCE IF NOT EXISTS " + secondarySequenceName );
|
||||
stmt.execute( "USE " + primaryDbName );
|
||||
stmt.execute( "DROP SEQUENCE IF EXISTS " + secondarySequenceName );
|
||||
stmt.execute( "CREATE SEQUENCE IF NOT EXISTS " + primarySequenceName );
|
||||
|
@ -48,20 +55,24 @@ public class MariaDBExtractSequenceMatadataTest extends BaseCoreFunctionalTestCa
|
|||
Assert.assertFalse( jdbcEnvironment.getExtractedDatabaseMetaData().getSequenceInformationList().isEmpty() );
|
||||
}
|
||||
|
||||
@AfterClassOnce
|
||||
public static void tearDownDBs() {
|
||||
@AfterClass
|
||||
public static void tearDownDBs() throws SQLException {
|
||||
try (Connection conn = getConnection()) {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
stmt.execute( "DROP DATABASE " + secondaryDbName );
|
||||
stmt.execute( "DROP DATABASE IF EXISTS " + secondaryDbName );
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
stmt.execute( "DROP SEQUENCE IF EXISTS " + primarySequenceName );
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Connection getConnection() throws SQLException {
|
||||
String url = Environment.getProperties().getProperty( Environment.URL );
|
||||
|
|
Loading…
Reference in New Issue