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();