[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/lock ...
Galder Zamarreno
galder.zamarreno at jboss.com
Fri Jun 29 09:33:38 EDT 2007
User: gzamarreno
Date: 07/06/29 09:33:38
Modified: tests/functional/org/jboss/cache/lock Tag:
Branch_JBossCache_1_4_0 StripedLockTest.java
Log:
[JBCACHE-1103] Finished the backport from head.
Revision Changes Path
No revision
No revision
1.1.2.4 +42 -8 JBossCache/tests/functional/org/jboss/cache/lock/StripedLockTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: StripedLockTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/StripedLockTest.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -b -r1.1.2.3 -r1.1.2.4
--- StripedLockTest.java 24 Jun 2007 21:28:12 -0000 1.1.2.3
+++ StripedLockTest.java 29 Jun 2007 13:33:38 -0000 1.1.2.4
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.cache.lock;
import junit.framework.TestCase;
@@ -9,7 +30,8 @@
import java.util.List;
import java.util.Map;
import java.util.Random;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import EDU.oswego.cs.dl.util.concurrent.ReentrantWriterPreferenceReadWriteLock;
public class StripedLockTest extends TestCase
{
@@ -23,20 +45,14 @@
public void testHashingDistribution()
{
// ensure even bucket distribution of lock stripes
- // Commented for JDK 1.4 use.
- //List<Fqn> fqns = createRandomFqns(1000);
List fqns = createRandomFqns(1000);
- //Commented for JDK 1.4 use.
- //Map<ReentrantReadWriteLock, Integer> distribution = new HashMap<ReentrantReadWriteLock, Integer>();
Map distribution = new HashMap();
- //Commented for JDK 1.4 use.
- //for (Fqn f : fqns)
Iterator fqnsIterator = fqns.iterator();
while (fqnsIterator.hasNext())
{
- ReentrantReadWriteLock lock = stripedLock.getLock((Fqn) fqnsIterator.next());
+ ReentrantWriterPreferenceReadWriteLock lock = stripedLock.getLock((Fqn) fqnsIterator.next());
if (distribution.containsKey(lock))
{
int count = ((Integer) distribution.get(lock)).intValue() + 1;
@@ -58,6 +74,24 @@
assertTrue(distribution.size() * 1.5 >= stripedLock.sharedLocks.length);
}
+ public void testAcquireReleaseLocks()
+ {
+ Fqn f = Fqn.fromString("/a/b/c");
+
+ /* acquire RL*/
+ stripedLock.acquireLock(f, false);
+ /* release RL*/
+ stripedLock.releaseLock(f);
+ /* acquire WL */
+ stripedLock.acquireLock(f, true);
+ /* reacquire RL without giving up lock */
+ stripedLock.acquireLock(f, false);
+ /* release RL */
+ stripedLock.releaseLock(f);
+ /* release WL */
+ stripedLock.releaseLock(f);
+ }
+
private List createRandomFqns(int number)
{
List f = new ArrayList(number);
More information about the jboss-cvs-commits
mailing list