REPO-1012 : DB builds: Fix a batch of tests that (regularly) fail on SQL Server

- adding retrying transactions for the propertyValueDAO.cleanupUnusedValues() method calls as MS SQL is slow and has problems coping with other threads updating the alf_prop_ tables
   - changed the order of the tests to help reduce other tests failing because of these clean up tests

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129495 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrei Rebegea
2016-08-12 16:04:19 +00:00
parent 2f2ce963d7
commit a73174a971
3 changed files with 117 additions and 90 deletions

View File

@@ -60,13 +60,17 @@ import org.junit.runners.Suite;
LocaleDAOTest.class,
QNameDAOTest.class,
PropertyValueDAOTest.class,
PropertyValueCleanupTest.class,
AuditDAOTest.class,
AppliedPatchDAOTest.class,
AclCrudDAOTest.class,
UsageDAOTest.class,
SOLRDAOTest.class,
TenantAdminDAOTest.class,
// REOPO-1012 : run AuditDAOTest and PropertyValueCleanupTest near the end
// because their failure can cause other tests to fail on MS SQL
// AuditDAOTest fails if it runs after CannedQueryDAOTest so this order is a compromise
// CannedQueryDAOTest will fail on MS SQL if either AuditDAOTest or PropertyValueCleanupTest fail
PropertyValueCleanupTest.class,
AuditDAOTest.class,
CannedQueryDAOTest.class
})
public class DomainTestSuite

View File

@@ -804,8 +804,6 @@ public class AuditDAOTest extends TestCase
txn.commit();
System.out.println("Created values for " + i + " entries in " + (System.currentTimeMillis() - startCreate) + " ms.");
txn = transactionService.getUserTransaction();
txn.begin();
if (!performance)
{
// Check there are some persisted values to delete.
@@ -827,8 +825,18 @@ public class AuditDAOTest extends TestCase
}
}
long startDelete = System.currentTimeMillis();
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
propertyValueDAO.cleanupUnusedValues();
txn.commit();
return null;
}
};
// use a new transaction so it will retry in that transaction
txnHelper.doInTransaction(callback,false,true);
System.out.println("Cleaned values for " + i + " entries in " + (System.currentTimeMillis() - startDelete) + " ms.");
if (!performance)

View File

@@ -34,6 +34,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.attributes.AttributeService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
@@ -60,15 +61,12 @@ public class PropertyValueCleanupTest
private TransactionService transactionService;
private AttributeService attributeService;
private RetryingTransactionHelper txnHelper;
private PropertyValueDAO propertyValueDAO;
@Before
public void setUp() throws Exception
{
transactionService = (TransactionService) ctx.getBean("TransactionService");
txnHelper = transactionService.getRetryingTransactionHelper();
txnHelper.setMaxRetries(0);
attributeService = (AttributeService) ctx.getBean("AttributeService");
propertyValueDAO = (PropertyValueDAO) ctx.getBean("propertyValueDAO");
@@ -103,6 +101,9 @@ public class PropertyValueCleanupTest
// Start threads that throw stuff into the AttributeService
ThreadGroup threadGroup = new ThreadGroup("testRapidCreationDuringCleanup");
InsertSerializableAttributes[] runnables = new InsertSerializableAttributes[2];
try
{
for (int i = 0; i < runnables.length; i++)
{
// Runnable
@@ -118,16 +119,30 @@ public class PropertyValueCleanupTest
// Wait a bit for data to really get in there
wait(1000L);
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
// do it in a retrying transaction because there may be other threads modifying
// the alf_prop_* and therefore the cleanup may fail sometimes
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
// Now run the cleanup script
propertyValueDAO.cleanupUnusedValues();
// Stop the threads
return null;
}
};
txnHelper.doInTransaction(callback);
}
finally
{
// Make sure we stop the Daemons
for (int i = 0; i < runnables.length; i++)
{
// Runnable
runnables[i].running.set(false);
}
}
// Clear any caches
clearCaches();