mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-9259 Improve stability of HazelcastLockStoreTxTest test (#3248)
This commit is contained in:
@@ -25,29 +25,30 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.lock.mem;
|
package org.alfresco.repo.lock.mem;
|
||||||
|
|
||||||
import java.util.Date;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import jakarta.transaction.NotSupportedException;
|
import jakarta.transaction.NotSupportedException;
|
||||||
import jakarta.transaction.SystemException;
|
import jakarta.transaction.SystemException;
|
||||||
import jakarta.transaction.UserTransaction;
|
import jakarta.transaction.UserTransaction;
|
||||||
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
||||||
import org.alfresco.service.cmr.lock.LockType;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
|
||||||
import org.alfresco.util.ApplicationContextHelper;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.dao.ConcurrencyFailureException;
|
import org.springframework.dao.ConcurrencyFailureException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import static org.junit.Assert.assertNull;
|
import org.alfresco.service.cmr.lock.LockType;
|
||||||
import static org.junit.Assert.fail;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests that check transaction related functionality of {@link LockStore} implementations.
|
* Integration tests that check transaction related functionality of {@link LockStore} implementations.
|
||||||
|
*
|
||||||
* @author Matt Ward
|
* @author Matt Ward
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
||||||
@@ -108,9 +109,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
|
final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
|
||||||
"jbloggs", expires, Lifetime.EPHEMERAL, null);
|
"jbloggs", expires, Lifetime.EPHEMERAL, null);
|
||||||
|
|
||||||
|
Thread txB = new Thread("TxB") {
|
||||||
Thread txB = new Thread("TxB")
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
@@ -152,7 +151,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// Stop 'main' from waiting
|
// Stop 'main' from waiting
|
||||||
synchronized(main)
|
synchronized (main)
|
||||||
{
|
{
|
||||||
main.notifyAll();
|
main.notifyAll();
|
||||||
}
|
}
|
||||||
@@ -166,6 +165,9 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
// txA set lock state 1
|
// txA set lock state 1
|
||||||
lockStore.set(nodeRef, lockState1);
|
lockStore.set(nodeRef, lockState1);
|
||||||
|
|
||||||
|
// Perform a read, that we know will retrieve a null value (and null will be cached for this transaction)
|
||||||
|
assertNull("nodeRef2 LockState", lockStore.get(nodeRef2));
|
||||||
|
|
||||||
// Wait while txB reads and checks the LockState
|
// Wait while txB reads and checks the LockState
|
||||||
txB.setDaemon(true);
|
txB.setDaemon(true);
|
||||||
txB.start();
|
txB.start();
|
||||||
@@ -186,13 +188,10 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
// Check we can see the update.
|
// Check we can see the update.
|
||||||
assertEquals("bsmith", lockStore.get(nodeRef).getOwner());
|
assertEquals("bsmith", lockStore.get(nodeRef).getOwner());
|
||||||
|
|
||||||
// Perform a read, that we know will retrieve a null value
|
|
||||||
assertNull("nodeRef2 LockState", lockStore.get(nodeRef2));
|
|
||||||
|
|
||||||
// Wait while txB populates the store with a value for nodeRef2
|
// Wait while txB populates the store with a value for nodeRef2
|
||||||
passControl(this, txB);
|
passControl(this, txB);
|
||||||
|
|
||||||
// Perform the read again - update should not be visible in this transaction
|
// Perform the read again - update should not be visible in this transaction (was already cached)
|
||||||
assertNull("nodeRef2 LockState", lockStore.get(nodeRef2));
|
assertNull("nodeRef2 LockState", lockStore.get(nodeRef2));
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -203,11 +202,11 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
|
|
||||||
protected void passControl(Object from, Object to)
|
protected void passControl(Object from, Object to)
|
||||||
{
|
{
|
||||||
synchronized(to)
|
synchronized (to)
|
||||||
{
|
{
|
||||||
to.notifyAll();
|
to.notifyAll();
|
||||||
}
|
}
|
||||||
synchronized(from)
|
synchronized (from)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -233,9 +232,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
|
final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
|
||||||
"jbloggs", expires, Lifetime.EPHEMERAL, null);
|
"jbloggs", expires, Lifetime.EPHEMERAL, null);
|
||||||
|
|
||||||
|
Thread txB = new Thread("TxB") {
|
||||||
Thread txB = new Thread("TxB")
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
@@ -280,7 +277,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// Stop 'main' from waiting
|
// Stop 'main' from waiting
|
||||||
synchronized(main)
|
synchronized (main)
|
||||||
{
|
{
|
||||||
main.notifyAll();
|
main.notifyAll();
|
||||||
}
|
}
|
||||||
@@ -329,8 +326,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
|
|
||||||
final LockState lockState2 = LockState.createWithOwner(lockState1, "another");
|
final LockState lockState2 = LockState.createWithOwner(lockState1, "another");
|
||||||
|
|
||||||
Thread txB = new Thread("TxB")
|
Thread txB = new Thread("TxB") {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
@@ -369,7 +365,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// Stop 'main' from waiting
|
// Stop 'main' from waiting
|
||||||
synchronized(main)
|
synchronized (main)
|
||||||
{
|
{
|
||||||
main.notifyAll();
|
main.notifyAll();
|
||||||
}
|
}
|
||||||
@@ -404,7 +400,6 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotOnlyCurrentLockOwnerCanChangeInfo() throws NotSupportedException, SystemException
|
public void testNotOnlyCurrentLockOwnerCanChangeInfo() throws NotSupportedException, SystemException
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user