From c9f58ec243d0053dc7fb312c5a37810ce01be250 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Tue, 10 Aug 2010 17:57:17 +0000 Subject: [PATCH] OPENJPA-1753 a) remove unneeded import, b) close and clean up em using add Act.CloseEm, c) add better diagnostic info in SequenceActionsTest and d) clean up and update find/lock permutation tests for more consistent testing. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@984147 13f79535-47bb-0310-9956-ffa450edef68 --- .../lockmgr/SequencedActionsTest.java | 27 +- .../persistence/lockmgr/TestFetchHints.java | 1 - .../lockmgr/TestMixedLockManagerDeadlock.java | 4 +- .../TestMixedLockManagerFindBasic.java | 1 + .../TestMixedLockManagerFindException.java | 4 + .../TestMixedLockManagerFindPermutation.java | 126 ++++---- .../TestMixedLockManagerLockBasic.java | 1 + .../TestMixedLockManagerLockException.java | 9 +- .../TestMixedLockManagerLockPermutation.java | 271 +++++++++++------- .../TestMixedLockManagerRefreshBasic.java | 1 + .../TestMixedLockManagerRefreshException.java | 8 +- ...estMixedLockManagerRefreshPermutation.java | 62 +++- .../TestOptimisticNamedQueryLockMode.java | 2 - 13 files changed, 334 insertions(+), 183 deletions(-) diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/SequencedActionsTest.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/SequencedActionsTest.java index ba891f919..148ebb03d 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/SequencedActionsTest.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/SequencedActionsTest.java @@ -81,6 +81,7 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase { private String empTableName; private List threads = null; + @SuppressWarnings("deprecation") protected void commonSetUp() { empTableName = getMapping(LockEmployee.class).getTable().getFullName(); @@ -326,10 +327,12 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase { LockEmployee employee = null; LockModeType lockMode = null; Act curAction = null; + int actIndex = 0; Object[][] threadSequence = actions[threadToRun]; for (Object[] args : threadSequence) { curAction = (Act) args[0]; - log.trace("** Act=" + Arrays.toString(args)); + String curAct = "Act[t" + threadToRun + ":" + (++actIndex) +"]=" + Arrays.toString(args); + log.trace("** " + curAct); try { switch (curAction) { case CreateEm: @@ -591,7 +594,7 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase { id = (Integer)args[1]; } employee = employees.get(id); - assertNotNull(employee); + assertNotNull(curAct, employee); break; case TestEmployee: id = 1; @@ -602,22 +605,22 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase { switch (args.length) { case 4: if (args[3] != null) { - assertEquals("", saveVersion + assertEquals(curAct, saveVersion + (Integer) args[3], employee.getVersion()); } case 3: if (args[2] != null) { - assertEquals("", (String) args[2], employee + assertEquals(curAct, (String) args[2], employee .getFirstName()); } case 2: if (args[1] != null) { - assertEquals("", id.intValue(), + assertEquals(curAct, id.intValue(), employee.getId()); } break; case 1: - assertNull(employee); + assertNull(curAct, employee); } break; case SaveVersion: @@ -640,7 +643,7 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase { + (saveVersion + increment) + ", testing=" + employee.getVersion()); - assertEquals("", saveVersion + increment, employee + assertEquals(curAct, saveVersion + increment, employee .getVersion()); break; case TestLockMode: @@ -654,7 +657,7 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase { log.trace("test version: expected=" + expectedlockMode + ", testing=" + testinglockMode); - assertEquals("", getCanonical(expectedlockMode), + assertEquals(curAct, getCanonical(expectedlockMode), getCanonical(testinglockMode)); break; case ResetException: @@ -696,7 +699,7 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase { && expectedExceptions.size() > 0) { for (Class expectedException : expectedExceptions) { - if (matchExpectedException(expectedException, + if (matchExpectedException(curAct, expectedException, curThrowable)) { exMatched = true; break; @@ -713,7 +716,7 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase { logStack(curThrowable); } } - assertTrue("Expecting=" + expectedExceptions + assertTrue(curAct + ":Expecting=" + expectedExceptions + ", Testing=" + testExClass, exMatched); exThread.throwable = null; break; @@ -908,9 +911,9 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase { return props; } - private boolean matchExpectedException(Class expected, + private boolean matchExpectedException(String curAct, Class expected, Throwable tested) { - assertNotNull(expected); + assertNotNull(curAct, expected); Class testExClass = null; boolean exMatched = true; if (tested != null) { diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestFetchHints.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestFetchHints.java index ffa6d2cef..7227f308d 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestFetchHints.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestFetchHints.java @@ -20,7 +20,6 @@ package org.apache.openjpa.persistence.lockmgr; import java.sql.Connection; import java.sql.ResultSet; -import java.util.HashMap; import javax.persistence.EntityManager; import javax.persistence.LockModeType; diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerDeadlock.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerDeadlock.java index fcf494bef..11ebae8e2 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerDeadlock.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerDeadlock.java @@ -121,7 +121,8 @@ public class TestMixedLockManagerDeadlock extends SequencedActionsTest { {Act.WaitAllChildren}, {Act.TestException, 1, t1Exceptions}, - {Act.RollbackTx} + {Act.RollbackTx}, + {Act.CloseEm} }; Object[][] thread1 = { {Act.CreateEm}, @@ -134,6 +135,7 @@ public class TestMixedLockManagerDeadlock extends SequencedActionsTest { {Act.NamedQueryWithLock, "findEmployeeById", 1, t1Lock, "openjpa.hint.IgnorePreparedQuery", true}, {Act.RollbackTx}, + {Act.CloseEm} }; launchActionSequence(testName, parameters, threadMain, thread1); } diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindBasic.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindBasic.java index e86a570b2..149dbd3b5 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindBasic.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindBasic.java @@ -111,6 +111,7 @@ public class TestMixedLockManagerFindBasic extends SequencedActionsTest { { Act.Clear }, { Act.Find, 1 }, { Act.TestEmployee, 1, lockMode.toString(), 0 }, + { Act.CloseEm } }; launchActionSequence(testName, "LockMode=" + lockMode, threadMain); diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindException.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindException.java index 0397bf035..859d3f500 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindException.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindException.java @@ -67,6 +67,7 @@ public class TestMixedLockManagerFindException extends SequencedActionsTest { {Act.FindWithLock, 1, LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, TransactionRequiredException.class }, + {Act.CloseEm}, }; launchActionSequence("testLockTxReqExceptions()", null, threadMainTxReqTest); @@ -182,6 +183,7 @@ public class TestMixedLockManagerFindException extends SequencedActionsTest { {Act.FindObject, LockEmployee.class, Boolean.TRUE, LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, IllegalArgumentException.class }, + {Act.CloseEm} }; launchActionSequence("testLockIllegalArgrumentExceptions()", "Test invalid entity.", threadMainInvEntityIllegalArgTest); @@ -239,6 +241,7 @@ public class TestMixedLockManagerFindException extends SequencedActionsTest { ? OptimisticLockException.class : null}, {Act.TestException, 1, expectingOptLockException2 ? OptimisticLockException.class : null}, + {Act.CloseEm} }; Object[][] thread1OptLockExTest = { {Act.CreateEm}, @@ -252,6 +255,7 @@ public class TestMixedLockManagerFindException extends SequencedActionsTest { {Act.CommitTx}, {Act.Notify, 0}, + {Act.CloseEm} }; launchActionSequence("testLockOptimisticLockExceptions()", null, threadMainOptLockExTest, thread1OptLockExTest); diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindPermutation.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindPermutation.java index f19be88af..8f57c1997 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindPermutation.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindPermutation.java @@ -59,8 +59,8 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { public void testFindReadPessimisticRead() { commonFindTest( "testFind(Read,Commit/PessimisticRead,Commit)", - LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null); + LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null); commonFindTest( "testFind(Read,Commit/PessimisticRead,Rollback)", LockModeType.READ, Act.CommitTx, 1, null, @@ -70,8 +70,8 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { public void testFindReadPessimisticWrite() { commonFindTest( "testFind(Read,Commit/PessimisticWrite,Commit)", - LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null); + LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null); commonFindTest( "testFind(Read,Commit/PessimisticWrite,Rollback)", LockModeType.READ, Act.CommitTx, 1, null, @@ -115,8 +115,8 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { public void testFindWritePessimisticRead() { commonFindTest( "testFind(Write,Commit/PessimisticRead,Commit)", - LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null); + LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null); commonFindTest( "testFind(Write,Commit/PessimisticRead,Rollback)", LockModeType.WRITE, Act.CommitTx, 1, null, @@ -126,8 +126,8 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { public void testFindWritePessimisticWrite() { commonFindTest( "testFind(Write,Commit/PessimisticWrite,Commit)", - LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null); + LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null); commonFindTest( "testFind(Write,Commit/PessimisticWrite,Rollback)", LockModeType.WRITE, Act.CommitTx, 1, null, @@ -172,7 +172,7 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { commonFindTest( "testFind(PessimisticRead,Commit/PessimisticRead,Commit)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null); + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null); commonFindTest( "testFind(PessimisticRead,Commit/PessimisticRead,Rollback)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, @@ -183,7 +183,7 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { commonFindTest( "testFind(PessimisticRead,Commit/PessimisticWrite,Commit)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null); + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null); commonFindTest( "testFind(PessimisticRead,Commit/PessimisticWrite,Rollback)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, @@ -228,7 +228,7 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { commonFindTest( "testFind(PessimsiticWrite,Commit/PessimisticRead,Commit)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null); + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null); commonFindTest( "testFind(PessimsiticWrite,Commit/PessimisticRead,Rollback)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, @@ -239,7 +239,7 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { commonFindTest( "testFind(PessimsiticWrite,Commit/PessimisticWrite,Commit)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null); + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null); commonFindTest( "testFind(PessimsiticWrite,Commit/PessimisticWrite,Rollback)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, @@ -284,7 +284,7 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { commonFindTest( "testFind(PessimsiticForceInc,Commit/PessimisticRead,Commit)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null); + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null); commonFindTest( "testFind(PessimsiticForceInc,Commit/PessimisticRead,Rollback)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, @@ -295,7 +295,7 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { commonFindTest( "testFind(PessimsiticForceInc,Commit/PessimisticWrite,Commit)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null); + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null); commonFindTest( "testFind(PessimsiticForceInc,Commit/PessimisticWrite,Rollback)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, @@ -327,51 +327,57 @@ public class TestMixedLockManagerFindPermutation extends SequencedActionsTest { ", expectedEx= " + Arrays.toString(t2Exceptions)}; Object[][] threadMain = { - {Act.CreateEm}, - {Act.Find}, - {Act.SaveVersion}, - {Act.TestEmployee, 1, Default_FirstName}, - - {Act.NewThread, 1 }, - {Act.NewThread, 2 }, - {Act.StartThread, 1 }, - {Act.Wait}, - {Act.StartThread, 2 }, - {Act.Notify, 1, 1000 }, - {Act.Notify, 2, 1000 }, - {Act.WaitAllChildren}, - {Act.Find}, - {Act.TestEmployee, 1}, - {Act.TestException, 1, t1Exceptions }, - {Act.TestException, 2, t2Exceptions }, - }; - Object[][] thread1 = { - {Act.CreateEm}, - {Act.StartTx}, - {Act.FindWithLock, 1, t1Lock}, - {Act.SaveVersion}, - {Act.TestException}, - {Act.Notify, 0}, - {Act.Wait}, - {Act.UpdateEmployee}, - - {t1IsCommit}, - {Act.Find}, - {Act.TestEmployee, 1, null, t1VersionInc} - }; - Object[][] thread2 = { - {Act.CreateEm}, - {Act.StartTx}, - {Act.FindWithLock, 1, t2Lock}, - {Act.SaveVersion}, - {Act.Notify, 0}, - {Act.Wait}, - - {t2IsCommit}, - {Act.Find}, - {Act.TestEmployee, 1, null, t2VersionInc} - }; - launchActionSequence(testName, parameters, threadMain, thread1, - thread2); + {Act.CreateEm}, + {Act.Find}, + {Act.SaveVersion}, + {Act.TestEmployee, 1, Default_FirstName}, + {Act.CloseEm}, + {Act.Sleep, 100}, + + {Act.CreateEm}, + {Act.StartTx}, + {Act.FindWithLock, 1, t1Lock}, + {Act.SaveVersion}, + {Act.TestException}, + + {Act.NewThread, 1 }, + {Act.StartThread, 1 }, + + {Act.Wait}, + {Act.UpdateEmployee}, + {t1IsCommit}, + + {Act.Notify, 1}, + + {Act.Find}, + + {Act.WaitAllChildren}, + {Act.Find}, + {Act.TestEmployee, 1, null, t1VersionInc}, + {Act.TestException, 0, t1Exceptions }, + {Act.TestException, 1, t2Exceptions }, + {Act.CloseEm} + }; + + Object[][] thread1 = { + {Act.CreateEm}, + {Act.StartTx}, + {Act.FindWithLock, 1, t2Lock}, + {Act.SaveVersion}, + {Act.TestException}, + {Act.Notify, 0}, + + {Act.Wait}, + {Act.Sleep, 2000}, // sleep for at least 2 sec so that the entity name updated with timestamp + // in each of the 2 threads are different. + {Act.UpdateEmployee}, + + {t2IsCommit}, + {Act.Sleep, 1000}, + {Act.Find}, + {Act.TestEmployee, 1, null, t2VersionInc}, + {Act.CloseEm} + }; + launchActionSequence(testName, parameters, threadMain, thread1); } } diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockBasic.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockBasic.java index b43fca6f7..c4b7f3401 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockBasic.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockBasic.java @@ -109,6 +109,7 @@ public class TestMixedLockManagerLockBasic extends SequencedActionsTest { { Act.Clear }, { Act.Find, 1 }, { Act.TestEmployee, 1, lockMode.toString(), 0 }, + { Act.CloseEm } }; launchActionSequence(testName, "LockMode=" + lockMode, threadMain); } diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockException.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockException.java index 4f0487783..4ecc9b032 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockException.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockException.java @@ -66,6 +66,7 @@ public class TestMixedLockManagerLockException extends SequencedActionsTest { {Act.Lock, 1, LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, TransactionRequiredException.class }, + {Act.CloseEm} }; launchActionSequence("testLockTxReqExceptions()", @@ -124,7 +125,8 @@ public class TestMixedLockManagerLockException extends SequencedActionsTest { {Act.TestException, 0, IllegalArgumentException.class }, {Act.LockObject, "null", LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, IllegalArgumentException.class }, - }; + {Act.CloseEm} + }; launchActionSequence("testLockIllegalArgrumentExceptions()", "Test invalid entity.", threadMainInvEntityIllegalArgTest); @@ -163,6 +165,7 @@ public class TestMixedLockManagerLockException extends SequencedActionsTest { {Act.Lock, 2, LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, IllegalArgumentException.class }, + {Act.CloseEm} }; launchActionSequence("testLockIllegalArgrumentExceptions()", "Test detached entity.", threadMainDetachEntityIllegalArgTest); @@ -200,6 +203,7 @@ public class TestMixedLockManagerLockException extends SequencedActionsTest { {Act.Lock, 2, LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, IllegalArgumentException.class }, + {Act.CloseEm} }; launchActionSequence("testLockIllegalArgrumentExceptions()", "Test detached entity using serialization.", @@ -238,6 +242,7 @@ public class TestMixedLockManagerLockException extends SequencedActionsTest { {Act.TestException}, {Act.RollbackTx}, + {Act.CloseEm} }; launchActionSequence( "testLockIllegalArgrumentExceptions()", @@ -296,6 +301,7 @@ public class TestMixedLockManagerLockException extends SequencedActionsTest { ? OptimisticLockException.class : null}, {Act.RollbackTx}, + {Act.CloseEm} }; Object[][] thread1OptLockExTest = { {Act.CreateEm}, @@ -309,6 +315,7 @@ public class TestMixedLockManagerLockException extends SequencedActionsTest { {Act.CommitTx}, {Act.Notify, 0}, + {Act.CloseEm} }; launchActionSequence("testLockOptimisticLockExceptions()", null, threadMainOptLockExTest, thread1OptLockExTest); diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockPermutation.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockPermutation.java index 5f72d6c2f..485965f00 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockPermutation.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockPermutation.java @@ -38,55 +38,55 @@ public class TestMixedLockManagerLockPermutation extends SequencedActionsTest { commonLockTest( "testLock(Read,Commit/Read,Commit)", LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.READ, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(Read,Commit/Read,Rollback)", LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.READ, Act.RollbackTx, 1, null); + LockModeType.READ, Act.RollbackTx, 1, null, null); } public void testLockReadWrite() { commonLockTest( "testLock(Read,Commit/Write,Commit)", LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.WRITE, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(Read,Commit/Write,Rollback)", LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.RollbackTx, 1, null); + LockModeType.WRITE, Act.RollbackTx, 1, null, null); } public void testLockReadPessimisticRead() { commonLockTest( "testLock(Read,Commit/PessimisticRead,Commit)", - LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null); + LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, null); commonLockTest( "testLock(Read,Commit/PessimisticRead,Rollback)", LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, null); + LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, null, null); } public void testLockReadPessimisticWrite() { commonLockTest( "testLock(Read,Commit/PessimisticWrite,Commit)", - LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null); + LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, null); commonLockTest( "testLock(Read,Commit/PessimisticWrite,Rollback)", LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, null); + LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, null, null); } public void testLockReadPessimisticForceInc() { commonLockTest( "testLock(Read,Commit/PessimisticForceInc,Commit)", LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, null); commonLockTest( "testLock(Read,Commit/PessimisticForceInc,Rollback)", LockModeType.READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, null); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, null, null); } /* ======== Thread 1 : Write Lock ============*/ @@ -94,55 +94,55 @@ public class TestMixedLockManagerLockPermutation extends SequencedActionsTest { commonLockTest( "testLock(Write,Commit/Read,Commit)", LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.READ, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(Write,Commit/Read,Rollback)", LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.READ, Act.RollbackTx, 1, null); + LockModeType.READ, Act.RollbackTx, 1, null, null); } public void testLockWriteWrite() { commonLockTest( "testLock(Write,Commit/Write,Commit)", LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.WRITE, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(Write,Commit/Write,Rollback)", LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.RollbackTx, 1, null); + LockModeType.WRITE, Act.RollbackTx, 1, null, null); } public void testLockWritePessimisticRead() { commonLockTest( "testLock(Write,Commit/PessimisticRead,Commit)", - LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null); + LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, null); commonLockTest( "testLock(Write,Commit/PessimisticRead,Rollback)", LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, null); + LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, null, null); } public void testLockWritePessimisticWrite() { commonLockTest( "testLock(Write,Commit/PessimisticWrite,Commit)", - LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null); + LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, null); commonLockTest( "testLock(Write,Commit/PessimisticWrite,Rollback)", LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, null); + LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, null, null); } public void testLockWritePessimisticForceInc() { commonLockTest( "testLock(Write,Commit/PessimisticForceInc,Commit)", LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, null); commonLockTest( "testLock(Write,Commit/PessimisticForceInc,Rollback)", LockModeType.WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, null); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, null, null); } /* ======== Thread 1 : PessimisticRead Lock ============*/ @@ -150,55 +150,58 @@ public class TestMixedLockManagerLockPermutation extends SequencedActionsTest { commonLockTest( "testLock(PessimisticRead,Commit/Read,Commit)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.READ, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimisticRead,Commit/Read,Rollback)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.READ, Act.RollbackTx, 1, null); + LockModeType.READ, Act.RollbackTx, 1, null, null); } public void testLockPessimisticReadWrite() { commonLockTest( "testLock(PessimisticRead,Commit/Write,Commit)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.WRITE, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimisticRead,Commit/Write,Rollback)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.RollbackTx, 1, null); + LockModeType.WRITE, Act.RollbackTx, 1, null, null); } public void testLockPessimisticReadPessimisticRead() { commonLockTest( "testLock(PessimisticRead,Commit/PessimisticRead,Commit)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimisticRead,Commit/PessimisticRead,Rollback)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, ExpectingOptimisticLockExClass, null); } public void testLockPessimisticReadPessimisticWrite() { commonLockTest( "testLock(PessimisticRead,Commit/PessimisticWrite,Commit)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimisticRead,Commit/PessimisticWrite,Rollback)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, ExpectingOptimisticLockExClass, null); } public void testLockPessimisticReadPessimisticForceInc() { commonLockTest( "testLock(PessimisticRead,Commit/PessimisticForceInc,Commit)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimisticRead,Commit/PessimisticForceInc,Rollback)", LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, ExpectingOptimisticLockExClass, null); } /* ======== Thread 1 : Pessimsitic Write Lock ============*/ @@ -206,55 +209,58 @@ public class TestMixedLockManagerLockPermutation extends SequencedActionsTest { commonLockTest( "testLock(PessimsiticWrite,Commit/Read,Commit)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.READ, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticWrite,Commit/Read,Rollback)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.READ, Act.RollbackTx, 1, null); + LockModeType.READ, Act.RollbackTx, 1, null, null); } public void testLockPessimsiticWriteWrite() { commonLockTest( "testLock(PessimsiticWrite,Commit/Write,Commit)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.WRITE, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticWrite,Commit/Write,Rollback)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.RollbackTx, 1, null); + LockModeType.WRITE, Act.RollbackTx, 1, null, null); } public void testLockPessimsiticWritePessimisticRead() { commonLockTest( "testLock(PessimsiticWrite,Commit/PessimisticRead,Commit)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticWrite,Commit/PessimisticRead,Rollback)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, ExpectingOptimisticLockExClass, null); } public void testLockPessimsiticWritePessimisticWrite() { commonLockTest( "testLock(PessimsiticWrite,Commit/PessimisticWrite,Commit)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticWrite,Commit/PessimisticWrite,Rollback)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, ExpectingOptimisticLockExClass, null); } public void testLockPessimsiticWritePessimisticForceInc() { commonLockTest( "testLock(PessimsiticWrite,Commit/PessimisticForceInc,Commit)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticWrite,Commit/PessimisticForceInc,Rollback)", LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, ExpectingOptimisticLockExClass, null); } /* ======== Thread 1 : Pessimsitic Force Increment Lock ============*/ @@ -262,62 +268,65 @@ public class TestMixedLockManagerLockPermutation extends SequencedActionsTest { commonLockTest( "testLock(PessimsiticForceInc,Commit/Read,Commit)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.READ, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticForceInc,Commit/Read,Rollback)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.READ, Act.RollbackTx, 1, null); + LockModeType.READ, Act.RollbackTx, 1, null, null); } public void testLockPessimsiticForceIncWrite() { commonLockTest( "testLock(PessimsiticForceInc,Commit/Write,Commit)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.WRITE, Act.CommitTx, 1, null, ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticForceInc,Commit/Write,Rollback)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.WRITE, Act.RollbackTx, 1, null); + LockModeType.WRITE, Act.RollbackTx, 1, null, null); } public void testLockPessimsiticForceIncPessimisticRead() { commonLockTest( "testLock(PessimsiticForceInc,Commit/PessimisticRead,Commit)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticForceInc,Commit/PessimisticRead,Rollback)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, ExpectingOptimisticLockExClass, null); } public void testLockPessimsiticForceIncPessimisticWrite() { commonLockTest( "testLock(PessimsiticForceInc,Commit/PessimisticWrite,Commit)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticForceInc,Commit/PessimisticWrite,Rollback)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, ExpectingOptimisticLockExClass, null); } public void testLockPessimsiticForceIncPessimisticForceInc() { commonLockTest( "testLock(PessimsiticForceInc,Commit/PessimisticForceInc,Commit)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, ExpectingOptimisticLockExClass, + ExpectingOptimisticLockExClass); commonLockTest( "testLock(PessimsiticForceInc,Commit/PessimisticForceInc,Rollback)", LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, - LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, ExpectingOptimisticLockExClass); + LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, ExpectingOptimisticLockExClass, null); } private void commonLockTest( String testName, LockModeType t1Lock, Act t1IsCommit, int t1VersionInc, Class[] t1Exceptions, LockModeType t2Lock, Act t2IsCommit, int t2VersionInc, - Class[] t2Exceptions ) { + Class[] t2Exceptions, Class[] t3Exceptions ) { String[] parameters = new String[] { "Thread 1: lock= " + t1Lock + ", isCommit= " + t1IsCommit + ", versionInc= +" + t1VersionInc + @@ -327,53 +336,109 @@ public class TestMixedLockManagerLockPermutation extends SequencedActionsTest { ", expectedEx= " + Arrays.toString(t2Exceptions)}; Object[][] threadMain = { - {Act.CreateEm}, - {Act.Find}, - {Act.SaveVersion}, - {Act.TestEmployee, 1, Default_FirstName}, - - {Act.NewThread, 1 }, - {Act.NewThread, 2 }, - {Act.StartThread, 1 }, - {Act.Wait}, - {Act.StartThread, 2 }, - {Act.Notify, 1, 1000 }, - {Act.Notify, 2, 1000 }, - {Act.WaitAllChildren}, - {Act.Find}, - {Act.TestEmployee, 1}, - {Act.TestException, 1, t1Exceptions }, - {Act.TestException, 2, t2Exceptions }, - }; - Object[][] thread1 = { - {Act.CreateEm}, - {Act.StartTx}, - {Act.Find}, - {Act.SaveVersion}, - {Act.Lock, 1, t1Lock }, - {Act.TestException}, - {Act.Notify, 0}, - {Act.Wait}, - {Act.UpdateEmployee}, - - {t1IsCommit}, - {Act.Find}, - {Act.TestEmployee, 1, null, t1VersionInc} - }; - Object[][] thread2 = { - {Act.CreateEm}, - {Act.StartTx}, - {Act.Find}, - {Act.SaveVersion}, - {Act.Lock, 1, t2Lock }, - {Act.Notify, 0}, - {Act.Wait}, - - {t2IsCommit}, - {Act.Find}, - {Act.TestEmployee, 1, null, t2VersionInc} - }; - launchActionSequence(testName, parameters, threadMain, thread1, - thread2); + {Act.CreateEm}, + {Act.Find}, + {Act.SaveVersion}, + {Act.TestEmployee, 1, Default_FirstName}, + {Act.CloseEm}, + {Act.Sleep, 100}, + + {Act.CreateEm}, + {Act.StartTx}, + {Act.Find}, + {Act.SaveVersion}, + {Act.Lock, 1, t1Lock}, + {Act.TestException}, + + {Act.NewThread, 1 }, + {Act.StartThread, 1 }, + + {Act.Wait}, + {Act.UpdateEmployee}, + {t1IsCommit}, + + {Act.Notify, 1}, + + {Act.Find}, + + {Act.WaitAllChildren}, + {Act.Find}, + {Act.TestEmployee, 1, null, t1VersionInc}, + {Act.TestException, 0, t1Exceptions }, + {Act.TestException, 1, t3Exceptions }, + {Act.CloseEm} + }; + + Object[][] thread1 = { + {Act.CreateEm}, + {Act.StartTx}, + {Act.Find}, + {Act.SaveVersion}, + {Act.Lock, 1, t2Lock}, + {Act.TestException, 1, t2Exceptions}, + {Act.Notify, 0}, + + {Act.Wait}, + {Act.Sleep, 2000}, // sleep for at least 2 sec so that the entity name updated with timestamp + // in each of the 2 threads are different. + {Act.UpdateEmployee}, + + {t2IsCommit}, + {Act.Sleep, 1000}, + {Act.Find}, + {Act.TestEmployee, 1, null, t2VersionInc}, + {Act.CloseEm} + }; + launchActionSequence(testName, parameters, threadMain, thread1); + +// Object[][] threadMain = { +// {Act.CreateEm}, +// {Act.Find}, +// {Act.SaveVersion}, +// {Act.TestEmployee, 1, Default_FirstName}, +// +// {Act.NewThread, 1 }, +// {Act.NewThread, 2 }, +// {Act.StartThread, 1 }, +// {Act.Wait}, +// {Act.StartThread, 2 }, +// {Act.Notify, 1, 1000 }, +// {Act.Notify, 2, 1000 }, +// {Act.WaitAllChildren}, +// {Act.Find}, +// {Act.TestEmployee, 1}, +// {Act.TestException, 1, t1Exceptions }, +// {Act.TestException, 2, t2Exceptions }, +// }; +// Object[][] thread1 = { +// {Act.CreateEm}, +// {Act.StartTx}, +// {Act.Find}, +// {Act.SaveVersion}, +// {Act.Lock, 1, t1Lock }, +// {Act.TestException}, +// {Act.Notify, 0}, +// {Act.Wait}, +// {Act.UpdateEmployee}, +// +// {t1IsCommit}, +// {Act.Find}, +// {Act.TestEmployee, 1, null, t1VersionInc} +// }; +// Object[][] thread2 = { +// {Act.CreateEm}, +// {Act.StartTx}, +// {Act.Find}, +// {Act.SaveVersion}, +// {Act.Lock, 1, t2Lock }, +// {Act.Notify, 0}, +// {Act.Wait}, +// +// {t2IsCommit}, +// {Act.Find}, +// {Act.TestEmployee, 1, null, t2VersionInc} +// }; +// launchActionSequence(testName, parameters, threadMain, thread1, +// thread2); } } diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshBasic.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshBasic.java index 040786872..ef06c8a20 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshBasic.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshBasic.java @@ -116,6 +116,7 @@ public class TestMixedLockManagerRefreshBasic extends SequencedActionsTest { { Act.Clear }, { Act.Find, 1 }, { Act.TestEmployee, 1, lockMode.toString(), 0 }, + { Act.CloseEm } }; launchActionSequence(testName, "LockMode=" + lockMode, threadMain); } diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshException.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshException.java index f599e4bf1..922f8a495 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshException.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshException.java @@ -66,6 +66,7 @@ public class TestMixedLockManagerRefreshException extends SequencedActionsTest { {Act.Refresh, 1, LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, null }, + {Act.CloseEm} }; launchActionSequence("testLockTxReqExceptions()", null, threadMainTxReqTest); @@ -104,6 +105,7 @@ public class TestMixedLockManagerRefreshException extends SequencedActionsTest { {Act.RefreshWithLock, 1, LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, TransactionRequiredException.class }, + {Act.CloseEm} }; launchActionSequence("testLockTxReqExceptions()", null, threadMainTxReqTest); @@ -165,6 +167,7 @@ public class TestMixedLockManagerRefreshException extends SequencedActionsTest { {Act.RefreshObject, "null", LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, IllegalArgumentException.class }, + {Act.CloseEm} }; launchActionSequence("testLockIllegalArgrumentExceptions()", "Test invalid entity.", threadMainInvEntityIllegalArgTest); @@ -204,6 +207,7 @@ public class TestMixedLockManagerRefreshException extends SequencedActionsTest { {Act.Refresh, 2, LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, IllegalArgumentException.class }, + {Act.CloseEm} }; launchActionSequence("testLockIllegalArgrumentExceptions()", "Test detached entity.", threadMainDetachEntityIllegalArgTest); @@ -241,7 +245,8 @@ public class TestMixedLockManagerRefreshException extends SequencedActionsTest { {Act.Refresh, 2, LockModeType.PESSIMISTIC_FORCE_INCREMENT }, {Act.TestException, 0, IllegalArgumentException.class }, - }; + {Act.CloseEm} + }; launchActionSequence("testLockIllegalArgrumentExceptions()", "Test detached entity using serialization.", threadMainDetachSerializeIllegalArgTest); @@ -279,6 +284,7 @@ public class TestMixedLockManagerRefreshException extends SequencedActionsTest { {Act.TestException, 1, IllegalArgumentException.class }, {Act.RollbackTx}, + {Act.CloseEm} }; launchActionSequence( "testLockIllegalArgrumentExceptions()", diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshPermutation.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshPermutation.java index 5a5527c25..f4ef5fe03 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshPermutation.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshPermutation.java @@ -332,6 +332,61 @@ public class TestMixedLockManagerRefreshPermutation String t1Message2 = "Refresh in Thread 1 Again"; String t2Message1 = "Refresh in Thread 2"; +// Object[][] threadMain = { +// {Act.CreateEm}, +// {Act.Find}, +// {Act.SaveVersion}, +// {Act.TestEmployee, 1, Default_FirstName}, +// +// {Act.CloseEm}, +// {Act.Sleep, 100}, +// +// {Act.CreateEm}, +// {Act.StartTx}, +// {Act.RefreshWithLock, 1, t1Lock}, +// {Act.SaveVersion}, +// {Act.TestException}, +// +// {Act.NewThread, 1 }, +// {Act.StartThread, 1 }, +// +// {Act.Wait}, +// {Act.UpdateEmployee}, +// {t1IsCommit}, +// +// {Act.Notify, 1}, +// +// {Act.Find}, +// +// {Act.WaitAllChildren}, +// {Act.Find}, +// {Act.TestEmployee, 1, null, t1VersionInc}, +// {Act.TestException, 0, t1Exceptions }, +// {Act.TestException, 1, t2Exceptions }, +// {Act.CloseEm} +// }; +// +// Object[][] thread1 = { +// {Act.CreateEm}, +// {Act.StartTx}, +// {Act.FindWithLock, 1, t2Lock}, +// {Act.SaveVersion}, +// {Act.TestException}, +// {Act.Notify, 0}, +// +// {Act.Wait}, +// {Act.Sleep, 2000}, // sleep for at least 2 sec so that the entity name updated with timestamp +// // in each of the 2 threads are different. +// {Act.UpdateEmployee}, +// +// {t2IsCommit}, +// {Act.Sleep, 1000}, +// {Act.Find}, +// {Act.TestEmployee, 1, null, t2VersionInc}, +// {Act.CloseEm} +// }; +// launchActionSequence(testName, parameters, threadMain, thread1); + Object[][] threadMain = { {Act.CreateEm}, {Act.Find}, @@ -351,6 +406,7 @@ public class TestMixedLockManagerRefreshPermutation {Act.TestEmployee, 1}, {Act.TestException, 1, t1Exceptions }, {Act.TestException, 2, t2Exceptions }, + {Act.CloseEm} }; Object[][] thread1 = { {Act.CreateEm}, @@ -381,7 +437,8 @@ public class TestMixedLockManagerRefreshPermutation {Act.Clear}, {Act.Find}, - {Act.TestEmployee, 1, null, t1VersionInc} + {Act.TestEmployee, 1, null, t1VersionInc}, + {Act.CloseEm} }; Object[][] thread2 = { {Act.CreateEm}, @@ -406,7 +463,8 @@ public class TestMixedLockManagerRefreshPermutation {Act.Clear}, {Act.Find}, {Act.TestEmployee, 1, null, t2VersionInc}, - }; + {Act.CloseEm} + }; launchActionSequence(testName, parameters, threadMain, thread1, thread2); diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestOptimisticNamedQueryLockMode.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestOptimisticNamedQueryLockMode.java index 2850dd998..4c549e9c4 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestOptimisticNamedQueryLockMode.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestOptimisticNamedQueryLockMode.java @@ -22,8 +22,6 @@ import javax.persistence.EntityManager; import javax.persistence.LockModeType; import javax.persistence.Query; -import org.apache.openjpa.jdbc.conf.JDBCConfiguration; -import org.apache.openjpa.jdbc.sql.DBDictionary; import org.apache.openjpa.persistence.FetchPlan; import org.apache.openjpa.persistence.OpenJPAEntityManager; import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;