Shireesh Anjal has uploaded a new change for review.

Change subject: core: Performance enhancement for DAO test cases
......................................................................

core: Performance enhancement for DAO test cases

 - create the test data only during initialization of the first test case,
   which includes creating the connection (with auto-commit = false),
   inserting fixtures data and committing it
 - roll back any changes done to the database during test case execution
   in the tearDown method

Change-Id: I75afb85ba154808cd3254a1310e0350e6c4279fa
Signed-off-by: Shireesh Anjal <san...@redhat.com>
---
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
1 file changed, 21 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/36/7336/1

diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
index 3c61cab..4d1144a 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
@@ -25,6 +25,7 @@
 import org.ovirt.engine.core.common.businessentities.DiskImageDynamic;
 import 
org.ovirt.engine.core.common.businessentities.LUN_storage_server_connection_map;
 import org.ovirt.engine.core.common.businessentities.LUNs;
+import org.ovirt.engine.core.common.businessentities.Network;
 import org.ovirt.engine.core.common.businessentities.RoleGroupMap;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VdcOption;
@@ -44,7 +45,6 @@
 import org.ovirt.engine.core.common.businessentities.event_subscriber;
 import org.ovirt.engine.core.common.businessentities.image_storage_domain_map;
 import org.ovirt.engine.core.common.businessentities.image_vm_map;
-import org.ovirt.engine.core.common.businessentities.Network;
 import org.ovirt.engine.core.common.businessentities.network_cluster;
 import org.ovirt.engine.core.common.businessentities.permissions;
 import org.ovirt.engine.core.common.businessentities.roles;
@@ -68,7 +68,6 @@
 import org.ovirt.engine.core.dal.dbbroker.DbFacadeLocator;
 import org.ovirt.engine.core.dal.dbbroker.user_sessions;
 import org.ovirt.engine.core.dal.dbbroker.generic.DBConfigUtils;
-import org.springframework.beans.factory.DisposableBean;
 import org.springframework.jdbc.datasource.SingleConnectionDataSource;
 import org.springframework.test.annotation.NotTransactional;
 import org.springframework.test.context.ContextConfiguration;
@@ -101,20 +100,32 @@
     @NotTransactional
     @BeforeClass
     public static void initTestCase() throws Exception {
-        dataSource = createDataSource();
-        dataset = initDataSet();
-        dbFacade = new DbFacade();
-        dbFacade.setDbEngineDialect(DbFacadeLocator.loadDbEngineDialect());
-        
dbFacade.setTemplate(dbFacade.getDbEngineDialect().createJdbcTemplate(dataSource));
+        if(dataSource == null) {
+            dataSource = createDataSource();
+            Connection con = dataSource.getConnection();
+            con.setAutoCommit(false);
 
-        // load data from fixtures to DB
-        DatabaseOperation.CLEAN_INSERT.execute(getConnection(), dataset);
+            dataset = initDataSet();
+            dbFacade = new DbFacade();
+            dbFacade.setDbEngineDialect(DbFacadeLocator.loadDbEngineDialect());
+            
dbFacade.setTemplate(dbFacade.getDbEngineDialect().createJdbcTemplate(dataSource));
+
+            // load data from fixtures to DB
+            DatabaseOperation.CLEAN_INSERT.execute(getConnection(), dataset);
+            con.commit();
+        }
     }
 
     @NotTransactional
     @AfterClass
     public static void tearDownTestCase() throws Exception {
-        ((DisposableBean) getDataSource()).destroy();
+        if(dataSource != null) {
+            Connection con = dataSource.getConnection();
+            if(con != null) {
+                // rollback any changes done to DB during the test case 
execution
+                con.rollback();
+            }
+        }
     }
 
     @Before


--
To view, visit http://gerrit.ovirt.org/7336
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I75afb85ba154808cd3254a1310e0350e6c4279fa
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Shireesh Anjal <san...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to