openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r834252 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
Date Mon, 09 Nov 2009 22:02:15 GMT
Author: curtisr7
Date: Mon Nov  9 22:02:15 2009
New Revision: 834252

URL: http://svn.apache.org/viewvc?rev=834252&view=rev
Log:
OPENJPA-1379: Fixed locking problem in AbstractQueryCache when using timestamp eviction policy
and added new test case.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java?rev=834252&r1=834251&r2=834252&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
Mon Nov  9 22:02:15 2009
@@ -94,9 +94,9 @@
     }
 
     public void onTypesChanged(TypesChangedEvent ev) {
-        writeLock();
-        Collection keys = null;
         if (evictPolicy == EvictPolicy.DEFAULT) {
+            writeLock();
+            Collection keys = null;
             try {
                 if (hasListeners())
                     fireEvent(ev);

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java?rev=834252&r1=834251&r2=834252&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
Mon Nov  9 22:02:15 2009
@@ -18,7 +18,11 @@
  */
 package org.apache.openjpa.persistence.jdbc.query.cache;
 
+import java.util.Collections;
+
 import org.apache.openjpa.datacache.ConcurrentQueryCache;
+import org.apache.openjpa.datacache.QueryCache;
+import org.apache.openjpa.datacache.TypesChangedEvent;
 import org.apache.openjpa.datacache.AbstractQueryCache.EvictPolicy;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 
@@ -58,5 +62,31 @@
 
         this.recreateData = false;
     }
+
+    /**
+     * This testcase was added for OPENJPA-1379. Prior to this fix, the main thread holds
a lock on
+     * the QueryCache which it never released. As a result, thread t2 will never successfully
obtain
+     * the writeLock().
+     * 
+     * The main thread holds the writeLock because setUp(..) calls deleteAllData() which
eventually
+     * results in AbstractQueryCache.onTypesChanges(TypesChangedEvent) being called.
+     * 
+     * @throws Exception
+     */
+    public void testWriteLock() throws Exception {
+        final QueryCache qc = emf.getConfiguration().getDataCacheManagerInstance().getSystemQueryCache();
+        Thread t2 = new Thread() {
+            public void run() {
+                qc.writeLock();
+                qc.writeUnlock();
+            }
+        };
+        t2.start();
+        t2.join(5000);
+        
+        if (t2.getState().equals(java.lang.Thread.State.WAITING)) {
+            fail("The thread is still waiting on a writeLock()!");
+        }
+    }
 }
 



Mime
View raw message