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/03/11 00:41:04 UTC

svn commit: r752306 [2/3] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/ openjpa-per...

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerLockPermutationTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerLockPermutationTest.java?rev=752306&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerLockPermutationTest.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerLockPermutationTest.java Tue Mar 10 23:41:03 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 MixedLockManagerLockPermutationTest 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/MixedLockManagerLockPermutationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshBasicTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshBasicTest.java?rev=752306&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshBasicTest.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshBasicTest.java Tue Mar 10 23:41:03 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 MixedLockManagerRefreshBasicTest 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/MixedLockManagerRefreshBasicTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshExceptionTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshExceptionTest.java?rev=752306&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshExceptionTest.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshExceptionTest.java Tue Mar 10 23:41:03 2009
@@ -0,0 +1,251 @@
+/*
+ * 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.TransactionRequiredException;
+
+/**
+ * Test JPA 2.0 em.refresh(LockMode) exception behaviors with "mixed"
+ * lock manager.
+ */
+public class MixedLockManagerRefreshExceptionTest extends SequencedActionsTest {
+    public void setUp() {
+        setUp(LockEmployee.class
+            , "openjpa.LockManager", "mixed"
+        );
+        commonSetUp();
+    }
+
+    /**
+     * TransactionRequiredException if there is no transaction
+     */
+    public void testRefreshTxReqExceptions() {
+        Object[][] threadMainTxReqTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            
+            {Act.Refresh, 1, LockModeType.NONE },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Refresh, 1, LockModeType.READ },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Refresh, 1, LockModeType.WRITE },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Refresh, 1, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Refresh, 1, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Refresh, 1, LockModeType.PESSIMISTIC/*_READ*/},
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Refresh, 1, LockModeType.PESSIMISTIC/*_WRITE*/},
+            {Act.TestException, 0, TransactionRequiredException.class },
+            
+            {Act.Refresh, 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 testRefreshIllegalArgrumentExceptions() {
+        // Test invalid entity argument throws IllegalArgumentException.
+        Object[][] threadMainInvEntityIllegalArgTest = {
+            {Act.CreateEm},
+            {Act.Find},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.StartTx},
+      
+            {Act.RefreshObject, null, LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.RefreshObject, "null", LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.RefreshObject, null, LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.RefreshObject, "null", LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.RefreshObject, null, LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.RefreshObject, "null", LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.RefreshObject, null, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.RefreshObject, "null", LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.RefreshObject, null, 
+                LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.RefreshObject, "null", 
+                LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.RefreshObject, null, LockModeType.PESSIMISTIC/*_READ*/ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.RefreshObject, "null", LockModeType.PESSIMISTIC/*_READ*/ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.RefreshObject, null, LockModeType.PESSIMISTIC/*_WRITE*/ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.RefreshObject, "null", LockModeType.PESSIMISTIC/*_WRITE*/ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.RefreshObject, null, 
+                LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            {Act.RefreshObject, "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.Refresh, 2, LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+            
+            {Act.Refresh, 2, LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+          
+            {Act.Refresh, 2, LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.PESSIMISTIC/*_READ*/ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.PESSIMISTIC/*_WRITE*/ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 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.Refresh, 2, LockModeType.NONE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+        
+            {Act.Refresh, 2, LockModeType.READ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.WRITE },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.OPTIMISTIC },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.PESSIMISTIC/*_READ*/ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 2, LockModeType.PESSIMISTIC/*_WRITE*/ },
+            {Act.TestException, 0, IllegalArgumentException.class },
+
+            {Act.Refresh, 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.Refresh, 1, LockModeType.NONE },
+            {Act.TestException},
+      
+            {Act.Refresh, 1, LockModeType.READ },
+            {Act.TestException},
+
+            {Act.Refresh, 1, LockModeType.WRITE },
+            {Act.TestException},
+
+            {Act.Refresh, 1, LockModeType.OPTIMISTIC },
+            {Act.TestException},
+
+            {Act.Refresh, 1, LockModeType.OPTIMISTIC_FORCE_INCREMENT },
+            {Act.TestException},
+
+            {Act.Refresh, 1, LockModeType.PESSIMISTIC/*_READ*/ },
+            {Act.TestException},
+
+            {Act.Refresh, 1, LockModeType.PESSIMISTIC/*_WRITE*/ },
+            {Act.TestException},
+
+            {Act.Refresh, 1, LockModeType.PESSIMISTIC_FORCE_INCREMENT },
+            {Act.TestException},
+            
+            {Act.RollbackTx},
+        };
+        launchActionSequence(
+            "testLockIllegalArgrumentExceptions()",
+            "Test removed entity - no exception since it is still "
+                + "in the context.",
+            threadMainRemoveIllegalArgTest);
+    }
+}

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

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshPermutationTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshPermutationTest.java?rev=752306&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshPermutationTest.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lockmgr/MixedLockManagerRefreshPermutationTest.java Tue Mar 10 23:41:03 2009
@@ -0,0 +1,420 @@
+/*
+ * 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 MixedLockManagerRefreshPermutationTest 
+    extends SequencedActionsTest {
+    public void setUp() {
+        setUp(LockEmployee.class
+            , "openjpa.LockManager", "mixed"
+        );
+        commonSetUp();
+    }
+
+    /* ======== Thread 1 : Read Lock ============*/
+    public void testRefreshReadRead() {
+        commonRefreshTest(
+            "testRefresh(Read,Commit/Read,Commit)",
+            LockModeType.READ, Act.CommitTx, 2, null, 
+            LockModeType.READ, Act.CommitTx, 2, ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(Read,Commit/Read,Rollback)",
+            LockModeType.READ, Act.CommitTx, 2, null,
+            LockModeType.READ, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshReadWrite() {
+        commonRefreshTest(
+            "testRefresh(Read,Commit/Write,Commit)",
+            LockModeType.READ, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.CommitTx, 2,
+                ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(Read,Commit/Write,Rollback)",
+            LockModeType.READ, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshReadPessimisticRead() {
+        commonRefreshTest(
+            "testRefresh(Read,Commit/PessimisticRead,Commit)",
+            LockModeType.READ, Act.CommitTx, 2, null, // thread 2 tmo  
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null);
+        commonRefreshTest(
+            "testRefresh(Read,Commit/PessimisticRead,Rollback)",
+            LockModeType.READ, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_READ*/, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshReadPessimisticWrite() {
+        commonRefreshTest(
+            "testRefresh(Read,Commit/PessimisticWrite,Commit)",
+            LockModeType.READ, Act.CommitTx, 2, null, 
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null);
+        commonRefreshTest(
+            "testRefresh(Read,Commit/PessimisticWrite,Rollback)",
+            LockModeType.READ, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshReadPessimisticForceInc() {
+        commonRefreshTest(
+            "testRefresh(Read,Commit/PessimisticForceInc,Commit)",
+            LockModeType.READ, Act.CommitTx, 2, ExpectingOptimisticLockExClass, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null);
+        commonRefreshTest(
+            "testRefresh(Read,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.READ, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 2, null);
+    }
+    
+    /* ======== Thread 1 : Write Lock ============*/
+    public void testRefreshWriteRead() {
+        commonRefreshTest(
+            "testRefresh(Write,Commit/Read,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 2, null, 
+            LockModeType.READ, Act.CommitTx, 2, ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(Write,Commit/Read,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 2, null,
+            LockModeType.READ, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshWriteWrite() {
+        commonRefreshTest(
+            "testRefresh(Write,Commit/Write,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.CommitTx, 2,
+                ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(Write,Commit/Write,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshWritePessimisticRead() {
+        commonRefreshTest(
+            "testRefresh(Write,Commit/PessimisticRead,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 2, null, 
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null);
+        commonRefreshTest(
+            "testRefresh(Write,Commit/PessimisticRead,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_READ*/, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshWritePessimisticWrite() {
+        commonRefreshTest(
+            "testRefresh(Write,Commit/PessimisticWrite,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 2, null, 
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null);
+        commonRefreshTest(
+            "testRefresh(Write,Commit/PessimisticWrite,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshWritePessimisticForceInc() {
+        commonRefreshTest(
+            "testRefresh(Write,Commit/PessimisticForceInc,Commit)",
+            LockModeType.WRITE, Act.CommitTx, 2, ExpectingOptimisticLockExClass, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null);
+        commonRefreshTest(
+            "testRefresh(Write,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.WRITE, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 2, null);
+    }
+    
+    /* ======== Thread 1 : PessimisticRead Lock ============*/
+    public void testRefreshPessimisticReadRead() {
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/Read,Commit)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null, 
+            LockModeType.READ, Act.CommitTx, 2, ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/Read,Rollback)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null,
+            LockModeType.READ, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshPessimisticReadWrite() {
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/Write,Commit)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.CommitTx, 2, 
+                ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/Write,Rollback)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshPessimisticReadPessimisticRead() {
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/PessimisticRead,Commit)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null, 
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null);
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/PessimisticRead,Rollback)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_READ*/, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshPessimisticReadPessimisticWrite() {
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/PessimisticWrite,Commit)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null, 
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null); 
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/PessimisticWrite,Rollback)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshPessimisticReadPessimisticForceInc() {
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/PessimisticForceInc,Commit)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 3, null, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 3, null);
+        commonRefreshTest(
+            "testRefresh(PessimisticRead,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 2, null);
+    }
+    
+    /* ======== Thread 1 : Pessimsitic Write Lock ============*/
+    public void testRefreshPessimsiticWriteRead() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/Read,Commit)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null, 
+            LockModeType.READ, Act.CommitTx, 2, ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/Read,Rollback)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null,
+            LockModeType.READ, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshPessimsiticWriteWrite() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/Write,Commit)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.CommitTx, 2, 
+                ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/Write,Rollback)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshPessimsiticWritePessimisticRead() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/PessimisticRead,Commit)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null, 
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null); 
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/PessimisticRead,Rollback)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_READ*/, Act.RollbackTx, 2, null); 
+    }
+    
+    public void testRefreshPessimsiticWritePessimisticWrite() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/PessimisticWrite,Commit)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null, 
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null);
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/PessimisticWrite,Rollback)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.RollbackTx, 2, null); 
+    }
+    
+    public void testRefreshPessimsiticWritePessimisticForceInc() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/PessimisticForceInc,Commit)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 3, null, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 3, null); 
+        commonRefreshTest(
+            "testRefresh(PessimsiticWrite,Commit/PessimisticForceInc,Rollback)",
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 2, null);
+    }
+    
+    /* ======== Thread 1 : Pessimsitic Force Increment Lock ============*/
+    public void testRefreshPessimsiticForceIncRead() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/Read,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null, 
+            LockModeType.READ, Act.CommitTx, 0, ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/Read,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null,
+            LockModeType.READ, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshPessimsiticForceIncWrite() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/Write,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.CommitTx, 0,
+                ExpectingOptimisticLockExClass);
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/Write,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null,
+            LockModeType.WRITE, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshPessimsiticForceIncPessimisticRead() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/PessimisticRead,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null, 
+            LockModeType.PESSIMISTIC/*_READ*/, Act.CommitTx, 2, null); 
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/PessimisticRead,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_READ*/, Act.RollbackTx, 2, null); 
+    }
+    
+    public void testRefreshPessimsiticForceIncPessimisticWrite() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/PessimisticWrite,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null, 
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.CommitTx, 2, null); 
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/PessimisticWrite,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC/*_WRITE*/, Act.RollbackTx, 2, null);
+    }
+    
+    public void testRefreshPessimsiticForceIncPessimisticForceInc() {
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/" 
+                + "PessimisticForceInc,Commit)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 3, null, 
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 3, null);
+        commonRefreshTest(
+            "testRefresh(PessimsiticForceInc,Commit/"
+                + "PessimisticForceInc,Rollback)",
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.CommitTx, 2, null,
+            LockModeType.PESSIMISTIC_FORCE_INCREMENT, Act.RollbackTx, 2, null); 
+    }
+
+    private void commonRefreshTest( 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)};
+            
+        String t1Message1 = "Refresh in Thread 1";
+        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.NewThread, 1 },
+            {Act.NewThread, 2 },
+            
+            {Act.StartThread, 1 },
+            {Act.Wait},
+            
+            {Act.StartThread, 2 },            
+            {Act.WaitAllChildren},
+            
+            {Act.Find},
+            {Act.TestEmployee, 1},
+            {Act.TestException, 1, t1Exceptions },
+            {Act.TestException, 2, t2Exceptions },
+        };
+        Object[][] thread1 = {
+            {Act.CreateEm},
+            {Act.Find, 1},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.Notify, 0},
+            {Act.Wait},
+            
+            {Act.StartTx},
+            {Act.UpdateEmployee, 1, t1Message1},
+            {Act.TestEmployee, 1, t1Message1},
+            {Act.CommitTx},
+            {Act.TestException},
+            {Act.Notify, 2},
+            {Act.Wait},
+            
+            {Act.StartTx},
+            {Act.RefreshWithLock, 1, t1Lock },
+            {Act.TestLockMode, 1, t1Lock},
+            {Act.TestEmployee, 1, t1Message1},
+            {Act.UpdateEmployee, 1, t1Message2},
+            {Act.TestEmployee, 1, t1Message2},
+            
+            {t1IsCommit},
+            {Act.Notify, 2},
+            {Act.Notify, 2},
+            
+            {Act.Clear},
+            {Act.Find},
+            {Act.TestEmployee, 1, null, t1VersionInc}
+        };
+        Object[][] thread2 = {
+            {Act.CreateEm},
+            {Act.Find, 1},
+            {Act.SaveVersion},
+            {Act.TestEmployee, 1, Default_FirstName},
+            {Act.Notify, 1},
+            {Act.Wait},
+
+            {Act.StartTx},
+            {Act.UpdateEmployee, 1, t2Message1},
+            {Act.TestEmployee, 1, t2Message1},
+            {Act.RefreshWithLock, 1, t2Lock },
+            {Act.TestLockMode, 1, t2Lock},
+            {Act.TestEmployee, 1, t1Message1},
+            
+            {Act.Notify, 1},
+            {Act.Wait},
+            {t2IsCommit},
+            {Act.Wait},
+            
+            {Act.Clear},
+            {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/MixedLockManagerRefreshPermutationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native