jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r627461 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java test/java/org/apache/jackrabbit/core/CachingHierarchyManagerTest.java test/java/org/apache/jackrabbit/core/TestAll.java
Date Wed, 13 Feb 2008 15:19:17 GMT
Author: thomasm
Date: Wed Feb 13 07:19:13 2008
New Revision: 627461

URL: http://svn.apache.org/viewvc?rev=627461&view=rev
Log:
JCR-1380 CachingHierarchyManager synchronization problem

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?rev=627461&r1=627460&r2=627461&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Wed Feb 13 07:19:13 2008
@@ -193,7 +193,9 @@
         } else {
             LRUEntry entry = (LRUEntry) element.get();
             if (element.hasPath(path)) {
-                entry.touch();
+                synchronized (cacheMonitor) {
+                    entry.touch();
+                }
                 return entry.getId();
             }
             // first try to resolve node path, then property path
@@ -749,24 +751,26 @@
      * @param ps print stream to dump to
      */
     public void dump(final PrintStream ps) {
-        pathCache.traverse(new PathMap.ElementVisitor() {
-            public void elementVisited(PathMap.Element element) {
-                StringBuffer line = new StringBuffer();
-                for (int i = 0; i < element.getDepth(); i++) {
-                    line.append("--");
-                }
-                line.append(element.getName());
-                int index = element.getIndex();
-                if (index != 0 && index != 1) {
-                    line.append('[');
-                    line.append(index);
-                    line.append(']');
-                }
-                line.append("  ");
-                line.append(element.get());
-                ps.println(line.toString());
-            }
-        }, true);
+        synchronized (cacheMonitor) {
+            pathCache.traverse(new PathMap.ElementVisitor() {
+                public void elementVisited(PathMap.Element element) {
+                    StringBuffer line = new StringBuffer();
+                    for (int i = 0; i < element.getDepth(); i++) {
+                        line.append("--");
+                    }
+                    line.append(element.getName());
+                    int index = element.getIndex();
+                    if (index != 0 && index != 1) {
+                        line.append('[');
+                        line.append(index);
+                        line.append(']');
+                    }
+                    line.append("  ");
+                    line.append(element.get());
+                    ps.println(line.toString());
+                }
+            }, true);
+        }
     }
 
     /**

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/CachingHierarchyManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/CachingHierarchyManagerTest.java?rev=627461&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/CachingHierarchyManagerTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/CachingHierarchyManagerTest.java
Wed Feb 13 07:19:13 2008
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+import org.apache.jackrabbit.core.nodetype.NodeDefId;
+import org.apache.jackrabbit.core.state.ItemState;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.ItemStateManager;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.NodeReferences;
+import org.apache.jackrabbit.core.state.NodeReferencesId;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+import org.apache.jackrabbit.uuid.UUID;
+
+import junit.framework.TestCase;
+
+public class CachingHierarchyManagerTest extends TestCase {
+
+    volatile Exception exception;
+    volatile boolean stop;
+    CachingHierarchyManager cache;
+
+    public void testResolveNodePath() throws Exception {
+        NodeId rootNodeId = new NodeId(UUID.randomUUID());
+        ItemStateManager provider = new MyItemStateManager();
+        cache = new CachingHierarchyManager(rootNodeId, provider, null);
+        PathFactory factory = PathFactoryImpl.getInstance();
+        final Path path = factory.create("{}\t{}");
+        for(int i=0; i<3; i++) {
+            new Thread(new Runnable() {
+                public void run() {
+                    while(!stop) {
+                        try {
+                            cache.resolveNodePath(path);
+                        } catch(Exception e) {
+                            exception = e;
+                        }
+                    }
+                }
+            }).start();
+        }
+        Thread.sleep(1000);
+        stop = true;
+        if(exception != null) {
+            throw exception;
+        }
+    }
+
+    static class MyItemStateManager implements ItemStateManager {
+
+        public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException
{
+            Name name = NameFactoryImpl.getInstance().create("", "");
+            NodeState ns = new NodeState((NodeId)id, name, null, NodeState.STATUS_NEW, false);
+            ns.setDefinitionId(NodeDefId.valueOf("1"));
+            return ns;
+        }
+
+        public NodeReferences getNodeReferences(NodeReferencesId id) throws NoSuchItemStateException,
ItemStateException {
+            return null;
+        }
+
+        public boolean hasItemState(ItemId id) {
+            return false;
+        }
+
+        public boolean hasNodeReferences(NodeReferencesId id) {
+            return false;
+        }
+
+    };
+
+}

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

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java?rev=627461&r1=627460&r2=627461&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
Wed Feb 13 07:19:13 2008
@@ -32,6 +32,7 @@
     public static Test suite() {
         TestSuite suite = new TestSuite("Core tests");
 
+        suite.addTestSuite(CachingHierarchyManagerTest.class);
         suite.addTestSuite(NamespaceRegistryImplTest.class);
         suite.addTestSuite(TransientRepositoryTest.class);
         suite.addTestSuite(XATest.class);



Mime
View raw message