aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-08-13 12:41:45 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-08-13 12:42:06 +0200
commit13e34d150e7bef921c1a2374517731de542680e7 (patch)
tree1316b5bee3d1333ac74fd78b87fb116a31bd0c08 /sonar-core
parent0e6b081d5a4aa28732b9e9ebd359be752f35c4f9 (diff)
downloadsonarqube-13e34d150e7bef921c1a2374517731de542680e7.tar.gz
sonarqube-13e34d150e7bef921c1a2374517731de542680e7.zip
improved test performances for sq #3 (use MetaDataHandler for MySQL)
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java42
-rw-r--r--sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerDaoTest.java1
2 files changed, 11 insertions, 32 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java b/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java
index 998d8963bc6..9b17e6e1d33 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java
@@ -38,6 +38,7 @@ import org.dbunit.dataset.ReplacementDataSet;
import org.dbunit.dataset.filter.DefaultColumnFilter;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.dbunit.ext.mssql.InsertIdentityOperation;
+import org.dbunit.ext.mysql.MySqlMetadataHandler;
import org.dbunit.operation.DatabaseOperation;
import org.junit.Assert;
import org.junit.Before;
@@ -47,6 +48,7 @@ import org.sonar.api.config.Settings;
import org.sonar.core.cluster.NullQueue;
import org.sonar.core.cluster.WorkQueue;
import org.sonar.core.config.Logback;
+import org.sonar.core.persistence.dialect.MySql;
import javax.sql.DataSource;
import java.io.File;
@@ -120,8 +122,14 @@ public abstract class AbstractDaoTestCase {
myBatis.start();
}
- if(connection == null){
- connection = createConnection();
+
+ if (connection == null) {
+ connection = databaseTester.getConnection();
+ connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, databaseCommands.getDbUnitFactory());
+ if (MySql.ID.equals(database.getDialect().getId())) {
+ connection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, false);
+ connection.getConfig().setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, new MySqlMetadataHandler());
+ }
}
databaseCommands.truncateDatabase(database.getDataSource());
@@ -199,18 +207,6 @@ public abstract class AbstractDaoTestCase {
new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, databaseTester.getDataSet());
} catch (Exception e) {
throw translateException("Could not setup DBUnit data", e);
- } finally {
- //closeQuietly(connection);
- }
- }
-
- private void closeQuietly(IDatabaseConnection connection) {
- try {
- if (connection != null) {
- connection.close();
- }
- } catch (SQLException e) {
- // ignore
}
}
@@ -231,8 +227,6 @@ public abstract class AbstractDaoTestCase {
fail(e.getMessage());
} catch (SQLException e) {
throw translateException("Error while checking results", e);
- } finally {
- //closeQuietly(connection);
}
}
@@ -248,8 +242,6 @@ public abstract class AbstractDaoTestCase {
fail(e.getMessage());
} catch (SQLException e) {
throw translateException("Error while checking results", e);
- } finally {
- //closeQuietly(connection);
}
}
@@ -266,18 +258,6 @@ public abstract class AbstractDaoTestCase {
}
} catch (SQLException e) {
throw translateException("Error while checking results", e);
- } finally {
- //closeQuietly(connection);
- }
- }
-
- private IDatabaseConnection createConnection() {
- try {
- IDatabaseConnection conn = databaseTester.getConnection();
- conn.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, databaseCommands.getDbUnitFactory());
- return conn;
- } catch (Exception e) {
- throw translateException("Error while getting connection", e);
}
}
@@ -312,6 +292,6 @@ public abstract class AbstractDaoTestCase {
}
protected Connection getConnection() throws SQLException {
- return database.getDataSource().getConnection();
+ return connection.getConnection();
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerDaoTest.java
index 11e1762ef7b..5fe8bb09402 100644
--- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerDaoTest.java
@@ -104,7 +104,6 @@ public class ResourceIndexerDaoTest extends AbstractDaoTestCase {
if (null != rs) {
rs.close();
}
- connection.close();
}
}