You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by oz...@apache.org on 2005/01/29 12:26:13 UTC
svn commit: r149027 - in jakarta/commons/proper/transaction/trunk: . src/java/org/apache/commons/transaction/locking src/test/org/apache/commons/transaction/locking
Author: ozeigermann
Date: Sat Jan 29 03:26:11 2005
New Revision: 149027
URL: http://svn.apache.org/viewcvs?view=rev&rev=149027
Log:
- Extensions for better information retrieval on lock levels and releases
- More lock tests by Armin Waibel
- Fix for GenericLock that releases all locks of a certain user when testing
if a lock level was available
Added:
jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/locking/LockTestRepeatableReads.java
Modified:
jakarta/commons/proper/transaction/trunk/RELEASE-NOTES.txt
jakarta/commons/proper/transaction/trunk/project.xml
jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLock.java
jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLockManager.java
jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/LockManager2.java
jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock.java
jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock2.java
jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java
Modified: jakarta/commons/proper/transaction/trunk/RELEASE-NOTES.txt
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/transaction/trunk/RELEASE-NOTES.txt?view=diff&rev=149027&p1=jakarta/commons/proper/transaction/trunk/RELEASE-NOTES.txt&r1=149026&p2=jakarta/commons/proper/transaction/trunk/RELEASE-NOTES.txt&r2=149027
==============================================================================
--- jakarta/commons/proper/transaction/trunk/RELEASE-NOTES.txt (original)
+++ jakarta/commons/proper/transaction/trunk/RELEASE-NOTES.txt Sat Jan 29 03:26:11 2005
@@ -57,10 +57,18 @@
-----------------------------------------
- PessimisticMapWrapper now throws the more general LockException from locking package
+- Both MultiLevelLock#release and LockManager2#release now return a boolean that indicates if the lock
+ really has been released
BUGFIXES FROM 1.0 beta1
-----------------------
- Fixed deadlock hazard in deadlock detection caused by interleaving access to locks set of an owner
+- Fixed timeout that in certain scenarios did not work
+- GenericLock test method released all locks held by the testing owner - fixed
+
+ENHANCEMENTS FROM 1.0 beta1
+-----------------------
+- Many extensions for information about locks
KNOWN ISSUES
------------
Modified: jakarta/commons/proper/transaction/trunk/project.xml
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/transaction/trunk/project.xml?view=diff&rev=149027&p1=jakarta/commons/proper/transaction/trunk/project.xml&r1=149026&p2=jakarta/commons/proper/transaction/trunk/project.xml&r2=149027
==============================================================================
--- jakarta/commons/proper/transaction/trunk/project.xml (original)
+++ jakarta/commons/proper/transaction/trunk/project.xml Sat Jan 29 03:26:11 2005
@@ -102,6 +102,12 @@
<contributor>
<name>Antranig Basman</name>
</contributor>
+ <contributor>
+ <name>Armin Waibel</name>
+ <id>arminw</id>
+ <email>arminw@apache.org</email>
+ <timezone>+1</timezone>
+ </contributor>
</contributors>
Modified: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLock.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLock.java?view=diff&rev=149027&p1=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLock.java&r1=149026&p2=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLock.java&r2=149027
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLock.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLock.java Sat Jan 29 03:26:11 2005
@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/java/org/apache/commons/transaction/locking/GenericLock.java,v 1.14 2005/01/13 23:12:44 ozeigermann Exp $
* $Revision: 1.14 $
- * $Date: 2005/01/13 23:12:44 $
+ * $Date$
*
* ====================================================================
*
@@ -171,16 +171,19 @@
* @see MultiLevelLock2#test(Object, int, int)
*/
public boolean test(Object ownerId, int targetLockLevel, int compatibility) {
- boolean success = false;
- try {
- success = tryLock(ownerId, targetLockLevel, compatibility, false);
- } finally {
- release(ownerId);
- }
+ boolean success = tryLock(ownerId, targetLockLevel, compatibility, false, true);
return success;
}
/**
+ * @see MultiLevelLock2#has(Object, int)
+ */
+ public boolean has(Object ownerId, int lockLevel) {
+ int level = getLockLevel(ownerId);
+ return (lockLevel <= level);
+ }
+
+ /**
* @see org.apache.commons.transaction.locking.MultiLevelLock#acquire(java.lang.Object,
* int, boolean, boolean, long)
*/
@@ -342,7 +345,7 @@
/**
* @see org.apache.commons.transaction.locking.MultiLevelLock#release(Object)
*/
- public synchronized void release(Object ownerId) {
+ public synchronized boolean release(Object ownerId) {
if (owners.remove(ownerId) != null) {
if (logger.isFinerEnabled()) {
logger.logFiner(
@@ -353,7 +356,9 @@
+ System.currentTimeMillis());
}
notifyAll();
+ return true;
}
+ return false;
}
/**
@@ -479,8 +484,13 @@
owners.put(ownerId, new LockOwner(ownerId, targetLockLevel, compatibility, intention));
}
- protected synchronized boolean tryLock(Object ownerId, int targetLockLevel, int compatibility,
+ protected boolean tryLock(Object ownerId, int targetLockLevel, int compatibility,
boolean preferred) {
+ return tryLock(ownerId, targetLockLevel, compatibility, preferred, false);
+ }
+
+ protected synchronized boolean tryLock(Object ownerId, int targetLockLevel, int compatibility,
+ boolean preferred, boolean tryOnly) {
LockOwner myLock = (LockOwner) owners.get(ownerId);
@@ -522,8 +532,10 @@
// we are only allowed to acquire our locks if we do not compromise locks of any other lock owner
if (isCompatible(targetLockLevel, currentLockLevel)) {
- // if we really have the lock, it no longer is an intention
- setLockLevel(ownerId, myLock, targetLockLevel, compatibility, false);
+ if (!tryOnly) {
+ // if we really have the lock, it no longer is an intention
+ setLockLevel(ownerId, myLock, targetLockLevel, compatibility, false);
+ }
return true;
} else {
return false;
Modified: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLockManager.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLockManager.java?view=diff&rev=149027&p1=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLockManager.java&r1=149026&p2=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLockManager.java&r2=149027
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLockManager.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/GenericLockManager.java Sat Jan 29 03:26:11 2005
@@ -134,6 +134,33 @@
}
/**
+ * @see LockManager2#checkLock(Object, Object, int, boolean)
+ * @since 1.1
+ */
+ public boolean checkLock(Object ownerId, Object resourceId, int targetLockLevel, boolean reentrant) {
+ timeoutCheck(ownerId);
+
+ GenericLock lock = (GenericLock) atomicGetOrCreateLock(resourceId);
+ boolean possible = lock.test(ownerId, targetLockLevel,
+ reentrant ? GenericLock.COMPATIBILITY_REENTRANT : GenericLock.COMPATIBILITY_NONE);
+
+ return possible;
+ }
+
+ /**
+ * @see LockManager2#hasLock(Object, Object, int)
+ * @since 1.1
+ */
+ public boolean hasLock(Object ownerId, Object resourceId, int lockLevel) {
+ timeoutCheck(ownerId);
+
+ GenericLock lock = (GenericLock) atomicGetOrCreateLock(resourceId);
+ boolean owned = lock.has(ownerId, lockLevel);
+
+ return owned;
+ }
+
+ /**
* @see LockManager2#lock(Object, Object, int, boolean)
* @since 1.1
*/
@@ -261,11 +288,12 @@
* @see LockManager2#release(Object, Object)
* @since 1.1
*/
- public void release(Object ownerId, Object resourceId) {
+ public boolean release(Object ownerId, Object resourceId) {
timeoutCheck(ownerId);
GenericLock lock = (GenericLock) atomicGetOrCreateLock(resourceId);
- lock.release(ownerId);
+ boolean released = lock.release(ownerId);
removeOwner(ownerId, lock);
+ return released;
}
/**
Modified: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/LockManager2.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/LockManager2.java?view=diff&rev=149027&p1=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/LockManager2.java&r1=149026&p2=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/LockManager2.java&r2=149027
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/LockManager2.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/LockManager2.java Sat Jan 29 03:26:11 2005
@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/java/org/apache/commons/transaction/locking/LockManager2.java,v 1.5 2005/01/10 00:04:27 ozeigermann Exp $
* $Revision: 1.5 $
- * $Date: 2005/01/10 00:04:27 $
+ * $Date$
*
* ====================================================================
*
@@ -40,6 +40,41 @@
public interface LockManager2 {
/**
+ * Determines if a lock is owner by an owner. <br>
+ *
+ * @param ownerId
+ * a unique id identifying the entity that wants to check this
+ * lock
+ * @param resourceId
+ * the resource to get the level for
+ * @param lockLevel
+ * the lock level to check
+ * @return <code>true</code> if the owner has the lock, <code>false</code> otherwise
+ *
+ */
+ public boolean hasLock(Object ownerId, Object resourceId, int lockLevel);
+
+ /**
+ * Determines if a lock <em>could</em> be acquire <em>without</em> actually acquiring it. <br>
+ * <br>
+ * This method does not block, but immediatly returns.
+ *
+ * @param ownerId
+ * a unique id identifying the entity that wants to check this
+ * lock
+ * @param resourceId
+ * the resource to get the level for
+ * @param targetLockLevel
+ * the lock level to check
+ * @param reentrant
+ * <code>true</code> if this request shall not be influenced by
+ * other locks held by the same owner
+ * @return <code>true</code> if the lock could be acquired, <code>false</code> otherwise
+ *
+ */
+ public boolean checkLock(Object ownerId, Object resourceId, int targetLockLevel, boolean reentrant);
+
+ /**
* Tries to acquire a lock on a resource. <br>
* <br>
* This method does not block, but immediatly returns. If a lock is not
@@ -53,7 +88,7 @@
* @param targetLockLevel
* the lock level to acquire
* @param reentrant
- * <code>true</code> if this request shall not be blocked by
+ * <code>true</code> if this request shall not be influenced by
* other locks held by the same owner
* @return <code>true</code> if the lock has been acquired, <code>false</code> otherwise
*
@@ -170,8 +205,10 @@
*
* @param ownerId the id of the owner of the lock
* @param resourceId the resource to releases the lock for
+ * @return <code>true</code> if the lock actually was released, <code>false</code> in case
+ * there was no lock held by the owner
*/
- public void release(Object ownerId, Object resourceId);
+ public boolean release(Object ownerId, Object resourceId);
/**
* Releases all locks (partially) held by an owner.
Modified: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock.java?view=diff&rev=149027&p1=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock.java&r1=149026&p2=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock.java&r2=149027
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock.java Sat Jan 29 03:26:11 2005
@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/java/org/apache/commons/transaction/locking/MultiLevelLock.java,v 1.1 2004/11/18 23:27:17 ozeigermann Exp $
* $Revision: 1.1 $
- * $Date: 2004/11/18 23:27:17 $
+ * $Date$
*
* ====================================================================
*
@@ -51,8 +51,10 @@
* Releases any lock levels the specified owner may hold on this lock.
*
* @param ownerId a unique id identifying the entity that wants to release all lock levels
+ * @return <code>true</code> if the lock actually was released, <code>false</code> in case
+ * there was no lock held by the owner
*/
- public void release(Object ownerId);
+ public boolean release(Object ownerId);
/**
* Retuns the highest lock level the specified owner holds on this lock or <code>0</code> if it holds no locks at all.
Modified: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock2.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock2.java?view=diff&rev=149027&p1=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock2.java&r1=149026&p2=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock2.java&r2=149027
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock2.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/MultiLevelLock2.java Sat Jan 29 03:26:11 2005
@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/java/org/apache/commons/transaction/locking/MultiLevelLock2.java,v 1.3 2005/01/09 23:56:07 ozeigermann Exp $
* $Revision: 1.3 $
- * $Date: 2005/01/09 23:56:07 $
+ * $Date$
*
* ====================================================================
*
@@ -63,11 +63,24 @@
public static final int COMPATIBILITY_REENTRANT_AND_SUPPORT = 3;
/**
+ * Tests if a certain lock level is owned by an owner.
+ *
+ * @param ownerId
+ * a unique id identifying the entity that wants to check a
+ * certain lock level on this lock
+ * @param lockLevel
+ * the lock level to test
+ * @return <code>true</code> if the lock could be acquired at the time
+ * this method was called
+ */
+ public boolean has(Object ownerId, int lockLevel);
+
+ /**
* Tests if a certain lock level <em>could</em> be acquired. This method
* tests only and does <em>not actually acquire</em> the lock.
*
* @param ownerId
- * a unique id identifying the entity that wants to acquire a
+ * a unique id identifying the entity that wants to test a
* certain lock level on this lock
* @param targetLockLevel
* the lock level to acquire
Modified: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java?view=diff&rev=149027&p1=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java&r1=149026&p2=jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java&r2=149027
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java Sat Jan 29 03:26:11 2005
@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java,v 1.4 2005/01/09 15:12:11 ozeigermann Exp $
* $Revision: 1.4 $
- * $Date: 2005/01/09 15:12:11 $
+ * $Date$
*
* ====================================================================
*
@@ -80,6 +80,72 @@
*/
public boolean tryWriteLock(Object ownerId, Object resourceId) {
return tryLock(ownerId, resourceId, ReadWriteLock.WRITE_LOCK, true);
+ }
+
+ /**
+ * Determines if a shared, reentrant read lock on a resource
+ * <em>could</em> be acquired without actually acquiring it. <br>
+ * <br>
+ * This method does not block, but immediatly returns. If a lock is not
+ * available <code>false</code> will be returned.
+ *
+ * @param ownerId
+ * a unique id identifying the entity that wants to acquire this
+ * lock
+ * @param resourceId
+ * the resource to get the lock for
+ * @return <code>true</code> if the lock could be acquired, <code>false</code> otherwise
+ */
+ public boolean checkReadLock(Object ownerId, Object resourceId) {
+ return checkLock(ownerId, resourceId, ReadWriteLock.READ_LOCK, true);
+ }
+
+ /**
+ * Determines if an exclusive, reentrant write lock on a resource
+ * is held by an owner. <br>
+ *
+ * @param ownerId
+ * a unique id identifying the entity that wants to check this
+ * lock
+ * @param resourceId
+ * the resource to get the lock for
+ * @return <code>true</code> if the lock is held by the owner, <code>false</code> otherwise
+ */
+ public boolean hasWriteLock(Object ownerId, Object resourceId) {
+ return hasLock(ownerId, resourceId, ReadWriteLock.WRITE_LOCK);
+ }
+
+ /**
+ * Determines if a shared, reentrant read lock on a resource
+ * is held by an owner. <br>
+ *
+ * @param ownerId
+ * a unique id identifying the entity that wants to check this
+ * lock
+ * @param resourceId
+ * the resource to get the lock for
+ * @return <code>true</code> if the lock is held by the owner, <code>false</code> otherwise
+ */
+ public boolean hasReadLock(Object ownerId, Object resourceId) {
+ return hasLock(ownerId, resourceId, ReadWriteLock.READ_LOCK);
+ }
+
+ /**
+ * Determines if an exclusive, reentrant write lock on a resource
+ * <em>could</em> be acquired without actually acquiring it. <br>
+ * <br>
+ * This method does not block, but immediatly returns. If a lock is not
+ * available <code>false</code> will be returned.
+ *
+ * @param ownerId
+ * a unique id identifying the entity that wants to acquire this
+ * lock
+ * @param resourceId
+ * the resource to get the lock for
+ * @return <code>true</code> if the lock could be acquired, <code>false</code> otherwise
+ */
+ public boolean checkWriteLock(Object ownerId, Object resourceId) {
+ return checkLock(ownerId, resourceId, ReadWriteLock.WRITE_LOCK, true);
}
/**
Added: jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/locking/LockTestRepeatableReads.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/locking/LockTestRepeatableReads.java?view=auto&rev=149027
==============================================================================
--- (empty file)
+++ jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/locking/LockTestRepeatableReads.java Sat Jan 29 03:26:11 2005
@@ -0,0 +1,276 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/test/org/apache/commons/transaction/locking/GenericLockTest.java,v 1.12 2005/01/13 16:44:03 ozeigermann Exp $
+ * $Revision: 1.12 $
+ * $Date: 2005-01-29 07:43:19 +0100 (Sa, 29 Jan 2005) $
+ *
+ * ====================================================================
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.commons.transaction.locking;
+
+import java.io.PrintWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.transaction.util.LoggerFacade;
+import org.apache.commons.transaction.util.PrintWriterLogger;
+
+/**
+ * Tests for repeatable read in locks as investigated for OJB.
+ *
+ * @version $Revision: 1.12 $
+ * @author Armin Waibel
+ */
+public class LockTestRepeatableReads extends TestCase
+{
+ private static final LoggerFacade logFacade = new PrintWriterLogger(new PrintWriter(System.out),
+ LockTestRepeatableReads.class.getName(), false);
+
+ protected static final long TIMEOUT = 1000000;
+
+ public static void main(String[] args)
+ {
+ String[] arr = {LockTestRepeatableReads.class.getName()};
+ junit.textui.TestRunner.main(arr);
+ }
+
+ public LockTestRepeatableReads(String name)
+ {
+ super(name);
+ }
+
+ Object tx1;
+ Object tx2;
+ Object obj;
+ ReadWriteUpgradeLockManager lockManager;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ lockManager = new ReadWriteUpgradeLockManager(logFacade, TIMEOUT);
+
+ // initialize the dummies
+ tx2 = new Object();
+ tx1 = new Object();
+ obj = new Object();
+ }
+
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ lockManager.release(tx1, obj);
+ lockManager.release(tx2, obj);
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ /**
+ * Test 19
+ */
+ public void testWriteReleaseCheckRead()
+ {
+ assertTrue(lockManager.tryWriteLock(tx2, obj));
+ assertTrue(lockManager.checkReadLock(tx2, obj));
+ assertTrue(lockManager.release(tx2, obj));
+ assertFalse(lockManager.hasReadLock(tx2, obj));
+ }
+
+ /**
+ * Test 20
+ */
+ public void testReadWriteReleaseCheckRead()
+ {
+ assertTrue(lockManager.tryReadLock(tx2, obj));
+ assertTrue(lockManager.tryWriteLock(tx2, obj));
+ assertTrue(lockManager.checkReadLock(tx2, obj));
+ assertTrue(lockManager.release(tx2, obj));
+ assertFalse(lockManager.hasReadLock(tx2, obj));
+ }
+
+ /**
+ * Test 1
+ */
+ public void testSingleReadLock()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ }
+
+ /**
+ * Test 2
+ */
+ public void testUpgradeReadLock()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.tryUpgradeLock(tx1, obj));
+ }
+
+ /**
+ * Test3
+ */
+ public void testReadThenWrite()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.tryWriteLock(tx1, obj));
+ }
+
+ /**
+ * Test 4
+ */
+ public void testSingleWriteLock()
+ {
+ assertTrue(lockManager.tryWriteLock(tx1, obj));
+ }
+
+ /**
+ * Test 5
+ */
+ public void testWriteThenRead()
+ {
+ assertTrue(lockManager.tryWriteLock(tx1, obj));
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ }
+
+ /**
+ * Test 6
+ */
+ public void testMultipleReadLock()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.tryReadLock(tx2, obj));
+ }
+
+ /**
+ * Test 7
+ */
+ public void testUpgradeWithExistingReader()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.tryUpgradeLock(tx2, obj));
+ }
+
+ /**
+ * Test 8
+ */
+ public void testWriteWithExistingReader()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertFalse(lockManager.tryWriteLock(tx2, obj));
+ }
+
+ /**
+ * Test 9
+ */
+ public void testUpgradeWithMultipleReaders()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.tryReadLock(tx2, obj));
+ assertTrue(lockManager.tryUpgradeLock(tx2, obj));
+ }
+
+ /**
+ * Test 10
+ */
+ public void testWriteWithMultipleReaders()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.tryReadLock(tx2, obj));
+ assertTrue(!lockManager.tryWriteLock(tx2, obj));
+ }
+
+ /**
+ * Test 11
+ */
+ public void testUpgradeWithMultipleReadersOn1()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.tryReadLock(tx2, obj));
+ assertTrue(lockManager.tryUpgradeLock(tx1, obj));
+ }
+
+ /**
+ * Test 12
+ */
+ public void testWriteWithMultipleReadersOn1()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.tryReadLock(tx2, obj));
+ assertFalse(lockManager.tryWriteLock(tx1, obj));
+ }
+
+ /**
+ * Test 13
+ */
+ public void testReadWithExistingWriter()
+ {
+ assertTrue(lockManager.tryWriteLock(tx1, obj));
+ assertFalse(lockManager.tryReadLock(tx2, obj));
+ }
+
+ /**
+ * Test 14
+ */
+ public void testMultipleWriteLock()
+ {
+ assertTrue(lockManager.tryWriteLock(tx1, obj));
+ assertFalse(lockManager.tryWriteLock(tx2, obj));
+ }
+
+ /**
+ * Test 15
+ */
+ public void testReleaseReadLock()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.release(tx1, obj));
+ assertTrue(lockManager.tryWriteLock(tx2, obj));
+ }
+
+ /**
+ * Test 16
+ */
+ public void testReleaseUpgradeLock()
+ {
+ assertTrue(lockManager.tryUpgradeLock(tx1, obj));
+ assertTrue(lockManager.release(tx1, obj));
+ assertTrue(lockManager.tryWriteLock(tx2, obj));
+ }
+
+ /**
+ * Test 17
+ */
+ public void testReleaseWriteLock()
+ {
+ assertTrue(lockManager.tryWriteLock(tx1, obj));
+ assertTrue(lockManager.release(tx1, obj));
+ assertTrue(lockManager.tryWriteLock(tx2, obj));
+ }
+
+ /**
+ * Test 18
+ */
+ public void testReadThenRead()
+ {
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ assertTrue(lockManager.tryReadLock(tx1, obj));
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org