Merged BRANCHES/DEV/HEAD-BUG-FIX to HEAD:

54579: ALF-19785: Deadlock during build



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54739 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2013-09-02 07:52:11 +00:00
parent 56f95056c6
commit 6ba121eb00
5 changed files with 67 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ package org.alfresco.repo.lock.mem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Comparator;
import java.util.Iterator;
@@ -29,6 +30,7 @@ import java.util.TreeSet;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.LockHelper.LockTryException;
import org.junit.Before;
import org.junit.Test;
@@ -156,4 +158,46 @@ public abstract class AbstractLockStoreTestBase<T extends LockStore>
assertEquals(nodeRef3, it.next());
assertEquals(nodeRef4, it.next());
}
@Test()
public void whenTryLockFailsTransactionWillRetry() throws InterruptedException
{
final NodeRef nodeRef = new NodeRef("workspace://SpacesStore/whenTryLockFailsTransactionWillRetry");
// The "other" thread, that got there first and took the lock.
Thread thread = new Thread(getClass().getSimpleName()+"-testTryLock")
{
@Override
public void run()
{
try
{
// Deliberately NOT releasing this lock, so we can check for tryLock failure.
lockStore.acquireConcurrencyLock(nodeRef);
}
catch (Throwable e)
{
// This shouldn't happen the first time.
fail("Failed to a acquire lock");
}
}
};
thread.start();
// Wait for the other thread to perform the lock.
thread.join();
// Second attempt will fail (already locked above), expected exception
// must be thrown for retrying behaviour to work correctly.
try
{
lockStore.acquireConcurrencyLock(nodeRef);
fail("Exception was not thrown when unable to acquire lock.");
}
catch (LockTryException e)
{
// Good, we got the correct exception.
}
}
}