Fix tearDown code for UsageTestSuite classes

- Ensure that we either commit (successfully) or do rollback
 - Added leaked transaction detection to tests
 - ALF-19787: RED BUILD: Build repeatedly hanging in UsageTestSuite 


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54587 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2013-08-28 14:41:04 +00:00
parent b5a4b2aed9
commit 859d4b9ce4
3 changed files with 54 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ import junit.framework.TestCase;
import org.alfresco.repo.lock.JobLockService;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.admin.RepoUsage;
import org.alfresco.service.cmr.admin.RepoUsage.LicenseMode;
@@ -59,6 +60,11 @@ public class RepoUsageComponentTest extends TestCase
@Override
protected void setUp() throws Exception
{
if (AlfrescoTransactionSupport.isActualTransactionActive())
{
fail("Test started with transaction in progress");
}
transactionService = (TransactionService) ctx.getBean("transactionComponent");
repoUsageComponent = (RepoUsageComponent) ctx.getBean("repoUsageComponent");
jobLockService = (JobLockService) ctx.getBean("jobLockService");
@@ -87,7 +93,15 @@ public class RepoUsageComponentTest extends TestCase
AuthenticationUtil.clearCurrentSecurityContext();
if (txn != null)
{
try { txn.commit(); } catch (Throwable e) {}
try
{
txn.commit();
}
catch (Throwable e)
{
try { txn.rollback(); } catch (Throwable ee) {}
throw new RuntimeException("Failed to commit test transaction", e);
}
}
}
@@ -130,6 +144,7 @@ public class RepoUsageComponentTest extends TestCase
public void test2NoTxn() throws Throwable
{
txn.commit();
txn = null;
try
{
repoUsageComponent.getUsage();

View File

@@ -33,6 +33,7 @@ import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.admin.RepoAdminService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileNotFoundException;
@@ -50,6 +51,8 @@ import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
/**
@@ -57,6 +60,8 @@ import org.springframework.context.ApplicationContext;
*/
public class UserUsageTest extends TestCase
{
private static Log logger = LogFactory.getLog(UserUsageTest.class);
private static ApplicationContext applicationContext = ApplicationContextHelper.getApplicationContext();
protected NodeService nodeService;
@@ -85,6 +90,11 @@ public class UserUsageTest extends TestCase
protected void setUp() throws Exception
{
if (AlfrescoTransactionSupport.isActualTransactionActive())
{
fail("Test started with transaction in progress");
}
nodeService = (NodeService) applicationContext.getBean("nodeService");
fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService");
@@ -163,21 +173,35 @@ public class UserUsageTest extends TestCase
protected void tearDown() throws Exception
{
boolean deltasDeleted = false;
try
{
usageService.deleteDeltas(personNodeRef);
usageService.deleteDeltas(personNodeRef2);
testTX.commit();
}
catch (Throwable t)
{
t.printStackTrace();
deltasDeleted = true;
}
finally
{
try
{
testTX.commit();
}
catch (Throwable e)
{
AuthenticationUtil.clearCurrentSecurityContext();
super.tearDown();
try { testTX.rollback(); } catch (Throwable ee) {}
if (deltasDeleted)
{
// The deltas did not cause this issue. So it's something else during commit;
throw new Exception("Failed to commit transaction after test", e);
}
else
{
// One of the deleteDelats calls failed and an exception is passing through.
// Do not rethrow so that we don't mask it.
logger.error("Transaction commit failed", e);
}
}
}
}

View File

@@ -30,6 +30,7 @@ import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
@@ -79,6 +80,11 @@ public class UserUsageTrackingComponentTest extends TestCase
protected void setUp() throws Exception
{
if (AlfrescoTransactionSupport.isActualTransactionActive())
{
fail("Test started with transaction in progress");
}
nodeService = (NodeService)applicationContext.getBean("NodeService");
authenticationService = (MutableAuthenticationService)applicationContext.getBean("authenticationService");
transactionService = (TransactionService)applicationContext.getBean("transactionComponent");