jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r790814 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/journal/ test/java/org/apache/jackrabbit/core/journal/
Date Fri, 03 Jul 2009 07:19:38 GMT
Author: mreutegg
Date: Fri Jul  3 07:19:37 2009
New Revision: 790814

URL: http://svn.apache.org/viewvc?rev=790814&view=rev
Log:
JCR-2182: LockableFileRevision not thread-safe

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/LockableFileRevisionTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/LockableFileRevision.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/LockableFileRevision.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/LockableFileRevision.java?rev=790814&r1=790813&r2=790814&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/LockableFileRevision.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/LockableFileRevision.java
Fri Jul  3 07:19:37 2009
@@ -77,7 +77,7 @@
      *
      * @param shared whether to allow other readers or not
      */
-    public void lock(boolean shared) throws JournalException {
+    public synchronized void lock(boolean shared) throws JournalException {
         if (lock == null) {
             try {
                 raf = new RandomAccessFile(file, shared ? "r" : "rw");
@@ -103,7 +103,7 @@
     /**
      * Unlock underlying file.
      */
-    public void unlock() {
+    public synchronized void unlock() {
         if (lock != null && --locks == 0) {
             try {
                 lock.release();

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/LockableFileRevisionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/LockableFileRevisionTest.java?rev=790814&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/LockableFileRevisionTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/LockableFileRevisionTest.java
Fri Jul  3 07:19:37 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.jackrabbit.core.journal;
+
+import java.io.File;
+
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.AbstractConcurrencyTest;
+
+/**
+ * <code>LockableFileRevisionTest</code> checks is concurrently locking and
+ * unlocking a LockableFileRevision works.
+ */
+public class LockableFileRevisionTest extends AbstractConcurrencyTest {
+
+    private LockableFileRevision rev;
+
+    private File tmp;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        tmp = File.createTempFile("test", "lock");
+        rev = new LockableFileRevision(tmp);
+    }
+
+    protected void tearDown() throws Exception {
+        tmp.delete();
+        super.tearDown();
+    }
+
+    public void testConcurrentLocking() throws Exception {
+        runTask(new Task() {
+            public void execute(Session session, Node test) throws
+                    RepositoryException {
+                for (int i = 0; i < 1000; i++) {
+                    try {
+                        rev.lock(true);
+                        rev.unlock();
+                    } catch (Exception e) {
+                        throw new RepositoryException(e);
+                    }
+                }
+            }
+        }, 50);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/LockableFileRevisionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/TestAll.java?rev=790814&r1=790813&r2=790814&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/TestAll.java
Fri Jul  3 07:19:37 2009
@@ -38,6 +38,7 @@
         TestSuite suite = new TestSuite();
 
         suite.addTestSuite(FileJournalTest.class);
+        suite.addTestSuite(LockableFileRevisionTest.class);
 
         return suite;
     }



Mime
View raw message