You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by al...@apache.org on 2009/04/05 23:29:44 UTC

svn commit: r762161 [4/7] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/ openjpa-kernel/src/main/ja...

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestFetchHints.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindBasic.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindBasic.java?rev=762161&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindBasic.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindBasic.java Sun Apr  5 21:29:42 2009
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.lockmgr;
+
+import javax.persistence.LockModeType;
+
+/**
+ * Test JPA 2.0 em.find(LockMode) behaviors with "mixed" lock manager.
+ */
+public class TestMixedLockManagerFindBasic extends SequencedActionsTest {
+    public void setUp() {
+        setUp(LockEmployee.class
+            , "openjpa.LockManager", "mixed"
+            );
+        commonSetUp();
+    }
+
+    public void testFindRead() {
+        testCommon("testFindRead",
+            LockModeType.READ, 0, 1);
+    }
+
+    public void testFindWrite() {
+        testCommon("testFindWrite",
+            LockModeType.WRITE, 1, 1);
+    }
+
+    public void testFindOptimistic() {
+        testCommon("testFindOptimistic",
+            LockModeType.OPTIMISTIC, 0, 1);
+    }
+
+    public void testFindOptimisticForceInc() {
+        testCommon("testFindOptimisticForceInc",
+            LockModeType.OPTIMISTIC_FORCE_INCREMENT, 1, 1);
+    }
+
+    public void testFindPessimisticRead() {
+        testCommon("testFindPessimisticRead",
+            LockModeType.PESSIMISTIC_READ, 0, 1);
+    }
+
+    public void testFindPessimisticWrite() {
+        testCommon("testFindPessimisticWrite",
+            LockModeType.PESSIMISTIC_WRITE, 0, 1);
+    }
+
+    public void testFindPessimisticForceInc() {
+        testCommon("testFindPessimisticForceInc",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, 1, 1);
+    }
+
+    public void testCommon(String testName, LockModeType lockMode,
+        int commitVersionIncrement, int updateCommitVersionIncrement) {
+        Object[][] threadMain = {
+            // Find entity, no transaction, no update.
+            { Act.CreateEm },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, Default_FirstName},
+
+            // Find entity with lLock, no update and commit.
+            { Act.StartTx },
+            { Act.Clear },
+            { Act.FindWithLock, 1, lockMode },
+            { Act.TestEmployee, 1, Default_FirstName},
+            { Act.SaveVersion },
+            { Act.CommitTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, Default_FirstName,
+                commitVersionIncrement },
+
+            // Find entity with lock, update and commit.
+            { Act.StartTx },
+            { Act.Clear },
+            { Act.FindWithLock, 1, lockMode },
+            { Act.SaveVersion },
+            { Act.TestEmployee, 1, Default_FirstName},
+            { Act.UpdateEmployee, 1, lockMode.toString() },
+            { Act.CommitTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, lockMode.toString(),
+                updateCommitVersionIncrement },
+
+            // Find entity with lock, update but rollback.
+            { Act.StartTx },
+            { Act.Clear },
+            { Act.FindWithLock, 1, lockMode },
+            { Act.SaveVersion },
+            { Act.TestEmployee, 1, lockMode.toString()},
+            { Act.UpdateEmployee, 1, lockMode.toString() + " Again" },
+            { Act.RollbackTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, lockMode.toString(), 0 },
+        };
+
+        launchActionSequence(testName, "LockMode=" + lockMode, threadMain);
+    }
+}
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindBasic.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindException.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindException.java?rev=762161&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindException.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindException.java Sun Apr  5 21:29:42 2009
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.lockmgr;
+
+import javax.persistence.EntityNotFoundException;
+import javax.persistence.LockModeType;
+import javax.persistence.OptimisticLockException;
+import javax.persistence.TransactionRequiredException;
+
+/**
+ * Test JPA 2.0 em.find(LockMode) exception behaviors with "mixed" lock manager.
+ */
+public class TestMixedLockManagerFindException extends SequencedActionsTest {
+    public void setUp() {
+        setUp(LockEmployee.class
+            , "openjpa.LockManager", "mixed"
+        );
+        commonSetUp();
+    }
+
+    /**
+     * TransactionRequiredException if there is no transaction
+     */
+    public void testFindTxReqExceptions() {
+        Object[][] threadMainTxReqTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            
+            {Act.FindWithLock, 1, LockModeType.NONE },
+            {Act.TestException},
+            
+            {Act.FindWithLock, 1, LockModeType.READ },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.FindWithLock, 1, LockModeType.WRITE },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.FindWithLock, 1, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.FindWithLock, 1, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.FindWithLock, 1, LockModeType.PESSIMISTIC_READ},
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.FindWithLock, 1, LockModeType.PESSIMISTIC_WRITE},
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.FindWithLock, 1, LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, TransactionRequiredException.class },
+        };
+        launchActionSequence("testLockTxReqExceptions()",
+            null, threadMainTxReqTest);
+    }
+
+    /*
+     * IllegalArgumentException if the instance is not an entity or is a
+     *      detached entity
+     */
+    public void testFindIllegalArgrumentExceptions() {
+        // Test invalid entity argument throws IllegalArgumentException.
+        Object[][] threadMainInvEntityIllegalArgTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.StartTx},
+      
+            {Act.FindObject, null, 0, LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, Object.class, 0, LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, LockEmployee.class, null, LockModeType.NONE },
+            {Act.TestException, 0, EntityNotFoundException.class },
+            {Act.FindObject, LockEmployee.class, Boolean.TRUE,
+                LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.FindObject, null, 0, LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, Object.class, 0, LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, LockEmployee.class, null, LockModeType.READ },
+            {Act.TestException, 0, EntityNotFoundException.class },
+            {Act.FindObject, LockEmployee.class, Boolean.TRUE,
+                LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.FindObject, null, 0, LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, Object.class, 0, LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, LockEmployee.class, null, LockModeType.WRITE },
+            {Act.TestException, 0, EntityNotFoundException.class },
+            {Act.FindObject, LockEmployee.class, Boolean.TRUE,
+                LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.FindObject, null, 0, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, Object.class, 0, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, LockEmployee.class, null,
+                LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, EntityNotFoundException.class },
+            {Act.FindObject, LockEmployee.class, Boolean.TRUE,
+                LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.FindObject, null, 0,
+                LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, Object.class, 0, 
+                LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, LockEmployee.class, null,
+                LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, EntityNotFoundException.class },
+            {Act.FindObject, LockEmployee.class, Boolean.TRUE,
+                LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.FindObject, null, 0,
+                LockModeType.PESSIMISTIC_READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, Object.class, 0,
+                LockModeType.PESSIMISTIC_READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.FindObject, LockEmployee.class, null,
+                LockModeType.PESSIMISTIC_READ },
+            {Act.TestException, 0, EntityNotFoundException.class },
+            {Act.FindObject, LockEmployee.class, Boolean.TRUE,
+                LockModeType.PESSIMISTIC_READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.FindObject, null, 0,
+                LockModeType.PESSIMISTIC_WRITE },
+            {Act.TestException, 0,
+                    IllegalArgumentException.class },
+            {Act.FindObject, Object.class, 0,
+                LockModeType.PESSIMISTIC_WRITE },
+            {Act.TestException, 0,
+                    IllegalArgumentException.class },
+            {Act.FindObject, LockEmployee.class, null,
+                LockModeType.PESSIMISTIC_WRITE },
+            {Act.TestException, 0,
+                    EntityNotFoundException.class },
+            {Act.FindObject, LockEmployee.class, Boolean.TRUE,
+                LockModeType.PESSIMISTIC_WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.FindObject, null, 0,
+                LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0,
+                IllegalArgumentException.class },
+            {Act.FindObject, Object.class, 0,
+                LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0,
+                IllegalArgumentException.class },
+            {Act.FindObject, LockEmployee.class, null,
+                LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, EntityNotFoundException.class },
+            {Act.FindObject, LockEmployee.class, Boolean.TRUE, 
+                LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+        };
+        launchActionSequence("testLockIllegalArgrumentExceptions()",
+            "Test invalid entity.", threadMainInvEntityIllegalArgTest);
+    }
+    
+    /*
+     * If a pessimistic lock mode type is specified and the entity
+     * contains a version attribute, the persistence provider must
+     * also perform optimistic version checks when obtaining the
+     * database lock. If these checks fail, the
+     * OptimisticLockException will be thrown.
+     */
+    public void testLockOptimisticLockExceptions() {
+        commonLockOptimisticLockExceptions(
+            LockModeType.NONE, true, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.READ, true, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.WRITE, true, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.OPTIMISTIC, true, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.OPTIMISTIC_FORCE_INCREMENT, true, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.PESSIMISTIC_READ, false, true);
+        commonLockOptimisticLockExceptions(
+            LockModeType.PESSIMISTIC_WRITE, false, true);
+        commonLockOptimisticLockExceptions(
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, false, true);
+    }
+    
+    public void commonLockOptimisticLockExceptions(LockModeType lockMode,
+        boolean expectingOptLockException1, 
+        boolean expectingOptLockException2) {
+        Object[][] threadMainOptLockExTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.Clear},
+            
+            {Act.NewThread, 1 },
+            {Act.StartThread, 1 },
+            {Act.Wait},
+            
+            {Act.StartTx},
+            {Act.FindWithLock, 1, lockMode},
+            {Act.UpdateEmployee},
+            {Act.Notify, 1},
+            {Act.Wait},
+            {Act.CommitTx},
+            
+            {Act.WaitAllChildren},
+            {Act.TestException, 0, expectingOptLockException1
+                ? OptimisticLockException.class : null},
+            {Act.TestException, 1, expectingOptLockException2
+                    ? OptimisticLockException.class : null},
+        };
+        Object[][] thread1OptLockExTest = {
+            {Act.CreateEm},
+            {Act.StartTx},
+            {Act.FindWithLock, 1, LockModeType.OPTIMISTIC},
+            {Act.SaveVersion},
+            {Act.UpdateEmployee},
+            
+            {Act.Notify, 0},
+            {Act.Wait},
+            
+            {Act.CommitTx},
+            {Act.Notify, 0},
+        };        
+        launchActionSequence("testLockOptimisticLockExceptions()", null,
+            threadMainOptLockExTest, thread1OptLockExTest);
+    }
+}
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindPermutation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindPermutation.java?rev=762161&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindPermutation.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindPermutation.java Sun Apr  5 21:29:42 2009
@@ -0,0 +1,384 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.lockmgr;
+
+import java.util.Arrays;
+
+import javax.persistence.LockModeType;
+
+/**
+ * Test JPA 2.0 LockMode type permutation behaviors with "mixed" lock manager.
+ */
+public class TestMixedLockManagerFindPermutation extends SequencedActionsTest {
+    public void setUp() {
+        setUp(LockEmployee.class
+            , "openjpa.LockManager", "mixed"
+        );
+        commonSetUp();
+    }
+
+    /* ======== Thread 1 : Read Lock ============*/
+    public void testFindReadRead() {
+        commonFindTest(
+            "testFind(Read,Commit/Read,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(Read,Commit/Read,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindReadWrite() {
+        commonFindTest(
+            "testFind(Read,Commit/Write,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0,
+                ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(Read,Commit/Write,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindReadPessimisticRead() {
+        commonFindTest(
+            "testFind(Read,Commit/PessimisticRead,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null);
+        commonFindTest(
+            "testFind(Read,Commit/PessimisticRead,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindReadPessimisticWrite() {
+        commonFindTest(
+            "testFind(Read,Commit/PessimisticWrite,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null);
+        commonFindTest(
+            "testFind(Read,Commit/PessimisticWrite,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindReadPessimisticForceInc() {
+        commonFindTest(
+            "testFind(Read,Commit/PessimisticForceInc,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null);
+        commonFindTest(
+            "testFind(Read,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, null);
+    }
+    
+    /* ======== Thread 1 : Write Lock ============*/
+    public void testFindWriteRead() {
+        commonFindTest(
+            "testFind(Write,Commit/Read,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(Write,Commit/Read,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindWriteWrite() {
+        commonFindTest(
+            "testFind(Write,Commit/Write,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0,
+                ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(Write,Commit/Write,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindWritePessimisticRead() {
+        commonFindTest(
+            "testFind(Write,Commit/PessimisticRead,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null);
+        commonFindTest(
+            "testFind(Write,Commit/PessimisticRead,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindWritePessimisticWrite() {
+        commonFindTest(
+            "testFind(Write,Commit/PessimisticWrite,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null);
+        commonFindTest(
+            "testFind(Write,Commit/PessimisticWrite,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindWritePessimisticForceInc() {
+        commonFindTest(
+            "testFind(Write,Commit/PessimisticForceInc,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null);
+        commonFindTest(
+            "testFind(Write,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, null);
+    }
+    
+    /* ======== Thread 1 : PessimisticRead Lock ============*/
+    public void testFindPessimisticReadRead() {
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/Read,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/Read,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindPessimisticReadWrite() {
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/Write,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0, 
+                ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/Write,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindPessimisticReadPessimisticRead() {
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/PessimisticRead,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null);
+//                ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/PessimisticRead,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 0, null); 
+//                ExpectingOptimisticLockExClass);
+    }
+    
+    public void testFindPessimisticReadPessimisticWrite() {
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/PessimisticWrite,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null); 
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/PessimisticWrite,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 0, null);
+    }
+    
+    public void testFindPessimisticReadPessimisticForceInc() {
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/PessimisticForceInc,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null);
+        commonFindTest(
+            "testFind(PessimisticRead,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 0, null);
+    }
+    
+    /* ======== Thread 1 : Pessimsitic Write Lock ============*/
+    public void testFindPessimsiticWriteRead() {
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/Read,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/Read,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindPessimsiticWriteWrite() {
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/Write,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0, 
+                ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/Write,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindPessimsiticWritePessimisticRead() {
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/PessimisticRead,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null); 
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/PessimisticRead,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 0, null); 
+    }
+    
+    public void testFindPessimsiticWritePessimisticWrite() {
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/PessimisticWrite,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null); 
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/PessimisticWrite,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 0, null); 
+    }
+    
+    public void testFindPessimsiticWritePessimisticForceInc() {
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/PessimisticForceInc,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null); 
+        commonFindTest(
+            "testFind(PessimsiticWrite,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 0, null);
+    }
+    
+    /* ======== Thread 1 : Pessimsitic Force Increment Lock ============*/
+    public void testFindPessimsiticForceIncRead() {
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/Read,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/Read,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindPessimsiticForceIncWrite() {
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/Write,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0,
+                ExpectingOptimisticLockExClass);
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/Write,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testFindPessimsiticForceIncPessimisticRead() {
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/PessimisticRead,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null); 
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/PessimisticRead,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 0, null); 
+    }
+    
+    public void testFindPessimsiticForceIncPessimisticWrite() {
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/PessimisticWrite,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null);
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/PessimisticWrite,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 0, null); 
+    }
+    
+    public void testFindPessimsiticForceIncPessimisticForceInc() {
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/PessimisticForceInc,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null); 
+        commonFindTest(
+            "testFind(PessimsiticForceInc,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 0, null);
+    }
+
+    private void commonFindTest( String testName, 
+        LockModeType t1Lock, Act t1IsCommit, int t1VersionInc, 
+            Class<?>[] t1Exceptions, 
+        LockModeType t2Lock, Act t2IsCommit, int t2VersionInc,
+            Class<?>[] t2Exceptions ) {
+        String[] parameters = new String[] {
+            "Thread 1: lock= " + t1Lock + ", isCommit= " + t1IsCommit +
+                ", versionInc= +" + t1VersionInc +
+                ", expectedEx= " + Arrays.toString(t1Exceptions),
+            "Thread 2: lock= " + t2Lock + ", isCommit= " + t2IsCommit + 
+                ", versionInc= +" + t2VersionInc +
+                ", 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);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerFindPermutation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockBasic.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockBasic.java?rev=762161&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockBasic.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockBasic.java Sun Apr  5 21:29:42 2009
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.lockmgr;
+
+import javax.persistence.LockModeType;
+
+/**
+ * Test JPA 2.0 em.lock(LockMode) basic behaviors with "mixed" lock manager.
+ */
+public class TestMixedLockManagerLockBasic extends SequencedActionsTest {
+    public void setUp() {
+        setUp(LockEmployee.class
+            , "openjpa.LockManager", "mixed"
+            );
+        commonSetUp();
+    }
+
+    public void testLockRead() {
+        testCommon("testLockRead",
+            LockModeType.READ, 0, 1);
+    }
+
+    public void testLockWrite() {
+        testCommon("testLockWrite",
+            LockModeType.WRITE, 1, 1);
+    }
+
+    public void testLockOptimistic() {
+        testCommon("testLockOptimistic",
+            LockModeType.OPTIMISTIC, 0, 1);
+    }
+
+    public void testLockOptimisticForceInc() {
+        testCommon("testLockOptimisticForceInc",
+            LockModeType.OPTIMISTIC_FORCE_INCREMENT, 1, 1);
+    }
+
+    public void testLockPessimisticRead() {
+        testCommon("testLockPessimisticRead",
+            LockModeType.PESSIMISTIC_READ, 0, 1);
+    }
+
+    public void testLockPessimisticWrite() {
+        testCommon("testLockPessimisticWrite",
+            LockModeType.PESSIMISTIC_WRITE, 0, 1);
+    }
+
+    public void testLockPessimisticForceInc() {
+        testCommon("testLockPessimisticForceInc",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, 1, 1);
+    }
+
+    public void testCommon(String testName, LockModeType lockMode,
+        int commitVersionIncrement, int updateCommitVersionIncrement) {
+        Object[][] threadMain = {
+            // Find entity, lock, no update and commit.
+            { Act.CreateEm },
+            { Act.StartTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, Default_FirstName},
+            { Act.SaveVersion },
+            { Act.Lock, 1, lockMode },
+            { Act.CommitTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, Default_FirstName,
+                commitVersionIncrement },
+
+            // Find entity, lock, update and commit.
+            { Act.StartTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, Default_FirstName},
+            { Act.SaveVersion },
+            { Act.Lock, 1, lockMode },
+            { Act.UpdateEmployee, 1, lockMode.toString() },
+            { Act.CommitTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, lockMode.toString(),
+                updateCommitVersionIncrement },
+
+            // Find entity, lock, update but rollback.
+            { Act.StartTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, lockMode.toString()},
+            { Act.SaveVersion },
+            { Act.Lock, 1, lockMode },
+            { Act.UpdateEmployee, 1, lockMode.toString() + " Again" },
+            { Act.RollbackTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, lockMode.toString(), 0 },
+        };
+        launchActionSequence(testName, "LockMode=" + lockMode, threadMain);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockBasic.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockException.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockException.java?rev=762161&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockException.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockException.java Sun Apr  5 21:29:42 2009
@@ -0,0 +1,316 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.lockmgr;
+
+import javax.persistence.LockModeType;
+import javax.persistence.OptimisticLockException;
+import javax.persistence.TransactionRequiredException;
+
+/**
+ * Test JPA 2.0 em.lock(LockMode) exception behaviors with "mixed" lock manager.
+ */
+public class TestMixedLockManagerLockException extends SequencedActionsTest {
+    public void setUp() {
+        setUp(LockEmployee.class
+            , "openjpa.LockManager", "mixed"
+        );
+        commonSetUp();
+    }
+
+    /**
+     * TransactionRequiredException if there is no transaction
+     */
+    public void testLockTxReqExceptions() {
+        Object[][] threadMainTxReqTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            
+            {Act.Lock, 1, LockModeType.NONE },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Lock, 1, LockModeType.READ },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Lock, 1, LockModeType.WRITE },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Lock, 1, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Lock, 1, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Lock, 1, LockModeType.PESSIMISTIC_READ},
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Lock, 1, LockModeType.PESSIMISTIC_WRITE},
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Lock, 1, LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, TransactionRequiredException.class },
+        };
+        
+        launchActionSequence("testLockTxReqExceptions()",
+            null, threadMainTxReqTest);
+    }
+
+    /*
+     * IllegalArgumentException if the instance is not an entity or is a
+     *      detached entity
+     */
+    public void testLockIllegalArgrumentExceptions() {
+        // Test invalid entity argument throws IllegalArgumentException.
+        Object[][] threadMainInvEntityIllegalArgTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.StartTx},
+      
+            {Act.LockObject, null, LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.LockObject, "null", LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.LockObject, null, LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.LockObject, "null", LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.LockObject, null, LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.LockObject, "null", LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.LockObject, null, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.LockObject, "null", LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.LockObject, null, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.LockObject, "null", LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.LockObject, null, LockModeType.PESSIMISTIC_READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.LockObject, "null", LockModeType.PESSIMISTIC_READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.LockObject, null, LockModeType.PESSIMISTIC_WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.LockObject, "null", LockModeType.PESSIMISTIC_WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.LockObject, null, LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.LockObject, "null", LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+        };
+        launchActionSequence("testLockIllegalArgrumentExceptions()",
+            "Test invalid entity.", threadMainInvEntityIllegalArgTest);
+        
+        // Test detached entity argument throws IllegalArgumentException.
+        Object[][] threadMainDetachEntityIllegalArgTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.StartTx},
+            {Act.Detach, 1, 2},
+            
+            {Act.Lock, 2, LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.Lock, 2, LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+          
+            {Act.Lock, 2, LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.PESSIMISTIC_READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.PESSIMISTIC_WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+        };
+        launchActionSequence("testLockIllegalArgrumentExceptions()",
+            "Test detached entity.", threadMainDetachEntityIllegalArgTest);
+
+        // Test detached argument from serialized entity throws 
+        //  IllegalArgumentException.
+        Object[][] threadMainDetachSerializeIllegalArgTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.StartTx},
+            {Act.DetachSerialize, 1, 2},
+            
+            {Act.Lock, 2, LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+        
+            {Act.Lock, 2, LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.PESSIMISTIC_READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.PESSIMISTIC_WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Lock, 2, LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+        };        
+        launchActionSequence("testLockIllegalArgrumentExceptions()",
+            "Test detached entity using serialization.",
+            threadMainDetachSerializeIllegalArgTest);
+        
+        Object[][] threadMainRemoveIllegalArgTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.StartTx},
+            {Act.Remove},
+
+            {Act.Lock, 1, LockModeType.NONE },
+            {Act.TestException},
+      
+            {Act.Lock, 1, LockModeType.READ },
+            {Act.TestException},
+
+            {Act.Lock, 1, LockModeType.WRITE },
+            {Act.TestException},
+
+            {Act.Lock, 1, LockModeType.OPTIMISTIC },
+            {Act.TestException},
+
+            {Act.Lock, 1, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException},
+
+            {Act.Lock, 1, LockModeType.PESSIMISTIC_READ },
+            {Act.TestException},
+
+            {Act.Lock, 1, LockModeType.PESSIMISTIC_WRITE },
+            {Act.TestException},
+
+            {Act.Lock, 1, LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException},
+            
+            {Act.RollbackTx},
+        };
+        launchActionSequence(
+            "testLockIllegalArgrumentExceptions()",
+            "Test removed entity - no exception since it is still "
+                +"in the context.",
+            threadMainRemoveIllegalArgTest);
+    }
+    
+    /*
+     * If a pessimistic lock mode type is specified and the entity
+     * contains a version attribute, the persistence provider must
+     * also perform optimistic version checks when obtaining the
+     * database lock. If these checks fail, the
+     * OptimisticLockException will be thrown.
+     */
+    public void testLockOptimisticLockExceptions() {
+        commonLockOptimisticLockExceptions(
+            LockModeType.NONE, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.READ, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.WRITE, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.OPTIMISTIC, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.OPTIMISTIC_FORCE_INCREMENT, false);
+        commonLockOptimisticLockExceptions(
+            LockModeType.PESSIMISTIC_READ, true);
+        commonLockOptimisticLockExceptions(
+            LockModeType.PESSIMISTIC_WRITE, true);
+        commonLockOptimisticLockExceptions(
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, true);
+    }
+    
+    public void commonLockOptimisticLockExceptions(LockModeType lockMode,
+        boolean expectingOptLockException) {
+        Object[][] threadMainOptLockExTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.Clear},
+            
+            {Act.NewThread, 1 },
+            {Act.StartThread, 1 },
+            {Act.Wait},
+            
+            {Act.StartTx},
+            {Act.Find},
+            {Act.Notify, 1},
+            
+            {Act.Wait},
+            {Act.Lock, 1, lockMode},
+            {Act.WaitAllChildren},
+            {Act.TestException, 0, expectingOptLockException
+                ? OptimisticLockException.class : null},
+            
+            {Act.RollbackTx},
+        };
+        Object[][] thread1OptLockExTest = {
+            {Act.CreateEm},
+            {Act.StartTx},
+            {Act.Find},
+            {Act.SaveVersion},
+            
+            {Act.Notify, 0},
+            {Act.Wait},
+            {Act.UpdateEmployee},
+            
+            {Act.CommitTx},
+            {Act.Notify, 0},
+        };        
+        launchActionSequence("testLockOptimisticLockExceptions()", null,
+            threadMainOptLockExTest, thread1OptLockExTest);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockPermutation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockPermutation.java?rev=762161&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockPermutation.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockPermutation.java Sun Apr  5 21:29:42 2009
@@ -0,0 +1,402 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.lockmgr;
+
+import java.util.Arrays;
+
+import javax.persistence.LockModeType;
+
+/**
+ * Test JPA 2.0 LockMode type permutation behaviors with "mixed" lock manager.
+ */
+public class TestMixedLockManagerLockPermutation extends SequencedActionsTest {
+    public void setUp() {
+        setUp(LockEmployee.class
+            , "openjpa.LockManager", "mixed"
+        );
+        commonSetUp();
+    }
+
+    /* ======== Thread 1 : Read Lock ============*/
+    public void testLockReadRead() {
+        commonLockTest(
+            "testLock(Read,Commit/Read,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(Read,Commit/Read,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockReadWrite() {
+        commonLockTest(
+            "testLock(Read,Commit/Write,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0,
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(Read,Commit/Write,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockReadPessimisticRead() {
+        commonLockTest(
+            "testLock(Read,Commit/PessimisticRead,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null);
+        commonLockTest(
+            "testLock(Read,Commit/PessimisticRead,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockReadPessimisticWrite() {
+        commonLockTest(
+            "testLock(Read,Commit/PessimisticWrite,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null);
+        commonLockTest(
+            "testLock(Read,Commit/PessimisticWrite,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockReadPessimisticForceInc() {
+        commonLockTest(
+            "testLock(Read,Commit/PessimisticForceInc,Commit)",
+            LockModeType.READ, Act.CommitTx, 1, ExpectingOptimisticLockExClass, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null);
+        commonLockTest(
+            "testLock(Read,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, null);
+    }
+    
+    /* ======== Thread 1 : Write Lock ============*/
+    public void testLockWriteRead() {
+        commonLockTest(
+            "testLock(Write,Commit/Read,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(Write,Commit/Read,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockWriteWrite() {
+        commonLockTest(
+            "testLock(Write,Commit/Write,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0,
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(Write,Commit/Write,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockWritePessimisticRead() {
+        commonLockTest(
+            "testLock(Write,Commit/PessimisticRead,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 0, null);
+        commonLockTest(
+            "testLock(Write,Commit/PessimisticRead,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockWritePessimisticWrite() {
+        commonLockTest(
+            "testLock(Write,Commit/PessimisticWrite,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 0, null);
+        commonLockTest(
+            "testLock(Write,Commit/PessimisticWrite,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockWritePessimisticForceInc() {
+        commonLockTest(
+            "testLock(Write,Commit/PessimisticForceInc,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 1, ExpectingOptimisticLockExClass, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null);
+        commonLockTest(
+            "testLock(Write,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, null);
+    }
+    
+    /* ======== Thread 1 : PessimisticRead Lock ============*/
+    public void testLockPessimisticReadRead() {
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/Read,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/Read,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockPessimisticReadWrite() {
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/Write,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0, 
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/Write,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockPessimisticReadPessimisticRead() {
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/PessimisticRead,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, 
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/PessimisticRead,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, 
+                ExpectingOptimisticLockExClass);
+    }
+    
+    public void testLockPessimisticReadPessimisticWrite() {
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/PessimisticWrite,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, 
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/PessimisticWrite,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1,
+                ExpectingOptimisticLockExClass);
+    }
+    
+    public void testLockPessimisticReadPessimisticForceInc() {
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/PessimisticForceInc,Commit)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2,
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimisticRead,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1,
+                ExpectingOptimisticLockExClass);
+    }
+    
+    /* ======== Thread 1 : Pessimsitic Write Lock ============*/
+    public void testLockPessimsiticWriteRead() {
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/Read,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/Read,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockPessimsiticWriteWrite() {
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/Write,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0, 
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/Write,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockPessimsiticWritePessimisticRead() {
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/PessimisticRead,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_READ, Act.CommitTx, 1, 
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/PessimisticRead,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, 
+                ExpectingOptimisticLockExClass);
+    }
+    
+    public void testLockPessimsiticWritePessimisticWrite() {
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/PessimisticWrite,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, 
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/PessimisticWrite,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, 
+                ExpectingOptimisticLockExClass);
+    }
+    
+    public void testLockPessimsiticWritePessimisticForceInc() {
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/PessimisticForceInc,Commit)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, 
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimsiticWrite,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1,
+                ExpectingOptimisticLockExClass);
+    }
+    
+    /* ======== Thread 1 : Pessimsitic Force Increment Lock ============*/
+    public void testLockPessimsiticForceIncRead() {
+        commonLockTest(
+            "testLock(PessimsiticForceInc,Commit/Read,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimsiticForceInc,Commit/Read,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.READ, Act.RollbackTx, 1, null);
+    }
+    
+    public void testLockPessimsiticForceIncWrite() {
+        commonLockTest(
+            "testLock(PessimsiticForceInc,Commit/Write,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.CommitTx, 0,
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimsiticForceInc,Commit/Write,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.WRITE, Act.RollbackTx, 1, 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);
+        commonLockTest(
+            "testLock(PessimsiticForceInc,Commit/PessimisticRead,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_READ, Act.RollbackTx, 1, 
+                ExpectingOptimisticLockExClass);
+    }
+    
+    public void testLockPessimsiticForceIncPessimisticWrite() {
+        commonLockTest(
+            "testLock(PessimsiticForceInc,Commit/PessimisticWrite,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_WRITE, Act.CommitTx, 1, 
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimsiticForceInc,Commit/PessimisticWrite,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_WRITE, Act.RollbackTx, 1, 
+                ExpectingOptimisticLockExClass);
+    }
+    
+    public void testLockPessimsiticForceIncPessimisticForceInc() {
+        commonLockTest(
+            "testLock(PessimsiticForceInc,Commit/PessimisticForceInc,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, 
+                ExpectingOptimisticLockExClass);
+        commonLockTest(
+            "testLock(PessimsiticForceInc,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 1, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 1, 
+                ExpectingOptimisticLockExClass);
+    }
+
+    private void commonLockTest( String testName, 
+        LockModeType t1Lock, Act t1IsCommit, int t1VersionInc, 
+            Class<?>[] t1Exceptions, 
+        LockModeType t2Lock, Act t2IsCommit, int t2VersionInc,
+            Class<?>[] t2Exceptions ) {
+        String[] parameters = new String[] {
+            "Thread 1: lock= " + t1Lock + ", isCommit= " + t1IsCommit +
+                ", versionInc= +" + t1VersionInc +
+                ", expectedEx= " + Arrays.toString(t1Exceptions),
+            "Thread 2: lock= " + t2Lock + ", isCommit= " + t2IsCommit + 
+                ", versionInc= +" + t2VersionInc +
+                ", 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);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerLockPermutation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshBasic.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshBasic.java?rev=762161&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshBasic.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshBasic.java Sun Apr  5 21:29:42 2009
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.lockmgr;
+
+import javax.persistence.LockModeType;
+
+/**
+ * Test JPA 2.0 em.refresh(LockMode) basic behaviors with "mixed" lock manager.
+ */
+public class TestMixedLockManagerRefreshBasic extends SequencedActionsTest {
+    public void setUp() {
+        setUp(LockEmployee.class
+            , "openjpa.LockManager", "mixed"
+            );
+        commonSetUp();
+    }
+
+    public void testRefreshRead() {
+        testCommon("testRefreshRead",
+            LockModeType.READ, 0, 1);
+    }
+
+    public void testRefreshWrite() {
+        testCommon("testRefreshWrite",
+            LockModeType.WRITE, 1, 1);
+    }
+
+    public void testRefreshOptimistic() {
+        testCommon("testRefreshOptimistic",
+            LockModeType.OPTIMISTIC, 0, 1);
+    }
+
+    public void testRefreshOptimisticForceInc() {
+        testCommon("testRefreshOptimisticForceInc",
+            LockModeType.OPTIMISTIC_FORCE_INCREMENT, 1, 1);
+    }
+
+    public void testRefreshPessimisticRead() {
+        testCommon("testRefreshPessimisticRead",
+            LockModeType.PESSIMISTIC_READ, 0, 1);
+    }
+
+    public void testRefreshPessimisticWrite() {
+        testCommon("testRefreshPessimisticWrite",
+            LockModeType.PESSIMISTIC_WRITE, 0, 1);
+    }
+
+    public void testRefreshPessimisticForceInc() {
+        testCommon("testRefreshPessimisticForceInc",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, 1, 1);
+    }
+
+    public void testCommon(String testName, LockModeType lockMode,
+        int commitVersionIncrement, int updateCommitVersionIncrement) {
+        Object[][] threadMain = {
+            // Find entity, refresh with Lock, no update and commit.
+            { Act.CreateEm },
+            { Act.StartTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, Default_FirstName},
+            { Act.SaveVersion },
+            { Act.RefreshWithLock, 1, lockMode },
+            { Act.TestEmployee, 1, Default_FirstName},
+            { Act.CommitTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, Default_FirstName,
+                commitVersionIncrement },
+
+            // Find entity, refresh with Lock, update and commit.
+            { Act.StartTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, Default_FirstName},
+            { Act.SaveVersion },
+            { Act.UpdateEmployee, 1, "New Name 2"},
+            { Act.TestEmployee, 1, "New Name 2"},
+            { Act.RefreshWithLock, 1, lockMode },
+            { Act.TestEmployee, 1, Default_FirstName, 0},
+            { Act.UpdateEmployee, 1, lockMode.toString()},
+            { Act.CommitTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, lockMode.toString(),
+                updateCommitVersionIncrement },
+
+            // Find entity, refresh with Lock, update and rollback.
+            { Act.StartTx },
+            { Act.Clear },
+            { Act.Find, 1},
+            { Act.TestEmployee, 1, lockMode.toString()},
+            { Act.SaveVersion },
+            { Act.UpdateEmployee, 1, "New Name 3"},
+            { Act.TestEmployee, 1, "New Name 3", 0},
+            { Act.RefreshWithLock, 1, lockMode },
+            { Act.TestEmployee, 1, lockMode.toString(), 0},
+            { Act.UpdateEmployee, 1, lockMode.toString() + " Again" },
+            { Act.RollbackTx },
+            { Act.Clear },
+            { Act.Find, 1 },
+            { Act.TestEmployee, 1, lockMode.toString(), 0 },
+        };
+        launchActionSequence(testName, "LockMode=" + lockMode, threadMain);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/TestMixedLockManagerRefreshBasic.java
------------------------------------------------------------------------------
    svn:eol-style = native